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

Go to the SVN repository for this file.

1 /* $Id: GC_Sequence.cpp 82703 2018-06-25 15:54:22Z mozese2 $
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 the following specifications:
34  * 'genome_collection.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
47 
48 // generated classes
49 
51 
52 BEGIN_objects_SCOPE // namespace ncbi::objects::
53 
54 
55 // constructor
57  : m_Assembly(NULL)
58  , m_AssemblyUnit(NULL)
59  , m_Replicon(NULL)
60  , m_ParentSequence(NULL)
61  , m_ParentRel(CGC_TaggedSequences::eState_not_set)
62  , m_SeqLength(0)
63  , m_SeqLengthRetrieved(false)
64 {
65 }
66 
67 
68 // destructor
70 {
71 }
72 
73 
75 {
77 }
78 
80 {
82 }
83 
85 {
87 }
88 
90 {
92 }
93 
94 
96 {
97  return m_ParentRel;
98 }
99 
100 
102 {
103  CConstRef<CGC_Sequence> top(this);
104  for ( ; top && top->GetParent(); top = top->GetParent()) {
105  }
106  return top;
107 }
108 
110 {
111  CConstRef<CSeq_id> ret;
112  if( !IsSetSeq_id_synonyms() )
113  return ret;
114 
115  CConstRef<CGC_TypedSeqId> typed_seq_id;
116 
118  {
119  if( (*it_syn)->Which() == syn_type )
120  {
121  typed_seq_id = *it_syn;
122  break;
123  }
124  }
125 
126  if( typed_seq_id.IsNull() )
127  return ret;
128 
129 
130  if( syn_type == CGC_TypedSeqId::e_Genbank || syn_type == CGC_TypedSeqId::e_Refseq )
131  {
132  CConstRef<CGC_SeqIdAlias> seq_id_alias;
133  if( syn_type == CGC_TypedSeqId::e_Genbank )
134  seq_id_alias = CConstRef<CGC_SeqIdAlias> ( &typed_seq_id->GetGenbank() );
135  else
136  seq_id_alias = CConstRef<CGC_SeqIdAlias>( &typed_seq_id->GetRefseq() );
137 
138  switch( alias_type )
139  {
141  break;
143  if( seq_id_alias->IsSetPublic() )
144  ret = CConstRef<CSeq_id>( &seq_id_alias->GetPublic() );
145  break;
147  if( seq_id_alias->IsSetGpipe() )
148  ret = CConstRef<CSeq_id>( &seq_id_alias->GetGpipe() );
149  break;
151  if( seq_id_alias->IsSetGi() )
152  ret = CConstRef<CSeq_id>( &seq_id_alias->GetGi() );
153  break;
154  default:
155  NCBI_THROW(CException, eUnknown, "unhandled alias type");
156  }
157 
158  }
159  else if( syn_type == CGC_TypedSeqId::e_Private )
160  ret = CConstRef<CSeq_id>( &typed_seq_id->GetPrivate() );
161 
162  else if( syn_type == CGC_TypedSeqId::e_External )
163  ret = CConstRef<CSeq_id>( &typed_seq_id->GetExternal().GetId() );
164 
165  return ret;
166 }
167 
168 
170 {
171  CConstRef<CSeq_id> ret;
172 
173  if( !IsSetSeq_id_synonyms() )
174  return ret;
175 
176  CConstRef<CGC_TypedSeqId> typed_seq_id;
178  {
179  if( (*it_syn)->IsExternal() &&
180  NStr::EqualNocase((*it_syn)->GetExternal().GetExternal(), "SUBMITTER") )
181  {
182  ret = &((*it_syn)->GetExternal().GetId());
183  break;
184  }
185  }
186 
187  return ret;
188 
189 }
190 
191 bool CGC_Sequence::HasRole(int Role) const
192 {
193  if( !CanGetRoles() )
194  return false;
195 
196  ITERATE(TRoles, roleiter, GetRoles()) {
197  if(*roleiter == Role)
198  return true;
199  }
200 
201  return false;
202 }
203 
205  EChildrenSubset subset,
207  int level) const
208 {
209  x_GetChildren(children, subset, state, level);
210 }
211 
213  EChildrenSubset subset,
215  int level) const
216 {
217  for (const CRef<CGC_TaggedSequences> &tag: GetSequences()) {
218  if (state != 0 && tag->GetState() != state) {
219  /// Doesn't belong to required state
220  continue;
221  }
222  for (const CRef<CGC_Sequence> &child: tag->GetSeqs()) {
223  if (level == 0 || level == 1) {
224  /// Looking at either this specific level or all levels; add
225  /// this child to results, if it belongs to the requested subset
226  bool is_in_subset = false;
227  switch (subset) {
228  case eScaffold:
229  is_in_subset = child->HasRole(eGC_SequenceRole_scaffold);
230  break;
231 
232  case eComponent:
233  is_in_subset = child->HasRole(eGC_SequenceRole_component);
234  break;
235 
236  case eAll:
237  is_in_subset = true;
238  break;
239 
240  default:
242  "Unrecogtnized subset specification");
243  }
244  if (is_in_subset) {
245  children.push_back(child);
246  }
247  }
248  if (level != 1) {
249  /// If level is specified as 1, we're only looking at this level;
250  /// otherwise keep looking at next level
251  /// Subset selection applies at all levels; stats selection only
252  /// applies at the first level (e.g. if you're looking for
253  /// component children of a chromosome, and specify unplaced
254  /// status, include placed components of unplaced scaffolds
255  child->x_GetChildren(children, subset, 0, max(level-1,0));
256  }
257  }
258  }
259 }
260 
262 {
263  if (GetTopLevelParent()->GetReplicon() &&
264  GetTopLevelParent()->GetReplicon()->IsSetName())
265  {
266  return GetTopLevelParent()->GetReplicon()->GetName();
267  } else {
268  return "Un";
269  }
270 }
271 
273 {
274  return GetAssemblyUnit()->GetDisplayName();
275 }
276 
277 
279 {
280  return GetChrName() == "MT" || GetChrName() == "Pltd";
281 }
282 
284 {
285  return ( x_GetLength() != 0);
286 }
287 
289 {
291  if (result == 0) {
292  NCBI_THROW(CUnassignedMember, eGet, "CGC_Sequence::GetLength(): Sequence length not set.");
293  }
294  return result;
295 }
296 
298 {
299  if ( ! m_SeqLengthRetrieved) {
301  if (CanGetStats() && GetStats().CanGetOrdered_scaf()) {
302  ITERATE(list< CRef< CGC_Scaf_stats > >, stat_it, GetStats().GetOrdered_scaf()) {
303  if ( (*stat_it)->GetStats_category() == CGC_Scaf_stats::eStats_category_total_length)
304  {
305  m_SeqLength = static_cast<TSeqPos>((*stat_it)->GetValue());
306  break;
307  }
308  }
309  }
310  } else {
311  if (CanGetStats() && GetStats().CanGetAll_scaf()) {
312  ITERATE(list< CRef< CGC_Scaf_stats > >, stat_it, GetStats().GetAll_scaf()) {
313  if ( (*stat_it)->GetStats_category() == CGC_Scaf_stats::eStats_category_total_length)
314  {
315  m_SeqLength = static_cast<TSeqPos>((*stat_it)->GetValue());
316  break;
317  }
318  }
319  }
320  }
321  m_SeqLengthRetrieved = true;
322  }
323  return m_SeqLength;
324 }
325 
326 
327 END_objects_SCOPE // namespace ncbi::objects::
328 
330 
331 /* Original file checksum: lines: 57, chars: 1758, CRC32: 7250bf25 */
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
#define false
Definition: bool.h:36
CConstRef –.
Definition: ncbiobj.hpp:1266
CGC_Replicon * m_Replicon
CGC_Sequence * m_ParentSequence
list< CConstRef< CGC_Sequence > > TSequenceList
Definition: GC_Sequence.hpp:98
CConstRef< CGC_Replicon > GetReplicon() const
Access the replicon the sequence belongs to.
Definition: GC_Sequence.cpp:84
string GetChrName() const
Get name of chromosome that this sequence belongs to, if any.
CGC_AssemblyUnit * m_AssemblyUnit
CConstRef< CSeq_id > GetSubmitterName() const
bool CanGetLength() const
Is the length statistic available?
CConstRef< CGC_AssemblyUnit > GetAssemblyUnit() const
Access the assembly unit the sequence belongs to.
Definition: GC_Sequence.cpp:74
TSeqPos m_SeqLength
CConstRef< CSeq_id > GetSynonymSeq_id(CGC_TypedSeqId::E_Choice type, CGC_SeqIdAlias::E_AliasTypes) const
void GetChildren(TSequenceList &children, EChildrenSubset subset=eAll, CGC_TaggedSequences::TState state=0, int level=0) const
Get sub-sequences.
TSeqPos GetLength() const
return the length of this sequence.
bool m_SeqLengthRetrieved
CConstRef< CGC_Assembly > GetFullAssembly() const
Access the most specific full assembly the sequence belongs to This is needed because assemblies are ...
Definition: GC_Sequence.cpp:79
void x_GetChildren(TSequenceList &children, EChildrenSubset subset, CGC_TaggedSequences::TState state, int level) const
TSeqPos x_GetLength() const
bool HasRole(int Role) const
string GetUnitDisplayName() const
Get full display name of assmebly unit.
bool IsOrganelle() const
Is this aN organelle sequence?
~CGC_Sequence(void)
Definition: GC_Sequence.cpp:69
CConstRef< CGC_Sequence > GetTopLevelParent() const
Access the top-most parent sequence of this sequence.
CGC_TaggedSequences::TState GetParentRelation() const
Access the relationship to the parent.
Definition: GC_Sequence.cpp:95
CConstRef< CGC_Sequence > GetParent() const
Access the parent sequence of this sequence.
Definition: GC_Sequence.cpp:89
CGC_Assembly * m_Assembly
CGC_TaggedSequences::TState m_ParentRel
CGC_Sequence(void)
Definition: GC_Sequence.cpp:56
CGC_TaggedSequences –.
CRef –.
Definition: ncbiobj.hpp:618
Thrown on an attempt to write unassigned data member.
Definition: exception.hpp:84
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 NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:1401
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5352
E_Choice
Choice variants.
const TStats & GetStats(void) const
Get the Stats member data.
const TRoles & GetRoles(void) const
Get the Roles member data.
bool CanGetStats(void) const
Check if it is safe to call GetStats method.
list< CRef< CGC_TypedSeqId > > TSeq_id_synonyms
const TSeq_id_synonyms & GetSeq_id_synonyms(void) const
Get the Seq_id_synonyms member data.
bool CanGetRoles(void) const
Check if it is safe to call GetRoles method.
const TSequences & GetSequences(void) const
Get the Sequences member data.
bool CanGetAll_scaf(void) const
Check if it is safe to call GetAll_scaf method.
bool IsSetSeq_id_synonyms(void) const
Other known identifiers: Local / gpipe-satellite / genbank / refseq Check if a value has been assigne...
list< int > TRoles
@ eGC_SequenceRole_component
@ eGC_SequenceRole_scaffold
@ eGC_SequenceRole_chromosome
const char * tag
T max(T x_, T y_)
@ eGet
Definition: ns_types.hpp:55
else result
Definition: token2.c:20
Modified on Sat Dec 02 09:24:14 2023 by modify_doxy.py rev. 669887