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

Go to the SVN repository for this file.

1 /* $Id: graph_ci.cpp 90176 2020-05-19 14:39:05Z vasilche $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Aleksey Grichenko, Eugene Vasilchenko
27 *
28 * File Description:
29 * Object manager iterators
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <objmgr/graph_ci.hpp>
38 
41 
42 class CAnnotObject_Ref;
43 
44 
46  const CAnnotObject_Ref& annot_ref)
47 {
48  _ASSERT(annot_ref.IsGraph());
49  m_Collector.Reset(&collector);
50  m_GraphRef = &annot_ref;
53 }
54 
55 
57 {
60  m_GraphRef = 0;
62 }
63 
64 
66 {
70  CRef<CSeq_loc> created_loc;
71  if ( !m_Collector->m_CreatedMapped ) {
73  }
74  m_Collector->m_CreatedMapped->ReleaseRefsTo(0, &created_loc, 0, 0);
75  CRef<CSeq_point> created_pnt;
76  CRef<CSeq_interval> created_int;
78  created_pnt,
79  created_int,
80  0);
81  m_MappedLoc = created_loc;
82  m_Collector->m_CreatedMapped->ResetRefsFrom(0, &created_loc, 0, 0);
83  }
84  else if ( m_GraphRef->GetMappingInfo().IsMapped() ) {
86  }
87  else {
89  }
90 }
91 
92 
94 {
96 }
97 
98 
100 {
102 }
103 
104 
106 {
107  if ( m_GraphRef->GetMappingInfo().IsMapped() ) {
108  CSeq_loc& loc = const_cast<CSeq_loc&>(GetLoc());
109  CSeq_graph* tmp;
111  tmp->Assign(GetOriginalGraph());
113  tmp->SetLoc(loc);
114  }
115  else {
117  }
118 }
119 
120 
121 template<class TData> void CopyGraphData(const TData& src,
122  TData& dst,
123  TSeqPos from,
124  TSeqPos to)
125 {
126  _ASSERT(from < src.size() && to <= src.size());
127  dst.insert(dst.end(), src.begin() + from, src.begin() + to);
128 }
129 
130 
132 {
133  const TGraphRanges& ranges = GetMappedGraphRanges();
134  CSeq_graph::TGraph& dst_data = dst.SetGraph();
135  dst_data.Reset();
136  const CSeq_graph& src = GetOriginalGraph();
137  const CSeq_graph::TGraph& src_data = src.GetGraph();
138 
139  TSeqPos comp = (src.IsSetComp() && src.GetComp()) ? src.GetComp() : 1;
140  TSeqPos numval = 0;
141 
142  switch ( src_data.Which() ) {
144  dst_data.SetByte().SetMin(src_data.GetByte().GetMin());
145  dst_data.SetByte().SetMax(src_data.GetByte().GetMax());
146  dst_data.SetByte().SetAxis(src_data.GetByte().GetAxis());
147  dst_data.SetByte().SetValues();
148  ITERATE(TGraphRanges, it, ranges) {
149  TSeqPos from = it->GetFrom()/comp;
150  TSeqPos to = it->GetTo()/comp + 1;
151  CopyGraphData(src_data.GetByte().GetValues(),
152  dst_data.SetByte().SetValues(),
153  from, to);
154  numval += to - from;
155  }
156  break;
158  dst_data.SetInt().SetMin(src_data.GetInt().GetMin());
159  dst_data.SetInt().SetMax(src_data.GetInt().GetMax());
160  dst_data.SetInt().SetAxis(src_data.GetInt().GetAxis());
161  dst_data.SetInt().SetValues();
162  ITERATE(TGraphRanges, it, ranges) {
163  TSeqPos from = it->GetFrom()/comp;
164  TSeqPos to = it->GetTo()/comp + 1;
165  CopyGraphData(src_data.GetInt().GetValues(),
166  dst_data.SetInt().SetValues(),
167  from, to);
168  numval += to - from;
169  }
170  break;
172  dst_data.SetReal().SetMin(src_data.GetReal().GetMin());
173  dst_data.SetReal().SetMax(src_data.GetReal().GetMax());
174  dst_data.SetReal().SetAxis(src_data.GetReal().GetAxis());
175  dst_data.SetReal().SetValues();
176  ITERATE(TGraphRanges, it, ranges) {
177  TSeqPos from = it->GetFrom()/comp;
178  TSeqPos to = it->GetTo()/comp + 1;
179  CopyGraphData(src_data.GetReal().GetValues(),
180  dst_data.SetReal().SetValues(),
181  from, to);
182  numval += to - from;
183  }
184  break;
185  default:
186  break;
187  }
188  dst.SetNumval(numval);
189 }
190 
191 
193 {
194  if ( !m_GraphRef->GetMappingInfo().IsPartial() ) {
195  return GetOriginalGraph().GetGraph();
196  }
197  MakeMappedGraph();
198  return m_MappedGraph->GetGraph();
199 }
200 
201 
204 {
206  _ASSERT(rgs);
207  return rgs->GetTotalRange();
208 }
209 
210 
213 {
215  _ASSERT(rgs);
216  return rgs->GetRanges();
217 }
218 
219 
221  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph, scope, loc)
222 {
223  x_Update();
224 }
225 
226 
228  const SAnnotSelector& sel)
229  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph, scope, loc, &sel)
230 {
231  x_Update();
232 }
233 
234 
236  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph,
237  bioseq,
238  CRange<TSeqPos>::GetWhole(),
240 {
241  x_Update();
242 }
243 
244 
246  const CRange<TSeqPos>& range,
247  ENa_strand strand)
248  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph,
249  bioseq,
250  range,
251  strand)
252 {
253  x_Update();
254 }
255 
256 
258  const SAnnotSelector& sel)
259  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph,
260  bioseq,
261  CRange<TSeqPos>::GetWhole(),
263  &sel)
264 {
265  x_Update();
266 }
267 
268 
270  const CRange<TSeqPos>& range,
271  const SAnnotSelector& sel)
272  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph,
273  bioseq,
274  range,
276  &sel)
277 {
278  x_Update();
279 }
280 
281 
283  const CRange<TSeqPos>& range,
284  ENa_strand strand,
285  const SAnnotSelector& sel)
286  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph,
287  bioseq,
288  range,
289  strand,
290  &sel)
291 {
292  x_Update();
293 }
294 
295 
297  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph, annot)
298 {
299  x_Update();
300 }
301 
302 
304  const SAnnotSelector& sel)
305  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph, annot, &sel)
306 {
307  x_Update();
308 }
309 
310 
312  const CSeq_annot_Handle& annot)
313  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph,
314  loc,
315  annot)
316 {
317  x_Update();
318 }
319 
320 
322  const CSeq_annot_Handle& annot,
323  const SAnnotSelector& sel)
324  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph,
325  loc,
326  annot,
327  &sel)
328 {
329  x_Update();
330 }
331 
332 
334  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph, entry)
335 {
336  x_Update();
337 }
338 
339 
341  const SAnnotSelector& sel)
342  : CAnnotTypes_CI(CSeq_annot::C_Data::e_Graph, entry, &sel)
343 {
344  x_Update();
345 }
346 
347 
349 {
350 }
351 
352 
354 {
355  if ( this != &iter ) {
356  CAnnotTypes_CI::operator=(iter);
357  x_Update();
358  }
359  return *this;
360 }
361 
362 
364 {
365  if ( IsValid() ) {
367  }
368  else {
369  m_Graph.Reset();
370  }
371 }
372 
373 
bool MappedSeq_locNeedsUpdate(void) const
const CGraphRanges * GetGraphRanges(void) const
bool IsMapped(void) const
void UpdateMappedSeq_loc(CRef< CSeq_loc > &loc, CRef< CSeq_point > &pnt_ref, CRef< CSeq_interval > &int_ref, const CSeq_feat *orig_feat) const
bool IsPartial(void) const
const CSeq_loc & GetMappedSeq_loc(void) const
const CSeq_annot_Handle & GetSeq_annot_Handle(void) const
TAnnotIndex GetAnnotIndex(void) const
bool IsGraph(void) const
CAnnotMapping_Info & GetMappingInfo(void) const
CAnnot_Collector & GetCollector(void)
bool IsValid(void) const
const TIterator & GetIterator(void) const
CRef< CCreatedFeat_Ref > m_CreatedMapped
CBioseq_Handle –.
void ReleaseRefsTo(CRef< CSeq_feat > *feat, CRef< CSeq_loc > *loc, CRef< CSeq_point > *point, CRef< CSeq_interval > *interval)
void ResetRefsFrom(CRef< CSeq_feat > *feat, CRef< CSeq_loc > *loc, CRef< CSeq_point > *point, CRef< CSeq_interval > *interval)
Helper class for mapping graphs.
CGraph_CI –.
Definition: graph_ci.hpp:234
CScope –.
Definition: scope.hpp:92
CSeq_annot_Handle –.
CSeq_entry_Handle –.
static char tmp[3200]
Definition: utf8.c:42
void CopyGraphData(const TData &src, TData &dst, TSeqPos from, TSeqPos to)
Definition: graph_ci.cpp:121
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
const TGraphRanges & GetRanges(void) const
const TRange & GetTotalRange(void) const
void MakeMappedGraph(void) const
Definition: graph_ci.cpp:105
CGraphRanges::TGraphRanges TGraphRanges
Definition: graph_ci.hpp:197
virtual ~CGraph_CI(void)
Definition: graph_ci.cpp:348
void MakeMappedLoc(void) const
Definition: graph_ci.cpp:65
const TGraphRanges & GetMappedGraphRanges(void) const
Get all mapped graph ranges.
Definition: graph_ci.cpp:212
CSeq_annot_Handle GetAnnot(void) const
Get containing annot handle.
Definition: graph_ci.cpp:99
void Set(CAnnot_Collector &collector, const CAnnotObject_Ref &annot_ref)
Definition: graph_ci.cpp:45
CMappedGraph m_Graph
Definition: graph_ci.hpp:363
CConstRef< CSeq_loc > m_MappedLoc
Definition: graph_ci.hpp:224
CRef< CAnnot_Collector > m_Collector
Definition: graph_ci.hpp:220
void MakeMappedGraphData(CSeq_graph &dst) const
Definition: graph_ci.cpp:131
void x_Update(void)
Definition: graph_ci.cpp:363
void Reset(void)
Definition: graph_ci.cpp:56
CGraph_CI(void)
Create an empty iterator.
Definition: graph_ci.hpp:368
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
CGraph_CI & operator=(const CGraph_CI &iter)
Definition: graph_ci.cpp:353
const CSeq_graph::C_Graph & GetGraph(void) const
Definition: graph_ci.cpp:192
const TRange & GetMappedGraphTotalRange(void) const
Get the range of graph data used in the mapped graph.
Definition: graph_ci.cpp:203
CSeq_graph_Handle GetSeq_graph_Handle(void) const
Get original graph handle.
Definition: graph_ci.cpp:93
const CAnnotObject_Ref * m_GraphRef
Definition: graph_ci.hpp:221
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
bool IsSetComp(void) const
compression (residues/value) Check if a value has been assigned to Comp data member.
Definition: Seq_graph_.hpp:981
void SetMin(TMin value)
Assign a value to Min data member.
void SetAxis(TAxis value)
Assign a value to Axis data member.
TValues & SetValues(void)
Assign a value to Values data member.
void SetAxis(TAxis value)
Assign a value to Axis data member.
Definition: Int_graph_.hpp:394
TByte & SetByte(void)
Select the variant.
Definition: Seq_graph_.cpp:159
TMin GetMin(void) const
Get the Min member data.
const TInt & GetInt(void) const
Get the variant data.
Definition: Seq_graph_.cpp:131
void SetNumval(TNumval value)
Assign a value to Numval data member.
TAxis GetAxis(void) const
Get the Axis member data.
TReal & SetReal(void)
Select the variant.
Definition: Seq_graph_.cpp:115
TInt & SetInt(void)
Select the variant.
Definition: Seq_graph_.cpp:137
const TGraph & GetGraph(void) const
Get the Graph member data.
TValues & SetValues(void)
Assign a value to Values data member.
const TValues & GetValues(void) const
Get the Values member data.
Definition: Int_graph_.hpp:425
TMin GetMin(void) const
Get the Min member data.
Definition: Int_graph_.hpp:338
TMax GetMax(void) const
Get the Max member data.
const TByte & GetByte(void) const
Get the variant data.
Definition: Seq_graph_.cpp:153
void SetGraph(TGraph &value)
Assign a value to Graph data member.
Definition: Seq_graph_.cpp:250
void SetMax(TMax value)
Assign a value to Max data member.
const TReal & GetReal(void) const
Get the variant data.
Definition: Seq_graph_.cpp:109
void SetMax(TMax value)
Assign a value to Max data member.
TAxis GetAxis(void) const
Get the Axis member data.
Definition: Int_graph_.hpp:385
TMin GetMin(void) const
Get the Min member data.
TMax GetMax(void) const
Get the Max member data.
void SetMax(TMax value)
Assign a value to Max data member.
Definition: Int_graph_.hpp:300
const TValues & GetValues(void) const
Get the Values member data.
E_Choice Which(void) const
Which variant is currently selected.
Definition: Seq_graph_.hpp:716
const TValues & GetValues(void) const
Get the Values member data.
void SetAxis(TAxis value)
Assign a value to Axis data member.
void Reset(void)
Reset the whole object.
Definition: Seq_graph_.cpp:54
void SetMin(TMin value)
Assign a value to Min data member.
TComp GetComp(void) const
Get the Comp member data.
TMax GetMax(void) const
Get the Max member data.
Definition: Int_graph_.hpp:291
void SetMin(TMin value)
Assign a value to Min data member.
Definition: Int_graph_.hpp:347
TValues & SetValues(void)
Assign a value to Values data member.
Definition: Int_graph_.hpp:431
TAxis GetAxis(void) const
Get the Axis member data.
range(_Ty, _Ty) -> range< _Ty >
SAnnotSelector –.
#define _ASSERT
Modified on Thu Apr 11 15:05:58 2024 by modify_doxy.py rev. 669887