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

Go to the SVN repository for this file.

1 /* $Id: autodef_options.cpp 100148 2023-06-23 19:49:35Z kans $
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: Colleen Bollin
27 *
28 * File Description:
29 * Generate unique definition lines for a set of sequences using organism
30 * descriptions and feature clauses.
31 */
32 
33 #include <ncbi_pch.hpp>
35 #include <corelib/ncbimisc.hpp>
36 
38 
39 
42 
43 
45 {
46  x_Reset();
47 }
48 
49 
51 {
52  CRef<CUser_object> user(new CUser_object());
53 
55  user->SetClass("1.0");
56 
57  for (unsigned int i = 0; i < eOptionFieldMax; i++) {
58  if (x_IsBoolean(i) && m_BooleanFlags[i]) {
60  user->SetData().push_back(field);
61  }
62  }
63 
64  user->SetData().push_back(x_MakeMaxMods());
65  user->SetData().push_back(x_MakeFeatureListType());
66  user->SetData().push_back(x_MakeMiscFeatRule());
67  user->SetData().push_back(x_MakeHIVRule());
68  if (!GetSpecifyNuclearProduct()) {
69  user->SetData().push_back(x_MakeProductFlag());
70  user->SetData().push_back(x_MakeNuclearCopyFlag());
71  }
73  x_MakeModifierList(*user);
75  user->SetData().push_back(x_MakeTargetedLocusName());
76  }
78  user->SetData().push_back(x_MakeCustomFeatureClause());
79  }
80 
81  return user;
82 }
83 
84 
85 #define INITENUMFIELD(Fieldname) \
86  } else if (field_type == eOptionFieldType_##Fieldname) { \
87  if ((*it)->IsSetData() && (*it)->GetData().IsStr()) { \
88  m_##Fieldname = Get##Fieldname((*it)->GetData().GetStr()); \
89  }
90 
91 
93 {
94  x_Reset();
96  ITERATE(CUser_object::TData, it, obj.GetData()) {
97  if ((*it)->IsSetLabel() && (*it)->GetLabel().IsStr()) {}
98  TFieldType field_type = GetFieldType((*it)->GetLabel().GetStr());
99  if (field_type == eOptionFieldType_Unknown && NStr::EqualNocase((*it)->GetLabel().GetStr(), "KeepPromoters")) {
101  }
102  if (field_type != eOptionFieldType_Unknown) {
103  if (x_IsBoolean(field_type)) {
104  if ((*it)->IsSetData() && (*it)->GetData().IsBool() && (*it)->GetData().GetBool()) {
105  m_BooleanFlags[field_type] = true;
106  }
107  } else if (field_type == eOptionFieldType_SpecifyNuclearProduct &&
108  (*it)->GetData().IsBool() && (*it)->GetData().GetBool()) {
110  } else if (field_type == eOptionFieldType_ProductFlag) {
111  if ((*it)->IsSetData() && (*it)->GetData().IsStr()) {
112  m_ProductFlag = GetProductFlag((*it)->GetData().GetStr());
115  }
116  } else if (field_type == eOptionFieldType_NuclearCopyFlag) {
117  if ((*it)->IsSetData() && (*it)->GetData().IsStr()) {
118  m_NuclearCopyFlag = GetProductFlag((*it)->GetData().GetStr());
121  }
122  INITENUMFIELD(FeatureListType)
123  INITENUMFIELD(MiscFeatRule)
124  INITENUMFIELD(HIVRule)
125  }
126  else if (field_type == eOptionFieldType_SuppressedFeatures) {
128  } else if (field_type == eOptionFieldType_MaxMods) {
129  if ((*it)->IsSetData() && (*it)->GetData().IsInt()) {
130  m_MaxMods = (*it)->GetData().GetInt();
131  }
132  } else if (field_type == eOptionFieldType_ModifierList) {
133  x_SetModifierList(**it);
134  } else if (field_type == eOptionFieldType_TargetedLocusName) {
135  if ((*it)->IsSetData() && (*it)->GetData().IsStr()) {
136  m_TargetedLocusName = (*it)->GetString();
137  }
138  } else if (field_type == eOptionFieldType_CustomFeatureClause) {
139  if ((*it)->IsSetData() && (*it)->GetData().IsStr()) {
140  m_CustomFeatureClause = (*it)->GetString();
141  }
142  }
143  }
144  }
145 }
146 
147 
149 {
155  m_MaxMods = -99;
156 
159 
160  for (unsigned int i = 0; i < eOptionFieldMax; i++) {
161  m_BooleanFlags[i] = false;
162  }
164 }
165 
166 
169  { "AllowModAtEndOfTaxname", CAutoDefOptions::eOptionFieldType_AllowModAtEndOfTaxname },
177  { "GeneClusterOppStrand", CAutoDefOptions::eOptionFieldType_GeneClusterOppStrand },
189  { "KeepRegulatoryFeatures", CAutoDefOptions::eOptionFieldType_KeepRegulatoryFeatures },
198  { "SpecifyNuclearProduct", CAutoDefOptions::eOptionFieldType_SpecifyNuclearProduct },
201  { "SuppressFeatureAltSplice", CAutoDefOptions::eOptionFieldType_SuppressFeatureAltSplice },
203  { "SuppressMiscFeatureSubfeatures", CAutoDefOptions::eOptionFieldType_SuppressMiscFeatureSubfeatures },
204  { "SuppressMobileElementSubfeatures", CAutoDefOptions::eOptionFieldType_SuppressMobileElementSubfeatures },
205  { "Targeted Locus Name", CAutoDefOptions::eOptionFieldType_TargetedLocusName },
209 };
210 
213 
215  { "Complete Genome", CAutoDefOptions::eCompleteGenome },
216  { "Complete Sequence", CAutoDefOptions::eCompleteSequence },
217  { "List All Features", CAutoDefOptions::eListAllFeatures },
218  { "Partial Genome", CAutoDefOptions::ePartialGenome },
219  { "Partial Sequence", CAutoDefOptions::ePartialSequence },
220  { "Sequence", CAutoDefOptions::eSequence },
221  { "Whole Genome Shotgun Sequence", CAutoDefOptions::eWholeGenomeShotgunSequence }
222 };
224 
226  { "CommentFeat", CAutoDefOptions::eCommentFeat },
227  { "Delete", CAutoDefOptions::eDelete },
228  { "NoncodingProductFeat", CAutoDefOptions::eNoncodingProductFeat }
229 };
231 
233  { "PreferClone", CAutoDefOptions::ePreferClone },
234  { "PreferIsolate", CAutoDefOptions::ePreferIsolate },
235  { "WantBoth", CAutoDefOptions::eWantBoth }
236 };
238 
239 
240 
241 #define AUTODEFGETENUM(Fieldname, Map, Default) \
242 string CAutoDefOptions::Get##Fieldname(unsigned int value) const \
243 { \
244  TNameValPairMap::const_iterator it = Map.begin(); \
245  while (it != Map.end()) { \
246  if (value == it->second) { \
247  return it->first; \
248  } \
249  ++it; \
250  } \
251  return kEmptyStr; \
252 } \
253 CAutoDefOptions::T##Fieldname CAutoDefOptions::Get##Fieldname(const string& value) const \
254 { \
255  TNameValPairMap::const_iterator it = Map.find(value.c_str()); \
256  if (it != Map.end()) { \
257  return it->second; \
258  } \
259  return Default; \
260 }
261 
262 AUTODEFGETENUM(FieldType, sc_FieldTypeStrsMap, eOptionFieldType_Unknown)
263 AUTODEFGETENUM(FeatureListType, sc_FeatureListTypeStrsMap, eListAllFeatures)
264 AUTODEFGETENUM(MiscFeatRule, sc_MiscFeatRuleStrsMap, eNoncodingProductFeat);
265 AUTODEFGETENUM(HIVRule, sc_HIVRuleStrsMap, eWantBoth);
266 
267 string CAutoDefOptions::GetProductFlag(CBioSource::TGenome value) const
268 {
270 }
271 
272 
274 {
276 }
277 
278 
280 {
282 }
283 
284 
286 {
288 }
289 
290 
291 
293 {
294  bool rval = true;
295  switch (field_type)
296  {
307  rval = false;
308  break;
309  default:
310  rval = true;
311  break;
312  }
313  return rval;
314 }
315 
316 
318 {
319  CRef<CUser_field> field(new CUser_field());
320  field->SetLabel().SetStr(GetFieldType(field_type));
321  field->SetData().SetBool(true);
322  return field;
323 }
324 
325 
327 {
330 }
331 
332 
334 {
336  if (subtype == *it || *it == CSeqFeatData::eSubtype_any) {
337  return true;
338  }
339  }
340  return false;
341 }
342 
344 {
345  m_SuppressedFeatureSubtypes.push_back(subtype);
346 }
347 
348 
350 {
352 }
353 
354 
356 {
357  if (m_SuppressedFeatureSubtypes.empty()) {
358  return;
359  }
360  CRef<CUser_field> field(new CUser_field());
362 
364  if (*it == CSeqFeatData::eSubtype_any) {
365  field->SetData().SetStr("All");
366  user.SetData().push_back(field);
367  return;
368  }
369  field->SetData().SetStrs().push_back(CSeqFeatData::SubtypeValueToName(*it));
370  }
371  user.SetData().push_back(field);
372 }
373 
374 
376 {
378 
379  if (!field.IsSetData()) {
380  return;
381  }
382  if (field.GetData().IsStr() && NStr::EqualNocase(field.GetData().GetStr(), "All")) {
384  return;
385  }
386 
387  if (!field.GetData().IsStrs()){
388  return;
389  }
390 
394  m_SuppressedFeatureSubtypes.push_back(val);
395  }
396  }
397 }
398 
399 
401 {
402  m_SubSources.push_back(subtype);
403 }
404 
405 
407 {
408  m_OrgMods.push_back(subtype);
409 }
410 
411 
413 {
414  m_OrgMods.clear();
415  m_SubSources.clear();
416 }
417 
418 
419 const string kSubSources = "SubSources";
420 const string kOrgMods = "OrgMods";
421 
423 {
424  try {
425  CRef<CUser_field> field(new CUser_field());
427 
428  if (!m_SubSources.empty()) {
429  CRef<CUser_field> subsources(new CUser_field());
430  subsources->SetLabel().SetStr(kSubSources);
431  vector<string> vals;
433  vals.push_back(CSubSource::GetSubtypeName(*it));
434  }
435  sort(vals.begin(), vals.end());
436  vector<string>::iterator sort_it = std::unique(vals.begin(), vals.end());
437  vals.resize(distance(vals.begin(), sort_it));
438  ITERATE(vector<string>, it, vals) {
439  subsources->SetData().SetStrs().push_back(*it);
440  }
441  field->SetData().SetFields().push_back(subsources);
442  }
443 
444  if (!m_OrgMods.empty()) {
445  CRef<CUser_field> orgmods(new CUser_field());
446  orgmods->SetLabel().SetStr(kOrgMods);
447  vector<string> vals;
448  ITERATE(TOrgMods, it, m_OrgMods) {
449  vals.push_back(COrgMod::GetSubtypeName(*it));
450  }
451  sort(vals.begin(), vals.end());
452  vector<string>::iterator sort_it = std::unique(vals.begin(), vals.end());
453  vals.resize(distance(vals.begin(), sort_it));
454  ITERATE(vector<string>, it, vals) {
455  orgmods->SetData().SetStrs().push_back(*it);
456  }
457  field->SetData().SetFields().push_back(orgmods);
458  }
459 
460  if (field->IsSetData() && field->GetData().IsFields() && field->GetData().GetFields().size() > 0) {
461  user.SetData().push_back(field);
462  }
463  } catch ( ... ) {
464  }
465 }
466 
467 
469 {
471 
472  try {
473  if (!field.IsSetData() || !field.GetData().IsFields()) {
474  return;
475  }
476 
478  if ((*it)->IsSetLabel() && (*it)->GetLabel().IsStr() &&
479  (*it)->IsSetData() && (*it)->GetData().IsStrs()) {
480  if (NStr::EqualNocase((*it)->GetLabel().GetStr(), kSubSources)) {
481  ITERATE(CUser_field::TData::TStrs, s, (*it)->GetData().GetStrs()) {
483  m_SubSources.push_back(subtype);
484  }
485  } else if (NStr::EqualNocase((*it)->GetLabel().GetStr(), kOrgMods)) {
486  ITERATE(CUser_field::TData::TStrs, s, (*it)->GetData().GetStrs()) {
488  m_OrgMods.push_back(subtype);
489  }
490  }
491  }
492  }
493  } catch ( ... ) {
494  }
495 }
496 
497 
499 {
500  CRef<CUser_field> field(new CUser_field());
502  field->SetData().SetInt(m_MaxMods);
503  return field;
504 }
505 
506 
508 {
509  CRef<CUser_field> field(new CUser_field());
511  field->SetData().SetStr(m_TargetedLocusName);
512  return field;
513 }
514 
515 
517 {
518  CRef<CUser_field> field(new CUser_field());
520  field->SetData().SetStr(m_CustomFeatureClause);
521  return field;
522 }
523 
524 
525 
CStaticArrayMap< const char *, unsigned int, PNocase > TNameValPairMap
#define AUTODEFGETENUM(Fieldname, Map, Default)
#define INITENUMFIELD(Fieldname)
SStaticPair< const char *, unsigned int > TNameValPair
DEFINE_STATIC_ARRAY_MAP_WITH_COPY(TNameValPairMap, sc_FieldTypeStrsMap, sc_FieldTypes)
const TNameValPair sc_HIVRuleStr[]
const TNameValPair sc_FeatureListTypeStr[]
const string kSubSources
const TNameValPair sc_MiscFeatRuleStr[]
const string kOrgMods
const TNameValPair sc_FieldTypes[]
CRef< CUser_field > x_MakeHIVRule() const
CRef< CUser_field > x_MakeNuclearCopyFlag() const
void SuppressFeature(CSeqFeatData::ESubtype subtype)
CRef< CUser_field > x_MakeBooleanField(TFieldType field_type) const
void ClearSuppressedFeatures()
void AddOrgMod(COrgMod::TSubtype subtype)
CRef< CUser_field > x_MakeFeatureListType() const
CBioSource::TGenome m_NuclearCopyFlag
CRef< CUser_field > x_MakeMiscFeatRule() const
bool x_IsBoolean(TFieldType field_type) const
string GetFieldType(TFieldType field_type) const
TMiscFeatRule m_MiscFeatRule
CRef< CUser_object > MakeUserObject() const
void x_MakeSuppressedFeatures(CUser_object &user) const
void InitFromUserObject(const CUser_object &obj)
TFeatureListType m_FeatureListType
void x_SetSuppressedFeatures(const CUser_field &field)
vector< CSeqFeatData::ESubtype > TSuppressedFeatureSubtypes
TSubSources m_SubSources
unsigned int TFieldType
CRef< CUser_field > x_MakeMaxMods() const
CBioSource::TGenome GetNuclearCopyFlag() const
CBioSource::TGenome m_ProductFlag
void x_SetModifierList(const CUser_field &field)
CBioSource::TGenome GetProductFlag() const
vector< COrgMod::TSubtype > TOrgMods
TSuppressedFeatureSubtypes m_SuppressedFeatureSubtypes
@ eOptionFieldType_AllowModAtEndOfTaxname
@ eOptionFieldType_SpecifyNuclearProduct
@ eOptionFieldType_CustomFeatureClause
@ eOptionFieldType_GeneClusterOppStrand
@ eOptionFieldType_SuppressFeatureAltSplice
@ eOptionFieldType_SuppressMobileElementSubfeatures
@ eOptionFieldType_SuppressMiscFeatureSubfeatures
@ eOptionFieldType_KeepRegulatoryFeatures
CRef< CUser_field > x_MakeCustomFeatureClause() const
void x_MakeModifierList(CUser_object &user) const
bool m_BooleanFlags[eOptionFieldMax]
bool GetSpecifyNuclearProduct() const
void AddSubSource(CSubSource::TSubtype subtype)
CRef< CUser_field > x_MakeProductFlag() const
bool IsFeatureSuppressed(CSeqFeatData::ESubtype subtype) const
CRef< CUser_field > x_MakeTargetedLocusName() const
vector< CSubSource::TSubtype > TSubSources
static string GetOrganelleByGenome(unsigned int genome)
Definition: BioSource.cpp:216
static CBioSource::EGenome GetGenomeByOrganelle(const string &organelle, NStr::ECase use_case=NStr::eCase, bool starts_with=false)
Definition: BioSource.cpp:168
static string GetSubtypeName(TSubtype stype, EVocabulary vocabulary=eVocabulary_raw)
Definition: OrgMod.cpp:108
static TSubtype GetSubtypeValue(const string &str, EVocabulary vocabulary=eVocabulary_raw)
Definition: OrgMod.cpp:62
@ eSubtype_bad
These no longer need to match the FEATDEF values in the C toolkit's objfdef.h.
static ESubtype SubtypeNameToValue(CTempString sName)
Turn a string into its ESubtype which is NOT necessarily related to the identifier of the enum.
static CTempString SubtypeValueToName(ESubtype eSubtype)
Turns a ESubtype into its string value which is NOT necessarily related to the identifier of the enum...
class CStaticArrayMap<> provides access to a static array in much the same way as CStaticArraySet<>,...
Definition: static_map.hpp:175
static TSubtype GetSubtypeValue(const string &str, EVocabulary vocabulary=eVocabulary_raw)
Definition: SubSource.cpp:94
static string GetSubtypeName(CSubSource::TSubtype stype, EVocabulary vocabulary=eVocabulary_raw)
Definition: SubSource.cpp:151
void SetObjectType(EObjectType obj_type)
@ eObjectType_AutodefOptions
char value[7]
Definition: config.c:431
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#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
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
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
const TStr & GetStr(void) const
Get the variant data.
bool IsStrs(void) const
Check if variant Strs is selected.
const TStrs & GetStrs(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
const TFields & GetFields(void) const
Get the variant data.
vector< CRef< CUser_field > > TFields
bool IsFields(void) const
Check if variant Fields is selected.
bool IsStr(void) const
Check if variant Str is selected.
void SetClass(const TClass &value)
Assign a value to Class data member.
TData & SetData(void)
Assign a value to Data data member.
void SetLabel(TLabel &value)
Assign a value to Label data member.
const TData & GetData(void) const
Get the Data member data.
void SetData(TData &value)
Assign a value to Data data member.
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
vector< CStringUTF8 > TStrs
vector< CRef< CUser_field > > TData
int i
constexpr auto sort(_Init &&init)
Miscellaneous common-use basic types and functionality.
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
Modified on Tue Oct 03 02:53:10 2023 by modify_doxy.py rev. 669887