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

Go to the SVN repository for this file.

1 /* $Id: Seq_loc_mix.cpp 53956 2012-04-27 17:47:52Z 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: Eugene Vasilchenko
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using specifications from the ASN data definition file
34  * 'seqloc.asn'.
35  */
36 
37 #include <ncbi_pch.hpp>
42 
43 
45 BEGIN_objects_SCOPE // namespace ncbi::objects::
46 
48 {
49  return;
50 }
51 
52 
54 {
55 }
56 
58 {
59  const Tdata& arr = Get();
60  ITERATE ( Tdata, it, arr ) {
61  const CSeq_loc* ret = *it;
62  if ( null_seg == eNullSegAllow || !ret->IsNull() ) {
63  return ret;
64  }
65  }
66  return 0;
67 }
68 
70 {
71  const Tdata& arr = Get();
72  REVERSE_ITERATE ( Tdata, it, arr ) {
73  const CSeq_loc* ret = *it;
74  if ( null_seg == eNullSegAllow || !ret->IsNull() ) {
75  return ret;
76  }
77  }
78  return 0;
79 }
80 
82 {
83  Tdata& arr = Set();
84  NON_CONST_ITERATE ( Tdata, it, arr ) {
85  CSeq_loc* ret = *it;
86  if ( null_seg == eNullSegAllow || !ret->IsNull() ) {
87  return ret;
88  }
89  }
90  return 0;
91 }
92 
94 {
95  Tdata& arr = Set();
97  CSeq_loc* ret = *it;
98  if ( null_seg == eNullSegAllow || !ret->IsNull() ) {
99  return ret;
100  }
101  }
102  return 0;
103 }
104 
106  ENullSegType null_seg) const
107 {
108  return (ext == eExtreme_Positional && IsReverseStrand()) ?
109  GetLastLoc(null_seg): GetFirstLoc(null_seg);
110 }
111 
113  ENullSegType null_seg) const
114 {
115  return (ext == eExtreme_Positional && IsReverseStrand()) ?
116  GetFirstLoc(null_seg): GetLastLoc(null_seg);
117 }
118 
120  ENullSegType null_seg)
121 {
122  return (ext == eExtreme_Positional && IsReverseStrand()) ?
123  SetLastLoc(null_seg): SetFirstLoc(null_seg);
124 }
125 
127  ENullSegType null_seg)
128 {
129  return (ext == eExtreme_Positional && IsReverseStrand()) ?
130  SetFirstLoc(null_seg): SetLastLoc(null_seg);
131 }
132 
134 {
135  if (!Get().empty()) {
136  return GetStartLoc(ext)->IsPartialStart(ext);
137  }
138  return false;
139 }
140 
142 {
143  if (!Get().empty()) {
144  return GetStopLoc(ext)->IsPartialStop(ext);
145  }
146  return false;
147 }
148 
149 
151 {
152  if (IsPartialStart(ext) == val || Set().empty()) {
153  return;
154  }
155  SetStartLoc(ext)->SetPartialStart(val, ext);
156 }
157 
158 
160 {
161  if (IsPartialStop(ext) == val || Set().empty()) {
162  return;
163  }
164  SetStopLoc(ext)->SetPartialStop(val, ext);
165 }
166 
167 
169 {
170  if (!Get().empty()) {
171  return GetStartLoc(ext)->IsTruncatedStart(ext);
172  }
173  return false;
174 }
175 
177 {
178  if (!Get().empty()) {
179  return GetStopLoc(ext)->IsTruncatedStop(ext);
180  }
181  return false;
182 }
183 
184 
186 {
187  if (IsTruncatedStart(ext) == val || Set().empty()) {
188  return;
189  }
190  SetStartLoc(ext)->SetTruncatedStart(val, ext);
191 }
192 
193 
195 {
196  if (IsTruncatedStop(ext) == val || Set().empty()) {
197  return;
198  }
199  SetStopLoc(ext)->SetTruncatedStop(val, ext);
200 }
201 
202 
204 {
205  ITERATE(Tdata, it, Get()) {
206  switch (flag) {
207  case eIsSetStrand_Any:
208  if ( (*it)->GetStrand() ) return true;
209  break;
210  case eIsSetStrand_All:
211  if ( !(*it)->GetStrand() ) return false;
212  break;
213  }
214  }
215  return flag == eIsSetStrand_Any ? false : true;
216 }
217 
218 
220 {
222  bool strand_set = false;
223  const CSeq_id* id = NULL;
224  ITERATE(Tdata, it, Get()) {
225  if ((*it)->IsNull() || (*it)->IsEmpty()) {
226  continue;
227  }
228 
229  // check fro multiple IDs
230  const CSeq_id* iid = (*it)->GetId();
231  if (iid == NULL) {
232  return eNa_strand_other;
233  }
234  if (id == NULL) {
235  id = iid;
236  } else {
237  if (id->Compare(*iid) != CSeq_id::e_YES) {
238  return eNa_strand_other;
239  }
240  }
241 
242  ENa_strand istrand = (*it)->GetStrand();
243  if (strand == eNa_strand_unknown && istrand == eNa_strand_plus) {
244  strand = istrand;
245  strand_set = true;
246  } else if (strand == eNa_strand_plus && istrand == eNa_strand_unknown) {
247  } else if (!strand_set) {
248  strand = istrand;
249  strand_set = true;
250  } else if (istrand != strand) {
251  return eNa_strand_other;
252  }
253  }
254  return strand;
255 }
256 
257 
259 {
260  if (!Get().empty()) {
261  return GetStartLoc(ext, eNullSegSkip)->GetStart(ext);
262  }
263  return kInvalidSeqPos;
264 }
265 
266 
268 {
269  if (!Get().empty()) {
270  return GetStopLoc(ext, eNullSegSkip)->GetStop(ext);
271  }
272  return kInvalidSeqPos;
273 }
274 
275 
277 {
278  if ( !other.IsMix() ) {
279  CRef<CSeq_loc> loc(new CSeq_loc);
280  loc->Assign(other);
281  Set().push_back(loc);
282  } else {
283  // "flatten" the other seq-loc
284  ITERATE(CSeq_loc_mix::Tdata, li, other.GetMix().Get()) {
285  AddSeqLoc(**li);
286  }
287  }
288 }
289 
290 
292 {
293  if ( !other.IsMix() ) {
294  CRef<CSeq_loc> loc(&other);
295  Set().push_back(loc);
296  } else {
297  // "flatten" the other seq-loc
298  NON_CONST_ITERATE(CSeq_loc_mix::Tdata, li, other.SetMix().Set()) {
299  AddSeqLoc(**li);
300  }
301  }
302 }
303 
304 
306  ENa_strand strand)
307 {
308  CRef<CSeq_loc> loc(new CSeq_loc);
309  if (from == to) {
310  CSeq_point& pnt = loc->SetPnt();
311  pnt.SetPoint(from);
312  pnt.SetId().Assign(id);
313  if (strand != eNa_strand_unknown) {
314  pnt.SetStrand(strand);
315  }
316  } else {
317  CSeq_interval& ival = loc->SetInt();
318  ival.SetFrom(from);
319  ival.SetTo(to);
320  ival.SetId().Assign(id);
321  if (strand != eNa_strand_unknown) {
322  ival.SetStrand(strand);
323  }
324  }
325  Set().push_back(loc);
326 }
327 
328 
330 {
331  NON_CONST_ITERATE (Tdata, it, Set()) {
332  (*it)->SetStrand(strand);
333  }
334 }
335 
336 
338 {
339  NON_CONST_ITERATE (Tdata, it, Set()) {
340  (*it)->ResetStrand();
341  }
342 }
343 
344 
346 {
347  NON_CONST_ITERATE (Tdata, it, Set()) {
348  (*it)->FlipStrand();
349  }
350 }
351 
352 END_objects_SCOPE // namespace ncbi::objects::
ESeqLocExtremes
Used to determine the meaning of a location's Start/Stop positions.
Definition: Na_strand.hpp:61
@ eExtreme_Positional
numerical value
Definition: Na_strand.hpp:63
EIsSetStrand
Flag used by IsSetStrand() to switch between any/all modes.
Definition: Na_strand.hpp:51
@ eIsSetStrand_All
Check if all parts have strand.
Definition: Na_strand.hpp:53
@ eIsSetStrand_Any
Check if any part has strand.
Definition: Na_strand.hpp:52
~CSeq_loc_mix(void)
Definition: Seq_loc_mix.cpp:53
bool IsReverseStrand(void) const
void SetPartialStart(bool val, ESeqLocExtremes ext)
void AddInterval(const CSeq_id &id, TSeqPos from, TSeqPos to, ENa_strand strand=eNa_strand_unknown)
const CSeq_loc * GetLastLoc(ENullSegType null_seg=eNullSegAllow) const
Definition: Seq_loc_mix.cpp:69
bool IsTruncatedStop(ESeqLocExtremes ext) const
CSeq_loc * SetStartLoc(ESeqLocExtremes ext, ENullSegType null_seg=eNullSegAllow)
const CSeq_loc * GetStopLoc(ESeqLocExtremes ext, ENullSegType null_seg=eNullSegAllow) const
void SetPartialStop(bool val, ESeqLocExtremes ext)
void ResetStrand(void)
Reset the strand to 'not set'.
bool IsSetStrand(EIsSetStrand flag=eIsSetStrand_Any) const
void SetTruncatedStart(bool val, ESeqLocExtremes ext)
set / remove e_Lim fuzz on start or stop (tl/tr - indicating removed parts of the seq-loc)
TSeqPos GetStop(ESeqLocExtremes ext) const
void AddSeqLoc(const CSeq_loc &other)
bool IsPartialStart(ESeqLocExtremes ext) const
CSeq_loc * SetStopLoc(ESeqLocExtremes ext, ENullSegType null_seg=eNullSegAllow)
ENa_strand GetStrand(void) const
CSeq_loc * SetLastLoc(ENullSegType null_seg=eNullSegAllow)
Definition: Seq_loc_mix.cpp:93
TSeqPos GetStart(ESeqLocExtremes ext) const
bool IsPartialStop(ESeqLocExtremes ext) const
void SetStrand(ENa_strand strand)
Set the strand for all of the location's ranges.
CSeq_loc * SetFirstLoc(ENullSegType null_seg=eNullSegAllow)
Definition: Seq_loc_mix.cpp:81
CSeq_loc_mix(void)
Definition: Seq_loc_mix.cpp:47
const CSeq_loc * GetStartLoc(ESeqLocExtremes ext, ENullSegType null_seg=eNullSegAllow) const
bool IsTruncatedStart(ESeqLocExtremes ext) const
check if parts of the seq-loc are missing
const CSeq_loc * GetFirstLoc(ENullSegType null_seg=eNullSegAllow) const
Definition: Seq_loc_mix.cpp:57
void FlipStrand(void)
Flip the strand (e.g. plus to minus)
void SetTruncatedStop(bool val, ESeqLocExtremes ext)
#define false
Definition: bool.h:36
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
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NON_CONST_REVERSE_ITERATE(Type, Var, Cont)
Non constant version of REVERSE_ITERATE macro.
Definition: ncbimisc.hpp:834
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
#define REVERSE_ITERATE(Type, Var, Cont)
ITERATE macro to reverse sequence through container elements.
Definition: ncbimisc.hpp:827
#define NULL
Definition: ncbistd.hpp:225
E_SIC Compare(const CSeq_id &sid2) const
Compare() - more general.
Definition: Seq_id.cpp:411
@ e_YES
SeqIds compared, but are different.
Definition: Seq_id.hpp:583
void SetTruncatedStart(bool val, ESeqLocExtremes ext)
set / remove e_Lim fuzz on start or stop (tl/tr - indicating removed parts of the seq-loc)
Definition: Seq_loc.cpp:3398
void SetMix(TMix &v)
Definition: Seq_loc.hpp:987
bool IsPartialStart(ESeqLocExtremes ext) const
check start or stop of location for e_Lim fuzz
Definition: Seq_loc.cpp:3222
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Override Assign() to incorporate cache invalidation.
Definition: Seq_loc.cpp:337
TSeqPos GetStart(ESeqLocExtremes ext) const
Return start and stop positions of the seq-loc.
Definition: Seq_loc.cpp:915
void SetPnt(TPnt &v)
Definition: Seq_loc.hpp:985
void SetInt(TInt &v)
Definition: Seq_loc.hpp:983
bool IsTruncatedStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:3372
bool IsTruncatedStart(ESeqLocExtremes ext) const
check if parts of the seq-loc are missing
Definition: Seq_loc.cpp:3346
void SetPartialStart(bool val, ESeqLocExtremes ext)
set / remove e_Lim fuzz on start or stop (lt/gt - indicating partial interval)
Definition: Seq_loc.cpp:3280
void SetPartialStop(bool val, ESeqLocExtremes ext)
Definition: Seq_loc.cpp:3313
bool IsPartialStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:3251
void SetTruncatedStop(bool val, ESeqLocExtremes ext)
Definition: Seq_loc.cpp:3431
TSeqPos GetStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:963
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void SetTo(TTo value)
Assign a value to To data member.
void SetPoint(TPoint value)
Assign a value to Point data member.
Definition: Seq_point_.hpp:312
void SetId(TId &value)
Assign a value to Id data member.
Definition: Seq_point_.cpp:61
bool IsMix(void) const
Check if variant Mix is selected.
Definition: Seq_loc_.hpp:552
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
void SetId(TId &value)
Assign a value to Id data member.
void SetStrand(TStrand value)
Assign a value to Strand data member.
Definition: Seq_point_.hpp:359
list< CRef< CSeq_loc > > Tdata
void SetFrom(TFrom value)
Assign a value to From data member.
const Tdata & Get(void) const
Get the member data.
Tdata & Set(void)
Assign a value to data member.
bool IsNull(void) const
Check if variant Null is selected.
Definition: Seq_loc_.hpp:504
void SetStrand(TStrand value)
Assign a value to Strand data member.
const TMix & GetMix(void) const
Get the variant data.
Definition: Seq_loc_.cpp:282
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_other
Definition: Na_strand_.hpp:70
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
constexpr bool empty(list< Ts... >) noexcept
Modified on Wed Apr 17 13:10:21 2024 by modify_doxy.py rev. 669887