annot_collector.cpp
来自「ncbi源码」· C++ 代码 · 共 1,431 行 · 第 1/4 页
CPP
1,431 行
/* * =========================================================================== * PRODUCTION $Log: annot_collector.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:22:32 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * PRODUCTION * =========================================================================== *//* $Id: annot_collector.cpp,v 1000.3 2004/06/01 19:22:32 gouriano Exp $* ===========================================================================** PUBLIC DOMAIN NOTICE* National Center for Biotechnology Information** This software/database is a "United States Government Work" under the* terms of the United States Copyright Act. It was written as part of* the author's official duties as a United States Government employee and* thus cannot be copyrighted. This software/database is freely available* to the public for use. The National Library of Medicine and the U.S.* Government have not placed any restriction on its use or reproduction.** Although all reasonable efforts have been taken to ensure the accuracy* and reliability of the software and data, the NLM and the U.S.* Government do not and cannot warrant the performance or results that* may be obtained by using this software or data. The NLM and the U.S.* Government disclaim all warranties, express or implied, including* warranties of performance, merchantability or fitness for any particular* purpose.** Please cite the author in any work or product based on this material.** ===========================================================================** Author: Aleksey Grichenko, Eugene Vasilchenko** File Description:* Annotation collector for annot iterators**/#include <ncbi_pch.hpp>#include <objmgr/impl/annot_collector.hpp>#include <objmgr/scope.hpp>#include <objmgr/bioseq_handle.hpp>#include <objmgr/seq_entry_handle.hpp>#include <objmgr/seq_annot_handle.hpp>#include <objmgr/seq_map_ci.hpp>#include <objmgr/impl/annot_object.hpp>#include <objmgr/impl/tse_info.hpp>#include <objmgr/impl/annot_type_index.hpp>#include <objmgr/impl/tse_chunk_info.hpp>#include <objmgr/impl/data_source.hpp>#include <objmgr/impl/seq_annot_info.hpp>#include <objmgr/impl/bioseq_set_info.hpp>#include <objmgr/impl/handle_range_map.hpp>#include <objmgr/impl/synonyms.hpp>#include <objmgr/impl/seq_loc_cvt.hpp>#include <objmgr/impl/seq_align_mapper.hpp>#include <objmgr/impl/snp_annot_info.hpp>#include <objmgr/impl/scope_impl.hpp>#include <objmgr/objmgr_exception.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objects/seqalign/Seq_align.hpp>#include <objects/seqfeat/Seq_feat.hpp>#include <objects/seqres/Seq_graph.hpp>#include <objects/seqfeat/SeqFeatData.hpp>#include <objects/seqloc/Seq_loc_equiv.hpp>#include <objects/seqloc/Seq_bond.hpp>#include <serial/typeinfo.hpp>#include <serial/objostr.hpp>#include <serial/objostrasn.hpp>#include <serial/serial.hpp>#include <serial/serialutil.hpp>#include <algorithm>#include <typeinfo>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)/////////////////////////////////////////////////////////////////////////////// CAnnotObject_Ref/////////////////////////////////////////////////////////////////////////////inlineCAnnotObject_Ref::CAnnotObject_Ref(const CAnnotObject_Info& object) : m_Object(&object.GetSeq_annot_Info()), m_AnnotObject_Index(object.GetSeq_annot_Info() .GetAnnotObjectIndex(object)), m_ObjectType(eType_Seq_annot_Info), m_MappedFlags(0), m_MappedObjectType(eMappedObjType_not_set), m_MappedStrand(eNa_strand_unknown){ if ( object.IsFeat() ) { const CSeq_feat& feat = *object.GetFeatFast(); if ( feat.IsSetPartial() ) { SetPartial(feat.GetPartial()); } }}inlineCAnnotObject_Ref::CAnnotObject_Ref(const CSeq_annot_SNP_Info& snp_annot, TSeqPos index) : m_Object(&snp_annot), m_AnnotObject_Index(index), m_ObjectType(eType_Seq_annot_SNP_Info), m_MappedFlags(0), m_MappedObjectType(eMappedObjType_not_set), m_MappedStrand(eNa_strand_unknown){}const CAnnotObject_Info& CAnnotObject_Ref::GetAnnotObject_Info(void) const{ return GetSeq_annot_Info().GetAnnotObject_Info(GetAnnotObjectIndex());}const SSNP_Info& CAnnotObject_Ref::GetSNP_Info(void) const{ return GetSeq_annot_SNP_Info().GetSNP_Info(GetAnnotObjectIndex());}bool CAnnotObject_Ref::IsFeat(void) const{ return GetObjectType() == eType_Seq_annot_SNP_Info || (GetObjectType() == eType_Seq_annot_Info && GetAnnotObject_Info().IsFeat());}bool CAnnotObject_Ref::IsGraph(void) const{ return GetObjectType() == eType_Seq_annot_Info && GetAnnotObject_Info().IsGraph();}bool CAnnotObject_Ref::IsAlign(void) const{ return GetObjectType() == eType_Seq_annot_Info && GetAnnotObject_Info().IsAlign();}const CSeq_feat& CAnnotObject_Ref::GetFeat(void) const{ return GetAnnotObject_Info().GetFeat();}const CSeq_graph& CAnnotObject_Ref::GetGraph(void) const{ return GetAnnotObject_Info().GetGraph();}const CSeq_align& CAnnotObject_Ref::GetAlign(void) const{ return GetAnnotObject_Info().GetAlign();}inlinevoid CAnnotObject_Ref::SetSNP_Point(const SSNP_Info& snp, CSeq_loc_Conversion* cvt){ _ASSERT(GetObjectType() == eType_Seq_annot_SNP_Info); TSeqPos src_from = snp.GetFrom(), src_to = snp.GetTo(); ENa_strand src_strand = snp.MinusStrand()? eNa_strand_minus: eNa_strand_plus; if ( !cvt ) { SetTotalRange(TRange(src_from, src_to)); SetMappedSeq_id(const_cast<CSeq_id&>(GetSeq_annot_SNP_Info(). GetSeq_id()), true); SetMappedStrand(src_strand); return; } cvt->Reset(); if ( src_from == src_to ) { // point _VERIFY(cvt->ConvertPoint(src_from, src_strand)); } else { // interval _VERIFY(cvt->ConvertInterval(src_from, src_to, src_strand)); } cvt->SetMappedLocation(*this, CSeq_loc_Conversion::eLocation);}const CSeq_align&CAnnotObject_Ref::GetMappedSeq_align(void) const{ if (m_MappedObjectType == eMappedObjType_Seq_loc_Conv_Set) { // Map the alignment, replace conv-set with the mapped align CSeq_loc_Conversion_Set& cvts = const_cast<CSeq_loc_Conversion_Set&>( *CTypeConverter<CSeq_loc_Conversion_Set>:: SafeCast(m_MappedObject.GetPointer())); CRef<CSeq_align> dst; cvts.Convert(GetAlign(), &dst); const_cast<CAnnotObject_Ref&>(*this). SetMappedSeq_align(dst.GetPointerOrNull()); } _ASSERT(m_MappedObjectType == eMappedObjType_Seq_align); return *CTypeConverter<CSeq_align>:: SafeCast(m_MappedObject.GetPointer());}void CAnnotObject_Ref::SetMappedSeq_align_Cvts(CSeq_loc_Conversion_Set& cvts){ _ASSERT(!IsMapped()); m_MappedObject.Reset(&cvts); m_MappedObjectType = eMappedObjType_Seq_loc_Conv_Set;}void CAnnotObject_Ref::SetMappedSeq_align(CSeq_align* align){ _ASSERT(m_MappedObjectType == eMappedObjType_Seq_loc_Conv_Set); m_MappedObject.Reset(align); m_MappedObjectType = align? eMappedObjType_Seq_align: eMappedObjType_not_set;}void CAnnotObject_Ref::UpdateMappedSeq_loc(CRef<CSeq_loc>& loc) const{ _ASSERT(MappedSeq_locNeedsUpdate()); CSeq_id& id = const_cast<CSeq_id&>(GetMappedSeq_id()); if ( !loc || !loc->ReferencedOnlyOnce() ) { loc.Reset(new CSeq_loc); } else { loc->InvalidateTotalRangeCache(); } if ( IsMappedPoint() ) { CSeq_point& point = loc->SetPnt(); point.SetId(id); point.SetPoint(m_TotalRange.GetFrom()); if ( GetMappedStrand() != eNa_strand_unknown ) point.SetStrand(GetMappedStrand()); else point.ResetStrand(); } else { CSeq_interval& interval = loc->SetInt(); interval.SetId(id); interval.SetFrom(GetTotalRange().GetFrom()); interval.SetTo(GetTotalRange().GetTo()); if ( GetMappedStrand() != eNa_strand_unknown ) interval.SetStrand(GetMappedStrand()); else interval.ResetStrand(); }}void CAnnotObject_Ref::UpdateMappedSeq_loc(CRef<CSeq_loc>& loc, CRef<CSeq_point>& pnt_ref, CRef<CSeq_interval>& int_ref) const{ _ASSERT(MappedSeq_locNeedsUpdate()); CSeq_id& id = const_cast<CSeq_id&>(GetMappedSeq_id()); if ( !loc || !loc->ReferencedOnlyOnce() ) { loc.Reset(new CSeq_loc); } else { loc->Reset(); loc->InvalidateTotalRangeCache(); } if ( IsMappedPoint() ) { if ( !pnt_ref || !pnt_ref->ReferencedOnlyOnce() ) { pnt_ref.Reset(new CSeq_point); } CSeq_point& point = *pnt_ref; loc->SetPnt(point); point.SetId(id); point.SetPoint(m_TotalRange.GetFrom()); if ( GetMappedStrand() != eNa_strand_unknown ) point.SetStrand(GetMappedStrand()); else point.ResetStrand(); } else { if ( !int_ref || !int_ref->ReferencedOnlyOnce() ) { int_ref.Reset(new CSeq_interval); } CSeq_interval& interval = *int_ref; loc->SetInt(interval); interval.SetId(id); interval.SetFrom(m_TotalRange.GetFrom()); interval.SetTo(m_TotalRange.GetTo()); if ( GetMappedStrand() != eNa_strand_unknown ) interval.SetStrand(GetMappedStrand()); else interval.ResetStrand(); }}bool CAnnotObject_Ref::operator<(const CAnnotObject_Ref& ref) const{ if ( m_Object != ref.m_Object ) { return m_Object < ref.m_Object; } return GetAnnotObjectIndex() < ref.GetAnnotObjectIndex();}/////////////////////////////////////////////////////////////////////////////// CAnnotObject_Ref comparision/////////////////////////////////////////////////////////////////////////////struct CAnnotObjectType_Less{ bool operator()(const CAnnotObject_Ref& x, const CAnnotObject_Ref& y) const; static const CSeq_loc& GetLocation(const CAnnotObject_Ref& ref, const CSeq_feat& feat);};const CSeq_loc& CAnnotObjectType_Less::GetLocation(const CAnnotObject_Ref& ref, const CSeq_feat& feat){ if ( ref.GetMappedObjectType() == ref.eMappedObjType_Seq_loc && !ref.IsProduct() ) { return ref.GetMappedSeq_loc(); } else { return feat.GetLocation(); }}bool CAnnotObjectType_Less::operator()(const CAnnotObject_Ref& x, const CAnnotObject_Ref& y) const{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?