scope_impl.cpp

来自「ncbi源码」· C++ 代码 · 共 1,802 行 · 第 1/4 页

CPP
1,802
字号
/* * =========================================================================== * PRODUCTION $Log: scope_impl.cpp,v $ * PRODUCTION Revision 1000.3  2004/06/01 19:23:39  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15 * PRODUCTION * =========================================================================== *//*  $Id: scope_impl.cpp,v 1000.3 2004/06/01 19:23:39 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.** ===========================================================================** Authors:*           Andrei Gourianov*           Aleksey Grichenko*           Michael Kimelman*           Denis Vakatov*           Eugene Vasilchenko** File Description:*           Scope is top-level object available to a client.*           Its purpose is to define a scope of visibility and reference*           resolution and provide access to the bio sequence data**/#include <ncbi_pch.hpp>#include <objmgr/scope.hpp>#include <objmgr/bioseq_handle.hpp>#include <objmgr/seq_entry_handle.hpp>#include <objmgr/seq_annot_handle.hpp>#include <objmgr/bioseq_set_handle.hpp>#include <objmgr/object_manager.hpp>#include <objmgr/seqmatch_info.hpp>#include <objmgr/objmgr_exception.hpp>#include <objmgr/impl/data_source.hpp>#include <objmgr/impl/tse_info.hpp>#include <objmgr/impl/scope_info.hpp>#include <objmgr/impl/bioseq_info.hpp>#include <objmgr/impl/bioseq_set_info.hpp>#include <objmgr/impl/seq_annot_info.hpp>#include <objmgr/impl/priority.hpp>#include <objmgr/impl/synonyms.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/Delta_seq.hpp>#include <objects/seq/Seq_literal.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Textseq_id.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objmgr/impl/scope_impl.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)/////////////////////////////////////////////////////////////////////////////////  CScope_Impl///////////////////////////////////////////////////////////////////////////////CScope_Impl::CScope_Impl(CObjectManager& objmgr)    : m_HeapScope(0), m_pObjMgr(0){    TWriteLockGuard guard(m_Scope_Conf_RWLock);    x_AttachToOM(objmgr);}CScope_Impl::~CScope_Impl(void){    TWriteLockGuard guard(m_Scope_Conf_RWLock);    x_DetachFromOM();}void CScope_Impl::x_AttachToOM(CObjectManager& objmgr){    if ( m_pObjMgr != &objmgr ) {        x_DetachFromOM();                m_pObjMgr = &objmgr;        m_pObjMgr->RegisterScope(*this);    }}void CScope_Impl::x_DetachFromOM(void){    if ( m_pObjMgr ) {        // Drop and release all TSEs        x_ResetHistory();        m_pObjMgr->RevokeScope(*this);        for (CPriority_I it(m_setDataSrc); it; ++it) {            _ASSERT(it->m_DataSource);            m_pObjMgr->ReleaseDataSource(it->m_DataSource);            _ASSERT(!it->m_DataSource);        }        m_pObjMgr = 0;    }}void CScope_Impl::AddDefaults(TPriority priority){    CObjectManager::TDataSourcesLock ds_set;    m_pObjMgr->AcquireDefaultDataSources(ds_set);    TWriteLockGuard guard(m_Scope_Conf_RWLock);    NON_CONST_ITERATE( CObjectManager::TDataSourcesLock, it, ds_set ) {        m_setDataSrc.Insert(const_cast<CDataSource&>(**it),            (priority == kPriority_NotSet) ?            (*it)->GetDefaultPriority() : priority);    }    x_ClearCacheOnNewData();}void CScope_Impl::AddDataLoader (const string& loader_name,                                 TPriority priority){    CRef<CDataSource> ds = m_pObjMgr->AcquireDataLoader(loader_name);    TWriteLockGuard guard(m_Scope_Conf_RWLock);    m_setDataSrc.Insert(*ds, (priority == kPriority_NotSet) ?        ds->GetDefaultPriority() : priority);    x_ClearCacheOnNewData();}CSeq_entry_Handle CScope_Impl::AddTopLevelSeqEntry(CSeq_entry& top_entry,                                                   TPriority priority){    CRef<CDataSource> ds = m_pObjMgr->AcquireTopLevelSeqEntry(top_entry);    TWriteLockGuard guard(m_Scope_Conf_RWLock);    m_setDataSrc.Insert(*ds, (priority == kPriority_NotSet) ?        ds->GetDefaultPriority() : priority);    x_ClearCacheOnNewData();    return CSeq_entry_Handle(*m_HeapScope, *x_GetSeq_entry_Info(top_entry));}void CScope_Impl::AddScope(CScope_Impl& scope,                           TPriority priority){    TReadLockGuard src_guard(scope.m_Scope_Conf_RWLock);    CPriorityTree tree(scope.m_setDataSrc);    src_guard.Release();        TWriteLockGuard guard(m_Scope_Conf_RWLock);    m_setDataSrc.Insert(tree, priority);    x_ClearCacheOnNewData();}CBioseq_Handle CScope_Impl::AddBioseq(CBioseq& bioseq,                                      TPriority priority){    CRef<CSeq_entry> entry(new CSeq_entry);    entry->SetSeq(bioseq);    return AddTopLevelSeqEntry(*entry, priority).GetSeq();}CSeq_entry_EditHandleCScope_Impl::x_AttachEntry(const CBioseq_set_EditHandle& seqset,                           CRef<CSeq_entry_Info> entry,                           int index){    _ASSERT(seqset && bool(entry));    TWriteLockGuard guard(m_Scope_Conf_RWLock);    //seqset.GetDataSource().AttachEntry(seqset, entry, index);    seqset.x_GetInfo().AddEntry(entry, index);    x_ClearCacheOnNewData();    return CSeq_entry_EditHandle(*m_HeapScope, *entry);}CBioseq_EditHandleCScope_Impl::x_SelectSeq(const CSeq_entry_EditHandle& entry,                         CRef<CBioseq_Info> bioseq){    _ASSERT(entry && bool(bioseq));    _ASSERT(entry.Which() == CSeq_entry::e_not_set);    TWriteLockGuard guard(m_Scope_Conf_RWLock);    // duplicate bioseq info    entry.x_GetInfo().SelectSeq(*bioseq);    x_ClearCacheOnNewData();    return GetBioseqHandle(*bioseq).GetEditHandle();}CBioseq_set_EditHandleCScope_Impl::x_SelectSet(const CSeq_entry_EditHandle& entry,                         CRef<CBioseq_set_Info> seqset){    _ASSERT(entry && bool(seqset));    _ASSERT(entry.Which() == CSeq_entry::e_not_set);    TWriteLockGuard guard(m_Scope_Conf_RWLock);    // duplicate bioseq info    entry.x_GetInfo().SelectSet(*seqset);    x_ClearCacheOnNewData();    return CBioseq_set_EditHandle(*m_HeapScope, *seqset);}CSeq_annot_EditHandleCScope_Impl::x_AttachAnnot(const CSeq_entry_EditHandle& entry,                           CRef<CSeq_annot_Info> annot){    _ASSERT(entry && bool(annot));    TWriteLockGuard guard(m_Scope_Conf_RWLock);    entry.x_GetInfo().AddAnnot(annot);    x_ClearAnnotCache();    return CSeq_annot_EditHandle(*m_HeapScope, *annot);}CSeq_entry_EditHandleCScope_Impl::AttachEntry(const CBioseq_set_EditHandle& seqset,                         CSeq_entry& entry,                         int index){    return x_AttachEntry(seqset, Ref(new CSeq_entry_Info(entry)), index);}CSeq_entry_EditHandleCScope_Impl::CopyEntry(const CBioseq_set_EditHandle& seqset,                       const CSeq_entry_Handle& entry,                       int index){    return x_AttachEntry(seqset, Ref(new CSeq_entry_Info(entry.x_GetInfo())),                         index);}CSeq_entry_EditHandleCScope_Impl::TakeEntry(const CBioseq_set_EditHandle& seqset,                       const CSeq_entry_EditHandle& entry,                       int index){    CRef<CSeq_entry_Info> info(&entry.x_GetInfo());    entry.Remove();    return x_AttachEntry(seqset, info, index);}CBioseq_EditHandle CScope_Impl::SelectSeq(const CSeq_entry_EditHandle& entry,                                          CBioseq& seq){    return x_SelectSeq(entry, Ref(new CBioseq_Info(seq)));}CBioseq_EditHandle CScope_Impl::CopySeq(const CSeq_entry_EditHandle& entry,                                        const CBioseq_Handle& seq){    return x_SelectSeq(entry, Ref(new CBioseq_Info(seq.x_GetInfo())));}CBioseq_EditHandle CScope_Impl::TakeSeq(const CSeq_entry_EditHandle& entry,                                        const CBioseq_EditHandle& seq){    CRef<CBioseq_Info> info(&seq.x_GetInfo());    seq.Remove();    return x_SelectSeq(entry, info);}CBioseq_set_EditHandleCScope_Impl::SelectSet(const CSeq_entry_EditHandle& entry,                       CBioseq_set& seqset){    return x_SelectSet(entry, Ref(new CBioseq_set_Info(seqset)));}CBioseq_set_EditHandleCScope_Impl::CopySet(const CSeq_entry_EditHandle& entry,                     const CBioseq_set_Handle& seqset){    return x_SelectSet(entry, Ref(new CBioseq_set_Info(seqset.x_GetInfo())));}CBioseq_set_EditHandleCScope_Impl::TakeSet(const CSeq_entry_EditHandle& entry,                     const CBioseq_set_EditHandle& seqset){    CRef<CBioseq_set_Info> info(&seqset.x_GetInfo());    seqset.Remove();    return x_SelectSet(entry, info);}CSeq_annot_EditHandleCScope_Impl::AttachAnnot(const CSeq_entry_EditHandle& entry,                         const CSeq_annot& annot){    return x_AttachAnnot(entry, Ref(new CSeq_annot_Info(annot)));}CSeq_annot_EditHandleCScope_Impl::CopyAnnot(const CSeq_entry_EditHandle& entry,                       const CSeq_annot_Handle& annot){    return x_AttachAnnot(entry, Ref(new CSeq_annot_Info(annot.x_GetInfo())));}CSeq_annot_EditHandleCScope_Impl::TakeAnnot(const CSeq_entry_EditHandle& entry,                       const CSeq_annot_EditHandle& annot){    CRef<CSeq_annot_Info> info(&annot.x_GetInfo());    annot.Remove();    return x_AttachAnnot(entry, info);}void CScope_Impl::x_ClearCacheOnNewData(void){    // Clear unresolved bioseq handles    // Clear annot cache    if (!m_Seq_idMap.empty()) {        LOG_POST(Info <<            "CScope_Impl: -- "            "adding new data to a scope with non-empty cache "            "may cause the cached data to become inconsistent");    }    NON_CONST_ITERATE ( TSeq_idMap, it, m_Seq_idMap ) {        if ( it->second.m_Bioseq_Info &&             !it->second.m_Bioseq_Info->HasBioseq() ) {            it->second.m_Bioseq_Info->m_SynCache.Reset();            it->second.m_Bioseq_Info.Reset();        }        it->second.m_AllAnnotRef_Info.Reset();    }}void CScope_Impl::x_ClearAnnotCache(void){    // Clear annot cache    NON_CONST_ITERATE ( TSeq_idMap, it, m_Seq_idMap ) {        it->second.m_AllAnnotRef_Info.Reset();    }}void CScope_Impl::x_ClearCacheOnRemoveData(const CSeq_entry_Info& info){    if ( info.IsSeq() ) {        x_ClearCacheOnRemoveData(info.GetSeq());    }    else {        x_ClearCacheOnRemoveData(info.GetSet());    }}void CScope_Impl::x_ClearCacheOnRemoveData(const CBioseq_Info& seq){    // Clear bioseq from the scope cache    ITERATE ( CBioseq_Info::TId, si, seq.GetId() ) {        TSeq_idMap::iterator bs_id = m_Seq_idMap.find(*si);        if (bs_id != m_Seq_idMap.end()) {            if ( bs_id->second.m_Bioseq_Info ) {                // detaching from scope                bs_id->second.m_Bioseq_Info->m_ScopeInfo = 0;                // breaking the link                bs_id->second.m_Bioseq_Info->m_SynCache.Reset();            }            m_Seq_idMap.erase(bs_id);        }        m_BioseqMap.erase(&seq);    }}void CScope_Impl::x_ClearCacheOnRemoveData(const CBioseq_set_Info& seqset){    ITERATE( CBioseq_set_Info::TSeq_set, ei, seqset.GetSeq_set() ) {        x_ClearCacheOnRemoveData(**ei);    }}CSeq_entry_Handle CScope_Impl::GetSeq_entryHandle(const CSeq_entry& entry){    TReadLockGuard guard(m_Scope_Conf_RWLock);    return CSeq_entry_Handle(*m_HeapScope, *x_GetSeq_entry_Info(entry));}CSeq_annot_Handle CScope_Impl::GetSeq_annotHandle(const CSeq_annot& annot){    TReadLockGuard guard(m_Scope_Conf_RWLock);    return CSeq_annot_Handle(*m_HeapScope, *x_GetSeq_annot_Info(annot));}CBioseq_Handle CScope_Impl::GetBioseqHandle(const CBioseq& seq){    CBioseq_Handle ret;    {{        TReadLockGuard guard(m_Scope_Conf_RWLock);

⌨️ 快捷键说明

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