📄 data_source.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: data_source.hpp,v $ * PRODUCTION Revision 1000.2 2004/04/16 16:59:58 gouriano * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.74 * PRODUCTION * =========================================================================== */#ifndef OBJECTS_OBJMGR_IMPL___DATA_SOURCE__HPP#define OBJECTS_OBJMGR_IMPL___DATA_SOURCE__HPP/* $Id: data_source.hpp,v 1000.2 2004/04/16 16:59:58 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, Michael Kimelman, Eugene Vasilchenko** File Description:* Data source for object manager**/#include <objmgr/impl/tse_info.hpp>#include <objmgr/seq_id_mapper.hpp>#include <objmgr/scope.hpp>#include <objmgr/data_loader.hpp>#include <corelib/ncbimtx.hpp>#include <set>#include <map>#include <list>#include <vector>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)// objectsclass CDelta_seq;class CDelta_ext;class CSeq_interval;class CSeq_data;class CSeq_entry;class CSeq_annot;class CBioseq;class CBioseq_set;// infosclass CTSE_Info;class CSeq_entry_Info;class CSeq_annot_Info;class CBioseq_Info;// othersclass CBioseq_Handle;class CPrefetchToken_Impl;class CPrefetchThread;class CTSE_LockingSetLock;class NCBI_XOBJMGR_EXPORT CTSE_LockingSet{public: CTSE_LockingSet(void); CTSE_LockingSet(const CTSE_LockingSet&); ~CTSE_LockingSet(void); CTSE_LockingSet& operator=(const CTSE_LockingSet&); typedef set<CTSE_Info*> TTSESet; typedef TTSESet::iterator iterator; typedef TTSESet::const_iterator const_iterator; bool insert(CTSE_Info* tse); bool erase(CTSE_Info* tse); const_iterator begin(void) const { return m_TSE_set.begin(); } const_iterator end(void) const { return m_TSE_set.end(); } bool empty(void) const { return m_TSE_set.empty(); } friend class CTSE_LockingSetLock;private: bool x_Locked(void) const { return m_LockCount != 0; } void x_Lock(void); void x_Unlock(void); DECLARE_CLASS_STATIC_FAST_MUTEX(sm_Mutex); int m_LockCount; TTSESet m_TSE_set;};class NCBI_XOBJMGR_EXPORT CTSE_LockingSetLock{public: CTSE_LockingSetLock(void) : m_TSE_set(0) { } CTSE_LockingSetLock(CTSE_LockingSet& tse_set) : m_TSE_set(&tse_set) { x_Lock(); } CTSE_LockingSetLock(const CTSE_LockingSetLock& lock) : m_TSE_set(lock.m_TSE_set) { x_Lock(); } ~CTSE_LockingSetLock(void) { x_Unlock(); } CTSE_LockingSetLock& operator=(const CTSE_LockingSetLock& lock) { x_Lock(lock.m_TSE_set); return *this; } void Lock(CTSE_LockingSet& lock) { x_Lock(&lock); } void Unlock(void) { x_Lock(0); }private: void x_Lock(void) { if ( m_TSE_set ) { m_TSE_set->x_Lock(); } } void x_Unlock(void) { if ( m_TSE_set ) { m_TSE_set->x_Unlock(); } } void x_Lock(CTSE_LockingSet* lock) { if ( m_TSE_set != lock ) { x_Unlock(); m_TSE_set = lock; x_Lock(); } } CTSE_LockingSet* m_TSE_set;};class NCBI_XOBJMGR_EXPORT CDataSource : public CObject{public: /// 'ctors CDataSource(CDataLoader& loader, CObjectManager& objmgr); CDataSource(CSeq_entry& entry, CObjectManager& objmgr); virtual ~CDataSource(void); /// Register new TSE (Top Level Seq-entry) typedef set<TTSE_Lock> TTSE_LockSet; CRef<CTSE_Info> AddTSE(CSeq_entry& se, bool dead = false, const CObject* blob_id = 0); void AddTSE(CRef<CTSE_Info> tse); // Modification methods. /// Add new sub-entry to "parent". CRef<CSeq_entry_Info> AttachEntry(CBioseq_set_Info& parent, CSeq_entry& entry, int index = -1); void RemoveEntry(CSeq_entry_Info& entry); /// Add annotations to a Seq-entry. CRef<CSeq_annot_Info> AttachAnnot(CSeq_entry_Info& parent, const CSeq_annot& annot); CRef<CSeq_annot_Info> AttachAnnot(CBioseq_Base_Info& parent, const CSeq_annot& annot); // Remove/replace seq-annot from the given entry void RemoveAnnot(CSeq_annot_Info& annot); CRef<CSeq_annot_Info> ReplaceAnnot(CSeq_annot_Info& old_annot, const CSeq_annot& new_annot); /// Get TSE info by seq-id handle. This should also get the list of all /// seq-ids for all bioseqs and the list of seq-ids used in annotations. TTSE_Lock GetBlobById(const CSeq_id_Handle& idh); /// Get Bioseq info by Seq-Id. /// Return "NULL" handle if the Bioseq cannot be resolved. CConstRef<CBioseq_Info> GetBioseq_Info(const CSeqMatch_Info& info); // Remove TSE from the datasource, update indexes void DropAllTSEs(void); bool DropTSE(CTSE_Info& info); // Contains (or can load) any entries? bool IsEmpty(void) const; CDataLoader* GetDataLoader(void) const; CConstRef<CSeq_entry> GetTopEntry(void); CConstRef<CTSE_Info> GetTopEntry_Info(void); // Internal typedefs typedef CTSE_Info::TRange TRange; typedef CTSE_Info::TRangeMap TRangeMap; typedef map<CSeq_id_Handle, CTSE_LockingSet> TTSEMap; typedef map<CConstRef<CSeq_entry>, CTSE_Info*> TTSE_InfoMap; typedef map<CConstRef<CSeq_entry>, CSeq_entry_Info*> TSeq_entry_InfoMap; typedef map<CConstRef<CSeq_annot>, CSeq_annot_Info*> TSeq_annot_InfoMap; typedef map<CConstRef<CBioseq>, CBioseq_Info*> TBioseq_InfoMap; //typedef map<const CObject*, CAnnotObject_Info* > TAnnotObject_InfoMap; typedef set< CRef<CTSE_Info> > TTSE_Set; typedef int TPriority; typedef set<CTSE_Info*> TDirtyAnnot_TSEs; void UpdateAnnotIndex(void); void UpdateAnnotIndex(const CSeq_entry_Info& entry_info); void UpdateAnnotIndex(const CSeq_annot_Info& annot_info); void GetSynonyms(const CSeq_id_Handle& id, set<CSeq_id_Handle>& syns); void GetTSESetWithAnnots(const CSeq_id_Handle& idh, TTSE_LockSet& tse_set); // Fill the set with bioseq handles for all sequences from a given TSE. // Return empty tse lock if the entry was not found or is not a TSE. // "filter" may be used to select a particular sequence type. // "level" may be used to select bioseqs from given levels only. // Used to initialize bioseq iterators. typedef vector< CConstRef<CBioseq_Info> > TBioseq_InfoSet; typedef int TBioseqLevelFlag; void GetBioseqs(const CSeq_entry_Info& entry, TBioseq_InfoSet& bioseqs, CSeq_inst::EMol filter, TBioseqLevelFlag level); CSeqMatch_Info BestResolve(CSeq_id_Handle idh); CSeqMatch_Info HistoryResolve(CSeq_id_Handle idh, const TTSE_LockSet& tse_set); // Select the best of the two bioseqs if possible (e.g. dead vs live). CSeqMatch_Info* ResolveConflict(const CSeq_id_Handle& id, CSeqMatch_Info& info1, CSeqMatch_Info& info2); bool IsLive(const CTSE_Info& tse); //bool IsSynonym(const CSeq_id_Handle& h1, const CSeq_id_Handle& h2) const; string GetName(void) const; TPriority GetDefaultPriority(void) const; void SetDefaultPriority(TPriority priority); virtual void DebugDump(CDebugDumpContext ddc, unsigned int depth) const; CConstRef<CTSE_Info> FindTSEInfo(const CSeq_entry& entry); CConstRef<CSeq_entry_Info> FindSeq_entry_Info(const CSeq_entry& entry); CConstRef<CSeq_annot_Info> FindSeq_annot_Info(const CSeq_annot& annot); CConstRef<CBioseq_Info> FindBioseq_Info(const CBioseq& bioseq); virtual void Prefetch(CPrefetchToken_Impl& token);private: friend class CAnnotTypes_CI; // using mutex etc. friend class CBioseq_Handle; // using mutex friend class CGBDataLoader; // friend class CTSE_Info; friend class CSeq_entry_Info; friend class CSeq_annot_Info; friend class CBioseq_Info; friend class CPrefetchToken_Impl; // attach, detach, index & unindex methods // TSE void x_DropTSE(CTSE_Info& info); void x_Map(CConstRef<CSeq_entry> obj, CTSE_Info* info); void x_Unmap(CConstRef<CSeq_entry> obj, CTSE_Info* info); void x_Map(CConstRef<CSeq_entry> obj, CSeq_entry_Info* info); void x_Unmap(CConstRef<CSeq_entry> obj, CSeq_entry_Info* info); void x_Map(CConstRef<CSeq_annot> obj, CSeq_annot_Info* info); void x_Unmap(CConstRef<CSeq_annot> obj, CSeq_annot_Info* info); void x_Map(CConstRef<CBioseq> obj, CBioseq_Info* info); void x_Unmap(CConstRef<CBioseq> obj, CBioseq_Info* info); //void x_AttachMap(CSeq_entry_Info& bioseq, CSeqMap& seqmap); // lookup Xxx_Info objects // TSE CConstRef<CTSE_Info> x_FindTSE_Info(const CSeq_entry& tse); // Seq-entry CConstRef<CSeq_entry_Info> x_FindSeq_entry_Info(const CSeq_entry& entry); // Bioseq CConstRef<CBioseq_Info> x_FindBioseq_Info(const CBioseq& seq); // Seq-annot CConstRef<CSeq_annot_Info> x_FindSeq_annot_Info(const CSeq_annot& annot); // Find the seq-entry with best bioseq for the seq-id handle. // The best bioseq is the bioseq from the live TSE or from the // only one TSE containing the ID (no matter live or dead). // If no matches were found, return 0. TTSE_Lock x_FindBestTSE(const CSeq_id_Handle& handle) const; void x_SetDirtyAnnotIndex(CTSE_Info& tse); void x_ResetDirtyAnnotIndex(CTSE_Info& tse); void x_IndexTSE(TTSEMap& tse_map, const CSeq_id_Handle& id, CTSE_Info* tse_info); void x_UnindexTSE(TTSEMap& tse_map, const CSeq_id_Handle& id, CTSE_Info* tse_info); void x_IndexSeqTSE(const CSeq_id_Handle& idh, CTSE_Info* tse_info); void x_UnindexSeqTSE(const CSeq_id_Handle& idh, CTSE_Info* tse_info); void x_IndexAnnotTSE(const CSeq_id_Handle& idh, CTSE_Info* tse_info); void x_UnindexAnnotTSE(const CSeq_id_Handle& idh, CTSE_Info* tse_info); void x_IndexAnnotTSEs(CTSE_Info* tse_info); void x_UnindexAnnotTSEs(CTSE_Info* tse_info); // Global cleanup -- search for unlocked TSEs and drop them. void x_CleanupUnusedEntries(void); // Change live/dead status of a TSE void x_UpdateTSEStatus(CTSE_Info& tse, bool dead); void x_CollectBioseqs(const CSeq_entry_Info& info, TBioseq_InfoSet& bioseqs, CSeq_inst::EMol filter, TBioseqLevelFlag level);#if 0 typedef CRWLock TMainLock;#else typedef CMutex TMainLock;#endif#if 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -