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

Go to the SVN repository for this file.

1 /* $Id: OrgName.cpp 79377 2017-09-06 15:45:28Z domrach $
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  * 'seqfeat.asn'.
35  */
36 
37 // standard includes
38 
39 // generated includes
40 #include <ncbi_pch.hpp>
42 
45 
46 // generated classes
47 
49 
50 BEGIN_objects_SCOPE // namespace ncbi::objects::
51 
52 // destructor
54 {
55 }
56 
57 
58 bool COrgName::GetFlatName(string& name_out, string* lineage) const
59 {
60  if (lineage && lineage->empty() && IsSetLineage()) {
61  *lineage = GetLineage();
62  }
63 
64  if ( !IsSetName() ) {
65  return false;
66  }
67 
68  const TName& name = GetName();
69  name_out.clear();
70  switch (name.Which()) {
71  case C_Name::e_Namedhybrid: {
72  const CBinomialOrgName& bin = name.GetNamedhybrid();
73  name_out += bin.GetGenus();
74  if( bin.IsSetSpecies() ) {
75  name_out += " x ";
76  name_out += bin.GetSpecies();
77  }
78  return true;
79  }
80  case C_Name::e_Binomial: {
81  const CBinomialOrgName& bin = name.GetBinomial();
82  if (bin.IsSetSpecies()) {
83  string sSpecies = bin.GetSpecies();
84  if( sSpecies.find(" ") != string::npos &&
85  !( NStr::StartsWith(sSpecies,"sp. ") ||
86  NStr::StartsWith(sSpecies,"species ") ) ) {
87  // When species epithet is complex -- occurs when genus name doesn't coincide with beginning of species name
88  name_out += sSpecies;
89  } else { // Simple case with single genus and species epithets
90  if (bin.IsSetSubspecies() && !NStr::TruncateSpaces(bin.GetSubspecies()).empty()) {
91  string sSubspecies = NStr::TruncateSpaces(bin.GetSubspecies());
92  bool bSubspIndicator = NStr::StartsWith(sSubspecies, "subsp. ") ||
93  NStr::StartsWith(sSubspecies, "ssp. ") ||
94  NStr::StartsWith(sSubspecies, "subspecies ");
95  if( sSubspecies.find(" ") != string::npos && !bSubspIndicator ) {
96  // When subspecies epithet is complex -- occurs when species name doesn't coincide with beginning of subspecies name
97  name_out += sSubspecies;
98  } else { // Simple case with single sub-species epithet
99  name_out += bin.GetGenus();
100  name_out += ' ' + bin.GetSpecies();
101  if( !bSubspIndicator ) {
102  string sNomenclature;
103  bool bZooCode = false;
104  if( GetNomenclature( sNomenclature ) ) {
105  bZooCode = sNomenclature == "Z";
106  } else { // we still have to support old nomenclature-less orgnames
107  string sLineage = lineage ? *lineage : IsSetLineage() ? GetLineage() : NcbiEmptyString;
108  bZooCode = sLineage.find("Metazoa;") != string::npos ||
109  sLineage.find("Slopalinida;") != string::npos ||
110  sLineage.find("Blastocystis;") != string::npos;
111  }
112  if( !bZooCode ) {
113  name_out += " subsp.";
114  } else { // check if subspecies is well-specified
115  if( sSubspecies.find_first_not_of("abcdefghijklmnopqrstuvwxyz-") != string::npos ||
116  sSubspecies[0] == '-' ) {
117  name_out += " ssp.";
118  }
119  }
120  }
121  name_out += ' ' + sSubspecies;
122  }
123  } else { // No subspecies
124  name_out += bin.GetGenus();
125  name_out += ' ' + bin.GetSpecies();
126  }
127  if( IsSetMod() ) { // Add variety and forma to flat name -- those are valid classification categories
128  ITERATE (COrgName::TMod, it, GetMod()) {
129  if( (*it)->GetSubtype() == COrgMod::eSubtype_variety ) {
130  name_out += " var. ";
131  name_out += (*it)->GetSubname();
132  break;
133  }
134  }
135  ITERATE (COrgName::TMod, it, GetMod()) {
136  if( (*it)->GetSubtype() == COrgMod::eSubtype_forma ) {
137  name_out += " f. ";
138  name_out += (*it)->GetSubname();
139  break;
140  } else if( (*it)->GetSubtype() == COrgMod::eSubtype_forma_specialis ) {
141  name_out += " f.sp. ";
142  name_out += (*it)->GetSubname();
143  break;
144  }
145  }
146  }
147  }
148  }
149  return true;
150  }
151 
153  name_out = name.GetVirus();
154  return true;
155 
157  {
158  string tmp;
159  string delim;
160  string sLineage = lineage ? *lineage : IsSetLineage() ? GetLineage() : NcbiEmptyString;
161  ITERATE (CMultiOrgName::Tdata, it, name.GetHybrid().Get()) {
162  tmp.clear();
163  if ((*it)->GetFlatName(tmp, &sLineage)) {
164  name_out += delim;
165  if( (*it)->IsSetName() && (*it)->GetName().IsHybrid() ) {
166  name_out += '(';
167  name_out += tmp;
168  name_out += ')';
169  } else {
170  name_out += tmp;
171  }
172  delim = " x ";
173  } else {
174  return false;
175  }
176  }
177  return true;
178  }
179 
181  {
182  string delim;
183  ITERATE (CPartialOrgName::Tdata, it, name.GetPartial().Get()) {
184  name_out += delim + (*it)->GetName();
185  delim = " ";
186  }
187  return true;
188  }
189 
190  default:
191  return false;
192  }
193 }
194 
195 // The proposed format for orgname flags: flagname1[;flagname2]...[;flagnameN]
196 // where flagnameX consists of ascii alphanum characters only. Each value of flagnameX is unique.
197 // Presence of flag name in the strings means 'true' value for the flag.
199 
200 void COrgName::x_SetAttribFlag( const string& name, bool bStartsWith )
201 {
202  if( !x_GetAttribFlag( name, bStartsWith ) ) {
203  if( IsSetAttrib() && !GetAttrib().empty() ) {
204  SetAttrib().append(s_flagDelim).append(name);
205  } else {
206  SetAttrib( name );
207  }
208  }
209 }
210 
211 void COrgName::x_ResetAttribFlag( const string& name, bool bStartsWith )
212 {
213  if( !name.empty() && IsSetAttrib() ) {
214  const string& attr = GetAttrib();
215  list< CTempString > lVals;
217  for( list< CTempString >::iterator i = lVals.begin(), li = lVals.end(); i != li; ) {
219  if( (!bStartsWith && NStr::EqualNocase( *i, name )) ||
220  (bStartsWith && NStr::StartsWith( *i, name, NStr::eNocase )) ) {
221  i = lVals.erase( i );
222  } else {
223  ++i;
224  }
225  }
226  SetAttrib( NStr::Join( lVals, s_flagDelim ) );
227  if( SetAttrib().empty() ) {
228  ResetAttrib();
229  }
230  }
231 }
232 
233 bool COrgName::x_GetAttribFlag( const string& name, bool bStartsWith ) const
234 {
235  if( !name.empty() && IsSetAttrib() ) {
236  const string& attr = GetAttrib();
237  list< CTempString > lVals;
239  NON_CONST_ITERATE( list< CTempString >, i, lVals ) {
241  if( (!bStartsWith && NStr::EqualNocase( *i, name )) ||
242  (bStartsWith && NStr::StartsWith( *i, name, NStr::eNocase )) ) {
243  return true;
244  }
245  }
246  }
247  return false;
248 }
249 
250 // Getting attribute value for pairs like attrname=value;
251 // value cannot contain ';'
252 bool COrgName::x_GetAttribValue( const string& name, string& sValue ) const
253 {
254  if( !name.empty() && IsSetAttrib() ) {
255  const string& attr = GetAttrib();
256  list< CTempString > lVals;
258  NON_CONST_ITERATE( list< CTempString >, i, lVals ) {
260  if( NStr::StartsWith( *i, name, NStr::eNocase ) &&
261  i->size() > name.size() && (*i)[name.size()] == '=' ) {
262  sValue.assign( i->substr(name.size()+1) );
263  return true;
264  }
265  }
266  }
267  return false;
268 }
269 
270 // Flag indicating that node's scientific name is "well specified" according to the
271 // respective taxonomic nomenclature (e.g. Genus species subspecies).
272 // Based on "specified" property from Taxonomy database
274 {
275  return x_GetAttribFlag( "specified" );
276 }
277 
278 void COrgName::SetFormalNameFlag( bool bFormalName )
279 {
280  if( bFormalName ) {
281  x_SetAttribFlag( "specified" );
282  } else {
283  x_ResetAttribFlag( "specified" );
284  }
285 }
286 
288 {
289  return x_GetAttribFlag( "uncultured" );
290 }
291 
292 void COrgName::SetUncultured( bool bUncultured )
293 {
294  if( bUncultured ) {
295  x_SetAttribFlag( "uncultured" );
296  } else {
297  x_ResetAttribFlag( "uncultured" );
298  }
299 }
300 
301 // Modifier forwarding flag. Used during org-ref lookup to enable/disable
302 // modifier forwarding. If set modifier forwarding is disabled.
303 // Flag is kept along with other flags in orgname.attrib field
304 // (see comments to x_SetAttribFlag() function)
306 {
307  return x_GetAttribFlag( "nomodforward" );
308 }
309 
311 {
312  x_SetAttribFlag( "nomodforward" );
313 }
314 
316 {
317  x_ResetAttribFlag( "nomodforward" );
318 }
319 
320 #define MAKE_COMMON(o1,o2,o3,Field) if (o1.IsSet##Field() && o2.IsSet##Field() && NStr::Equal(o1.Get##Field(), o2.Get##Field())) o3.Set##Field(o1.Get##Field());
321 #define MAKE_COMMON_INT(o1,o2,o3,Field) if (o1.IsSet##Field() && o2.IsSet##Field() && o1.Get##Field() == o2.Get##Field()) o3.Set##Field(o1.Get##Field());
322 
324 {
325  bool any = false;
326  CRef<COrgName> common(new COrgName());
327 
328  // name
329  if (IsSetName() && other.IsSetName() && GetName().Equals(other.GetName())) {
330  common->SetName().Assign(GetName());
331  any = true;
332  }
333 
334  // mod
335  if (IsSetMod() && other.IsSetMod()) {
336  ITERATE(TMod, it1, GetMod()) {
337  bool found = false;
338  ITERATE(TMod, it2, other.GetMod()) {
339  if ((*it1)->Equals(**it2)) {
340  found = true;
341  }
342  }
343  if (found) {
344  CRef<COrgMod> add(new COrgMod());
345  add->Assign(**it1);
346  common->SetMod().push_back(add);
347  any = true;
348  }
349  }
350  }
351 
352  MAKE_COMMON((*this), other, (*common), Attrib);
353  MAKE_COMMON((*this), other, (*common), Lineage);
354  MAKE_COMMON((*this), other, (*common), Div);
355  MAKE_COMMON_INT((*this), other, (*common), Gcode);
356  MAKE_COMMON_INT((*this), other, (*common), Mgcode);
357  MAKE_COMMON_INT((*this), other, (*common), Pgcode);
358  if (common->IsSetAttrib() || common->IsSetLineage() || common->IsSetDiv() ||
359  common->IsSetGcode() || common->IsSetMgcode() || common->IsSetPgcode()) {
360  any = true;
361  }
362 
363  if (!any) {
364  common.Reset(NULL);
365  }
366  return common;
367 }
368 
369 // Nomenclature information stored in attrib field as string in following format:
370 // nomenclature=[BPVZ]*;
371 bool COrgName::GetNomenclature( string& result ) const
372 {
373  if( IsSetMod() ) {
374  ITERATE( COrgName::TMod, ci, GetMod() ) {
375  if( (*ci)->GetSubtype() == COrgMod::eSubtype_nomenclature ) {
376  result = (*ci)->GetSubname();
377  return true;
378  }
379  }
380  }
381  return false;
382 }
383 
384 // returns false if value is unsupported
385 bool COrgName::SetNomenclature( const string& nomenclature )
386 {
387  // Analyze value. Make sure it consists of [BPVZ]
388  char norm_nom[4];
389  memset( norm_nom, 0, sizeof(norm_nom) );
390  ITERATE( string, ci, nomenclature ) {
391  switch( *ci ) {
392  case 'b': case 'B': norm_nom[0] = 'B'; break;
393  case 'p': case 'P': norm_nom[1] = 'P'; break;
394  case 'v': case 'V': norm_nom[2] = 'V'; break;
395  case 'z': case 'Z': norm_nom[3] = 'Z'; break;
396  default: return false;
397  }
398  }
399  string sNewVal;
400  for( size_t i = 0; i < sizeof(norm_nom); ++i ) {
401  if( norm_nom[i] != 0 ) {
402  sNewVal += norm_nom[i];
403  }
404  }
405 
406  string sOldVal;
407  if( GetNomenclature( sOldVal ) ) {
408  if( sOldVal == sNewVal ) {
409  return true; // already set to this value
410  } else {
412  }
413  }
414  if( !sNewVal.empty() ) {
415  CRef<COrgMod> pMod( new COrgMod( COrgMod::eSubtype_nomenclature, sNewVal ) );
416  SetMod().push_back( pMod );
417  }
418  return true;
419 }
420 
421 // returns false if value is unsupported
423 {
425 }
426 
427 unsigned int // returns number of removed modifiers
429 {
430  unsigned result = 0;
431  if( IsSetMod() ) {
432  for( TMod::iterator i = SetMod().begin(); i != SetMod().end(); ) {
433  if( (*i)->GetSubtype() == to_remove ) {
434  i = SetMod().erase(i);
435  ++result;
436  } else {
437  ++i;
438  }
439  }
440  }
441  return result;
442 }
443 
444 END_objects_SCOPE // namespace ncbi::objects::
445 
447 
448 /* Original file checksum: lines: 64, chars: 1877, CRC32: 38972243 */
#define MAKE_COMMON(o1, o2, o3, Field)
Definition: OrgName.cpp:320
#define MAKE_COMMON_INT(o1, o2, o3, Field)
Definition: OrgName.cpp:321
const CTempString s_flagDelim
Definition: OrgName.cpp:198
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CBinomialOrgName –.
@OrgMod.hpp User-defined methods of the data storage class.
Definition: OrgMod.hpp:54
bool x_GetAttribValue(const string &name, string &sValue) const
Definition: OrgName.cpp:252
~COrgName(void)
Definition: OrgName.cpp:53
COrgName(void)
Definition: OrgName.hpp:117
bool IsFormalName() const
Definition: OrgName.cpp:273
bool x_GetAttribFlag(const string &name, bool bStartsWith=false) const
Definition: OrgName.cpp:233
bool GetFlatName(string &name_out, string *lineage=0) const
Definition: OrgName.cpp:58
unsigned int RemoveModBySubtype(COrgMod::ESubtype to_remove)
Definition: OrgName.cpp:428
void DisableModifierForwarding()
Definition: OrgName.cpp:310
void SetFormalNameFlag(bool bFormalName)
Definition: OrgName.cpp:278
bool IsUncultured() const
Definition: OrgName.cpp:287
void x_SetAttribFlag(const string &name, bool bStartsWith=false)
Definition: OrgName.cpp:200
CRef< COrgName > MakeCommon(const COrgName &other) const
Definition: OrgName.cpp:323
void SetUncultured(bool bUncultured)
Definition: OrgName.cpp:292
void EnableModifierForwarding()
Definition: OrgName.cpp:315
bool GetNomenclature(string &result) const
Definition: OrgName.cpp:371
bool SetNomenclature(const string &nomenclature)
Definition: OrgName.cpp:385
bool IsModifierForwardingDisabled() const
Definition: OrgName.cpp:305
void ResetNomenclature()
Definition: OrgName.cpp:422
void x_ResetAttribFlag(const string &name, bool bStartsWith=false)
Definition: OrgName.cpp:211
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
static char tmp[3200]
Definition: utf8.c:42
#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 NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
virtual bool Equals(const CSerialObject &object, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
#define NcbiEmptyString
Definition: ncbistr.hpp:122
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
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:5353
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
Definition: ncbistr.cpp:3186
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2508
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
const TMod & GetMod(void) const
Get the Mod member data.
Definition: OrgName_.hpp:839
void ResetAttrib(void)
Reset Attrib data member.
Definition: OrgName_.cpp:262
const TLineage & GetLineage(void) const
Get the Lineage member data.
Definition: OrgName_.hpp:864
bool IsSetPgcode(void) const
plastid genetic code Check if a value has been assigned to Pgcode data member.
Definition: OrgName_.hpp:1040
const TVirus & GetVirus(void) const
Get the variant data.
Definition: OrgName_.hpp:727
E_Choice Which(void) const
Which variant is currently selected.
Definition: OrgName_.hpp:686
const THybrid & GetHybrid(void) const
Get the variant data.
Definition: OrgName_.cpp:149
void SetName(TName &value)
Assign a value to Name data member.
Definition: OrgName_.cpp:250
bool IsSetLineage(void) const
lineage with semicolon separators Check if a value has been assigned to Lineage data member.
Definition: OrgName_.hpp:852
bool IsSetSubspecies(void) const
Check if a value has been assigned to Subspecies data member.
const TName & GetName(void) const
Get the Name member data.
Definition: OrgName_.hpp:771
bool IsSetMgcode(void) const
mitochondrial genetic code Check if a value has been assigned to Mgcode data member.
Definition: OrgName_.hpp:946
const TBinomial & GetBinomial(void) const
Get the variant data.
Definition: OrgName_.cpp:121
bool IsSetDiv(void) const
GenBank division code Check if a value has been assigned to Div data member.
Definition: OrgName_.hpp:993
bool IsSetMod(void) const
Check if a value has been assigned to Mod data member.
Definition: OrgName_.hpp:827
const Tdata & Get(void) const
Get the member data.
list< CRef< COrgMod > > TMod
Definition: OrgName_.hpp:332
bool IsSetAttrib(void) const
attribution of name Check if a value has been assigned to Attrib data member.
Definition: OrgName_.hpp:780
list< CRef< COrgName > > Tdata
const TSpecies & GetSpecies(void) const
Get the Species member data.
list< CRef< CTaxElement > > Tdata
bool IsSetGcode(void) const
genetic code (see CdRegion) Check if a value has been assigned to Gcode data member.
Definition: OrgName_.hpp:899
TMod & SetMod(void)
Assign a value to Mod data member.
Definition: OrgName_.hpp:845
const TGenus & GetGenus(void) const
Get the Genus member data.
const TPartial & GetPartial(void) const
Get the variant data.
Definition: OrgName_.cpp:193
TAttrib & SetAttrib(void)
Assign a value to Attrib data member.
Definition: OrgName_.hpp:815
const TNamedhybrid & GetNamedhybrid(void) const
Get the variant data.
Definition: OrgName_.cpp:171
bool IsSetSpecies(void) const
species required if subspecies used Check if a value has been assigned to Species data member.
bool IsSetName(void) const
Check if a value has been assigned to Name data member.
Definition: OrgName_.hpp:759
const Tdata & Get(void) const
Get the member data.
const TSubspecies & GetSubspecies(void) const
Get the Subspecies member data.
const TAttrib & GetAttrib(void) const
Get the Attrib member data.
Definition: OrgName_.hpp:792
@ eSubtype_variety
Definition: OrgMod_.hpp:89
@ eSubtype_nomenclature
code of nomenclature in subname (B,P,V,Z or combination)
Definition: OrgMod_.hpp:122
@ eSubtype_forma_specialis
Definition: OrgMod_.hpp:109
@ e_Hybrid
hybrid between organisms
Definition: OrgName_.hpp:115
@ e_Namedhybrid
some hybrids have genus x species name
Definition: OrgName_.hpp:116
@ e_Binomial
genus/species type name
Definition: OrgName_.hpp:113
@ e_Partial
when genus not known
Definition: OrgName_.hpp:117
@ e_Virus
virus names are different
Definition: OrgName_.hpp:114
int i
constexpr bool empty(list< Ts... >) noexcept
else result
Definition: token2.c:20
Modified on Sun Jun 16 04:30:42 2024 by modify_doxy.py rev. 669887