NCBI C++ ToolKit
bioseq_info.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

00001 /*  $Id: bioseq_info.cpp 62784 2014-05-07 20:58:24Z vasilche $
00002 * ===========================================================================
00003 *
00004 *                            PUBLIC DOMAIN NOTICE
00005 *               National Center for Biotechnology Information
00006 *
00007 *  This software/database is a "United States Government Work" under the
00008 *  terms of the United States Copyright Act.  It was written as part of
00009 *  the author's official duties as a United States Government employee and
00010 *  thus cannot be copyrighted.  This software/database is freely available
00011 *  to the public for use. The National Library of Medicine and the U.S.
00012 *  Government have not placed any restriction on its use or reproduction.
00013 *
00014 *  Although all reasonable efforts have been taken to ensure the accuracy
00015 *  and reliability of the software and data, the NLM and the U.S.
00016 *  Government do not and cannot warrant the performance or results that
00017 *  may be obtained by using this software or data. The NLM and the U.S.
00018 *  Government disclaim all warranties, express or implied, including
00019 *  warranties of performance, merchantability or fitness for any particular
00020 *  purpose.
00021 *
00022 *  Please cite the author in any work or product based on this material.
00023 *
00024 * ===========================================================================
00025 *
00026 * Author: Aleksey Grichenko, Eugene Vasilchenko
00027 *
00028 * File Description:
00029 *   Bioseq info for data source
00030 *
00031 */
00032 
00033 
00034 #include <ncbi_pch.hpp>
00035 #include <objmgr/impl/bioseq_info.hpp>
00036 #include <objmgr/impl/seq_entry_info.hpp>
00037 #include <objmgr/impl/tse_info.hpp>
00038 #include <objmgr/impl/data_source.hpp>
00039 
00040 #include <objects/seq/seq_id_handle.hpp>
00041 
00042 #include <objmgr/seq_map.hpp>
00043 
00044 #include <objects/seq/Bioseq.hpp>
00045 
00046 #include <objects/seq/Seq_inst.hpp>
00047 #include <objects/seq/Seq_data.hpp>
00048 #include <objects/seq/Seq_hist.hpp>
00049 #include <objects/seq/Seq_ext.hpp>
00050 #include <objects/seq/Seg_ext.hpp>
00051 #include <objects/seq/Delta_ext.hpp>
00052 #include <objects/seq/Delta_seq.hpp>
00053 #include <objects/seq/Seq_literal.hpp>
00054 #include <objects/seq/Ref_ext.hpp>
00055 #include <objects/seq/Seq_descr.hpp>
00056 #include <objects/seq/Seqdesc.hpp>
00057 #include <objects/seqfeat/BioSource.hpp>
00058 #include <objects/seqfeat/Org_ref.hpp>
00059 
00060 #include <objects/seqloc/Seq_id.hpp>
00061 #include <objects/seqloc/Packed_seqint.hpp>
00062 #include <objects/seqloc/Seq_loc.hpp>
00063 #include <objects/seqloc/Seq_interval.hpp>
00064 #include <objects/seqloc/Seq_loc_mix.hpp>
00065 #include <objects/seqloc/Seq_loc_equiv.hpp>
00066 #include <objects/general/Int_fuzz.hpp>
00067 #include <objects/general/User_object.hpp>
00068 #include <objects/general/User_field.hpp>
00069 #include <objects/general/Object_id.hpp>
00070 #include <algorithm>
00071 
00072 
00073 BEGIN_NCBI_SCOPE
00074 BEGIN_SCOPE(objects)
00075 
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //
00079 //  CBioseq_Info::
00080 //
00081 //    Structure to keep bioseq's parent seq-entry along with the list
00082 //    of seq-id synonyms for the bioseq.
00083 //
00084 
00085 
00086 CBioseq_Info::CBioseq_Info(CBioseq& seq)
00087     : m_AssemblyChunk(-1),
00088       m_FeatureFetchPolicy(-1)
00089 {
00090     x_SetObject(seq);
00091 }
00092 
00093 
00094 CBioseq_Info::CBioseq_Info(const CBioseq_Info& info, TObjectCopyMap* copy_map)
00095     : TParent(info, copy_map),
00096       m_Seq_dataChunks(info.m_Seq_dataChunks),
00097       m_AssemblyChunk(info.m_AssemblyChunk),
00098       m_FeatureFetchPolicy(info.m_FeatureFetchPolicy)
00099 {
00100     x_SetObject(info, copy_map);
00101 }
00102 
00103 
00104 CBioseq_Info::~CBioseq_Info(void)
00105 {
00106     x_ResetSeqMap();
00107 }
00108 
00109 
00110 CConstRef<CBioseq> CBioseq_Info::GetCompleteBioseq(void) const
00111 {
00112     x_UpdateComplete();
00113     return m_Object;
00114 }
00115 
00116 
00117 CConstRef<CBioseq> CBioseq_Info::GetBioseqCore(void) const
00118 {
00119     x_UpdateCore();
00120     return m_Object;
00121 }
00122 
00123 
00124 void CBioseq_Info::x_SetChangedSeqMap(void)
00125 {
00126     x_SetNeedUpdate(fNeedUpdate_seq_data);
00127 }
00128 
00129 
00130 void CBioseq_Info::x_AddSeq_dataChunkId(TChunkId chunk_id)
00131 {
00132     m_Seq_dataChunks.push_back(chunk_id);
00133     x_SetNeedUpdate(fNeedUpdate_seq_data);
00134 }
00135 
00136 
00137 void CBioseq_Info::x_AddAssemblyChunkId(TChunkId chunk_id)
00138 {
00139     _ASSERT(m_AssemblyChunk < 0);
00140     _ASSERT(chunk_id >= 0);
00141     m_AssemblyChunk = chunk_id;
00142     x_SetNeedUpdate(fNeedUpdate_assembly);
00143 }
00144 
00145 
00146 void CBioseq_Info::x_DoUpdate(TNeedUpdateFlags flags)
00147 {
00148     if ( flags & fNeedUpdate_seq_data ) {
00149         if ( !m_Seq_dataChunks.empty() ) {
00150             x_LoadChunks(m_Seq_dataChunks);
00151         }
00152         if ( m_SeqMap ) {
00153             m_SeqMap->x_UpdateSeq_inst(m_Object->SetInst());
00154         }
00155     }
00156     if ( flags & fNeedUpdate_assembly ) {
00157         TChunkId chunk = m_AssemblyChunk;
00158         if ( chunk >= 0 ) {
00159             x_LoadChunk(chunk);
00160         }
00161     }
00162     TParent::x_DoUpdate(flags);
00163 }
00164 
00165 
00166 void CBioseq_Info::x_DSAttachContents(CDataSource& ds)
00167 {
00168     TParent::x_DSAttachContents(ds);
00169     x_DSMapObject(m_Object, ds);
00170 }
00171 
00172 
00173 void CBioseq_Info::x_DSDetachContents(CDataSource& ds)
00174 {
00175     x_DSUnmapObject(m_Object, ds);
00176     TParent::x_DSDetachContents(ds);
00177 }
00178 
00179 
00180 void CBioseq_Info::x_DSMapObject(CConstRef<TObject> obj, CDataSource& ds)
00181 {
00182     ds.x_Map(obj, this);
00183 }
00184 
00185 
00186 void CBioseq_Info::x_DSUnmapObject(CConstRef<TObject> obj, CDataSource& ds)
00187 {
00188     ds.x_Unmap(obj, this);
00189 }
00190 
00191 
00192 void CBioseq_Info::x_TSEAttachContents(CTSE_Info& tse)
00193 {
00194     TParent::x_TSEAttachContents(tse);
00195     SetBioObjectId(tse.x_IndexBioseq(this));
00196     /*
00197     x_RegisterRemovedIds(m_Object, *this);
00198     ITERATE ( TId, it, m_Id ) {
00199         tse.x_SetBioseqId(*it, this);
00200     }
00201     */
00202 }
00203 
00204 
00205 void CBioseq_Info::x_TSEDetachContents(CTSE_Info& tse)
00206 {
00207     ITERATE ( TId, it, m_Id ) {
00208         tse.x_ResetBioseqId(*it, this);
00209     }
00210     TParent::x_TSEDetachContents(tse);
00211 }
00212 
00213 
00214 void CBioseq_Info::x_ParentAttach(CSeq_entry_Info& parent)
00215 {
00216     TParent::x_ParentAttach(parent);
00217     CSeq_entry& entry = parent.x_GetObject();
00218     entry.ParentizeOneLevel();
00219 #ifdef _DEBUG
00220     _ASSERT(&entry.GetSeq() == m_Object);
00221     _ASSERT(m_Object->GetParentEntry() == &entry);
00222 #endif
00223 }
00224 
00225 
00226 void CBioseq_Info::x_ParentDetach(CSeq_entry_Info& parent)
00227 {
00228     //m_Object->ResetParentEntry();
00229     TParent::x_ParentDetach(parent);
00230 }
00231 
00232 
00233 int CBioseq_Info::GetFeatureFetchPolicy(void) const
00234 {
00235     if ( m_FeatureFetchPolicy == -1 ) {
00236         int policy = -1;
00237         if ( IsSetDescr() ) {
00238             for ( TDesc_CI it = x_GetFirstDesc(1<<CSeqdesc::e_User);
00239                   policy == -1 && !x_IsEndDesc(it);
00240                   it = x_GetNextDesc(it, 1<<CSeqdesc::e_User) ) {
00241                 const CSeqdesc& desc = **it;
00242                 if ( !desc.IsUser() ) {
00243                     continue;
00244                 }
00245                 const CUser_object& user = desc.GetUser();
00246                 const CObject_id& id = user.GetType();
00247                 if ( !id.IsStr() || id.GetStr() != "FeatureFetchPolicy" ) {
00248                     continue;
00249                 }
00250                 ITERATE ( CUser_object::TData, fit, user.GetData() ) {
00251                     const CUser_field& field = **fit;
00252                     const CObject_id& fid = field.GetLabel();
00253                     if ( !fid.IsStr() || fid.GetStr() != "Policy" ) {
00254                         continue;
00255                     }
00256                     if ( !field.GetData().IsStr() ) {
00257                         continue;
00258                     }
00259                     const string& str = field.GetData().GetStr();
00260                     if ( str == "OnlyNearFeatures" ) {
00261                         policy = CBioseq_Handle::eFeatureFetchPolicy_only_near;
00262                     }
00263                     else {
00264                         policy = CBioseq_Handle::eFeatureFetchPolicy_default;
00265                     }
00266                     break;
00267                 }
00268             }
00269         }
00270         if ( policy == -1 ) {
00271             policy = CBioseq_Handle::eFeatureFetchPolicy_default;
00272         }
00273         m_FeatureFetchPolicy = policy;
00274     }
00275     return m_FeatureFetchPolicy;
00276 }
00277 
00278 
00279 void CBioseq_Info::x_SetObject(TObject& obj)
00280 {
00281     _ASSERT(!m_Object);
00282 
00283     m_Object.Reset(&obj);
00284     if ( HasDataSource() ) {
00285         x_DSMapObject(m_Object, GetDataSource());
00286     }
00287     if ( obj.IsSetId() ) {
00288         ITERATE ( TObject::TId, it, obj.GetId() ) {
00289             m_Id.push_back(CSeq_id_Handle::GetHandle(**it));
00290         }
00291     }
00292     if ( obj.IsSetAnnot() ) {
00293         x_SetAnnot();
00294     }
00295     m_FeatureFetchPolicy = -1;
00296 }
00297 
00298 
00299 void CBioseq_Info::x_SetObject(const CBioseq_Info& info,
00300                                TObjectCopyMap* copy_map)
00301 {
00302     _ASSERT(!m_Object);
00303 
00304     m_Object = sx_ShallowCopy(*info.m_Object);
00305     if ( HasDataSource() ) {
00306         x_DSMapObject(m_Object, GetDataSource());
00307     }
00308     m_Id = info.m_Id;
00309     if ( info.m_SeqMap ) {
00310         m_SeqMap = info.m_SeqMap->CloneFor(*m_Object);
00311         m_SeqMap->m_Bioseq = this;
00312     }
00313     if ( info.IsSetAnnot() ) {
00314         x_SetAnnot(info, copy_map);
00315     }
00316     m_FeatureFetchPolicy = info.m_FeatureFetchPolicy;
00317 }
00318 
00319 
00320 CRef<CBioseq> CBioseq_Info::sx_ShallowCopy(const TObject& src)
00321 {        
00322     CRef<TObject> obj(new TObject);
00323     if ( src.IsSetId() ) {
00324         obj->SetId() = src.GetId();
00325     }
00326     if ( src.IsSetDescr() ) {
00327         obj->SetDescr().Set() = src.GetDescr().Get();
00328     }
00329     if ( src.IsSetInst() ) {
00330         CRef<TInst> inst = sx_ShallowCopy(src.GetInst());
00331         obj->SetInst(*inst);
00332     }
00333     if ( src.IsSetAnnot() ) {
00334         obj->SetAnnot() = src.GetAnnot();
00335     }
00336     return obj;
00337 }
00338 
00339 
00340 CRef<CSeq_inst> CBioseq_Info::sx_ShallowCopy(const TInst& src)
00341 {
00342     CRef<TInst> obj(new TInst);
00343     if ( src.IsSetRepr() ) {
00344         obj->SetRepr(src.GetRepr());
00345     }
00346     if ( src.IsSetMol() ) {
00347         obj->SetMol(src.GetMol());
00348     }
00349     if ( src.IsSetLength() ) {
00350         obj->SetLength(src.GetLength());
00351     }
00352     if ( src.IsSetFuzz() ) {
00353         obj->SetFuzz(const_cast<TInst_Fuzz&>(src.GetFuzz()));
00354     }
00355     if ( src.IsSetTopology() ) {
00356         obj->SetTopology(src.GetTopology());
00357     }
00358     if ( src.IsSetStrand() ) {
00359         obj->SetStrand(src.GetStrand());
00360     }
00361     if ( src.IsSetSeq_data() ) {
00362         obj->SetSeq_data(const_cast<TInst_Seq_data&>(src.GetSeq_data()));
00363     }
00364     if ( src.IsSetExt() ) {
00365         obj->SetExt(const_cast<TInst_Ext&>(src.GetExt()));
00366     }
00367     if ( src.IsSetHist() ) {
00368         obj->SetHist(const_cast<TInst_Hist&>(src.GetHist()));
00369     }
00370     return obj;
00371 }
00372 
00373 
00374 /////////////////////////////////////////////////////////////////////////////
00375 // id
00376 /////////////////////////////////////////////////////////////////////////////
00377 
00378 bool CBioseq_Info::IsSetId(void) const
00379 {
00380     return m_Object->IsSetId();
00381 }
00382 
00383 
00384 bool CBioseq_Info::CanGetId(void) const
00385 {
00386     return m_Object->CanGetId();
00387 }
00388 
00389 
00390 const CBioseq_Info::TId& CBioseq_Info::GetId(void) const
00391 {
00392     return m_Id;
00393 }
00394 
00395 
00396 void CBioseq_Info::ResetId(void)
00397 {
00398     ITERATE(TId, id, m_Id) {
00399         GetTSE_Info().x_ResetBioseqId(*id,this);        
00400     }
00401     m_Id.clear();
00402     m_Object->ResetId();
00403     SetBioObjectId(GetTSE_Info().x_RegisterBioObject(*this));
00404 }
00405 
00406 
00407 bool CBioseq_Info::HasId(const CSeq_id_Handle& id) const
00408 {
00409     return find(m_Id.begin(), m_Id.end(), id) != m_Id.end();
00410 }
00411 
00412 
00413 bool CBioseq_Info::AddId(const CSeq_id_Handle& id)
00414 {
00415     TId::iterator found = find(m_Id.begin(), m_Id.end(), id);
00416     if ( found != m_Id.end() ) {
00417         return false;
00418     }
00419     m_Id.push_back(id);
00420     CRef<CSeq_id> seq_id(new CSeq_id);
00421     seq_id->Assign(*id.GetSeqId());
00422     m_Object->SetId().push_back(seq_id);
00423     GetTSE_Info().x_SetBioseqId(id,this);
00424     return true;
00425 }
00426 
00427 
00428 bool CBioseq_Info::RemoveId(const CSeq_id_Handle& id)
00429 {
00430     TId::iterator found = find(m_Id.begin(), m_Id.end(), id);
00431     if ( found == m_Id.end() ) {
00432         return false;
00433     }
00434     m_Id.erase(found);
00435     NON_CONST_ITERATE ( TObject::TId, it, m_Object->SetId() ) {
00436         if ( CSeq_id_Handle::GetHandle(**it) == id ) {
00437             m_Object->SetId().erase(it);
00438             break;
00439         }
00440     }
00441     GetTSE_Info().x_ResetBioseqId(id,this);
00442     if (GetBioObjectId() == CBioObjectId(id)) {
00443         SetBioObjectId(GetTSE_Info().x_RegisterBioObject(*this));
00444     }
00445     return true;
00446 }
00447 
00448 
00449 /////////////////////////////////////////////////////////////////////////////
00450 // descr
00451 /////////////////////////////////////////////////////////////////////////////
00452 
00453 bool CBioseq_Info::x_IsSetDescr(void) const
00454 {
00455     return m_Object->IsSetDescr();
00456 }
00457 
00458 
00459 bool CBioseq_Info::x_CanGetDescr(void) const
00460 {
00461     return m_Object->CanGetDescr();
00462 }
00463 
00464 
00465 const CSeq_descr& CBioseq_Info::x_GetDescr(void) const
00466 {
00467     return m_Object->GetDescr();
00468 }
00469 
00470 
00471 CSeq_descr& CBioseq_Info::x_SetDescr(void)
00472 {
00473     return m_Object->SetDescr();
00474 }
00475 
00476 
00477 void CBioseq_Info::x_SetDescr(TDescr& v)
00478 {
00479     m_Object->SetDescr(v);
00480 }
00481 
00482 
00483 void CBioseq_Info::x_ResetDescr(void)
00484 {
00485     m_Object->ResetDescr();
00486 }
00487 
00488 
00489 /////////////////////////////////////////////////////////////////////////////
00490 // annot
00491 /////////////////////////////////////////////////////////////////////////////
00492 
00493 CBioseq::TAnnot& CBioseq_Info::x_SetObjAnnot(void)
00494 {
00495     return m_Object->SetAnnot();
00496 }
00497 
00498 
00499 void CBioseq_Info::x_ResetObjAnnot(void)
00500 {
00501     m_Object->ResetAnnot();
00502 }
00503 
00504 
00505 /////////////////////////////////////////////////////////////////////////////
00506 // inst
00507 /////////////////////////////////////////////////////////////////////////////
00508 
00509 bool CBioseq_Info::IsSetInst(void) const
00510 {
00511     return m_Object->IsSetInst();
00512 }
00513 
00514 
00515 bool CBioseq_Info::CanGetInst(void) const
00516 {
00517     return m_Object->CanGetInst();
00518 }
00519 
00520 
00521 const CBioseq_Info::TInst& CBioseq_Info::GetInst(void) const
00522 {
00523     x_Update(fNeedUpdate_seq_data|fNeedUpdate_assembly);
00524     return m_Object->GetInst();
00525 }
00526 
00527 
00528 void CBioseq_Info::SetInst(TInst& v)
00529 {
00530     x_ResetSeqMap();
00531     m_Seq_dataChunks.clear();
00532     m_Object->SetInst(v);
00533 }
00534 
00535 void CBioseq_Info::ResetInst()
00536 {
00537     if (IsSetInst()) {
00538         x_ResetSeqMap();
00539         m_Seq_dataChunks.clear();
00540         m_Object->ResetInst();
00541     }
00542 }
00543 
00544 
00545 void CBioseq_Info::x_ResetSeqMap(void)
00546 {
00547     CFastMutexGuard guard(m_SeqMap_Mtx);
00548     if ( m_SeqMap ) {
00549         m_SeqMap->m_Bioseq = 0;
00550         m_SeqMap.Reset();
00551     }
00552 }
00553 
00554 
00555 /////////////////////////////////////////////////////////////////////////////
00556 // inst.repr
00557 /////////////////////////////////////////////////////////////////////////////
00558 
00559 bool CBioseq_Info::IsSetInst_Repr(void) const
00560 {
00561     return IsSetInst() && m_Object->GetInst().IsSetRepr();
00562 }
00563 
00564 
00565 bool CBioseq_Info::CanGetInst_Repr(void) const
00566 {
00567     return CanGetInst() && m_Object->GetInst().CanGetRepr();
00568 }
00569 
00570 
00571 CBioseq_Info::TInst_Repr CBioseq_Info::GetInst_Repr(void) const
00572 {
00573     return m_Object->GetInst().GetRepr();
00574 }
00575 
00576 
00577 void CBioseq_Info::SetInst_Repr(TInst_Repr v)
00578 {
00579     CFastMutexGuard guard(m_SeqMap_Mtx);
00580     if ( m_SeqMap ) {
00581         m_SeqMap->SetRepr(v);
00582     }
00583     m_Object->SetInst().SetRepr(v);
00584 }
00585 
00586 void CBioseq_Info::ResetInst_Repr()
00587 {
00588     if (IsSetInst_Repr()) {
00589         CFastMutexGuard guard(m_SeqMap_Mtx);
00590         if ( m_SeqMap ) {
00591             m_SeqMap->ResetRepr();
00592         }
00593         m_Object->SetInst().ResetRepr();
00594     }
00595 }
00596 
00597 /////////////////////////////////////////////////////////////////////////////
00598 // inst.mol
00599 /////////////////////////////////////////////////////////////////////////////
00600 
00601 bool CBioseq_Info::IsSetInst_Mol(void) const
00602 {
00603     return IsSetInst() && m_Object->GetInst().IsSetMol();
00604 }
00605 
00606 
00607 bool CBioseq_Info::CanGetInst_Mol(void) const
00608 {
00609     return CanGetInst() && m_Object->GetInst().CanGetMol();
00610 }
00611 
00612 
00613 CBioseq_Info::TInst_Mol CBioseq_Info::GetInst_Mol(void) const
00614 {
00615     return m_Object->GetInst().GetMol();
00616 }
00617 
00618 
00619 void CBioseq_Info::SetInst_Mol(TInst_Mol v)
00620 {
00621     CFastMutexGuard guard(m_SeqMap_Mtx);
00622     if ( m_SeqMap ) {
00623         m_SeqMap->SetMol(v);
00624     }
00625     m_Object->SetInst().SetMol(v);
00626 }
00627 
00628 void CBioseq_Info::ResetInst_Mol()
00629 {
00630     if (IsSetInst_Mol()) {
00631         CFastMutexGuard guard(m_SeqMap_Mtx);
00632         if ( m_SeqMap ) {
00633             m_SeqMap->ResetMol();
00634         }
00635         m_Object->SetInst().ResetMol();
00636     }
00637 }
00638 
00639 
00640 /////////////////////////////////////////////////////////////////////////////
00641 // inst.length
00642 /////////////////////////////////////////////////////////////////////////////
00643 
00644 bool CBioseq_Info::IsSetInst_Length(void) const
00645 {
00646     return IsSetInst() && m_Object->GetInst().IsSetLength();
00647 }
00648 
00649 
00650 bool CBioseq_Info::CanGetInst_Length(void) const
00651 {
00652     return CanGetInst() && m_Object->GetInst().CanGetLength();
00653 }
00654 
00655 
00656 CBioseq_Info::TInst_Length CBioseq_Info::GetInst_Length(void) const
00657 {
00658     CFastMutexGuard guard(m_SeqMap_Mtx);
00659     if ( m_SeqMap ) {
00660         return m_SeqMap->GetLength(0);
00661     }
00662     else {
00663         return m_Object->GetInst().GetLength();
00664     }
00665 }
00666 
00667 
00668 void CBioseq_Info::SetInst_Length(TInst_Length v)
00669 {
00670     x_Update(fNeedUpdate_seq_data);
00671     x_ResetSeqMap();
00672     m_Object->SetInst().SetLength(v);
00673 }
00674 
00675 void CBioseq_Info::ResetInst_Length()
00676 {
00677     if (IsSetInst_Length()) {
00678         x_Update(fNeedUpdate_seq_data);
00679         x_ResetSeqMap();
00680         m_Object->SetInst().ResetLength();
00681     }
00682 }
00683 
00684 CBioseq_Info::TInst_Length CBioseq_Info::GetBioseqLength(void) const
00685 {
00686     if ( IsSetInst_Length() ) {
00687         return GetInst_Length();
00688     }
00689     else {
00690         return x_CalcBioseqLength();
00691     }
00692 }
00693 
00694 
00695 /////////////////////////////////////////////////////////////////////////////
00696 // inst.fuzz
00697 /////////////////////////////////////////////////////////////////////////////
00698 
00699 bool CBioseq_Info::IsSetInst_Fuzz(void) const
00700 {
00701     return IsSetInst() && m_Object->GetInst().IsSetFuzz();
00702 }
00703 
00704 
00705 bool CBioseq_Info::CanGetInst_Fuzz(void) const
00706 {
00707     return CanGetInst() && m_Object->GetInst().CanGetFuzz();
00708 }
00709 
00710 
00711 const CBioseq_Info::TInst_Fuzz& CBioseq_Info::GetInst_Fuzz(void) const
00712 {
00713     return m_Object->GetInst().GetFuzz();
00714 }
00715 
00716 
00717 void CBioseq_Info::SetInst_Fuzz(TInst_Fuzz& v)
00718 {
00719     m_Object->SetInst().SetFuzz(v);
00720 }
00721 
00722 void CBioseq_Info::ResetInst_Fuzz()
00723 {
00724     if (IsSetInst_Fuzz()) {
00725         m_Object->SetInst().ResetFuzz();
00726     }
00727 }
00728 
00729 /////////////////////////////////////////////////////////////////////////////
00730 // inst.topology
00731 /////////////////////////////////////////////////////////////////////////////
00732 
00733 bool CBioseq_Info::IsSetInst_Topology(void) const
00734 {
00735     return IsSetInst() && m_Object->GetInst().IsSetTopology();
00736 }
00737 
00738 
00739 bool CBioseq_Info::CanGetInst_Topology(void) const
00740 {
00741     return CanGetInst() && m_Object->GetInst().CanGetTopology();
00742 }
00743 
00744 
00745 CBioseq_Info::TInst_Topology CBioseq_Info::GetInst_Topology(void) const
00746 {
00747     return m_Object->GetInst().GetTopology();
00748 }
00749 
00750 
00751 void CBioseq_Info::SetInst_Topology(TInst_Topology v)
00752 {
00753     m_Object->SetInst().SetTopology(v);
00754 }
00755 
00756 void CBioseq_Info::ResetInst_Topology()
00757 {
00758     if (IsSetInst_Topology()) {
00759         m_Object->SetInst().ResetTopology();
00760     }
00761 }
00762 
00763 /////////////////////////////////////////////////////////////////////////////
00764 // inst.strand
00765 /////////////////////////////////////////////////////////////////////////////
00766 
00767 bool CBioseq_Info::IsSetInst_Strand(void) const
00768 {
00769     return IsSetInst() && m_Object->GetInst().IsSetStrand();
00770 }
00771 
00772 
00773 bool CBioseq_Info::CanGetInst_Strand(void) const
00774 {
00775     return CanGetInst() && m_Object->GetInst().CanGetStrand();
00776 }
00777 
00778 
00779 CBioseq_Info::TInst_Strand CBioseq_Info::GetInst_Strand(void) const
00780 {
00781     return m_Object->GetInst().GetStrand();
00782 }
00783 
00784 
00785 void CBioseq_Info::SetInst_Strand(TInst_Strand v)
00786 {
00787     m_Object->SetInst().SetStrand(v);
00788 }
00789 
00790 void CBioseq_Info::ResetInst_Strand()
00791 {
00792     if (IsSetInst_Strand()) {
00793         m_Object->SetInst().ResetStrand();
00794     }
00795 }
00796 
00797 
00798 /////////////////////////////////////////////////////////////////////////////
00799 // inst.seq-data
00800 /////////////////////////////////////////////////////////////////////////////
00801 
00802 bool CBioseq_Info::IsSetInst_Seq_data(void) const
00803 {
00804     return IsSetInst() && GetInst().IsSetSeq_data();
00805 }
00806 
00807 
00808 bool CBioseq_Info::CanGetInst_Seq_data(void) const
00809 {
00810     return CanGetInst() && GetInst().CanGetSeq_data();
00811 }
00812 
00813 
00814 const CBioseq_Info::TInst_Seq_data& CBioseq_Info::GetInst_Seq_data(void) const
00815 {
00816     return GetInst().GetSeq_data();
00817 }
00818 
00819 
00820 void CBioseq_Info::SetInst_Seq_data(TInst_Seq_data& v)
00821 {
00822     x_Update(fNeedUpdate_seq_data);
00823     x_ResetSeqMap();
00824     m_Seq_dataChunks.clear();
00825     m_Object->SetInst().SetSeq_data(v);
00826 }
00827 
00828 void CBioseq_Info::ResetInst_Seq_data()
00829 {
00830     if (IsSetInst_Seq_data()) {
00831         x_Update(fNeedUpdate_seq_data);
00832         x_ResetSeqMap();
00833         m_Seq_dataChunks.clear();
00834         m_Object->SetInst().ResetSeq_data();
00835     }
00836 }
00837 
00838 
00839 /////////////////////////////////////////////////////////////////////////////
00840 // inst.ext
00841 /////////////////////////////////////////////////////////////////////////////
00842 
00843 bool CBioseq_Info::IsSetInst_Ext(void) const
00844 {
00845     return IsSetInst() && GetInst().IsSetExt();
00846 }
00847 
00848 
00849 bool CBioseq_Info::CanGetInst_Ext(void) const
00850 {
00851     return CanGetInst() && GetInst().CanGetExt();
00852 }
00853 
00854 
00855 const CBioseq_Info::TInst_Ext& CBioseq_Info::GetInst_Ext(void) const
00856 {
00857     return GetInst().GetExt();
00858 }
00859 
00860 
00861 void CBioseq_Info::SetInst_Ext(TInst_Ext& v)
00862 {
00863     x_Update(fNeedUpdate_seq_data);
00864     x_ResetSeqMap();
00865     m_Seq_dataChunks.clear();
00866     m_Object->SetInst().SetExt(v);
00867 }
00868 
00869 void CBioseq_Info::ResetInst_Ext()
00870 {
00871     if (IsSetInst_Ext()) {
00872         x_Update(fNeedUpdate_seq_data);
00873         x_ResetSeqMap();
00874         m_Seq_dataChunks.clear();
00875         m_Object->SetInst().ResetExt();
00876     }
00877 }
00878 
00879 
00880 /////////////////////////////////////////////////////////////////////////////
00881 // inst.hist
00882 /////////////////////////////////////////////////////////////////////////////
00883 
00884 bool CBioseq_Info::IsSetInst_Hist(void) const
00885 {
00886     return IsSetInst() && m_Object->GetInst().IsSetHist();
00887 }
00888 
00889 
00890 bool CBioseq_Info::CanGetInst_Hist(void) const
00891 {
00892     return CanGetInst() && m_Object->GetInst().CanGetHist();
00893 }
00894 
00895 
00896 const CBioseq_Info::TInst_Hist& CBioseq_Info::GetInst_Hist(void) const
00897 {
00898     x_Update(fNeedUpdate_assembly);
00899     return m_Object->GetInst().GetHist();
00900 }
00901 
00902 
00903 void CBioseq_Info::SetInst_Hist(TInst_Hist& v)
00904 {
00905     x_Update(fNeedUpdate_assembly);
00906     m_AssemblyChunk = -1;
00907     m_Object->SetInst().SetHist(v);
00908 }
00909 
00910 
00911 void CBioseq_Info::ResetInst_Hist()
00912 {
00913     if (IsSetInst_Hist()) {
00914         x_Update(fNeedUpdate_assembly);
00915         m_AssemblyChunk = -1;
00916         m_Object->SetInst().ResetHist();
00917     }
00918 }
00919 
00920 
00921 /////////////////////////////////////////////////////////////////////////////
00922 // inst.hist.assembly
00923 /////////////////////////////////////////////////////////////////////////////
00924 
00925 bool CBioseq_Info::IsSetInst_Hist_Assembly(void) const
00926 {
00927     return IsSetInst_Hist() &&
00928         (m_AssemblyChunk >= 0||m_Object->GetInst().GetHist().IsSetAssembly());
00929 }
00930 
00931 
00932 bool CBioseq_Info::CanGetInst_Hist_Assembly(void) const
00933 {
00934     return CanGetInst_Hist();
00935 }
00936 
00937 
00938 const CBioseq_Info::TInst_Hist_Assembly&
00939 CBioseq_Info::GetInst_Hist_Assembly(void) const
00940 {
00941     x_Update(fNeedUpdate_assembly);
00942     return m_Object->GetInst().GetHist().GetAssembly();
00943 }
00944 
00945 
00946 void CBioseq_Info::SetInst_Hist_Assembly(const TInst_Hist_Assembly& v)
00947 {
00948     x_Update(fNeedUpdate_assembly);
00949     m_AssemblyChunk = -1;
00950     m_Object->SetInst().SetHist().SetAssembly() = v;
00951 }
00952 
00953 
00954 /////////////////////////////////////////////////////////////////////////////
00955 // inst.hist.replaces
00956 /////////////////////////////////////////////////////////////////////////////
00957 
00958 bool CBioseq_Info::IsSetInst_Hist_Replaces(void) const
00959 {
00960     return IsSetInst_Hist() && m_Object->GetInst().GetHist().IsSetReplaces();
00961 }
00962 
00963 
00964 bool CBioseq_Info::CanGetInst_Hist_Replaces(void) const
00965 {
00966     return CanGetInst_Hist() && m_Object->GetInst().GetHist().CanGetReplaces();
00967 }
00968 
00969 
00970 const CBioseq_Info::TInst_Hist_Replaces&
00971 CBioseq_Info::GetInst_Hist_Replaces(void) const
00972 {
00973     return m_Object->GetInst().GetHist().GetReplaces();
00974 }
00975 
00976 
00977 void CBioseq_Info::SetInst_Hist_Replaces(TInst_Hist_Replaces& v)
00978 {
00979     m_Object->SetInst().SetHist().SetReplaces(v);
00980 }
00981 
00982 
00983 /////////////////////////////////////////////////////////////////////////////
00984 // inst.hist.replaced-by
00985 /////////////////////////////////////////////////////////////////////////////
00986 
00987 bool CBioseq_Info::IsSetInst_Hist_Replaced_by(void) const
00988 {
00989     return IsSetInst_Hist() &&
00990         m_Object->GetInst().GetHist().IsSetReplaced_by();
00991 }
00992 
00993 
00994 bool CBioseq_Info::CanGetInst_Hist_Replaced_by(void) const
00995 {
00996     return CanGetInst_Hist() &&
00997         m_Object->GetInst().GetHist().CanGetReplaced_by();
00998 }
00999 
01000 
01001 const CBioseq_Info::TInst_Hist_Replaced_by&
01002 CBioseq_Info::GetInst_Hist_Replaced_by(void) const
01003 {
01004     return m_Object->GetInst().GetHist().GetReplaced_by();
01005 }
01006 
01007 
01008 void CBioseq_Info::SetInst_Hist_Replaced_by(TInst_Hist_Replaced_by& v)
01009 {
01010     m_Object->SetInst().SetHist().SetReplaced_by(v);
01011 }
01012 
01013 
01014 /////////////////////////////////////////////////////////////////////////////
01015 // inst.hist.deleted
01016 /////////////////////////////////////////////////////////////////////////////
01017 
01018 bool CBioseq_Info::IsSetInst_Hist_Deleted(void) const
01019 {
01020     return IsSetInst_Hist() && m_Object->GetInst().GetHist().IsSetDeleted();
01021 }
01022 
01023 
01024 bool CBioseq_Info::CanGetInst_Hist_Deleted(void) const
01025 {
01026     return CanGetInst_Hist() && m_Object->GetInst().GetHist().CanGetDeleted();
01027 }
01028 
01029 
01030 const CBioseq_Info::TInst_Hist_Deleted&
01031 CBioseq_Info::GetInst_Hist_Deleted(void) const
01032 {
01033     return m_Object->GetInst().GetHist().GetDeleted();
01034 }
01035 
01036 
01037 void CBioseq_Info::SetInst_Hist_Deleted(TInst_Hist_Deleted& v)
01038 {
01039     m_Object->SetInst().SetHist().SetDeleted(v);
01040 }
01041 
01042 
01043 bool CBioseq_Info::IsNa(void) const
01044 {
01045     return m_Object->IsNa();
01046 }
01047 
01048 
01049 bool CBioseq_Info::IsAa(void) const
01050 {
01051     return m_Object->IsAa();
01052 }
01053 
01054 
01055 /////////////////////////////////////////////////////////////////////////////
01056 // calculate bioseq length if inst.length field is not set
01057 /////////////////////////////////////////////////////////////////////////////
01058 
01059 TSeqPos CBioseq_Info::x_CalcBioseqLength(void) const
01060 {
01061     return x_CalcBioseqLength(GetInst());
01062 }
01063 
01064 
01065 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CSeq_inst& inst) const
01066 {
01067     if ( !inst.IsSetExt() ) {
01068         NCBI_THROW(CObjMgrException, eOtherError,
01069                    "CBioseq_Info::x_CalcBioseqLength: "
01070                    "failed: Seq-inst.ext is not set");
01071     }
01072     switch ( inst.GetExt().Which() ) {
01073     case CSeq_ext::e_Seg:
01074         return x_CalcBioseqLength(inst.GetExt().GetSeg());
01075     case CSeq_ext::e_Ref:
01076         return x_CalcBioseqLength(inst.GetExt().GetRef().Get());
01077     case CSeq_ext::e_Delta:
01078         return x_CalcBioseqLength(inst.GetExt().GetDelta());
01079     default:
01080         NCBI_THROW(CObjMgrException, eOtherError,
01081                    "CBioseq_Info::x_CalcBioseqLength: "
01082                    "failed: bad Seg-ext type");
01083     }
01084 }
01085 
01086 
01087 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CSeq_id& whole) const
01088 {
01089     CConstRef<CBioseq_Info> ref =
01090         GetTSE_Info().FindMatchingBioseq(CSeq_id_Handle::GetHandle(whole));
01091     if ( !ref ) {
01092         NCBI_THROW(CObjMgrException, eOtherError,
01093                    "CBioseq_Info::x_CalcBioseqLength: "
01094                    "failed: external whole reference");
01095     }
01096     return ref->GetBioseqLength();
01097 }
01098 
01099 
01100 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CPacked_seqint& ints) const
01101 {
01102     TSeqPos ret = 0;
01103     ITERATE ( CPacked_seqint::Tdata, it, ints.Get() ) {
01104         ret += (*it)->GetLength();
01105     }
01106     return ret;
01107 }
01108 
01109 
01110 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CSeq_loc& seq_loc) const
01111 {
01112     switch ( seq_loc.Which() ) {
01113     case CSeq_loc::e_not_set:
01114     case CSeq_loc::e_Null:
01115     case CSeq_loc::e_Empty:
01116         return 0;
01117     case CSeq_loc::e_Whole:
01118         return x_CalcBioseqLength(seq_loc.GetWhole());
01119     case CSeq_loc::e_Int:
01120         return seq_loc.GetInt().GetLength();
01121     case CSeq_loc::e_Pnt:
01122         return 1;
01123     case CSeq_loc::e_Packed_int:
01124         return x_CalcBioseqLength(seq_loc.GetPacked_int());
01125     case CSeq_loc::e_Packed_pnt:
01126         return seq_loc.GetPacked_pnt().GetPoints().size();
01127     case CSeq_loc::e_Mix:
01128         return x_CalcBioseqLength(seq_loc.GetMix());
01129     case CSeq_loc::e_Equiv:
01130         return x_CalcBioseqLength(seq_loc.GetEquiv());
01131     default:
01132         NCBI_THROW(CObjMgrException, eOtherError,
01133                    "CBioseq_Info::x_CalcBioseqLength: "
01134                    "failed: bad Seq-loc type");
01135     }
01136 }
01137 
01138 
01139 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CSeq_loc_mix& seq_mix) const
01140 {
01141     TSeqPos ret = 0;
01142     ITERATE ( CSeq_loc_mix::Tdata, it, seq_mix.Get() ) {
01143         ret += x_CalcBioseqLength(**it);
01144     }
01145     return ret;
01146 }
01147 
01148 
01149 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CSeq_loc_equiv& seq_equiv) const
01150 {
01151     TSeqPos ret = 0;
01152     ITERATE ( CSeq_loc_equiv::Tdata, it, seq_equiv.Get() ) {
01153         ret += x_CalcBioseqLength(**it);
01154     }
01155     return ret;
01156 }
01157 
01158 
01159 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CSeg_ext& seg_ext) const
01160 {
01161     TSeqPos ret = 0;
01162     ITERATE ( CSeg_ext::Tdata, it, seg_ext.Get() ) {
01163         ret += x_CalcBioseqLength(**it);
01164     }
01165     return ret;
01166 }
01167 
01168 
01169 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CDelta_ext& delta) const
01170 {
01171     TSeqPos ret = 0;
01172     ITERATE ( CDelta_ext::Tdata, it, delta.Get() ) {
01173         ret += x_CalcBioseqLength(**it);
01174     }
01175     return ret;
01176 }
01177 
01178 
01179 TSeqPos CBioseq_Info::x_CalcBioseqLength(const CDelta_seq& delta_seq) const
01180 {
01181     switch ( delta_seq.Which() ) {
01182     case CDelta_seq::e_Loc:
01183         return x_CalcBioseqLength(delta_seq.GetLoc());
01184     case CDelta_seq::e_Literal:
01185         return delta_seq.GetLiteral().GetLength();
01186     default:
01187         NCBI_THROW(CObjMgrException, eOtherError,
01188                    "CBioseq_Info::x_CalcBioseqLength: "
01189                    "failed: bad Delta-seq type");
01190     }
01191 }
01192 
01193 
01194 string CBioseq_Info::IdString(void) const
01195 {
01196     CNcbiOstrstream os;
01197     ITERATE ( TId, it, m_Id ) {
01198         if ( it != m_Id.begin() )
01199             os << " | ";
01200         os << it->AsString();
01201     }
01202     return CNcbiOstrstreamToString(os);
01203 }
01204 
01205 
01206 void CBioseq_Info::x_AttachMap(CSeqMap& seq_map)
01207 {
01208     CFastMutexGuard guard(m_SeqMap_Mtx);
01209     if ( m_SeqMap || seq_map.m_Bioseq ) {
01210         NCBI_THROW(CObjMgrException, eAddDataError,
01211                      "CBioseq_Info::AttachMap: bioseq already has SeqMap");
01212     }
01213     m_SeqMap.Reset(&seq_map);
01214     seq_map.m_Bioseq = this;
01215 }
01216 
01217 
01218 const CSeqMap& CBioseq_Info::GetSeqMap(void) const
01219 {
01220     const CSeqMap* ret = m_SeqMap.GetPointer();
01221     if ( !ret ) {
01222         CFastMutexGuard guard(m_SeqMap_Mtx);
01223         ret = m_SeqMap.GetPointer();
01224         if ( !ret ) {
01225             m_SeqMap = CSeqMap::CreateSeqMapForBioseq(*m_Object);
01226             m_SeqMap->m_Bioseq = const_cast<CBioseq_Info*>(this);
01227             ret = m_SeqMap.GetPointer();
01228             _ASSERT(ret);
01229         }
01230     }
01231     return *ret;
01232 }
01233 
01234 
01235 int CBioseq_Info::GetTaxId(void) const
01236 {
01237     const COrg_ref* org_ref = 0;
01238     if ( const CSeqdesc* desc = x_SearchFirstDesc(1<<CSeqdesc::e_Source) ) {
01239         org_ref = &desc->GetSource().GetOrg();
01240     }
01241     else if ( const CSeqdesc* desc = x_SearchFirstDesc(1<<CSeqdesc::e_Org) ) {
01242         org_ref = &desc->GetOrg();
01243     }
01244     else {
01245         return 0;
01246     }
01247     try {
01248         return org_ref->GetTaxId();
01249     }
01250     catch ( CException& /*ignored*/ ) {
01251         return 0;
01252     }
01253 }
01254 
01255 
01256 END_SCOPE(objects)
01257 END_NCBI_SCOPE
Modified on Thu Jul 24 19:35:53 2014 by modify_doxy.py rev. 426318