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

Go to the SVN repository for this file.

1 /* $Id: Seq_annot.cpp 96733 2022-05-04 15:46:34Z 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: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using specifications from the data definition file
34  * 'seq.asn'.
35  */
36 
37 // standard includes
38 
39 // generated includes
40 #include <ncbi_pch.hpp>
42 #include <objects/general/Date.hpp>
45 
46 
47 #define NCBI_USE_ERRCODE_X Objects_SeqAnnot
48 
49 // generated classes
50 
52 
53 BEGIN_objects_SCOPE // namespace ncbi::objects::
54 
55 // destructor
57 {
58 }
59 
60 
61 void CSeq_annot::AddName(const string &name)
62 {
63  SetNameDesc(name);
64 }
65 
66 void CSeq_annot::SetNameDesc(const string &name)
67 {
68  //NB: this used list::remove_if(), which is not portable to Windows
69  TDesc::Tdata::iterator iter = SetDesc().Set().begin();
70  for ( ; iter != SetDesc().Set().end(); ) {
71  if ((*iter)->IsName() ) {
72  iter = SetDesc().Set().erase(iter);
73  } else {
74  ++iter;
75  }
76  }
77 
78  CRef<CAnnotdesc> desc(new CAnnotdesc());
79  desc->SetName(name);
80  SetDesc().Set().push_back(desc);
81 }
82 
83 
84 void CSeq_annot::SetTitle(const string& title)
85 {
86  SetTitleDesc(title);
87 }
88 
89 
90 void CSeq_annot::AddTitle(const string& title)
91 {
92  SetTitleDesc(title);
93 }
94 
95 
96 void CSeq_annot::SetTitleDesc(const string &title)
97 {
98  TDesc::Tdata::iterator iter = SetDesc().Set().begin();
99  for ( ; iter != SetDesc().Set().end(); ) {
100  if ((*iter)->IsTitle() ) {
101  iter = SetDesc().Set().erase(iter);
102  } else {
103  ++iter;
104  }
105  }
106 
107  CRef<CAnnotdesc> desc(new CAnnotdesc());
108  desc->SetTitle(title);
109  SetDesc().Set().push_back(desc);
110 }
111 
112 
113 void CSeq_annot::AddComment(const string &comment)
114 {
115  CRef<CAnnotdesc> desc(new CAnnotdesc());
116  desc->SetComment(comment);
117  SetDesc().Set().push_back(desc);
118 }
119 
120 
122 {
123  CRef<CDate> date(new CDate(dt));
124  SetCreateDate(*date);
125 }
126 
127 
129 {
130  TDesc::Tdata::iterator iter = SetDesc().Set().begin();
131  for ( ; iter != SetDesc().Set().end(); ) {
132  if ((*iter)->IsCreate_date() ) {
133  iter = SetDesc().Set().erase(iter);
134  } else {
135  ++iter;
136  }
137  }
138 
139  CRef<CAnnotdesc> desc(new CAnnotdesc());
140  desc->SetCreate_date(date);
141  SetDesc().Set().push_back(desc);
142 }
143 
144 
146 {
147  CRef<CDate> date(new CDate(dt));
148  SetUpdateDate(*date);
149 }
150 
151 
153 {
154  TDesc::Tdata::iterator iter = SetDesc().Set().begin();
155  for ( ; iter != SetDesc().Set().end(); ) {
156  if ((*iter)->IsUpdate_date() ) {
157  iter = SetDesc().Set().erase(iter);
158  } else {
159  ++iter;
160  }
161  }
162 
163  CRef<CAnnotdesc> desc(new CAnnotdesc());
164  desc->SetUpdate_date(date);
165  SetDesc().Set().push_back(desc);
166 }
167 
168 
170 {
171  CRef<CAnnotdesc> desc(new CAnnotdesc());
172  desc->SetUser(obj);
173  SetDesc().Set().push_back(desc);
174 }
175 
176 
177 bool CSeq_annot::IsFtable(void) const
178 {
179  return IsSetData () && GetData ().IsFtable ();
180 }
181 
182 bool CSeq_annot::IsAlign(void) const
183 {
184  return IsSetData () && GetData ().IsAlign ();
185 }
186 
187 bool CSeq_annot::IsGraph(void) const
188 {
189  return IsSetData () && GetData ().IsGraph ();
190 }
191 
192 bool CSeq_annot::IsIds(void) const
193 {
194  return IsSetData () && GetData ().IsIds ();
195 }
196 
197 bool CSeq_annot::IsLocs(void) const
198 {
199  return IsSetData () && GetData ().IsLocs ();
200 }
201 
202 bool CSeq_annot::IsSeq_table(void) const
203 {
204  return IsSetData () && GetData ().IsSeq_table ();
205 }
206 
207 
208 /////////////////////////////////////////////////////////////////////////////
209 // Zoom level manipulation functions
210 /////////////////////////////////////////////////////////////////////////////
211 
213 
214 
215 bool CSeq_annot::ExtractZoomLevel(const string& full_name, string* acc_ptr, int* zoom_level_ptr)
216 {
217  SIZE_TYPE pos = full_name.find(NCBI_ANNOT_TRACK_ZOOM_LEVEL_SUFFIX);
218  if ( pos != NPOS ) {
219  if ( acc_ptr ) {
220  *acc_ptr = full_name.substr(0, pos);
221  }
223  // assuming single asterisk "*" as wildcard for all zoom levels
224  if ( num_pos+1 == full_name.size() && full_name[num_pos] == '*' ) {
225  if ( zoom_level_ptr ) {
226  *zoom_level_ptr = -1;
227  }
228  return true;
229  }
230  else {
231  try {
232  int zoom_level = NStr::StringToInt(full_name.substr(num_pos));
233  if ( zoom_level_ptr ) {
234  *zoom_level_ptr = zoom_level;
235  }
236  return true;
237  }
238  catch ( CException& ) {
239  // invalid zoom level suffix, assume no zoom level
240  }
241  }
242  }
243  // no explicit zoom level
244  if ( acc_ptr ) {
245  *acc_ptr = full_name;
246  }
247  if ( zoom_level_ptr ) {
248  *zoom_level_ptr = 0;
249  }
250  return false;
251 }
252 
253 
254 string CSeq_annot::CombineWithZoomLevel(const string& acc, int zoom_level)
255 {
256  string ret = acc;
257  AddZoomLevel(ret, zoom_level);
258  return ret;
259 }
260 
261 
262 void CSeq_annot::AddZoomLevel(string& acc, int zoom_level)
263 {
264  int incl_level;
265  if ( !ExtractZoomLevel(acc, 0, &incl_level) ) {
266  if ( zoom_level == -1 ) {
267  // wildcard
269  }
270  else {
272  acc += NStr::IntToString(zoom_level);
273  }
274  }
275  else if ( incl_level != zoom_level ) {
276  // different zoom level
278  "AddZoomLevel: Incompatible zoom levels: "
279  <<acc<<" vs "<<zoom_level);
280  }
281 }
282 
283 
285 {
286  switch (GetErrCode()) {
287  case eZoom: return "Bad zoom level";
288  default: return CException::GetErrCodeString();
289  }
290 }
291 
292 
293 END_objects_SCOPE // namespace ncbi::objects::
294 
296 
297 #undef NCBI_USE_ERRCODE_X
298 
299 /* Original file checksum: lines: 64, chars: 1875, CRC32: 377b3912 */
static const size_t NCBI_ANNOT_TRACK_ZOOM_LEVEL_SUFFIX_LEN
Definition: Seq_annot.cpp:212
#define NCBI_ANNOT_TRACK_ZOOM_LEVEL_SUFFIX
Named annotations zoom level can be encoded in the accession string with @ suffix,...
Definition: Seq_annot.hpp:146
CAnnotdesc –.
Definition: Annotdesc.hpp:66
Definition: Date.hpp:53
virtual const char * GetErrCodeString(void) const override
Get error code interpreted as text.
Definition: Seq_annot.cpp:284
void AddUserObject(CUser_object &obj)
Definition: Seq_annot.cpp:169
void SetTitle(const string &title)
Definition: Seq_annot.cpp:84
bool IsGraph(void) const
Definition: Seq_annot.cpp:187
bool IsAlign(void) const
Definition: Seq_annot.cpp:182
bool IsSeq_table(void) const
Definition: Seq_annot.cpp:202
static string CombineWithZoomLevel(const string &acc, int zoom_level)
Combine accession string and zoom level into a string with separator.
Definition: Seq_annot.cpp:254
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
bool IsIds(void) const
Definition: Seq_annot.cpp:192
void SetCreateDate(const CTime &dt)
Definition: Seq_annot.cpp:121
static void AddZoomLevel(string &acc, int zoom_level)
Definition: Seq_annot.cpp:262
void SetUpdateDate(const CTime &dt)
Definition: Seq_annot.cpp:145
bool IsLocs(void) const
Definition: Seq_annot.cpp:197
void AddName(const string &name)
Definition: Seq_annot.cpp:61
void SetTitleDesc(const string &title)
Definition: Seq_annot.cpp:96
static bool ExtractZoomLevel(const string &full_name, string *acc_ptr, int *zoom_level_ptr)
Extract optional zoom level suffix from named annotation string.
Definition: Seq_annot.cpp:215
void AddTitle(const string &title)
Definition: Seq_annot.cpp:90
~CSeq_annot(void)
Definition: Seq_annot.cpp:56
bool IsFtable(void) const
Definition: Seq_annot.cpp:177
void AddComment(const string &comment)
Definition: Seq_annot.cpp:113
CTime –.
Definition: ncbitime.hpp:296
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
#define NPOS
Definition: ncbistr.hpp:133
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
Tdata & Set(void)
Assign a value to data member.
TTitle & SetTitle(void)
Select the variant.
Definition: Annotdesc_.hpp:528
bool IsAlign(void) const
Check if variant Align is selected.
Definition: Seq_annot_.hpp:635
TName & SetName(void)
Select the variant.
Definition: Annotdesc_.hpp:508
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
Definition: Seq_annot_.hpp:861
TUser & SetUser(void)
Select the variant.
Definition: Annotdesc_.cpp:190
TComment & SetComment(void)
Select the variant.
Definition: Annotdesc_.hpp:548
bool IsGraph(void) const
Check if variant Graph is selected.
Definition: Seq_annot_.hpp:655
bool IsFtable(void) const
Check if variant Ftable is selected.
Definition: Seq_annot_.hpp:615
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
bool IsSeq_table(void) const
Check if variant Seq_table is selected.
Definition: Seq_annot_.hpp:715
TUpdate_date & SetUpdate_date(void)
Select the variant.
Definition: Annotdesc_.cpp:234
bool IsIds(void) const
Check if variant Ids is selected.
Definition: Seq_annot_.hpp:675
TDesc & SetDesc(void)
Assign a value to Desc data member.
Definition: Seq_annot_.cpp:228
TCreate_date & SetCreate_date(void)
Select the variant.
Definition: Annotdesc_.cpp:212
bool IsLocs(void) const
Check if variant Locs is selected.
Definition: Seq_annot_.hpp:695
Definition of all error codes used in objects libraries.
Modified on Tue Apr 16 20:13:26 2024 by modify_doxy.py rev. 669887