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

Go to the SVN repository for this file.

1 /* $Id: Packed_seqint.cpp 48838 2011-03-02 18:19:45Z 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: .......
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 // standard includes
38 
39 // generated includes
40 #include <ncbi_pch.hpp>
44 #include <corelib/ncbiutil.hpp>
45 
46 
47 // generated classes
48 
50 
51 BEGIN_objects_SCOPE // namespace ncbi::objects::
52 
53 // constructor
55 {
56  ITERATE(TRanges, ival, ivals) {
57  AddInterval(id, ival->GetFrom(), ival->GetTo(), strand);
58  }
59 }
60 
61 
62 // destructor
64 {
65 }
66 
67 // length calculator
69 {
70  TSeqPos length = 0;
71  ITERATE ( Tdata, i, Get() ) {
72  length += (**i).GetLength();
73  }
74  return length;
75 }
76 
77 
79 {
80  return ext == eExtreme_Positional && IsReverseStrand() ?
81  Get().back() : Get().front();
82 }
83 
84 
86 {
87  return ext == eExtreme_Positional && IsReverseStrand() ?
88  Get().front() : Get().back();
89 }
90 
91 
93 {
94  return ext == eExtreme_Positional && IsReverseStrand() ?
95  Set().back() : Set().front();
96 }
97 
98 
100 {
101  return ext == eExtreme_Positional && IsReverseStrand() ?
102  Set().front() : Set().back();
103 }
104 
105 
107 {
108  if ( Get().empty() ) {
109  return false;
110  }
111  return GetStartInt(ext)->IsPartialStart(ext);
112 }
113 
114 
116 {
117  if ( Get().empty() ) {
118  return false;
119  }
120  return GetStopInt(ext)->IsPartialStop(ext);
121 }
122 
123 
125 {
126  if ( !Get().empty() ) {
127  SetStartInt(ext)->SetPartialStart(val, ext);
128  }
129 }
130 
131 
133 {
134  if ( !Get().empty() ) {
135  SetStopInt(ext)->SetPartialStop(val, ext);
136  }
137 }
138 
139 
141 {
142  if ( Get().empty() ) {
143  return false;
144  }
145  return GetStartInt(ext)->IsTruncatedStart(ext);
146 }
147 
148 
150 {
151  if ( Get().empty() ) {
152  return false;
153  }
154  return GetStopInt(ext)->IsTruncatedStop(ext);
155 }
156 
157 
159 {
160  if (!Set().empty()) {
161  SetStartInt(ext)->SetTruncatedStart(val, ext);
162  }
163 }
164 
165 
167 {
168  if (!Set().empty()) {
169  SetStopInt(ext)->SetTruncatedStop(val, ext);
170  }
171 }
172 
173 
175 {
176  ITERATE(Tdata, i, Get()) {
177  switch (flag) {
178  case eIsSetStrand_Any:
179  if ( (*i)->IsSetStrand() ) return true;
180  break;
181  case eIsSetStrand_All:
182  if ( !(*i)->IsSetStrand() ) return false;
183  break;
184  }
185  }
186  return flag == eIsSetStrand_Any ? false : true;
187 }
188 
189 
191 {
193  bool strand_set = false;
194  const CSeq_id* id = NULL;
195  ITERATE(Tdata, i, Get()) {
196  // check for multiple IDs
197  if (id == NULL) {
198  id = &((*i)->GetId());
199  } else if (id->Compare((*i)->GetId()) != CSeq_id::e_YES) {
200  return eNa_strand_other;
201  }
202 
203  ENa_strand istrand = (*i)->IsSetStrand() ? (*i)->GetStrand() : eNa_strand_unknown;
204  if (strand == eNa_strand_unknown && istrand == eNa_strand_plus) {
205  strand = istrand;
206  strand_set = true;
207  } else if (strand == eNa_strand_plus && istrand == eNa_strand_unknown) {
208  // treat unknown as plus - do nothing
209  } else if (!strand_set) {
210  strand = istrand;
211  strand_set = true;
212  } else if (istrand != strand) {
213  return eNa_strand_other;
214  }
215  }
216  return strand;
217 }
218 
219 
221 {
222  if (Get().empty()) {
223  return kInvalidSeqPos;
224  }
225  return GetStartInt(ext)->GetStart(ext);
226 }
227 
228 
230 {
231  if (Get().empty()) {
232  return kInvalidSeqPos;
233  }
234  return GetStopInt(ext)->GetStop(ext);
235 }
236 
237 
239 {
240  CRef<CSeq_interval> new_ival(new CSeq_interval);
241  new_ival->Assign(ival);
242  Set().push_back(new_ival);
243 }
244 
245 
247  ENa_strand strand)
248 {
249  CSeq_interval ival;
250  ival.SetFrom(from);
251  ival.SetTo(to);
252  ival.SetId().Assign(id);
253  if (strand != eNa_strand_unknown) {
254  ival.SetStrand(strand);
255  }
256  AddInterval(ival);
257 }
258 
259 
261 {
262  AddIntervals(ivals.Get());
263 }
264 
265 
267 {
268  copy(ivals.begin(), ivals.end(), back_inserter(Set()));
269 }
270 
271 
273 {
274  NON_CONST_ITERATE (Tdata, it, Set()) {
275  (*it)->SetStrand(strand);
276  }
277 }
278 
279 
281 {
282  NON_CONST_ITERATE (Tdata, it, Set()) {
283  (*it)->ResetStrand();
284  }
285 }
286 
287 
289 {
290  NON_CONST_ITERATE (Tdata, it, Set()) {
291  (*it)->FlipStrand();
292  }
293 }
294 
295 
296 END_objects_SCOPE // namespace ncbi::objects::
297 
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
void ResetStrand(void)
Reset the strand to 'not set'.
bool IsPartialStop(ESeqLocExtremes ext) const
void SetPartialStart(bool val, ESeqLocExtremes ext)
TSeqPos GetStop(ESeqLocExtremes ext) 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)
void FlipStrand(void)
Flip the strand (e.g. plus to minus)
bool IsTruncatedStart(ESeqLocExtremes ext) const
check if parts of the seq-loc are missing
void AddIntervals(const CPacked_seqint &ivals)
void SetTruncatedStop(bool val, ESeqLocExtremes ext)
TSeqPos GetStart(ESeqLocExtremes ext) const
TSeqPos GetLength(void) const
void SetPartialStop(bool val, ESeqLocExtremes ext)
bool IsPartialStart(ESeqLocExtremes ext) const
bool IsReverseStrand(void) const
CSeq_interval * SetStopInt(ESeqLocExtremes ext)
const CSeq_interval * GetStopInt(ESeqLocExtremes ext) const
const CSeq_interval * GetStartInt(ESeqLocExtremes ext) const
bool IsSetStrand(EIsSetStrand flag=eIsSetStrand_Any) const
bool IsTruncatedStop(ESeqLocExtremes ext) const
vector< CRange< TSeqPos > > TRanges
CSeq_interval * SetStartInt(ESeqLocExtremes ext)
ENa_strand GetStrand(void) const
void SetStrand(ENa_strand strand)
Set the strand for all of the location's ranges.
void AddInterval(const CSeq_interval &ival)
for convenience
bool IsTruncatedStop(ESeqLocExtremes ext) const
bool IsPartialStop(ESeqLocExtremes ext) 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 GetStart(ESeqLocExtremes ext) const
bool IsPartialStart(ESeqLocExtremes ext) const
bool IsTruncatedStart(ESeqLocExtremes ext) const
check if parts of the seq-loc are missing
TSeqPos GetStop(ESeqLocExtremes ext) const
void SetTruncatedStop(bool val, ESeqLocExtremes ext)
void SetPartialStart(bool val, ESeqLocExtremes ext)
void SetPartialStop(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
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
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
#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.
list< CRef< CSeq_interval > > Tdata
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
const Tdata & Get(void) const
Get the member data.
Tdata & Set(void)
Assign a value to data member.
void SetId(TId &value)
Assign a value to Id data member.
void SetFrom(TFrom value)
Assign a value to From data member.
void SetStrand(TStrand value)
Assign a value to Strand data member.
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_other
Definition: Na_strand_.hpp:70
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
int i
constexpr bool empty(list< Ts... >) noexcept
Useful/utility classes and methods.
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
Modified on Sun Apr 21 03:42:04 2024 by modify_doxy.py rev. 669887