scope_impl.cpp

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

CPP
1,802
字号
        CConstRef<CBioseq_Info> info = x_GetBioseq_Info(seq);        ITERATE ( CBioseq_Info::TId, id, info->GetId() ) {            ret = x_GetBioseqHandleFromTSE(*id, info->GetTSE_Info());            if ( ret ) {                _ASSERT(ret.GetBioseqCore() == &seq);                break;            }        }    }}    return ret;}CConstRef<CTSE_Info>CScope_Impl::x_GetTSE_Info(const CSeq_entry& tse){    for (CPriority_I it(m_setDataSrc); it; ++it) {        CConstRef<CTSE_Info> info = it->GetDataSource().FindTSEInfo(tse);        if ( info ) {            {{                CFastMutexGuard guard(it->GetMutex());                it->AddTSE(*info);            }}            return info;        }    }    NCBI_THROW(CObjMgrException, eFindFailed,               "CScope_Impl::x_GetTSE_Info: entry is not attached");}CConstRef<CSeq_entry_Info>CScope_Impl::x_GetSeq_entry_Info(const CSeq_entry& entry){    for (CPriority_I it(m_setDataSrc); it; ++it) {        CConstRef<CSeq_entry_Info> info =            it->GetDataSource().FindSeq_entry_Info(entry);        if ( info ) {            {{                CFastMutexGuard guard(it->GetMutex());                it->AddTSE(info->GetTSE_Info());            }}            return info;        }    }    NCBI_THROW(CObjMgrException, eFindFailed,               "CScope_Impl::x_GetSeq_entry_Info: entry is not attached");}CConstRef<CSeq_annot_Info>CScope_Impl::x_GetSeq_annot_Info(const CSeq_annot& annot){    for (CPriority_I it(m_setDataSrc); it; ++it) {        CConstRef<CSeq_annot_Info> info =            it->GetDataSource().FindSeq_annot_Info(annot);        if ( info ) {            {{                CFastMutexGuard guard(it->GetMutex());                it->AddTSE(info->GetTSE_Info());            }}            return info;        }    }    NCBI_THROW(CObjMgrException, eFindFailed,               "CScope_Impl::x_GetSeq_annot_Info: annot is not attached");}CConstRef<CBioseq_Info>CScope_Impl::x_GetBioseq_Info(const CBioseq& bioseq){    for (CPriority_I it(m_setDataSrc); it; ++it) {        CConstRef<CBioseq_Info> info =            it->GetDataSource().FindBioseq_Info(bioseq);        if ( info ) {            {{                CFastMutexGuard guard(it->GetMutex());                it->AddTSE(info->GetTSE_Info());            }}            return info;        }    }    NCBI_THROW(CObjMgrException, eFindFailed,               "CScope_Impl::x_GetBioseq_Info: bioseq is not attached");}void CScope_Impl::RemoveAnnot(const CSeq_annot_EditHandle& annot){    TWriteLockGuard guard(m_Scope_Conf_RWLock);    CSeq_annot_Info& info = annot.x_GetInfo();    info.GetDataSource().RemoveAnnot(info);    x_ClearAnnotCache();}void CScope_Impl::SelectNone(const CSeq_entry_EditHandle& entry){    _ASSERT(entry);    TWriteLockGuard guard(m_Scope_Conf_RWLock);    CSeq_entry_Info& info = entry.x_GetInfo();    x_ClearAnnotCache();    switch ( info.Which() ) {    case CSeq_entry::e_Set:        x_ClearCacheOnRemoveData(info.GetSet());        break;    case CSeq_entry::e_Seq:        x_ClearCacheOnRemoveData(info.GetSeq());        break;    default:        break;    }    // duplicate bioseq info    info.Reset();}void CScope_Impl::RemoveEntry(const CSeq_entry_EditHandle& entry){    TWriteLockGuard guard(m_Scope_Conf_RWLock);    CSeq_entry_Info& info = entry.x_GetInfo();    x_ClearAnnotCache();    x_ClearCacheOnRemoveData(info);    if ( entry.GetParentEntry() ) {        info.GetDataSource().RemoveEntry(info);    }    else {        // top level entry        CDataSource_ScopeInfo* ds_info = 0;        for (CPriority_I it(m_setDataSrc); it; ++it) {            if ( &it->GetDataSource() == &info.GetDataSource() ) {                ds_info = &*it;                break;            }        }        if ( ds_info ) {            m_setDataSrc.Erase(*ds_info);        }        else {            // not found...            NCBI_THROW(CObjMgrException, eModifyDataError,                       "CScope::RemoveEntry(): cannot find data source");        }    }}void CScope_Impl::RemoveBioseq(const CBioseq_EditHandle& seq){    TWriteLockGuard guard(m_Scope_Conf_RWLock);    CBioseq_Info& info = seq.x_GetInfo();    x_ClearAnnotCache();    x_ClearCacheOnRemoveData(info);    info.GetParentSeq_entry_Info().Reset();}void CScope_Impl::RemoveBioseq_set(const CBioseq_set_EditHandle& seqset){    TWriteLockGuard guard(m_Scope_Conf_RWLock);    CBioseq_set_Info& info = seqset.x_GetInfo();    x_ClearAnnotCache();    x_ClearCacheOnRemoveData(info);    info.GetParentSeq_entry_Info().Reset();}CScope_Impl::TSeq_idMapValue&CScope_Impl::x_GetSeq_id_Info(const CSeq_id_Handle& id){    {{        TReadLockGuard guard(m_Seq_idMapLock);        TSeq_idMap::iterator it = m_Seq_idMap.lower_bound(id);        if ( it != m_Seq_idMap.end() && it->first == id )            return *it;    }}    {{        TWriteLockGuard guard(m_Seq_idMapLock);        return *m_Seq_idMap.insert(            TSeq_idMapValue(id, SSeq_id_ScopeInfo(m_HeapScope))).first;    }}}inlineCScope_Impl::TSeq_idMapValue&CScope_Impl::x_GetSeq_id_Info(const CBioseq_Handle& bh){    TSeq_idMapValue* info = bh.x_GetScopeInfo().m_ScopeInfo;    if ( info->first != bh.GetSeq_id_Handle() ) {        info = &x_GetSeq_id_Info(bh.GetSeq_id_Handle());    }    return *info;}CScope_Impl::TSeq_idMapValue*CScope_Impl::x_FindSeq_id_Info(const CSeq_id_Handle& id){    TReadLockGuard guard(m_Seq_idMapLock);    TSeq_idMap::iterator it = m_Seq_idMap.lower_bound(id);    if ( it != m_Seq_idMap.end() && it->first == id )        return &*it;    return 0;}CRef<CBioseq_ScopeInfo>CScope_Impl::x_InitBioseq_Info(TSeq_idMapValue& info, int get_flag){    if (get_flag != CScope::eGetBioseq_Resolved) {        // Resolve only if the flag allows        CInitGuard init(info.second.m_Bioseq_Info, m_MutexPool);        if ( init ) {            x_ResolveSeq_id(info, get_flag);        }    }    //_ASSERT(info.second.m_Bioseq_Info);    return info.second.m_Bioseq_Info;}bool CScope_Impl::x_InitBioseq_Info(TSeq_idMapValue& info,                                    CBioseq_ScopeInfo& bioseq_info){    {{        CInitGuard init(info.second.m_Bioseq_Info, m_MutexPool);        if ( init ) {            _ASSERT(!info.second.m_Bioseq_Info);            info.second.m_Bioseq_Info.Reset(&bioseq_info);            return true;        }    }}    return info.second.m_Bioseq_Info.GetPointerOrNull() == &bioseq_info;}CRef<CBioseq_ScopeInfo>CScope_Impl::x_GetBioseq_Info(const CSeq_id_Handle& id, int get_flag){    return x_InitBioseq_Info(x_GetSeq_id_Info(id), get_flag);}CRef<CBioseq_ScopeInfo>CScope_Impl::x_FindBioseq_Info(const CSeq_id_Handle& id, int get_flag){    CRef<CBioseq_ScopeInfo> ret;    TSeq_idMapValue* info = x_FindSeq_id_Info(id);    if ( info ) {        ret = x_InitBioseq_Info(*info, get_flag);    }    return ret;}CBioseq_Handle CScope_Impl::x_GetBioseqHandleFromTSE(const CSeq_id_Handle& id,                                                     const CTSE_Info& tse){    CBioseq_Handle ret;    TReadLockGuard rguard(m_Scope_Conf_RWLock);    CRef<CBioseq_ScopeInfo> info = x_FindBioseq_Info(id, CScope::eGetBioseq_Loaded);    if ( bool(info)  &&  info->HasBioseq() ) {        if ( &info->GetTSE_Info() == &tse ) {            ret.m_Bioseq_Info = info.GetPointer();        }    }    else {        // new bioseq - try to find it in source TSE        {{            // first try main id            CSeqMatch_Info match(id, tse);            CConstRef<CBioseq_Info> bioseq = match.GetBioseq_Info();            if ( bioseq ) {                _ASSERT(m_HeapScope);                CBioseq_Handle bh =                    GetBioseqHandle(id, CScope::eGetBioseq_Loaded);                if ( bh && &bh.x_GetInfo().GetTSE_Info() == &tse ) {                    ret = bh;                    return ret;                }            }        }}                CSeq_id_Mapper& mapper = CSeq_id_Mapper::GetSeq_id_Mapper();        if ( mapper.HaveMatchingHandles(id) ) {            // than try matching handles            TSeq_id_HandleSet hset;            mapper.GetMatchingHandles(id, hset);            ITERATE ( TSeq_id_HandleSet, hit, hset ) {                if ( *hit == id ) // already checked                    continue;                CSeqMatch_Info match(*hit, tse);                CConstRef<CBioseq_Info> bioseq = match.GetBioseq_Info();                if ( bioseq ) {                    _ASSERT(m_HeapScope);                    CBioseq_Handle bh = GetBioseqHandle(*hit,                        CScope::eGetBioseq_Loaded);                    if ( bh && &bh.x_GetInfo().GetTSE_Info() == &tse ) {                        ret = bh;                        break;                    }                }            }        }    }    ret.m_Seq_id = id;    ret.m_Scope.Set(m_HeapScope);    return ret;}CBioseq_Handle CScope_Impl::GetBioseqHandle(const CSeq_id_Handle& id,                                            int get_flag){    CBioseq_Handle ret;    if ( id )  {        {{            TReadLockGuard rguard(m_Scope_Conf_RWLock);            ret.m_Bioseq_Info = x_GetBioseq_Info(id, get_flag).GetPointer();        }}        if ( bool(ret.m_Bioseq_Info) && !ret.x_GetScopeInfo().HasBioseq() ) {            ret.m_Bioseq_Info.Reset();        }        ret.m_Seq_id = id;    }    ret.m_Scope.Set(m_HeapScope);    return ret;}CBioseq_EditHandle CScope_Impl::GetEditHandle(const CBioseq_Handle& h){    if ( !h ) {        NCBI_THROW(CObjMgrException, eInvalidHandle,                   "CScope::GetEditHandle: null handle");    }        if ( h.x_GetInfo().GetDataSource().GetDataLoader() ) {        NCBI_THROW(CObjMgrException, eNotImplemented,                   "CScope::GetEditHandle: detach is not implemented");    }        return CBioseq_EditHandle(h);}CSeq_entry_EditHandle CScope_Impl::GetEditHandle(const CSeq_entry_Handle& h){    if ( !h ) {        NCBI_THROW(CObjMgrException, eInvalidHandle,                   "CScope::GetEditHandle: null handle");    }        if ( h.x_GetInfo().GetDataSource().GetDataLoader() ) {        NCBI_THROW(CObjMgrException, eNotImplemented,                   "CScope::GetEditHandle: detach is not implemented");    }        return CSeq_entry_EditHandle(h);}CSeq_annot_EditHandle CScope_Impl::GetEditHandle(const CSeq_annot_Handle& h){    if ( !h ) {        NCBI_THROW(CObjMgrException, eInvalidHandle,                   "CScope::GetEditHandle: null handle");    }        if ( h.x_GetInfo().GetDataSource().GetDataLoader() ) {        NCBI_THROW(CObjMgrException, eNotImplemented,                   "CScope::GetEditHandle: detach is not implemented");    }        return CSeq_annot_EditHandle(h);}CBioseq_set_EditHandle CScope_Impl::GetEditHandle(const CBioseq_set_Handle& h){    if ( !h ) {        NCBI_THROW(CObjMgrException, eInvalidHandle,                   "CScope::GetEditHandle: null handle");    }        if ( h.x_GetInfo().GetDataSource().GetDataLoader() ) {        NCBI_THROW(CObjMgrException, eNotImplemented,                   "CScope::GetEditHandle: detach is not implemented");    }        return CBioseq_set_EditHandle(h);}CBioseq_Handle CScope_Impl::GetBioseqHandle(const CSeq_id& id, int get_flag){    return GetBioseqHandle(CSeq_id_Handle::GetHandle(id), get_flag);}CBioseq_HandleCScope_Impl::GetBioseqHandleFromTSE(const CSeq_id_Handle& id,                                    const CBioseq_Handle& bh){    CBioseq_Handle ret;    if ( bh ) {        ret = x_GetBioseqHandleFromTSE(id, bh.x_GetInfo().GetTSE_Info());    }    else {        ret.m_Seq_id = id;        ret.m_Scope.Set(m_HeapScope);    }    return ret;}CBioseq_HandleCScope_Impl::GetBioseqHandleFromTSE(const CSeq_id_Handle& id,                                    const CSeq_entry_Handle& seh){    CBioseq_Handle ret;    if ( seh ) {        ret = x_GetBioseqHandleFromTSE(id, seh.x_GetInfo().GetTSE_Info());    }    else {        ret.m_Seq_id = id;        ret.m_Scope.Set(m_HeapScope);    }    return ret;}CBioseq_HandleCScope_Impl::GetBioseqHandleFromTSE(const CSeq_id& id,                                    const CBioseq_Handle& bh){    return GetBioseqHandleFromTSE(CSeq_id_Handle::GetHandle(id), bh);}

⌨️ 快捷键说明

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