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

Go to the SVN repository for this file.

1 #ifndef ANNOT_OBJECT__HPP
2 #define ANNOT_OBJECT__HPP
3 
4 /* $Id: annot_object.hpp 89284 2020-03-16 13:17:32Z gouriano $
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, Michael Kimelman, Eugene Vasilchenko
30 *
31 * File Description:
32 * Annotation object wrapper
33 *
34 */
35 
36 #include <corelib/ncbiobj.hpp>
37 
43 
45 
46 #include <serial/serialbase.hpp> // for CUnionBuffer
47 
48 #include <vector>
49 
52 
53 class CDataSource;
54 class CHandleRangeMap;
55 class CMasterSeqSegments;
56 struct SAnnotTypeSelector;
57 class CSeq_align;
58 class CSeq_graph;
59 class CSeq_feat;
60 class CSeq_entry;
61 class CSeq_entry_Info;
62 class CSeq_annot;
63 class CSeq_annot_Info;
64 class CTSE_Info;
65 class CTSE_Chunk_Info;
66 
68 {
69  bool IsSingle(void) const
70  {
71  return m_Handle;
72  }
73  void SetMultiple(size_t from, size_t to)
74  {
75  m_Handle.Reset();
76  m_Range.SetFrom(TSeqPos(from));
78  }
79  size_t begin(void) const
80  {
81  _ASSERT(!IsSingle());
82  return size_t(m_Range.GetFrom());
83  }
84  size_t end(void) const
85  {
86  _ASSERT(!IsSingle());
87  return size_t(m_Range.GetToOpen());
88  }
89  void Reset()
90  {
91  m_Handle.Reset();
92  m_Range.SetFrom(0);
93  m_Range.SetToOpen(0);
94  }
97 };
98 
99 // General Seq-annot object
101 {
102 public:
111  typedef Int4 TIndex;
112 
113  CAnnotObject_Info(void);
115  TFtable::iterator iter);
117  TAlign::iterator iter);
119  TGraph::iterator iter);
121  TLocs::iterator iter);
123  TFtable& cont, const CSeq_feat& obj);
125  TAlign& cont, const CSeq_align& obj);
127  TGraph& cont, const CSeq_graph& obj);
129  TLocs& cont, const CSeq_loc& obj);
131  const SAnnotTypeSelector& type);
133  const SAnnotTypeSelector& sel);
134 
136 #ifdef NCBI_NON_POD_TYPE_STL_ITERATORS
138  CAnnotObject_Info& operator=(const CAnnotObject_Info& info);
139 #endif
140 
141  // state check
142  bool IsEmpty(void) const;
143  bool IsRemoved(void) const; // same as empty
144  bool IsRegular(void) const;
145  bool IsChunkStub(void) const;
146 
147  // reset to empty state
148  void Reset(void);
149 
150  // Get Seq-annot, containing the element
151  const CSeq_annot_Info& GetSeq_annot_Info(void) const;
152  CSeq_annot_Info& GetSeq_annot_Info(void);
153 
154  // Get Seq-entry, containing the annotation
155  const CSeq_entry_Info& GetSeq_entry_Info(void) const;
156 
157  // Get top level Seq-entry, containing the annotation
158  const CTSE_Info& GetTSE_Info(void) const;
159  CTSE_Info& GetTSE_Info(void);
160 
161  // Get CDataSource object
162  CDataSource& GetDataSource(void) const;
163 
164  // Get index of this annotation within CSeq_annot_Info
165  TIndex GetAnnotIndex(void) const;
166 
167  const SAnnotTypeSelector& GetTypeSelector(void) const;
168  TAnnotType Which(void) const;
169  TAnnotType GetAnnotType(void) const;
170  TFeatType GetFeatType(void) const;
171  TFeatSubtype GetFeatSubtype(void) const;
172 
173  CConstRef<CObject> GetObject(void) const;
174  const CObject* GetObjectPointer(void) const;
175 
176  bool IsFeat(void) const;
177  const CSeq_feat& GetFeat(void) const;
178  const CSeq_feat* GetFeatFast(void) const; // unchecked & unsafe
179 
180  bool IsAlign(void) const;
181  const CSeq_align& GetAlign(void) const;
182  const CSeq_align* GetAlignFast(void) const;
183 
184  bool IsGraph(void) const;
185  const CSeq_graph& GetGraph(void) const;
186  const CSeq_graph* GetGraphFast(void) const; // unchecked & unsafe
187 
188  typedef pair<size_t, size_t> TIndexRange;
189  typedef vector<TIndexRange> TTypeIndexSet;
190 
191  bool IsLocs(void) const;
192  const CSeq_loc& GetLocs(void) const;
193  void GetLocsTypes(TTypeIndexSet& idx_set) const;
194 
195  void GetMaps(vector<CHandleRangeMap>& hrmaps,
196  const CMasterSeqSegments* master = 0) const;
197 
198  // split support
199  const CTSE_Chunk_Info& GetChunk_Info(void) const;
200 
201  void x_SetObject(const CSeq_feat& new_obj);
202  void x_SetObject(const CSeq_align& new_obj);
203  void x_SetObject(const CSeq_graph& new_obj);
204 
205  const TFtable::iterator& x_GetFeatIter(void) const;
206  const TAlign::iterator& x_GetAlignIter(void) const;
207  const TGraph::iterator& x_GetGraphIter(void) const;
208  const TLocs::iterator& x_GetLocsIter(void) const;
209 
210  void x_MoveToBack(TFtable& cont);
211 
212  static void x_ProcessAlign(vector<CHandleRangeMap>& hrmaps,
213  const CSeq_align& align,
214  const CMasterSeqSegments* master);
215  static void x_ProcessFeat(vector<CHandleRangeMap>& hrmaps,
216  const CSeq_feat& feat,
217  const CMasterSeqSegments* master);
218  static void x_ProcessGraph(vector<CHandleRangeMap>& hrmaps,
219  const CSeq_graph& graph,
220  const CMasterSeqSegments* master);
221 
222  bool HasSingleKey(void) const
223  {
224  return m_Key.IsSingle();
225  }
226  const SAnnotObject_Key& GetKey(void) const
227  {
228  _ASSERT(m_Key.IsSingle());
229  return m_Key;
230  }
231  size_t GetKeysBegin(void) const
232  {
233  return m_Key.begin();
234  }
235  size_t GetKeysEnd(void) const
236  {
237  return m_Key.end();
238  }
240  {
241  _ASSERT(key.IsSingle());
242  m_Key = key;
243  }
244  void SetKeys(size_t begin, size_t end)
245  {
246  m_Key.SetMultiple(begin, end);
247  }
248  void ResetKey(void)
249  {
250  m_Key.Reset();
251  }
252 
253 private:
254  friend class CSeq_annot_Info;
255 
256  // Constructors used by CAnnotTypes_CI only to create fake annotations
257  // for sequence segments. The annot object points to the seq-annot
258  // containing the original annotation object.
259 
260  void x_Locs_AddFeatSubtype(int ftype,
261  int subtype,
262  TTypeIndexSet& idx_set) const;
263 
264  // Special values for m_ObjectIndex
265  // regular indexes start from 0 so all special values are negative
266  enum {
267  eEmpty = -1,
268  eChunkStub = -2
269  };
270 
271  // Possible states:
272  // 0. empty
273  // all fields are null
274  // m_ObjectIndex == eEmpty
275  // m_Iter.m_RawPtr == 0
276  // A. regular annotation (feat, align, graph):
277  // m_Seq_annot_Info points to containing Seq-annot
278  // m_Type contains type of the annotation
279  // m_ObjectIndex contains index of CAnnotObject_Info within CSeq_annot_Info
280  // m_ObjectIndex >= 0
281  // m_Iter.m_(Feat|Align|Graph) contains iterator in CSeq_annot's container
282  // m_Iter.m_RawPtr != 0
283  // B. Seq-locs type of annotation
284  // m_Seq_annot_Info points to containing Seq-annot
285  // m_Type == e_Locs
286  // m_ObjectIndex contains index of CAnnotObject_Info within CSeq_annot_Info
287  // m_ObjectIndex >= 0
288  // m_Iter.m_Locs contains iterator in CSeq_annot's container
289  // m_Iter.m_RawPtr != 0
290  // C. Split chunk annotation info:
291  // m_Seq_annot_Info == 0
292  // m_Type contains type of split annotations
293  // m_ObjectIndex == eChunkStub
294  // m_Iter.m_RawPtr == 0
295  // D. Removed regular annotation:
296  // same as empty
297  // m_ObjectIndex == eEmpty
298  // m_Iter.m_RawPtr == 0
299 
300  CSeq_annot_Info* m_Seq_annot_Info; // owner Seq-annot
301  union {
302  const void* m_RawPtr;
308  } m_Iter;
310  SAnnotTypeSelector m_Type; // annot type
311  SAnnotObject_Key m_Key; // single key or range of keys
312 };
313 
314 
315 /////////////////////////////////////////////////////////////////////
316 //
317 // Inline methods
318 //
319 /////////////////////////////////////////////////////////////////////
320 
321 
322 inline
324  : m_Seq_annot_Info(0),
325  m_ObjectIndex(eEmpty)
326 {
327  m_Iter.m_RawPtr = 0;
328 }
329 
330 
331 inline
333 {
334  return m_Type;
335 }
336 
337 
338 inline
340 {
341  return GetTypeSelector().GetAnnotType();
342 }
343 
344 
345 inline
347 {
348  return GetTypeSelector().GetAnnotType();
349 }
350 
351 
352 inline
354 {
355  return GetTypeSelector().GetFeatType();
356 }
357 
358 
359 inline
361 {
362  return GetTypeSelector().GetFeatSubtype();
363 }
364 
365 
366 inline
368 {
369  return m_ObjectIndex == eEmpty;
370 }
371 
372 
373 inline
375 {
376  return m_ObjectIndex == eEmpty;
377 }
378 
379 
380 inline
382 {
383  return m_ObjectIndex >= 0 && m_Iter.m_RawPtr;
384 }
385 
386 
387 inline
389 {
390  return m_ObjectIndex == eChunkStub;
391 }
392 
393 
394 inline
396 {
397  return m_ObjectIndex;
398 }
399 
400 
401 inline
403 {
404  return Which() == C_Data::e_Ftable;
405 }
406 
407 
408 inline
410 {
411  return Which() == C_Data::e_Align;
412 }
413 
414 
415 inline
417 {
418  return Which() == C_Data::e_Graph;
419 }
420 
421 
422 inline
424 {
425  return Which() == C_Data::e_Locs;
426 }
427 
428 
429 inline
430 const CSeq_annot::C_Data::TFtable::iterator&
432 {
433  _ASSERT(IsFeat() && IsRegular() && m_Iter.m_RawPtr);
434  return *m_Iter.m_Feat;
435 }
436 
437 
438 inline
439 const CSeq_annot::C_Data::TAlign::iterator&
441 {
442  _ASSERT(IsAlign() && IsRegular() && m_Iter.m_RawPtr);
443  return *m_Iter.m_Align;
444 }
445 
446 
447 inline
448 const CSeq_annot::C_Data::TGraph::iterator&
450 {
451  _ASSERT(IsGraph() && IsRegular() && m_Iter.m_RawPtr);
452  return *m_Iter.m_Graph;
453 }
454 
455 
456 inline
457 const CSeq_annot::C_Data::TLocs::iterator&
459 {
460  _ASSERT(IsLocs() && IsRegular() && m_Iter.m_RawPtr);
461  return *m_Iter.m_Locs;
462 }
463 
464 
465 inline
467 {
468  return *x_GetFeatIter();
469 }
470 
471 
472 inline
474 {
475  return *x_GetAlignIter();
476 }
477 
478 
479 inline
481 {
482  return *x_GetGraphIter();
483 }
484 
485 
486 inline
488 {
489  return *GetFeatFast();
490 }
491 
492 
493 inline
495 {
496  return *GetAlignFast();
497 }
498 
499 
500 inline
502 {
503  return *GetGraphFast();
504 }
505 
506 
507 inline
509 {
510  return **x_GetLocsIter();
511 }
512 
513 
514 inline
516 {
517  _ASSERT(IsChunkStub() && m_Iter.m_Chunk && !m_Seq_annot_Info);
518  return *m_Iter.m_Chunk;
519 }
520 
521 
522 inline
524 {
526  return *m_Seq_annot_Info;
527 }
528 
529 
530 inline
532 {
534  return *m_Seq_annot_Info;
535 }
536 
537 
540 
541 #endif // ANNOT_OBJECT__HPP
User-defined methods of the data storage class.
@ eEmpty
no filtering at all.
CSeqFeatData::ESubtype TFeatSubtype
const TFtable::iterator & x_GetFeatIter(void) const
TAnnotType Which(void) const
union CAnnotObject_Info::@747 m_Iter
const CTSE_Chunk_Info & GetChunk_Info(void) const
const CSeq_loc & GetLocs(void) const
bool IsAlign(void) const
CUnionBuffer< TFtable::iterator > m_Feat
const CSeq_align * GetAlignFast(void) const
const CSeq_annot_Info & GetSeq_annot_Info(void) const
CTSE_Chunk_Info * m_Chunk
SAnnotObject_Key m_Key
const TLocs::iterator & x_GetLocsIter(void) const
const TGraph::iterator & x_GetGraphIter(void) const
const CSeq_graph & GetGraph(void) const
bool IsRegular(void) const
vector< TIndexRange > TTypeIndexSet
CUnionBuffer< TLocs::iterator > m_Locs
CUnionBuffer< TGraph::iterator > m_Graph
bool IsEmpty(void) const
const CSeq_feat * GetFeatFast(void) const
C_Data::TGraph TGraph
TFeatSubtype GetFeatSubtype(void) const
bool IsLocs(void) const
size_t GetKeysBegin(void) const
TIndex GetAnnotIndex(void) const
CSeq_annot_Info * m_Seq_annot_Info
const CSeq_feat & GetFeat(void) const
bool IsGraph(void) const
CSeqFeatData::E_Choice TFeatType
C_Data::TAlign TAlign
void SetKeys(size_t begin, size_t end)
C_Data::TLocs TLocs
const SAnnotTypeSelector & GetTypeSelector(void) const
TFeatType GetFeatType(void) const
void SetKey(const SAnnotObject_Key &key)
SAnnotTypeSelector m_Type
const TAlign::iterator & x_GetAlignIter(void) const
bool IsChunkStub(void) const
pair< size_t, size_t > TIndexRange
TAnnotType GetAnnotType(void) const
C_Data::TFtable TFtable
const SAnnotObject_Key & GetKey(void) const
C_Data::E_Choice TAnnotType
const void * m_RawPtr
bool HasSingleKey(void) const
bool IsFeat(void) const
const CSeq_align & GetAlign(void) const
CUnionBuffer< TAlign::iterator > m_Align
bool IsRemoved(void) const
const CSeq_graph * GetGraphFast(void) const
size_t GetKeysEnd(void) const
CSeq_annot::C_Data C_Data
CObject –.
Definition: ncbiobj.hpp:180
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
objects::CSeqFeatData::ESubtype GetFeatSubtype(const string &feat_type)
Definition: macro_util.cpp:350
void Reset(void)
Reset the handle (remove seq-id reference)
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
TThisType & SetToOpen(position_type toOpen)
Definition: range.hpp:175
position_type GetToOpen(void) const
Definition: range.hpp:138
#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
#define NCBI_XOBJMGR_EXPORT
Definition: ncbi_export.h:1307
void SetFrom(TFrom value)
Assign a value to From data member.
Definition: Range_.hpp:231
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
E_Choice
Choice variants.
list< CRef< CSeq_graph > > TGraph
Definition: Seq_annot_.hpp:195
list< CRef< CSeq_align > > TAlign
Definition: Seq_annot_.hpp:194
E_Choice
Choice variants.
Definition: Seq_annot_.hpp:131
list< CRef< CSeq_loc > > TLocs
Definition: Seq_annot_.hpp:197
list< CRef< CSeq_feat > > TFtable
Definition: Seq_annot_.hpp:193
@ e_Locs
used for communication between tools
Definition: Seq_annot_.hpp:137
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::KEY key
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
size_t end(void) const
CSeq_id_Handle m_Handle
size_t begin(void) const
void SetMultiple(size_t from, size_t to)
CRange< TSeqPos > m_Range
bool IsSingle(void) const
TFeatSubtype GetFeatSubtype(void) const
TAnnotType GetAnnotType(void) const
TFeatType GetFeatType(void) const
Definition: type.c:6
#define _ASSERT
Modified on Sun Apr 14 05:29:24 2024 by modify_doxy.py rev. 669887