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

Go to the SVN repository for this file.

1 #ifndef GRAPH_CI__HPP
2 #define GRAPH_CI__HPP
3 
4 /* $Id: graph_ci.hpp 90176 2020-05-19 14:39:05Z 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, Michael Kimelman, Eugene Vasilchenko
30 *
31 * File Description:
32 * Object manager iterators
33 *
34 */
35 
41 #include <corelib/ncbistd.hpp>
43 
46 
47 class CAnnot_Collector;
48 class CAnnotObject_Ref;
49 
50 /** @addtogroup ObjectManagerIterators
51  *
52  * @{
53  */
54 
55 /////////////////////////////////////////////////////////////////////////////
56 ///
57 /// CMappedGraph --
58 ///
59 
61 {
62 public:
63  /// empty CMappedGraph
65  : m_GraphRef(0)
66  {
67  }
68 
69  /// Get original graph with unmapped location/product
70  const CSeq_graph& GetOriginalGraph(void) const
71  {
72  return m_GraphRef->GetGraph();
73  }
74 
75  /// Get containing annot handle
76  CSeq_annot_Handle GetAnnot(void) const;
77 
78  /// Get original graph handle
79  CSeq_graph_Handle GetSeq_graph_Handle(void) const;
80 
81  /// Check if it's the same graph
82  bool operator==(const CMappedGraph& graph) const
83  {
84  return GetAnnot() == graph.GetAnnot() &&
85  m_GraphRef->GetAnnotIndex() == graph.m_GraphRef->GetAnnotIndex();
86  }
87  bool operator!=(const CMappedGraph& graph) const
88  {
89  return !(*this == graph);
90  }
91  bool operator<(const CMappedGraph& graph) const
92  {
93  return (GetAnnot() < graph.GetAnnot()) ||
94  (GetAnnot() == graph.GetAnnot() &&
95  m_GraphRef->GetAnnotIndex() < graph.m_GraphRef->GetAnnotIndex());
96  }
97 
98  /// Graph mapped to the master sequence.
99  /// WARNING! The function is rather slow and should be used with care.
100  const CSeq_graph& GetMappedGraph(void) const
101  {
102  if ( !m_MappedGraph ) {
103  MakeMappedGraph();
104  }
105  return *m_MappedGraph;
106  }
107 
108  bool IsSetTitle(void) const
109  {
110  return GetOriginalGraph().IsSetTitle();
111  }
112  const string& GetTitle(void) const
113  {
114  return GetOriginalGraph().GetTitle();
115  }
116 
117  bool IsSetComment(void) const
118  {
119  return GetOriginalGraph().IsSetComment();
120  }
121  const string& GetComment(void) const
122  {
123  return GetOriginalGraph().GetComment();
124  }
125 
126  const CSeq_loc& GetLoc(void) const
127  {
128  if ( !m_MappedLoc ) {
129  MakeMappedLoc();
130  }
131  return *m_MappedLoc;
132  }
133 
134  bool IsSetTitle_x(void) const
135  {
136  return GetOriginalGraph().IsSetTitle_x();
137  }
138  const string& GetTitle_x(void) const
139  {
140  return GetOriginalGraph().GetTitle_x();
141  }
142 
143  bool IsSetTitle_y(void) const
144  {
145  return GetOriginalGraph().IsSetTitle_y();
146  }
147  const string& GetTitle_y(void) const
148  {
149  return GetOriginalGraph().GetTitle_y();
150  }
151 
152  bool IsSetComp(void) const
153  {
154  return GetOriginalGraph().IsSetComp();
155  }
156  TSeqPos GetComp(void) const
157  {
158  return GetOriginalGraph().GetComp();
159  }
160 
161  bool IsSetA(void) const
162  {
163  return GetOriginalGraph().IsSetA();
164  }
165  double GetA(void) const
166  {
167  return GetOriginalGraph().GetA();
168  }
169 
170  bool IsSetB(void) const
171  {
172  return GetOriginalGraph().IsSetB();
173  }
174  double GetB(void) const
175  {
176  return GetOriginalGraph().GetB();
177  }
178 
179  TSeqPos GetNumval(void) const
180  {
181  if ( m_MappedGraph ) {
182  return m_MappedGraph->GetNumval();
183  }
184  if ( !m_GraphRef->GetMappingInfo().IsMapped() ) {
185  return GetOriginalGraph().GetNumval();
186  }
187  TSeqPos numval = 0;
188  ITERATE(TGraphRanges, it, GetMappedGraphRanges()) {
189  numval += it->GetLength();
190  }
191  return numval;
192  }
193 
194  const CSeq_graph::C_Graph& GetGraph(void) const;
195 
198 
199  /// Get the range of graph data used in the mapped graph. The range is
200  /// provided in the sequence coordinates, to get array index divide
201  /// each value by 'comp'.
202  const TRange& GetMappedGraphTotalRange(void) const;
203  /// Get all mapped graph ranges. The ranges are provided in the sequence
204  /// coordinates, to get array index divide each value by 'comp'.
205  const TGraphRanges& GetMappedGraphRanges(void) const;
206 
207 private:
208  friend class CGraph_CI;
209  friend class CAnnot_CI;
210  friend class CAnnot_Collector;
211 
212  void Set(CAnnot_Collector& collector,
213  const CAnnotObject_Ref& annot_ref);
214  void Reset(void);
215 
216  void MakeMappedGraph(void) const;
217  void MakeMappedLoc(void) const;
218  void MakeMappedGraphData(CSeq_graph& dst) const;
219 
222 
225 };
226 
227 
228 /////////////////////////////////////////////////////////////////////////////
229 ///
230 /// CGraph_CI --
231 ///
232 
234 {
235 public:
236  /// Create an empty iterator
237  CGraph_CI(void);
238 
239  /// Create an iterator that enumerates CSeq_graph objects
240  /// related to the given bioseq
241  explicit
242  CGraph_CI(const CBioseq_Handle& bioseq);
243 
244  /// Create an iterator that enumerates CSeq_graph objects
245  /// related to the given bioseq
246  ///
247  /// @sa
248  /// SAnnotSelector
249  CGraph_CI(const CBioseq_Handle& bioseq,
250  const SAnnotSelector& sel);
251 
252  /// Create an iterator that enumerates CSeq_graph objects
253  /// related to the given bioseq
254  CGraph_CI(const CBioseq_Handle& bioseq,
255  const CRange<TSeqPos>& range,
256  ENa_strand strand = eNa_strand_unknown);
257 
258  /// Create an iterator that enumerates CSeq_graph objects
259  /// related to the given bioseq
260  ///
261  /// @sa
262  /// SAnnotSelector
263  CGraph_CI(const CBioseq_Handle& bioseq,
264  const CRange<TSeqPos>& range,
265  const SAnnotSelector& sel);
266 
267  /// Create an iterator that enumerates CSeq_graph objects
268  /// related to the given bioseq
269  ///
270  /// @sa
271  /// SAnnotSelector
272  CGraph_CI(const CBioseq_Handle& bioseq,
273  const CRange<TSeqPos>& range,
274  ENa_strand strand,
275  const SAnnotSelector& sel);
276 
277  /// Create an iterator that enumerates CSeq_graph objects
278  /// related to the given seq-loc
279  CGraph_CI(CScope& scope,
280  const CSeq_loc& loc);
281 
282  /// Create an iterator that enumerates CSeq_graph objects
283  /// related to the given seq-loc
284  ///
285  /// @sa
286  /// SAnnotSelector
287  CGraph_CI(CScope& scope,
288  const CSeq_loc& loc,
289  const SAnnotSelector& sel);
290 
291  /// Iterate all graphs from the seq-annot regardless of their location
292  explicit
293  CGraph_CI(const CSeq_annot_Handle& annot);
294 
295  /// Iterate all graphs from the seq-annot regardless of their location
296  ///
297  /// @sa
298  /// SAnnotSelector
299  CGraph_CI(const CSeq_annot_Handle& annot,
300  const SAnnotSelector& sel);
301 
302  /// Iterate all graphs from the seq-annot that annotate the location
303  CGraph_CI(const CSeq_loc& loc,
304  const CSeq_annot_Handle& annot);
305 
306  /// Iterate all graphs from the seq-annot that annotate the location
307  ///
308  /// @sa
309  /// SAnnotSelector
310  CGraph_CI(const CSeq_loc& loc,
311  const CSeq_annot_Handle& annot,
312  const SAnnotSelector& sel);
313 
314  /// Iterate all graphs from the seq-entry regardless of their location
315  explicit
316  CGraph_CI(const CSeq_entry_Handle& entry);
317 
318  /// Iterate all graphs from the seq-entry regardless of their location
319  ///
320  /// @sa
321  /// SAnnotSelector
322  CGraph_CI(const CSeq_entry_Handle& entry,
323  const SAnnotSelector& sel);
324 
325  CGraph_CI(const CGraph_CI& iter);
326  CGraph_CI& operator= (const CGraph_CI& iter);
327 
328  virtual ~CGraph_CI(void);
329 
330  CGraph_CI& operator++ (void);
331  CGraph_CI& operator-- (void);
332 
333  void Rewind(void);
334 
336 
337  const CGraph_CI& begin() const
338  {
339  return *this;
340  }
341  CGraph_CI end() const
342  {
343  return CGraph_CI(*this, at_end);
344  }
345  bool operator!=(const CGraph_CI& it) const
346  {
347  return CAnnotTypes_CI::operator!=(it);
348  }
349 
350  const CMappedGraph& operator* (void) const;
351  const CMappedGraph* operator-> (void) const;
352 private:
353  void x_Update(void);
354 
355  CGraph_CI operator++ (int);
357 
359  : CAnnotTypes_CI(it, at_end)
360  {
361  }
362 
363  CMappedGraph m_Graph; // current graph object returned by operator->()
364 };
365 
366 
367 inline
369 {
370 }
371 
372 
373 inline
375  : CAnnotTypes_CI(iter)
376 {
377  x_Update();
378 }
379 
380 
381 inline
383 {
384  Next();
385  x_Update();
386  return *this;
387 }
388 
389 inline
391 {
392  Prev();
393  x_Update();
394  return *this;
395 }
396 
397 
398 inline
400 {
402  x_Update();
403 }
404 
405 
406 inline
408 {
409  return m_Graph;
410 }
411 
412 
413 inline
415 {
416  return &m_Graph;
417 }
418 
419 
420 /* @} */
421 
422 
425 
426 #endif // GRAPH_CI__HPP
User-defined methods of the data storage class.
TAnnotIndex GetAnnotIndex(void) const
bool operator!=(const CAnnotTypes_CI &it) const
CAnnot_CI –.
Definition: annot_ci.hpp:59
CBioseq_Handle –.
CGraph_CI –.
Definition: graph_ci.hpp:234
CMappedGraph –.
Definition: graph_ci.hpp:61
CScope –.
Definition: scope.hpp:92
CSeq_annot_Handle –.
CSeq_entry_Handle –.
Include a standard set of the NCBI C++ Toolkit most basic headers.
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
CVect2< NCBI_PROMOTE(int,U) > operator*(int v1, const CVect2< U > &v2)
Definition: globals.hpp:371
bool IsValid(const CSeq_point &pt, CScope *scope)
Checks that point >= 0 and point < length of Bioseq.
vector< TRange > TGraphRanges
CGraph_CI & operator--(void)
Definition: graph_ci.hpp:390
const string & GetTitle_x(void) const
Definition: graph_ci.hpp:138
TSeqPos GetComp(void) const
Definition: graph_ci.hpp:156
const string & GetTitle(void) const
Definition: graph_ci.hpp:112
const CMappedGraph * operator->(void) const
Definition: graph_ci.hpp:414
CGraphRanges::TGraphRanges TGraphRanges
Definition: graph_ci.hpp:197
bool IsSetTitle(void) const
Definition: graph_ci.hpp:108
bool operator<(const CMappedGraph &graph) const
Definition: graph_ci.hpp:91
CSeq_annot_Handle GetAnnot(void) const
Get containing annot handle.
Definition: graph_ci.cpp:99
double GetB(void) const
Definition: graph_ci.hpp:174
const string & GetTitle_y(void) const
Definition: graph_ci.hpp:147
TSeqPos GetNumval(void) const
Definition: graph_ci.hpp:179
bool operator!=(const CMappedGraph &graph) const
Definition: graph_ci.hpp:87
CMappedGraph m_Graph
Definition: graph_ci.hpp:363
bool IsSetComp(void) const
Definition: graph_ci.hpp:152
CConstRef< CSeq_loc > m_MappedLoc
Definition: graph_ci.hpp:224
DECLARE_OPERATOR_BOOL(IsValid())
CGraphRanges::TRange TRange
Definition: graph_ci.hpp:196
double GetA(void) const
Definition: graph_ci.hpp:165
CRef< CAnnot_Collector > m_Collector
Definition: graph_ci.hpp:220
CMappedGraph()
empty CMappedGraph
Definition: graph_ci.hpp:64
void Rewind(void)
Definition: graph_ci.hpp:399
const CSeq_graph & GetMappedGraph(void) const
Graph mapped to the master sequence.
Definition: graph_ci.hpp:100
const CGraph_CI & begin() const
Definition: graph_ci.hpp:337
CGraph_CI & operator++(void)
Definition: graph_ci.hpp:382
bool IsSetB(void) const
Definition: graph_ci.hpp:170
CGraph_CI end() const
Definition: graph_ci.hpp:341
CGraph_CI(const CGraph_CI &it, EAtEnd)
Definition: graph_ci.hpp:358
void x_Update(void)
Definition: graph_ci.cpp:363
bool IsSetTitle_x(void) const
Definition: graph_ci.hpp:134
bool operator!=(const CGraph_CI &it) const
Definition: graph_ci.hpp:345
bool IsSetTitle_y(void) const
Definition: graph_ci.hpp:143
CGraph_CI(void)
Create an empty iterator.
Definition: graph_ci.hpp:368
const CMappedGraph & operator*(void) const
Definition: graph_ci.hpp:407
bool IsSetA(void) const
Definition: graph_ci.hpp:161
bool operator==(const CMappedGraph &graph) const
Check if it's the same graph.
Definition: graph_ci.hpp:82
CConstRef< CSeq_graph > m_MappedGraph
Definition: graph_ci.hpp:223
const CSeq_graph & GetOriginalGraph(void) const
Get original graph with unmapped location/product.
Definition: graph_ci.hpp:70
const CSeq_loc & GetLoc(void) const
Definition: graph_ci.hpp:126
bool IsSetComment(void) const
Definition: graph_ci.hpp:117
const string & GetComment(void) const
Definition: graph_ci.hpp:121
const CAnnotObject_Ref * m_GraphRef
Definition: graph_ci.hpp:221
#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
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
const TGraph & GetGraph(void) const
Get the Graph member data.
range(_Ty, _Ty) -> range< _Ty >
S & operator--(CNetRef< S > &r, int)
SAnnotSelector –.
Modified on Fri Sep 20 14:58:04 2024 by modify_doxy.py rev. 669887