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

Go to the SVN repository for this file.

1 /* $Id: seqdesc_ci.cpp 91755 2020-12-07 11:41:53Z grichenk $
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
27 *
28 * File Description:
29 * Object manager iterators
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <objmgr/seqdesc_ci.hpp>
36 #include <objects/seq/Seq_ext.hpp>
37 #include <objects/seq/Ref_ext.hpp>
39 //#include <objmgr/impl/seq_entry_info.hpp>
41 #include <objmgr/scope.hpp>
42 
45 
46 
47 ////////////////////////////////////////////////////////////////////
48 //
49 // CSeqdesc_CI::
50 //
51 
52 
53 // inline methods first
54 inline
56 {
57  return m_Entry.x_GetBaseInfo();
58 }
59 
60 
61 inline
62 bool CSeqdesc_CI::x_ValidDesc(void) const
63 {
66 }
67 
68 
69 inline
71 {
74  return m_Choice & (1<<(**m_Desc_CI).Which()) ? true : false;
75 }
76 
77 
78 inline
79 bool CSeqdesc_CI::x_Valid(void) const
80 {
81  return !m_Entry || (x_ValidDesc() && x_RequestedType());
82 }
83 
84 
86 {
87  m_Ref.Reset();
88  if (!handle ||
89  !handle.IsSetInst_Repr() ||
90  handle.GetInst_Repr() != CSeq_inst::eRepr_ref ||
91  !handle.IsSetInst_Ext() ||
92  !handle.GetInst_Ext().IsRef()) {
93  return;
94  }
95  const CRef_ext& ref = handle.GetInst_Ext().GetRef();
96  CConstRef<CSeq_id> ref_id(ref.GetId());
97  if ( !ref_id ) return; // Bad reference location or multiple ids.
98  m_Ref = handle.GetScope().GetBioseqHandle(*ref_id);
99 }
100 
101 
103  : m_HaveTitle(false),
104  m_Depth(0)
105 {
106  _ASSERT(x_Valid());
107 }
108 
109 
111  CSeqdesc::E_Choice choice)
112  : m_HaveTitle(false),
113  m_Depth(0)
114 {
115  x_SetChoice(choice);
116  x_SetEntry(desc_it);
117  _ASSERT(x_Valid());
118 }
119 
120 
122  CSeqdesc::E_Choice choice,
123  size_t search_depth)
124  : m_HaveTitle(false),
125  m_Depth(search_depth)
126 {
127  x_SetChoice(choice);
128  x_CheckRef(handle);
129  x_SetEntry(CSeq_descr_CI(handle, search_depth));
130  _ASSERT(x_Valid());
131 }
132 
133 
135  CSeqdesc::E_Choice choice,
136  size_t search_depth)
137  : m_Entry(entry, search_depth),
138  m_HaveTitle(false),
139  m_Depth(search_depth)
140 {
141  x_SetChoice(choice);
142  x_SetEntry(CSeq_descr_CI(entry, search_depth));
143  _ASSERT(x_Valid());
144 }
145 
146 
148  const TDescChoices& choices,
149  size_t search_depth)
150  : m_HaveTitle(false),
151  m_Depth(search_depth)
152 {
153  x_SetChoices(choices);
154  x_CheckRef(handle);
155  x_SetEntry(CSeq_descr_CI(handle, search_depth));
156  _ASSERT(x_Valid());
157 }
158 
159 
161  const TDescChoices& choices,
162  size_t search_depth)
163  : m_HaveTitle(false),
164  m_Depth(search_depth)
165 {
166  x_SetChoices(choices);
167  x_SetEntry(CSeq_descr_CI(entry, search_depth));
168  _ASSERT(x_Valid());
169 }
170 
171 
173  : m_Choice(iter.m_Choice),
174  m_Entry(iter.m_Entry),
175  m_Desc_CI(iter.m_Desc_CI),
176  m_Ref(iter.m_Ref),
177  m_HaveTitle(iter.m_HaveTitle),
178  m_Depth(iter.m_Depth)
179 {
180  _ASSERT(x_Valid());
181 }
182 
183 
185 {
186 }
187 
188 
190 {
191  if (this != &iter) {
192  m_Choice = iter.m_Choice;
193  m_Entry = iter.m_Entry;
194  m_Desc_CI = iter.m_Desc_CI;
195  m_Ref = iter.m_Ref;
196  m_HaveTitle = iter.m_HaveTitle;
197  m_Depth = iter.m_Depth;
198  }
199  _ASSERT(x_Valid());
200  return *this;
201 }
202 
203 
205 {
206  if ( choice != CSeqdesc::e_not_set ) {
207  TDescTypeMask mask = 1 << choice;
208  _ASSERT(mask);
209  m_Choice |= (mask);
210  }
211  else {
212  // set all bits
213  m_Choice |= ~0;
214  }
215 }
216 
217 
219 {
220  if ( choice != CSeqdesc::e_not_set ) {
221  TDescTypeMask mask = 1 << choice;
222  _ASSERT(mask);
223  m_Choice &= ~(mask);
224  }
225 }
226 
227 
229 {
230  m_Choice = 0;
231  x_AddChoice(choice);
232 }
233 
234 
236 {
237  m_Choice = 0;
238  ITERATE ( TDescChoices, it, choices ) {
239  x_AddChoice(*it);
240  }
241 }
242 
243 
245 {
246  _ASSERT(x_ValidDesc());
248 }
249 
250 
252 {
253  if ( !m_Entry ) {
254  return;
255  }
257 }
258 
259 
261 {
262  while ( m_Entry && !x_ValidDesc() ) {
263  ++m_Entry;
264  x_FirstDesc();
265  }
266  if ( m_Ref ) {
267  if ( m_Entry && x_Valid() ) {
268  if ((*m_Desc_CI)->Which() == CSeqdesc::e_Title) {
269  m_HaveTitle = true;
270  }
271  }
272  if ( !m_Entry ) {
273  // Ignore pointed-to title if the ref contains one.
274  if ( m_HaveTitle ) {
276  }
277  m_HaveTitle = false;
278  // Ignore pointed-to source.
280  CBioseq_Handle ref_handle = m_Ref;
281  x_CheckRef(ref_handle);
282  x_SetEntry(CSeq_descr_CI(ref_handle, m_Depth));
283  }
284  }
285 }
286 
287 
289 {
290  m_Entry = entry;
291  x_FirstDesc();
292  // Advance to the first relevant Seqdesc, if any.
293  x_Settle();
294 }
295 
296 
298 {
299  x_NextDesc();
300  x_Settle();
301 }
302 
303 
305 {
306  x_Next();
307  _ASSERT(x_Valid());
308  return *this;
309 }
310 
311 
313 {
315  return **m_Desc_CI;
316 }
317 
318 
320 {
322  return *m_Desc_CI;
323 }
324 
325 
327 {
328  return m_Entry.GetSeq_entry_Handle();
329 }
330 
331 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
ncbi::TMaskedQueryRegions mask
TDesc_CI x_GetFirstDesc(TDescTypeMask types) const
bool x_IsEndDesc(TDesc_CI iter) const
TDesc_CI x_GetNextDesc(TDesc_CI iter, TDescTypeMask types) const
CBioseq_Handle –.
CRef_ext –.
Definition: Ref_ext.hpp:66
CSeq_descr_CI –.
CSeq_entry_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
#define false
Definition: bool.h:36
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
const TInst_Ext & GetInst_Ext(void) const
bool IsSetInst_Ext(void) const
void Reset(void)
Reset handle and make it not to point to any bioseq.
bool IsSetInst_Repr(void) const
TInst_Repr GetInst_Repr(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
TDescList_CI m_Desc_CI
Definition: seqdesc_ci.hpp:153
unsigned TDescTypeMask
Definition: seqdesc_ci.hpp:124
const CBioseq_Base_Info & x_GetBaseInfo(void) const
size_t m_Depth
Definition: seqdesc_ci.hpp:156
void x_Next(void)
Definition: seqdesc_ci.cpp:297
bool x_Valid(void) const
Definition: seqdesc_ci.cpp:79
CBioseq_Handle m_Ref
Definition: seqdesc_ci.hpp:154
const CSeqdesc & operator*(void) const
Definition: seqdesc_ci.cpp:312
CSeq_descr_CI m_Entry
Definition: seqdesc_ci.hpp:152
void x_SetChoices(const TDescChoices &choices)
Definition: seqdesc_ci.cpp:235
CSeqdesc_CI(void)
Definition: seqdesc_ci.cpp:102
void x_SetChoice(CSeqdesc::E_Choice choice)
Definition: seqdesc_ci.cpp:228
TDescTypeMask m_Choice
Definition: seqdesc_ci.hpp:151
void x_RemoveChoice(CSeqdesc::E_Choice choice)
Definition: seqdesc_ci.cpp:218
~CSeqdesc_CI(void)
Definition: seqdesc_ci.cpp:184
bool m_HaveTitle
Definition: seqdesc_ci.hpp:155
bool x_RequestedType(void) const
Definition: seqdesc_ci.cpp:70
void x_FirstDesc(void)
Definition: seqdesc_ci.cpp:251
CSeqdesc_CI & operator=(const CSeqdesc_CI &iter)
Definition: seqdesc_ci.cpp:189
const CSeqdesc * operator->(void) const
Definition: seqdesc_ci.cpp:319
void x_SetEntry(const CSeq_descr_CI &entry)
Definition: seqdesc_ci.cpp:288
void x_NextDesc(void)
Definition: seqdesc_ci.cpp:244
void x_CheckRef(const CBioseq_Handle &handle)
Definition: seqdesc_ci.cpp:85
CSeq_entry_Handle GetSeq_entry_Handle(void) const
vector< CSeqdesc::E_Choice > TDescChoices
Definition: seqdesc_ci.hpp:67
CSeqdesc_CI & operator++(void)
Move to the next object in iterated sequence.
Definition: seqdesc_ci.cpp:304
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Definition: seqdesc_ci.cpp:326
bool x_ValidDesc(void) const
Definition: seqdesc_ci.cpp:62
void x_Settle(void)
Definition: seqdesc_ci.cpp:260
const CBioseq_Base_Info & x_GetBaseInfo(void) const
Definition: seqdesc_ci.cpp:55
void x_AddChoice(CSeqdesc::E_Choice choice)
Definition: seqdesc_ci.cpp:204
#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
bool IsRef(void) const
Check if variant Ref is selected.
Definition: Seq_ext_.hpp:324
E_Choice
Choice variants.
Definition: Seqdesc_.hpp:109
const TRef & GetRef(void) const
Get the variant data.
Definition: Seq_ext_.cpp:136
@ eRepr_ref
reference to another sequence
Definition: Seq_inst_.hpp:97
@ e_MaxChoice
== e_Modelev+1
Definition: Seqdesc_.hpp:139
@ e_Title
a title for this sequence
Definition: Seqdesc_.hpp:115
@ e_not_set
No variant selected.
Definition: Seqdesc_.hpp:110
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
#define _ASSERT
Modified on Wed Apr 17 13:08:38 2024 by modify_doxy.py rev. 669887