annot_collector.cpp
来自「ncbi源码」· C++ 代码 · 共 1,431 行 · 第 1/4 页
CPP
1,431 行
_ASSERT(m_MappingCollector->m_LimitObjectInfo); return info == m_MappingCollector->m_LimitObjectInfo.GetPointer(); } return true;}inlinebool CAnnot_Collector::x_NeedSNPs(void) const{ if ( m_Selector.GetAnnotType() != CSeq_annot::C_Data::e_not_set ) { if ( m_Selector.GetAnnotType() != CSeq_annot::C_Data::e_Ftable ) { return false; } if ( !m_Selector.IncludedFeatSubtype( CSeqFeatData::eSubtype_variation) ) { return false; } else if ( !m_Selector.IncludedFeatType(CSeqFeatData::e_Imp) ) { return false; } } return true;}inlinebool CAnnot_Collector::x_MatchLocIndex(const SAnnotObject_Index& index) const{ return index.m_AnnotObject_Info->IsAlign() || m_Selector.m_FeatProduct == (index.m_AnnotLocationIndex == 1);}inlinebool CAnnot_Collector::x_MatchRange(const CHandleRange& hr, const CRange<TSeqPos>& range, const SAnnotObject_Index& index) const{ if ( m_Selector.m_OverlapType == SAnnotSelector::eOverlap_Intervals ) { if ( index.m_HandleRange ) { if ( !hr.IntersectingWith(*index.m_HandleRange) ) { return false; } } else { if ( !hr.IntersectingWith(range) ) { return false; } } } if ( !x_MatchLocIndex(index) ) { return false; } return true;}void CAnnot_Collector::x_GetTSE_Info(void){ // only one TSE is needed _ASSERT(m_TSE_LockSet.empty()); _ASSERT(m_Selector.m_LimitObjectType != SAnnotSelector::eLimit_None); _ASSERT(m_Selector.m_LimitObject); TTSE_Lock tse_info; switch ( m_Selector.m_LimitObjectType ) { case SAnnotSelector::eLimit_TSE: { const CSeq_entry* object = CTypeConverter<CSeq_entry>:: SafeCast(m_Selector.m_LimitObject.GetPointer()); CSeq_entry_Handle handle = m_Scope->GetSeq_entryHandle(*object); if ( !handle ) { NCBI_THROW(CAnnotException, eLimitError, "CAnnot_Collector::x_GetTSE_Info: " "unknown top level Seq-entry"); } const CTSE_Info& info = handle.x_GetInfo().GetTSE_Info(); tse_info.Reset(&info); // normalize TSE -> TSE_Info m_Selector.m_LimitObjectType = SAnnotSelector::eLimit_TSE_Info; m_Selector.m_LimitObject.Reset(&info); m_MappingCollector->m_LimitObjectInfo.Reset(&info); break; } case SAnnotSelector::eLimit_Seq_entry: { const CSeq_entry* object = CTypeConverter<CSeq_entry>:: SafeCast(m_Selector.m_LimitObject.GetPointer()); CSeq_entry_Handle handle = m_Scope->GetSeq_entryHandle(*object); if ( !handle ) { NCBI_THROW(CAnnotException, eLimitError, "CAnnot_Collector::x_GetTSE_Info: " "unknown Seq-entry"); } const CSeq_entry_Info& info = handle.x_GetInfo(); tse_info.Reset(&info.GetTSE_Info()); // normalize Seq_entry -> Seq_entry_Info m_Selector.m_LimitObjectType = SAnnotSelector::eLimit_Seq_entry_Info; m_Selector.m_LimitObject.Reset(&info); m_MappingCollector->m_LimitObjectInfo.Reset(&info); break; } case SAnnotSelector::eLimit_Seq_annot: { const CSeq_annot* object = CTypeConverter<CSeq_annot>:: SafeCast(m_Selector.m_LimitObject.GetPointer()); CSeq_annot_Handle handle = m_Scope->GetSeq_annotHandle(*object); if ( !handle ) { NCBI_THROW(CAnnotException, eLimitError, "CAnnot_Collector::x_GetTSE_Info: " "unknown Seq-annot"); } const CSeq_annot_Info& info = handle.x_GetInfo(); tse_info.Reset(&info.GetTSE_Info()); // normalize Seq_annot -> Seq_annot_Info m_Selector.m_LimitObjectType = SAnnotSelector::eLimit_Seq_annot_Info; m_Selector.m_LimitObject.Reset(&info); m_MappingCollector->m_LimitObjectInfo.Reset(&info); break; } case SAnnotSelector::eLimit_TSE_Info: { const CTSE_Info* info = CTypeConverter<CTSE_Info>:: SafeCast(m_Selector.m_LimitObject.GetPointer()); tse_info.Reset(info); m_MappingCollector->m_LimitObjectInfo.Reset(info); break; } case SAnnotSelector::eLimit_Seq_entry_Info: { const CSeq_entry_Info* info = CTypeConverter<CSeq_entry_Info>:: SafeCast(m_Selector.m_LimitObject.GetPointer()); tse_info.Reset(&info->GetTSE_Info()); m_MappingCollector->m_LimitObjectInfo.Reset(info); break; } case SAnnotSelector::eLimit_Seq_annot_Info: { const CSeq_annot_Info* info = CTypeConverter<CSeq_annot_Info>:: SafeCast(m_Selector.m_LimitObject.GetPointer()); tse_info.Reset(&info->GetTSE_Info()); m_MappingCollector->m_LimitObjectInfo.Reset(info); break; } default: // no limit object -> do nothing break; } _ASSERT(m_MappingCollector->m_LimitObjectInfo); _ASSERT(tse_info); tse_info->UpdateAnnotIndex(); //if ( !IsSetAnnotsNames() || x_MatchAnnotName(*tse_info) ) { m_TSE_LockSet.insert(tse_info); //}}bool CAnnot_Collector::x_Search(const CSeq_id_Handle& id, const CBioseq_Handle& bh, const CHandleRange& hr, CSeq_loc_Conversion* cvt){ if ( cvt ) cvt->SetSrcId(id); bool found = false; if ( m_Selector.m_LimitObjectType == SAnnotSelector::eLimit_None ) { // any data source CConstRef<CScope_Impl::TAnnotRefSet> tse_set; if ( bh ) { tse_set = m_Scope->GetTSESetWithAnnots(bh); } else { tse_set = m_Scope->GetTSESetWithAnnots(id); } if ( tse_set ) { found = x_Search(*tse_set, id, hr, cvt) || found; } } else { found = x_Search(m_TSE_LockSet, id, hr, cvt) || found; } return found;}static CSeqFeatData::ESubtype s_DefaultAdaptiveTriggers[] = { CSeqFeatData::eSubtype_gene, CSeqFeatData::eSubtype_cdregion, CSeqFeatData::eSubtype_mRNA};bool CAnnot_Collector::x_Search(const TTSE_LockSet& tse_set, const CSeq_id_Handle& id, const CHandleRange& hr, CSeq_loc_Conversion* cvt){ bool found = false; ITERATE ( TTSE_LockSet, tse_it, tse_set ) { const CTSE_Info& tse = **tse_it; CTSE_Info::TAnnotReadLockGuard guard(tse.m_AnnotObjsLock); // Skip excluded TSEs //if ( ExcludedTSE(tse) ) { //continue; //} if ( m_Selector.m_AdaptiveDepth && tse.ContainsSeqid(id) ) { const SIdAnnotObjs* objs = tse.x_GetUnnamedIdObjects(id); if ( objs ) { vector<char> indexes; if ( m_Selector.m_AdaptiveTriggers.empty() ) { const size_t count = sizeof(s_DefaultAdaptiveTriggers)/ sizeof(s_DefaultAdaptiveTriggers[0]); for ( int i = count - 1; i >= 0; --i ) { CSeqFeatData::ESubtype subtype = s_DefaultAdaptiveTriggers[i]; size_t index = CAnnotType_Index::GetSubtypeIndex(subtype); if ( index ) { indexes.resize(max(indexes.size(), index + 1)); indexes[index] = 1; } } } else { ITERATE ( SAnnotSelector::TAdaptiveTriggers, it, m_Selector.m_AdaptiveTriggers ) { pair<size_t, size_t> idxs = CAnnotType_Index::GetIndexRange(*it); indexes.resize(max(indexes.size(), idxs.second)); for ( size_t i = idxs.first; i < idxs.second; ++i ) { indexes[i] = 1; } } } for ( size_t index = 0; index < indexes.size(); ++index ) { if ( !indexes[index] ) { continue; } if ( index >= objs->m_AnnotSet.size() ) { break; } if ( !objs->m_AnnotSet[index].empty() ) { found = true; break; } } } } if ( !m_Selector.m_IncludeAnnotsNames.empty() ) { // only 'included' annots ITERATE ( SAnnotSelector::TAnnotsNames, iter, m_Selector.m_IncludeAnnotsNames ) { _ASSERT(!m_Selector.ExcludedAnnotName(*iter)); // consistency check const SIdAnnotObjs* objs = tse.x_GetIdObjects(*iter, id); if ( objs ) { x_Search(tse, objs, guard, *iter, id, hr, cvt); } } } else { // all annots, skipping 'excluded' ITERATE (CTSE_Info::TNamedAnnotObjs, iter, tse.m_NamedAnnotObjs) { if ( m_Selector.ExcludedAnnotName(iter->first) ) { continue; } const SIdAnnotObjs* objs = tse.x_GetIdObjects(iter->second, id); if ( objs ) { x_Search(tse, objs, guard, iter->first, id, hr, cvt); } } } } return found;}bool CAnnot_Collector::x_AddObjectMapping(CAnnotObject_Ref& object_ref, CSeq_loc_Conversion* cvt, unsigned int loc_index){ _ASSERT(object_ref.GetAnnotObject_Info().GetMultiIdFlags() || cvt->IsPartial() || object_ref.IsAlign() ); object_ref.ResetLocation(); CRef<CSeq_loc_Conversion_Set>& mapping_set = m_MappingCollector->m_AnnotMappingSet[object_ref]; if ( !mapping_set ) { mapping_set.Reset(new CSeq_loc_Conversion_Set(m_Scope)); } CRef<CSeq_loc_Conversion> cvt_copy(new CSeq_loc_Conversion(*cvt)); mapping_set->Add(*cvt_copy, loc_index); return x_GetAnnotCount() >= m_Selector.m_MaxSize;}inlinebool CAnnot_Collector::x_AddObject(CAnnotObject_Ref& object_ref){ m_AnnotSet.push_back(object_ref); return x_GetAnnotCount() >= m_Selector.m_MaxSize;}inlinebool CAnnot_Collector::x_AddObject(CAnnotObject_Ref& object_ref, CSeq_loc_Conversion* cvt, unsigned int loc_index){ // Always map aligns through conv. set return ( cvt && (cvt->IsPartial() || object_ref.IsAlign()) )? x_AddObjectMapping(object_ref, cvt, loc_index) : x_AddObject(object_ref);}void CAnnot_Collector::x_Search(const CTSE_Info& tse, const SIdAnnotObjs* objs, CReadLockGuard& guard, const CAnnotName& annot_name, const CSeq_id_Handle& id, const CHandleRange& hr, CSeq_loc_Conversion* cvt){ if (m_Selector.m_AnnotTypesSet.size() == 0) { pair<size_t, size_t> range = CAnnotType_Index::GetIndexRange(m_Selector, *objs); if ( range.first < range.second ) { x_SearchRange(tse, objs, guard, annot_name, id, hr, cvt, range.first, range.second); } } else { pair<size_t, size_t> range(0, 0); bool last_bit = false; bool cur_bit; for (size_t idx = 0; idx < objs->m_AnnotSet.size(); ++idx) { cur_bit = m_Selector.m_AnnotTypesSet[idx]; if (!last_bit && cur_bit) { // open range range.first = idx; } else if (last_bit && !cur_bit) { // close and search range range.second = idx; x_SearchRange(tse, objs, guard, annot_name, id, hr, cvt, range.first, range.second); } last_bit = cur_bit;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?