NCBI C++ ToolKit
seq_id_mapper.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef OBJECTS_OBJMGR___SEQ_ID_MAPPER__HPP
2 #define OBJECTS_OBJMGR___SEQ_ID_MAPPER__HPP
3 
4 /* $Id: seq_id_mapper.hpp 60405 2013-11-20 15:19:38Z vasilche $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Aleksey Grichenko, Eugene Vasilchenko
30 *
31 * File Description:
32 * Seq-id mapper for Object Manager
33 *
34 */
35 
36 #include <corelib/ncbiobj.hpp>
37 #include <corelib/ncbi_limits.hpp>
38 #include <corelib/ncbimtx.hpp>
39 #include <corelib/ncbicntr.hpp>
40 
42 
44 
45 #include <set>
46 
49 
50 /** @addtogroup OBJECTS_Seqid
51  *
52  * @{
53  */
54 
55 
56 class CSeq_id;
57 class CSeq_id_Which_Tree;
58 
59 
60 /////////////////////////////////////////////////////////////////////
61 ///
62 /// CSeq_id_Mapper::
63 ///
64 /// Allows fast convertions between CSeq_id and CSeq_id_Handle,
65 /// including searching for multiple matches for a given seq-id.
66 ///
67 
68 
70 
71 
73 {
74 public:
75  static CRef<CSeq_id_Mapper> GetInstance(void);
76 
77  virtual ~CSeq_id_Mapper(void);
78 
79  /// Get seq-id handle. Create new handle if not found and
80  /// do_not_create is false. Get only the exactly equal seq-id handle.
81  CSeq_id_Handle GetGiHandle(TGi gi);
82  CSeq_id_Handle GetHandle(const CSeq_id& id, bool do_not_create = false);
83 
84  /// Get the list of matching handles, do not create new handles
85  bool HaveMatchingHandles(const CSeq_id_Handle& id);
86  void GetMatchingHandles(const CSeq_id_Handle& id,
87  TSeq_id_HandleSet& h_set);
88  bool HaveReverseMatch(const CSeq_id_Handle& id);
89  void GetReverseMatchingHandles(const CSeq_id_Handle& id,
90  TSeq_id_HandleSet& h_set);
91  bool HaveMatchingHandles(const CSeq_id_Handle& id,
92  EAllowWeakMatch allow_weak_match);
93  void GetMatchingHandles(const CSeq_id_Handle& id,
94  TSeq_id_HandleSet& h_set,
95  EAllowWeakMatch allow_weak_match);
96  bool HaveReverseMatch(const CSeq_id_Handle& id,
97  EAllowWeakMatch allow_weak_match);
98  void GetReverseMatchingHandles(const CSeq_id_Handle& id,
99  TSeq_id_HandleSet& h_set,
100  EAllowWeakMatch allow_weak_match);
101  /// Get the list of string-matching handles, do not create new handles
102  void GetMatchingHandlesStr(string sid,
103  TSeq_id_HandleSet& h_set);
104 
105  /// Get seq-id for the given handle
106  static CConstRef<CSeq_id> GetSeq_id(const CSeq_id_Handle& handle);
107 
109  eCountTotalBytes, // no output, only return estimated memory
110  eDumpTotalBytes, // print and return estimated memory
111  eDumpStatistics, // print estimated memory for various Seq-id types
112  eDumpAllIds // print all mapped Seq-ids
113  };
114  size_t Dump(CNcbiOstream& out,
115  EDumpDetails details = eDumpTotalBytes) const;
116 
117 private:
118  CSeq_id_Mapper(void);
119 
120  friend class CSeq_id_Handle;
121  friend class CSeq_id_Info;
122 
123  // References to each handle must be tracked to re-use their values
124  // Each CSeq_id_Handle locks itself in the constructor and
125  // releases in the destructor.
126 
127 
128  bool x_Match(const CSeq_id_Handle& h1, const CSeq_id_Handle& h2);
129  bool x_IsBetter(const CSeq_id_Handle& h1, const CSeq_id_Handle& h2);
130 
131 
133  CSeq_id_Which_Tree& x_GetTree(const CSeq_id& id);
134  CSeq_id_Which_Tree& x_GetTree(const CSeq_id_Handle& idh);
135 
136  // Hide copy constructor and operator
139 
140  // Some map entries may point to the same subtree (e.g. gb, dbj, emb).
141  typedef vector<CRef<CSeq_id_Which_Tree> > TTrees;
142 
145 };
146 
147 
148 /////////////////////////////////////////////////////////////////////////////
149 //
150 // Inline methods
151 //
152 /////////////////////////////////////////////////////////////////////////////
153 
154 
155 inline
157 {
158  return h.GetSeqId();
159 }
160 
161 
162 inline
164 {
165  _ASSERT(size_t(type) < m_Trees.size());
166  return *m_Trees[type];
167 }
168 
169 
170 inline
172 {
173  return x_GetTree(seq_id.Which());
174 }
175 
176 /* @} */
177 
178 
181 
182 #endif /* OBJECTS_OBJMGR___SEQ_ID_MAPPER__HPP */
CMutex –.
Definition: ncbimtx.hpp:749
CObject –.
Definition: ncbiobj.hpp:180
Definition: set.hpp:45
std::ofstream out("events_result.xml")
main entry point for tests
static int type
Definition: getdata.c:31
CConstRef< CSeq_id > GetSeqId(void) const
CSeq_id_Mapper(const CSeq_id_Mapper &)
static CConstRef< CSeq_id > GetSeq_id(const CSeq_id_Handle &handle)
Get seq-id for the given handle.
EAllowWeakMatch
CSeq_id_Which_Tree & x_GetTree(CSeq_id::E_Choice type)
set< CSeq_id_Handle > TSeq_id_HandleSet
CSeq_id_Mapper::
vector< CRef< CSeq_id_Which_Tree > > TTrees
CObject & operator=(const CObject &src) THROWS_NONE
Assignment operator.
Definition: ncbiobj.hpp:482
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_SEQ_EXPORT
Definition: ncbi_export.h:825
E_Choice Which(void) const
Which variant is currently selected.
Definition: Seq_id_.hpp:746
E_Choice
Choice variants.
Definition: Seq_id_.hpp:93
Multi-threading – mutexes; rw-locks; semaphore.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
void Dump(CSplitCacheApp *app, const C &obj, ESerialDataFormat format, const string &key, const string &suffix=kEmptyStr)
Definition: type.c:6
#define _ASSERT
Modified on Fri Jan 05 07:21:43 2024 by modify_doxy.py rev. 669887