tse_info.cpp

来自「ncbi源码」· C++ 代码 · 共 928 行 · 第 1/2 页

CPP
928
字号
/* * =========================================================================== * PRODUCTION $Log: tse_info.cpp,v $ * PRODUCTION Revision 1000.4  2004/06/01 19:24:36  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.44 * PRODUCTION * =========================================================================== *//*  $Id: tse_info.cpp,v 1000.4 2004/06/01 19:24:36 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:*   TSE info -- entry for data source seq-id to TSE map**/#include <ncbi_pch.hpp>#include <objmgr/impl/tse_info.hpp>#include <objmgr/impl/annot_type_index.hpp>#include <objmgr/impl/tse_chunk_info.hpp>#include <objmgr/impl/bioseq_info.hpp>#include <objmgr/impl/annot_object.hpp>#include <objmgr/impl/seq_annot_info.hpp>#include <objmgr/impl/snp_annot_info.hpp>#include <objmgr/impl/data_source.hpp>#include <objmgr/impl/handle_range.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objmgr/objmgr_exception.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)SIdAnnotObjs::SIdAnnotObjs(void){}SIdAnnotObjs::~SIdAnnotObjs(void){}SIdAnnotObjs::SIdAnnotObjs(const SIdAnnotObjs& _DEBUG_ARG(objs)){    _ASSERT(objs.m_AnnotSet.empty());    _ASSERT(objs.m_SNPSet.empty());}////////////////////////////////////////////////////////////////////////  CTSE_Info::////    General information and indexes for top level seq-entries//CTSE_Info::CTSE_Info(CSeq_entry& entry,                     bool dead,                     const CObject* blob_id)    : m_DataSource(0),      m_Dead(dead),      m_Blob_ID(blob_id){    entry.Parentize();    x_SetObject(entry);    x_TSEAttach(*this);}CTSE_Info::CTSE_Info(const CTSE_Info& info)    : TParent(info),      m_DataSource(0),      m_Dead(false),      m_Name(info.m_Name){    x_TSEAttach(*this);}CTSE_Info::~CTSE_Info(void){}void CTSE_Info::SetBlobId(const CObject* blob_id){    m_Blob_ID.Reset(blob_id);}void CTSE_Info::SetName(const CAnnotName& name){    m_Name = name;}bool CTSE_Info::HasAnnot(const CAnnotName& name) const{    _ASSERT(!x_DirtyAnnotIndex());    return m_NamedAnnotObjs.find(name) != m_NamedAnnotObjs.end();}bool CTSE_Info::HasNamedAnnot(const string& name) const{    return HasAnnot(CAnnotName(name));}bool CTSE_Info::HasUnnamedAnnot(void) const{    return HasAnnot(CAnnotName());}CConstRef<CSeq_entry> CTSE_Info::GetCompleteTSE(void) const{    return GetCompleteSeq_entry();}CConstRef<CSeq_entry> CTSE_Info::GetTSECore(void) const{    return GetSeq_entryCore();}void CTSE_Info::x_DSAttachContents(CDataSource& ds){    _ASSERT(!m_DataSource);    m_DataSource = &ds;    TParent::x_DSAttachContents(ds);    ITERATE ( TBioseqs, it, m_Bioseqs ) {        ds.x_IndexSeqTSE(it->first, this);    }    ds.x_IndexAnnotTSEs(this);}void CTSE_Info::x_DSDetachContents(CDataSource& ds){    _ASSERT(m_DataSource == &ds);    ITERATE ( TBioseqs, it, m_Bioseqs ) {        ds.x_UnindexSeqTSE(it->first, this);    }    ds.x_UnindexAnnotTSEs(this);    TParent::x_DSDetachContents(ds);    m_DataSource = 0;}void CTSE_Info::x_DSMapObject(CConstRef<TObject> obj, CDataSource& ds){    ds.x_Map(obj, this);    TParent::x_DSMapObject(obj, ds);}void CTSE_Info::x_DSUnmapObject(CConstRef<TObject> obj, CDataSource& ds){    ds.x_Unmap(obj, this);    TParent::x_DSUnmapObject(obj, ds);}inlinevoid CTSE_Info::x_IndexSeqTSE(const CSeq_id_Handle& id){    if ( HasDataSource() ) {        GetDataSource().x_IndexSeqTSE(id, this);    }}inlinevoid CTSE_Info::x_UnindexSeqTSE(const CSeq_id_Handle& id){    if ( HasDataSource() ) {        GetDataSource().x_UnindexSeqTSE(id, this);    }}void CTSE_Info::x_IndexAnnotTSE(const CAnnotName& name,                                const CSeq_id_Handle& id){    TSeqIdToNames::iterator iter = m_SeqIdToNames.lower_bound(id);    if ( iter == m_SeqIdToNames.end() || iter->first != id ) {        iter = m_SeqIdToNames.insert(iter,                                     TSeqIdToNames::value_type(id, TNames()));        if ( HasDataSource() ) {            GetDataSource().x_IndexAnnotTSE(id, this);        }    }    _VERIFY(iter->second.insert(name).second);}void CTSE_Info::x_UnindexAnnotTSE(const CAnnotName& name,                                  const CSeq_id_Handle& id){    TSeqIdToNames::iterator iter = m_SeqIdToNames.lower_bound(id);    _ASSERT(iter != m_SeqIdToNames.end() && iter->first == id);    _VERIFY(iter->second.erase(name) == 1);    if ( iter->second.empty() ) {        m_SeqIdToNames.erase(iter);        if ( HasDataSource() ) {            GetDataSource().x_UnindexAnnotTSE(id, this);        }    }}CConstRef<CBioseq_Info> CTSE_Info::FindBioseq(const CSeq_id_Handle& id) const{    CConstRef<CBioseq_Info> ret;    //CFastMutexGuard guard(m_BioseqsLock);    TBioseqs::const_iterator it = m_Bioseqs.find(id);    if ( it != m_Bioseqs.end() ) {        ret = it->second;    }    return ret;}bool CTSE_Info::ContainsSeqid(const CSeq_id_Handle& id) const{    //CFastMutexGuard guard(m_BioseqsLock);    return m_Bioseqs.find(id) != m_Bioseqs.end();}void CTSE_Info::x_SetBioseqId(const CSeq_id_Handle& key,                              CBioseq_Info* info){    //CFastMutexGuard guard(m_BioseqsLock);    pair<TBioseqs::iterator, bool> ins =        m_Bioseqs.insert(TBioseqs::value_type(key, info));    if ( ins.second ) {        // register this TSE in data source as containing the sequence        x_IndexSeqTSE(key);    }    else {        // No duplicate bioseqs in the same TSE        NCBI_THROW(CObjMgrException, eAddDataError,                   " duplicate Bioseq id '"+key.AsString()+"' present in"+                   "\n  seq1: " + ins.first->second->IdString() +                   "\n  seq2: " + info->IdString());    }}void CTSE_Info::x_ResetBioseqId(const CSeq_id_Handle& key,                                CBioseq_Info* _DEBUG_ARG(info)){    //CFastMutexGuard guard(m_BioseqsLock);    TBioseqs::iterator iter = m_Bioseqs.lower_bound(key);    if ( iter != m_Bioseqs.end() && iter->first == key ) {        _ASSERT(iter->second == info);        m_Bioseqs.erase(iter);        x_UnindexSeqTSE(key);    }}void CTSE_Info::x_SetBioseq_setId(int key,                                  CBioseq_set_Info* info){    //CFastMutexGuard guard(m_BioseqsLock);    pair<TBioseq_sets::iterator, bool> ins =        m_Bioseq_sets.insert(TBioseq_sets::value_type(key, info));    if ( ins.second ) {        // everything is fine    }    else {        // No duplicate bioseqs in the same TSE        NCBI_THROW(CObjMgrException, eAddDataError,                   " duplicate Bioseq_set id '"+NStr::IntToString(key));    }}void CTSE_Info::x_ResetBioseq_setId(int key,                                    CBioseq_set_Info* _DEBUG_ARG(info)){    //CFastMutexGuard guard(m_BioseqsLock);    TBioseq_sets::iterator iter = m_Bioseq_sets.lower_bound(key);    if ( iter != m_Bioseq_sets.end() && iter->first == key ) {        _ASSERT(iter->second == info);        m_Bioseq_sets.erase(iter);    }}void CTSE_Info::x_SetDirtyAnnotIndexNoParent(void){    if ( HasDataSource() ) {        GetDataSource().x_SetDirtyAnnotIndex(*this);    }}void CTSE_Info::x_ResetDirtyAnnotIndexNoParent(void){    if ( HasDataSource() ) {        GetDataSource().x_ResetDirtyAnnotIndex(*this);    }}void CTSE_Info::UpdateAnnotIndex(void) const{    const_cast<CTSE_Info*>(this)->UpdateAnnotIndex();    _ASSERT(!x_DirtyAnnotIndex());}void CTSE_Info::UpdateAnnotIndex(const CTSE_Info_Object& object) const{    const_cast<CTSE_Info*>(this)->        UpdateAnnotIndex(const_cast<CTSE_Info_Object&>(object));    _ASSERT(!object.x_DirtyAnnotIndex());}void CTSE_Info::UpdateAnnotIndex(void){    UpdateAnnotIndex(*this);}void CTSE_Info::UpdateAnnotIndex(CTSE_Info_Object& object){    _ASSERT(&object.GetTSE_Info() == this);    CTSE_Info::TAnnotWriteLockGuard guard(m_AnnotObjsLock);    NON_CONST_ITERATE ( TChunks, it, m_Chunks ) {        it->second->x_UpdateAnnotIndex(*this);    }    object.x_UpdateAnnotIndex(*this);    _ASSERT(!object.x_DirtyAnnotIndex());}CRef<CTSE_Chunk_Info> CTSE_Info::GetNotLoadedChunk(void){    NON_CONST_ITERATE ( TChunks, it, m_Chunks ) {        if ( it->second->NotLoaded() ) {            return it->second;        }    }    return CRef<CTSE_Chunk_Info>();}void CTSE_Info::LoadAllChunks(void){    NON_CONST_ITERATE ( TChunks, it, m_Chunks ) {        it->second->Load();    }}CTSE_Info::TAnnotObjs& CTSE_Info::x_SetAnnotObjs(const CAnnotName& name){    TNamedAnnotObjs::iterator iter = m_NamedAnnotObjs.lower_bound(name);    if ( iter == m_NamedAnnotObjs.end() || iter->first != name ) {        typedef TNamedAnnotObjs::value_type value_type;        iter = m_NamedAnnotObjs.insert(iter, value_type(name, TAnnotObjs()));    }    return iter->second;}void CTSE_Info::x_RemoveAnnotObjs(const CAnnotName& name){    m_NamedAnnotObjs.erase(name);}const CTSE_Info::TAnnotObjs*CTSE_Info::x_GetAnnotObjs(const CAnnotName& name) const{    TNamedAnnotObjs::const_iterator iter = m_NamedAnnotObjs.lower_bound(name);    if ( iter == m_NamedAnnotObjs.end() || iter->first != name ) {        return 0;    }    return &iter->second;}const CTSE_Info::TAnnotObjs*CTSE_Info::x_GetUnnamedAnnotObjs(void) const{    TNamedAnnotObjs::const_iterator iter = m_NamedAnnotObjs.begin();    if ( iter == m_NamedAnnotObjs.end() || iter->first.IsNamed() ) {        return 0;    }    return &iter->second;}SIdAnnotObjs& CTSE_Info::x_SetIdObjects(TAnnotObjs& objs,                                        const CAnnotName& name,                                        const CSeq_id_Handle& id){    // repeat for more generic types of selector    TAnnotObjs::iterator it = objs.lower_bound(id);    if ( it == objs.end() || it->first != id ) {        // new id        it = objs.insert(it, TAnnotObjs::value_type(id, SIdAnnotObjs()));        x_IndexAnnotTSE(name, id);    }    _ASSERT(it != objs.end() && it->first == id);    return it->second;}SIdAnnotObjs& CTSE_Info::x_SetIdObjects(const CAnnotName& name,                                        const CSeq_id_Handle& id){    return x_SetIdObjects(x_SetAnnotObjs(name), name, id);}const SIdAnnotObjs* CTSE_Info::x_GetIdObjects(const TAnnotObjs& objs,                                              const CSeq_id_Handle& idh) const{    TAnnotObjs::const_iterator it = objs.lower_bound(idh);    if ( it == objs.end() || it->first != idh ) {        return 0;    }    return &it->second;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?