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

Go to the SVN repository for this file.

1 /* $Id: User_object.cpp 98526 2022-11-30 16:39:45Z gotvyans $
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 ASN data definition file
34  * 'general.asn'.
35  */
36 
37 // standard includes
38 
39 // generated includes
40 #include <ncbi_pch.hpp>
44 #include <util/static_map.hpp>
45 
46 // generated classes
47 
49 
50 BEGIN_objects_SCOPE // namespace ncbi::objects::
51 
52 
53 SAFE_CONST_STATIC_STRING(kUnverifiedOrganism, "Organism");
54 SAFE_CONST_STATIC_STRING(kUnverifiedMisassembled, "Misassembled");
55 SAFE_CONST_STATIC_STRING(kUnverifiedFeature, "Features");
56 SAFE_CONST_STATIC_STRING(kUnverifiedContaminant, "Contaminant");
57 
58 SAFE_CONST_STATIC_STRING(kUnreviewedUnannotated, "Unannotated");
59 
60 
61 // destructor
63 {
64 }
65 
66 
67 //
68 // retrieve a named field. The named field can recurse, depending
69 // on a set of user-defined delimiters
70 //
71 const CUser_field& CUser_object::GetField(const string& str,
72  const string& delim,
73  NStr::ECase use_case) const
74 {
75  CConstRef<CUser_field> ref(GetFieldRef(str, delim, use_case));
76  if (ref.Empty()) {
77  NCBI_THROW(CCoreException, eNullPtr,
78  "Unable to find User-field " + str);
79  }
80  return *ref;
81 }
82 
83 
85  const string& delim,
86  NStr::ECase use_case) const
87 {
88  list<string> toks;
89  NStr::Split(str, delim, toks, NStr::fSplit_Tokenize);
90  if ( !toks.size() ) {
91  return CConstRef<CUser_field>();
92  }
93 
94  ///
95  /// step 1: scan one level deep for a nested object
96  /// we scan only with the first token
97  ///
98  string sub;
99  string first;
100  {{
101  list<string>::iterator iter = toks.begin();
102  first = *iter;
103  for (++iter; iter != toks.end(); ++iter) {
104  if ( !sub.empty() ) {
105  sub += delim;
106  }
107  sub += *iter;
108  }
109  }}
110 
111  ITERATE(TData, field_iter, GetData()) {
112  bool found = false;
113  const CUser_field& field = **field_iter;
114  if (field.IsSetLabel() && field.GetLabel().IsStr()) {
115  const string& this_label = field.GetLabel().GetStr();
116  if ( NStr::Equal(this_label, first, use_case) ) {
117  found = true;
118  }
119  }
120  if ( !found ) {
121  continue;
122  }
123 
124  if ( !sub.empty() ) {
125  CConstRef<CUser_field> field_ref =
126  (*field_iter)->GetFieldRef(sub, delim, use_case);
127  if (field_ref) {
128  return field_ref;
129  }
130  } else {
131  return CConstRef<CUser_field>(&field);
132  }
133  }
134  return CConstRef<CUser_field>();
135 }
136 
137 
138 bool CUser_object::HasField(const string& str,
139  const string& delim,
140  NStr::ECase use_case) const
141 {
142  return GetFieldRef(str, delim, use_case).GetPointer() ? true : false;
143 }
144 
145 
146 //
147 // retrieve a named field. The named field can recurse, depending
148 // on a set of user-defined delimiters
149 //
151  const string& delim,
152  const string& obj_subtype,
153  NStr::ECase use_case)
154 {
155  return *SetFieldRef(str, delim, obj_subtype, use_case);
156 }
157 
158 
160  const string& delim,
161  const string& /* obj_subtype */,
162  NStr::ECase use_case)
163 {
164  list<string> toks;
165  NStr::Split(str, delim, toks, NStr::fSplit_Tokenize);
166 
167  CRef<CUser_field> field_ref;
168 
169  /// pass 1: see if we have a field that starts with this label already
170  NON_CONST_ITERATE(TData, field_iter, SetData()) {
171  CUser_field& field = **field_iter;
172  if (field.GetLabel().IsStr() &&
173  NStr::Equal(field.GetLabel().GetStr(), toks.front(), use_case))
174  {
175  field_ref = *field_iter;
176  break;
177  }
178  }
179 
180  if ( !field_ref ) {
181  field_ref.Reset(new CUser_field());
182  field_ref->SetLabel().SetStr(toks.front());
183  SetData().push_back(field_ref);
184  }
185 
186  toks.pop_front();
187  if (toks.size()) {
188  string s = NStr::Join(toks, delim);
189  CRef<CUser_field> f = field_ref->SetFieldRef(s, delim, use_case);
190  field_ref = f;
191  }
192 
193  return field_ref;
194 }
195 
196 
197 // add a data field to the user object that holds a given value
199  const string& value,
200  EParseField parse)
201 {
202  CRef<CUser_field> field(new CUser_field());
203  field->SetLabel().SetStr(label);
204  field->SetValue(value, CUser_field::EParseField(parse));
205 
206  SetData().push_back(field);
207  return *this;
208 }
209 
210 
212  const char* value,
213  EParseField parse)
214 {
215  return AddField(label, string(value), parse);
216 }
217 
218 
220  Int8 value)
221 {
222  CRef<CUser_field> field(new CUser_field());
223  field->SetLabel().SetStr(label);
224  field->SetValue(value);
225 
226  SetData().push_back(field);
227  return *this;
228 }
229 
230 
232  int value)
233 {
234  CRef<CUser_field> field(new CUser_field());
235  field->SetLabel().SetStr(label);
236  field->SetValue(value);
237 
238  SetData().push_back(field);
239  return *this;
240 }
241 
242 
243 #ifdef NCBI_STRICT_GI
245  TGi value)
246 {
247  CRef<CUser_field> field(new CUser_field());
248  field->SetLabel().SetStr(label);
249  field->SetValue(value);
250 
251  SetData().push_back(field);
252  return *this;
253 }
254 #endif
255 
256 
258  double value)
259 {
260  CRef<CUser_field> field(new CUser_field());
261  field->SetLabel().SetStr(label);
262  field->SetValue(value);
263 
264  SetData().push_back(field);
265  return *this;
266 }
267 
268 
270  bool value)
271 {
272  CRef<CUser_field> field(new CUser_field());
273  field->SetLabel().SetStr(label);
274  field->SetValue(value);
275 
276  SetData().push_back(field);
277  return *this;
278 }
279 
280 
281 
283  CUser_object& object)
284 {
285  CRef<CUser_field> field(new CUser_field());
286  field->SetLabel().SetStr(label);
287  field->SetValue(object);
288 
289  SetData().push_back(field);
290  return *this;
291 }
292 
293 
295  const vector<string>& value)
296 {
297  CRef<CUser_field> field(new CUser_field());
298  field->SetLabel().SetStr(label);
299  field->SetValue(value);
300 
301  SetData().push_back(field);
302  return *this;
303 }
304 
305 
307  const vector<int>& value)
308 {
309  CRef<CUser_field> field(new CUser_field());
310  field->SetLabel().SetStr(label);
311  field->SetValue(value);
312 
313  SetData().push_back(field);
314  return *this;
315 }
316 
317 
319  const vector<double>& value)
320 {
321  CRef<CUser_field> field(new CUser_field());
322  field->SetLabel().SetStr(label);
323  field->SetValue(value);
324 
325  SetData().push_back(field);
326  return *this;
327 }
328 
329 
332  const vector< CRef<CUser_object> >& objects)
333 {
334  CRef<CUser_field> field(new CUser_field());
335  field->SetLabel().SetStr(label);
336  field->SetValue(objects);
337 
338  SetData().push_back(field);
339  return *this;
340 }
341 
342 
344  const vector<CRef<CUser_field> >& objects)
345 {
346  CRef<CUser_field> field(new CUser_field());
347  field->SetLabel().SetStr(label);
348  field->SetValue(objects);
349 
350  SetData().push_back(field);
351  return *this;
352 }
353 
354 
355 
356 // static consts here allow us to use reference counting
357 static const char* s_ncbi = "NCBI";
358 static const char* s_expres = "experimental_results";
359 static const char* s_exp = "experiment";
360 static const char* s_sage = "SAGE";
361 static const char* s_tag = "tag";
362 static const char* s_count = "count";
363 
364 
365 // accessors: classify a given user object
367 {
368  if (!IsSetClass() ||
369  GetClass() != s_ncbi) {
370  // we fail to recognize non-NCBI classes of user-objects
371  return eCategory_Unknown;
372  }
373 
374  //
375  // experimental results
376  //
377  if (GetType().IsStr() &&
378  NStr::CompareNocase(GetType().GetStr(), s_expres) == 0 &&
379  GetData().size() == 1) {
380 
381  ITERATE (CUser_object::TData, iter, GetData()) {
382  const CUser_field& field = **iter;
383  const CUser_field::TData& data = field.GetData();
384  if (data.Which() != CUser_field::TData::e_Object ||
385  !field.IsSetLabel() ||
386  !field.GetLabel().IsStr() ||
388  s_exp) != 0) {
389  // poorly formed experiment spec
390  return eCategory_Unknown;
391  }
392  }
393 
394  return eCategory_Experiment;
395  }
396 
397  //
398  // unrecognized - catch-all
399  //
400  return eCategory_Unknown;
401 }
402 
403 
404 // sub-category accessors:
406 {
407  // check to see if we have an experiment
408  if ( GetCategory() != eCategory_Experiment) {
409  return eExperiment_Unknown;
410  }
411 
412  // we do - so we have one nested user object that contains the
413  // specification of the experimental data
414  const CUser_field& field = *GetData().front();
415  const CUser_object& obj = field.GetData().GetObject();
416  if (obj.GetType().IsStr() &&
417  NStr::CompareNocase(obj.GetType().GetStr(), s_sage) == 0) {
418  return eExperiment_Sage;
419  }
420 
421  //
422  // catch-all
423  //
424  return eExperiment_Unknown;
425 }
426 
427 
428 // sub-category accessors:
430 {
431  switch (GetExperimentType()) {
432  case eExperiment_Sage:
433  // we have one nested user object that contains the
434  // specification of the experimental data
435  return GetData().front()->GetData().GetObject();
436 
437  case eExperiment_Unknown:
438  default:
439  return *this;
440  }
441 }
442 
443 
444 //
445 // format the type specification fo a given user object
446 //
447 static string s_GetUserObjectType(const CUser_object& obj)
448 {
449  switch (obj.GetCategory()) {
451  switch (obj.GetExperimentType()) {
453  return "SAGE";
454 
456  default:
457  return "Experiment";
458  }
459  break;
460 
462  default:
463  break;
464  }
465 
466  return "User";
467 }
468 
469 
470 static string s_GetUserObjectContent(const CUser_object& obj)
471 {
472  switch (obj.GetCategory()) {
474  switch (obj.GetExperimentType()) {
476  {{
477  string label;
478  const CUser_object& nested_obj =
479  obj.GetData().front()->GetData().GetObject();
480 
481  // grab the tag and count fields
482  const CUser_field* tag = NULL;
483  const CUser_field* count = NULL;
484  ITERATE (CUser_object::TData, iter, nested_obj.GetData()) {
485  const CUser_field& field = **iter;
486  if (!field.GetLabel().IsStr()) {
487  continue;
488  }
489 
490  const string& lbl = field.GetLabel().GetStr();
491  if (NStr::CompareNocase(lbl, s_tag) == 0) {
492  tag = &field;
493  } else if (NStr::CompareNocase(lbl, s_count) == 0) {
494  count = &field;
495  }
496  }
497 
498  if (tag && tag->GetData().IsStr()) {
499  if ( !label.empty() ) {
500  label += " ";
501  }
502  label += string(s_tag) + "=" + tag->GetData().GetStr();
503  }
504 
505  if (count && count->GetData().IsInt()) {
506  if ( !label.empty() ) {
507  label += " ";
508  }
509  label += string(s_count) + "=" +
511  }
512 
513  return label;
514  }}
515 
517  default:
518  break;
519  }
520  return "[experiment]";
521 
523  default:
524  break;
525  }
526  return "[User]";
527 }
528 
529 
530 //
531 // append a formatted string to a label describing this object
532 //
534 {
535  // Check the label is not null
536  if (!label) {
537  return;
538  }
539 
540  switch (mode) {
541  case eType:
542  *label += s_GetUserObjectType(*this);
543  break;
544  case eContent:
545  *label += s_GetUserObjectContent(*this);
546  break;
547  case eBoth:
548  *label += s_GetUserObjectType(*this) + ": " +
549  s_GetUserObjectContent(*this);
550  break;
551  }
552 }
553 
554 
556 {
557  Reset();
558  SetClass(s_ncbi);
559  switch (category) {
562  {{
563  CRef<CUser_object> subobj(new CUser_object());
564  AddField(s_exp, *subobj);
565  SetClass(s_ncbi);
566  return *subobj;
567  }}
568 
569  case eCategory_Unknown:
570  default:
571  break;
572  }
573 
574  return *this;
575 }
576 
577 
579 {
580  Reset();
581  SetClass(s_ncbi);
582  switch (category) {
583  case eExperiment_Sage:
584  SetType().SetStr(s_sage);
585  break;
586 
587  case eExperiment_Unknown:
588  default:
589  break;
590  }
591 
592  return *this;
593 }
594 
595 
596 static const char* kDBLink = "DBLink";
597 static const char* kStructuredComment = "StructuredComment";
598 static const char* kOriginalId = "OriginalID";
599 static const char* kOrigIdAltSpell = "OrginalID";
600 static const char* kUnverified = "Unverified";
601 static const char* kValidationSuppression = "ValidationSuppression";
602 static const char* kNcbiCleanup = "NcbiCleanup";
603 static const char* kAutoDefOptions = "AutodefOptions";
604 static const char* kFileTrack = "FileTrack";
605 static const char* kRefGeneTracking = "RefGeneTracking";
606 static const char* kUnreviewed = "Unreviewed";
607 
620 };
623 
624 
626 {
627  if (!IsSetType() || !GetType().IsStr()) {
628  return eObjectType_Unknown;
629  }
631 
632  const string& label = GetType().GetStr();
633 
634  auto it = sc_ObjectTypeMap.find(label.c_str());
635  if (it == sc_ObjectTypeMap.end()) {
637  rval = eObjectType_OriginalId;
638  }
639  } else {
640  rval = it->second;
641  }
642 
643  return rval;
644 }
645 
646 
648 {
649  for (auto it = sc_ObjectTypeMap.begin(); it != sc_ObjectTypeMap.end(); it++) {
650  if (it->second == obj_type) {
651  SetType().SetStr(it->first);
652  return;
653  }
654  }
655  ResetType();
656 }
657 
658 
659 bool CUser_object::x_IsUnverifiedType(const string& val, const CUser_field& field) const
660 {
661  if (field.IsSetLabel() && field.GetLabel().IsStr()
662  && NStr::Equal(field.GetLabel().GetStr(), "Type")
663  && field.IsSetData()
664  && field.GetData().IsStr()
665  && NStr::Equal(field.GetData().GetStr(), val)) {
666  return true;
667  } else {
668  return false;
669  }
670 }
671 
672 
673 bool CUser_object::x_IsUnverifiedType(const string& val) const
674 {
676  return false;
677  }
678  if (!IsSetData()) {
679  return false;
680  }
681  bool found = false;
682 
684  if (x_IsUnverifiedType(val, **it)) {
685  found = true;
686  }
687  }
688  return found;
689 }
690 
691 
692 void CUser_object::x_AddUnverifiedType(const string& val)
693 {
695  if (x_IsUnverifiedType(val)) {
696  // value already set, nothing to do
697  return;
698  }
699  AddField("Type", val);
700 }
701 
702 
704 {
706  return;
707  }
708  if (!IsSetData()) {
709  return;
710  }
711  CUser_object::TData::iterator it = SetData().begin();
712  while (it != SetData().end()) {
713  if (x_IsUnverifiedType(val, **it)) {
714  it = SetData().erase(it);
715  } else {
716  it++;
717  }
718  }
719  if (GetData().empty()) {
720  ResetData();
721  }
722 }
723 
724 
725 bool CUser_object::x_IsUnreviewedType(const string& val, const CUser_field& field) const
726 {
727  if (field.IsSetLabel() && field.GetLabel().IsStr()
728  && NStr::Equal(field.GetLabel().GetStr(), "Type")
729  && field.IsSetData()
730  && field.GetData().IsStr()
731  && NStr::Equal(field.GetData().GetStr(), val)) {
732  return true;
733  } else {
734  return false;
735  }
736 }
737 
738 
739 bool CUser_object::x_IsUnreviewedType(const string& val) const
740 {
742  return false;
743  }
744  if (!IsSetData()) {
745  return false;
746  }
747  bool found = false;
748 
750  if (x_IsUnreviewedType(val, **it)) {
751  found = true;
752  }
753  }
754  return found;
755 }
756 
757 
758 void CUser_object::x_AddUnreviewedType(const string& val)
759 {
761  if (x_IsUnreviewedType(val)) {
762  // value already set, nothing to do
763  return;
764  }
765  AddField("Type", val);
766 }
767 
768 
770 {
772  return;
773  }
774  if (!IsSetData()) {
775  return;
776  }
777  CUser_object::TData::iterator it = SetData().begin();
778  while (it != SetData().end()) {
779  if (x_IsUnreviewedType(val, **it)) {
780  it = SetData().erase(it);
781  } else {
782  it++;
783  }
784  }
785  if (GetData().empty()) {
786  ResetData();
787  }
788 }
789 
790 
792 {
793  return x_IsUnverifiedType(kUnverifiedOrganism.Get());
794 }
795 
796 
798 {
799  x_AddUnverifiedType(kUnverifiedOrganism.Get());
800 }
801 
802 
804 {
805  x_RemoveUnverifiedType(kUnverifiedOrganism.Get());
806 }
807 
808 
810 {
811  return x_IsUnverifiedType(kUnverifiedFeature.Get());
812 }
813 
814 
816 {
817  x_AddUnverifiedType(kUnverifiedFeature.Get());
818 }
819 
820 
822 {
823  x_RemoveUnverifiedType(kUnverifiedFeature.Get());
824 }
825 
826 
828 {
829  return x_IsUnverifiedType(kUnverifiedMisassembled.Get());
830 }
831 
832 
834 {
835  x_AddUnverifiedType(kUnverifiedMisassembled.Get());
836 }
837 
838 
840 {
841  x_RemoveUnverifiedType(kUnverifiedMisassembled.Get());
842 }
843 
844 
846 {
847  return x_IsUnverifiedType(kUnverifiedContaminant.Get());
848 }
849 
850 
852 {
853  x_AddUnverifiedType(kUnverifiedContaminant.Get());
854 }
855 
856 
858 {
859  x_RemoveUnverifiedType(kUnverifiedContaminant.Get());
860 }
861 
862 
864 {
865  return x_IsUnreviewedType(kUnreviewedUnannotated.Get());
866 }
867 
868 
870 {
871  x_AddUnreviewedType(kUnreviewedUnannotated.Get());
872 }
873 
874 
876 {
877  x_RemoveUnreviewedType(kUnreviewedUnannotated.Get());
878 }
879 
880 
882 {
884  CRef<CUser_field> method = SetFieldRef("method");
885  method->SetValue("ExtendedSeqEntryCleanup");
886  CRef<CUser_field> version_field = SetFieldRef("version");
887  version_field->SetValue(version);
888 
889  // get current time
890  CTime curr_time(CTime::eCurrent);
891  CRef<CUser_field> month = SetFieldRef("month");
892  month->SetData().SetInt(curr_time.Month());
893  CRef<CUser_field> day = SetFieldRef("day");
894  day->SetData().SetInt(curr_time.Day());
895  CRef<CUser_field> year = SetFieldRef("year");
896  year->SetData().SetInt(curr_time.Year());
897 }
898 
899 
900 bool CUser_object::RemoveNamedField(const string& field_name, NStr::ECase ecase)
901 {
902  if (!IsSetData()) {
903  return false;
904  }
905  bool rval = false;
906  auto it = SetData().begin();
907  while (it != SetData().end()) {
908  bool do_remove = false;
909  if ((*it)->IsSetLabel()) {
910  if ((*it)->GetLabel().IsStr()) {
911  if (NStr::Equal((*it)->GetLabel().GetStr(), field_name, ecase)) {
912  do_remove = true;
913  }
914  } else if ((*it)->GetLabel().IsId()) {
915  string label = NStr::NumericToString((*it)->GetLabel().GetId());
916  if (NStr::Equal((*it)->GetLabel().GetStr(), field_name, ecase)) {
917  do_remove = true;
918  }
919  }
920  }
921  if (do_remove) {
922  it = SetData().erase(it);
923  rval = true;
924  } else {
925  it++;
926  }
927  }
928  return rval;
929 }
930 
931 
932 void CUser_object::SetFileTrackURL(const string& url)
933 {
935  CRef<CUser_field> fturl = SetFieldRef("BaseModification-FileTrackURL");
936  fturl->SetData().SetStr(url);
937 }
938 
939 
940 void CUser_object::SetFileTrackUploadId(const string& upload_id)
941 {
942  string url = "https://submit.ncbi.nlm.nih.gov/ft/byid/" + upload_id;
943  SetFileTrackURL(url);
944 }
945 
946 
947 // For RefGeneTracking
948 
949 void CUser_object::x_SetRefGeneTrackingField(const string& field_name, const string& value)
950 {
952  if (value.empty()) {
953  RemoveNamedField(field_name);
954  } else {
955  CUser_field& field = SetField(field_name);
956  field.SetString(value);
957  }
958 }
959 
960 const string& CUser_object::x_GetRefGeneTrackingField(const string& field_name) const
961 {
963  return kEmptyStr;
964  }
965  CConstRef<CUser_field> field = GetFieldRef(field_name);
966  if (field && field->IsSetData() && field->GetData().IsStr()) {
967  return field->GetData().GetStr();
968  }
969  return kEmptyStr;
970 }
971 
972 
982 };
985 
986 const string kRefGeneTrackingStatus = "Status";
987 
989 {
990  for (auto it = sc_RefGeneTrackingStatusMap.begin(); it != sc_RefGeneTrackingStatusMap.end(); it++) {
991  if (it->second == status) {
993  return;
994  }
995  }
996  NCBI_THROW(CRefGeneTrackingException, eBadStatus, "Unrecognized RefGeneTracking Status");
997 }
998 
1000 {
1003  }
1005  if (!field || !field->IsSetData()) {
1007  }
1008  if (!field->GetData().IsStr()) {
1010  }
1011  if (field->GetData().GetStr().empty()) {
1013  }
1014  auto it = sc_RefGeneTrackingStatusMap.find(field->GetData().GetStr().c_str());
1015  if (it != sc_RefGeneTrackingStatusMap.end()) {
1016  return it->second;
1017  }
1018  NCBI_THROW(CRefGeneTrackingException, eBadStatus, "Unrecognized RefGeneTracking Status " + field->GetData().GetStr());
1019 }
1020 
1021 
1023 {
1025 }
1026 
1027 
1028 const string kRefGeneTrackingGenomicSource = "GenomicSource";
1029 
1030 void CUser_object::SetRefGeneTrackingGenomicSource(const string& genomic_source)
1031 {
1033 }
1034 
1035 
1037 {
1039 }
1040 
1041 
1043 {
1045 }
1046 
1047 
1048 const string kRefGeneTrackingCollaborator = "Collaborator";
1050 {
1052 }
1053 
1054 
1056 {
1058 }
1059 
1060 
1062 {
1064 }
1065 
1066 
1067 const string kRefGeneTrackingCollaboratorURL = "CollaboratorURL";
1069 {
1071 }
1072 
1073 
1075 {
1077 }
1078 
1079 
1081 {
1083 }
1084 
1085 
1086 const string kRefGeneTrackingGenerated = "Generated";
1087 
1089 {
1092  field.SetBool(val);
1093 }
1094 
1095 
1097 {
1099  return false;
1100  }
1101  bool rval = false;
1103  if (field && field->IsSetData() && field->GetData().IsBool() &&
1104  field->GetData().GetBool()) {
1105  rval = true;
1106  }
1107  return rval;
1108 }
1109 
1110 
1112 {
1114 }
1115 
1116 
1117 const string kRGTAAccession = "accession";
1118 const string kRGTAName = "name";
1119 const string kRGTAGI = "gi";
1120 const string kRGTAFrom = "from";
1121 const string kRGTATo = "to";
1122 const string kRGTAComment = "comment";
1123 
1125 {
1126  CRef<CUser_field> top(new CUser_field());
1127  //use IsSet construction here
1128  if (!NStr::IsBlank(m_Accession)) {
1129  CRef<CUser_field> uf(new CUser_field());
1130  uf->SetLabel().SetStr(kRGTAAccession);
1131  uf->SetData().SetStr(m_Accession);
1132  top->SetData().SetFields().push_back(uf);
1133  }
1134  if (!NStr::IsBlank(m_Name)) {
1135  CRef<CUser_field> uf(new CUser_field());
1136  uf->SetLabel().SetStr(kRGTAName);
1137  uf->SetData().SetStr(m_Name);
1138  top->SetData().SetFields().push_back(uf);
1139  }
1140  if (m_GI > ZERO_GI) {
1141  CRef<CUser_field> uf(new CUser_field());
1142  uf->SetLabel().SetStr(kRGTAGI);
1143  uf->SetGi(m_GI);
1144  top->SetData().SetFields().push_back(uf);
1145  }
1146  if (m_From != kInvalidSeqPos) {
1147  CRef<CUser_field> uf(new CUser_field());
1148  uf->SetLabel().SetStr(kRGTAFrom);
1149  uf->SetData().SetInt(m_From);
1150  top->SetData().SetFields().push_back(uf);
1151  }
1152  if (m_To != kInvalidSeqPos) {
1153  CRef<CUser_field> uf(new CUser_field());
1154  uf->SetLabel().SetStr(kRGTATo);
1155  uf->SetData().SetInt(m_To);
1156  top->SetData().SetFields().push_back(uf);
1157  }
1158  if (!NStr::IsBlank(m_Comment)) {
1159  CRef<CUser_field> uf(new CUser_field());
1160  uf->SetLabel().SetStr(kRGTAComment);
1161  uf->SetData().SetStr(m_Comment);
1162  top->SetData().SetFields().push_back(uf);
1163  }
1164  if (top->IsSetData()) {
1165  top->SetLabel().SetId(0);
1166  } else {
1167  top.Reset(NULL);
1168  }
1169  return top;
1170 }
1171 
1172 
1175 {
1176  // TODO: Throw exception if no good fields or if any bad fields found
1177  if (!field.IsSetData() || !field.GetData().IsFields()) {
1179  }
1180 
1181  string accession, acc_name, comment;
1182  TSeqPos from = kInvalidSeqPos, to = kInvalidSeqPos;
1183  TGi gi = ZERO_GI;
1184  for (auto it : field.GetData().GetFields()) {
1185  if (it->IsSetLabel() && it->GetLabel().IsStr() && it->IsSetData()) {
1186  // finish taking out dereferences
1187  const string& label = it->GetLabel().GetStr();
1189  if (it->GetData().IsStr()) {
1190  accession = it->GetData().GetStr();
1191  } else {
1192  NCBI_THROW(CRefGeneTrackingException, eBadUserFieldData, kEmptyStr);
1193  }
1194  } else if (NStr::EqualNocase(label, kRGTAName)) {
1195  if (it->GetData().IsStr()) {
1196  acc_name = it->GetData().GetStr();
1197  } else {
1198  NCBI_THROW(CRefGeneTrackingException, eBadUserFieldData, kEmptyStr);
1199  }
1200  } else if (NStr::EqualNocase(label, kRGTAComment)) {
1201  if (it->GetData().IsStr()) {
1202  comment = it->GetData().GetStr();
1203  } else {
1204  NCBI_THROW(CRefGeneTrackingException, eBadUserFieldData, kEmptyStr);
1205  }
1206  } else if (NStr::EqualNocase(label, kRGTAGI)) {
1207  gi = it->GetGi();
1208  } else if (NStr::EqualNocase(label, kRGTAFrom)) {
1209  if (it->GetData().IsInt()) {
1210  from = it->GetData().GetInt();
1211  } else {
1212  NCBI_THROW(CRefGeneTrackingException, eBadUserFieldData, kEmptyStr);
1213  }
1214  } else if (NStr::EqualNocase(label, kRGTATo)) {
1215  if (it->GetData().IsInt()) {
1216  to = it->GetData().GetInt();
1217  } else {
1218  NCBI_THROW(CRefGeneTrackingException, eBadUserFieldData, kEmptyStr);
1219  }
1220  } else {
1221  NCBI_THROW(CRefGeneTrackingException, eBadUserFieldName, "Unrecognized field name " + label);
1222  }
1223  } else {
1224  NCBI_THROW(CRefGeneTrackingException, eUserFieldWithoutLabel, kEmptyStr);
1225  }
1226  }
1227  CRef<CRefGeneTrackingAccession> rval(new CRefGeneTrackingAccession(accession, gi, from, to, comment, acc_name));
1228  if (rval->IsEmpty()) {
1230  } else {
1231  return rval;
1232  }
1233 }
1234 
1235 
1236 const string kRefGeneTrackingIdenticalTo = "IdenticalTo";
1237 
1239 {
1241  field.ResetData();
1242  CRef<CUser_field> ident = accession.MakeAccessionField();
1243  if (ident) {
1244  field.SetData().SetFields().push_back(ident);
1245  }
1247 }
1248 
1249 
1251 {
1254  }
1256  if (field && field->IsSetData() && field->GetData().IsFields() && !field->GetData().GetFields().empty()) {
1258  }
1260 }
1261 
1262 
1264 {
1266 }
1267 
1268 const string kRefGeneTrackingAssembly = "Assembly";
1269 
1271 {
1273  field.ResetData();
1274  // use auto iterator syntax
1275  for (auto it : acc_list) {
1276  CRef<CUser_field> acc = it->MakeAccessionField();
1277  if (acc) {
1278  field.SetData().SetFields().push_back(acc);
1279  }
1280  }
1282 }
1283 
1284 
1286 {
1288 
1290  return rval;
1291  }
1293  if (field && field->IsSetData() && field->GetData().IsFields()) {
1294  rval.reserve(field->GetData().GetFields().size());
1295  for (auto it : field->GetData().GetFields()) {
1297  if (acc) {
1298  rval.push_back(acc);
1299  }
1300  }
1301  }
1302  return rval;
1303 }
1304 
1305 
1307 {
1309 }
1310 
1311 
1312 
1313 
1314 END_objects_SCOPE // namespace ncbi::objects::
1315 
static const TObjectTypePair k_object_type_map[]
CStaticArrayMap< const char *, CUser_object::ERefGeneTrackingStatus, PNocase_CStr > TRefGeneTrackingStatusMap
static const char * kFileTrack
const string kRGTAComment
const string kRefGeneTrackingGenerated
static const char * kAutoDefOptions
static const char * kRefGeneTracking
static const char * s_expres
static const char * kUnreviewed
static const char * kStructuredComment
static const char * s_count
static const char * kOrigIdAltSpell
SStaticPair< const char *, CUser_object::ERefGeneTrackingStatus > TRefGeneTrackingStatusPair
static const char * s_ncbi
static const char * kUnverified
const string kRGTAAccession
static const char * kValidationSuppression
const string kRefGeneTrackingCollaborator
const string kRefGeneTrackingCollaboratorURL
SStaticPair< const char *, CUser_object::EObjectType > TObjectTypePair
static const char * s_exp
static const char * kOriginalId
DEFINE_STATIC_ARRAY_MAP(TObjectTypeMap, sc_ObjectTypeMap, k_object_type_map)
const string kRefGeneTrackingStatus
static const char * kDBLink
const string kRefGeneTrackingIdenticalTo
const string kRGTAFrom
static string s_GetUserObjectContent(const CUser_object &obj)
static const char * kNcbiCleanup
CStaticArrayMap< const char *, CUser_object::EObjectType, PNocase_CStr > TObjectTypeMap
const string kRGTATo
const string kRefGeneTrackingAssembly
SAFE_CONST_STATIC_STRING(kUnverifiedOrganism, "Organism")
const string kRefGeneTrackingGenomicSource
const string kRGTAGI
const string kRGTAName
static string s_GetUserObjectType(const CUser_object &obj)
static const TRefGeneTrackingStatusPair k_refgene_tracking_status_map[]
static const char * s_sage
static const char * s_tag
CCoreException –.
Definition: ncbiexpt.hpp:1476
class CStaticArrayMap<> provides access to a static array in much the same way as CStaticArraySet<>,...
Definition: static_map.hpp:175
CTime –.
Definition: ncbitime.hpp:296
CRef< CUser_field > SetFieldRef(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase)
Return a field reference representing the tokenized key, or a NULL reference if the key cannot be cre...
Definition: User_field.cpp:345
CUser_field & SetString(const char *value)
Definition: User_field.cpp:445
CUser_field & SetGi(TGi gi)
Definition: User_field.hpp:311
CUser_field & SetValue(int value)
set a data field to a given value Int8 and TGi values can be stored into 'str' field if the value doe...
Definition: User_field.hpp:283
CConstRef< CUser_field > GetFieldRef(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Return a field reference representing the tokenized key, or a NULL reference if the key doesn't exist...
Definition: User_field.cpp:226
CUser_field & SetBool(bool value)
Definition: User_field.hpp:253
static CRef< CRefGeneTrackingAccession > MakeAccessionFromUserField(const CUser_field &field)
CRef< CUser_field > MakeAccessionField() const
const string & GetRefGeneTrackingCollaborator() const
void SetObjectType(EObjectType obj_type)
void ResetRefGeneTrackingAssembly()
void ResetRefGeneTrackingStatus()
CConstRef< CUser_field > GetFieldRef(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Definition: User_object.cpp:84
void RemoveUnreviewedUnannotated()
void RemoveUnverifiedFeature()
void AddUnverifiedOrganism()
void SetRefGeneTrackingCollaboratorURL(const string &collaborator_url)
ECategory GetCategory(void) const
accessors: classify a given user object
void AddUnreviewedUnannotated()
bool x_IsUnverifiedType(const string &val) const
const string & GetRefGeneTrackingCollaboratorURL() const
void AddUnverifiedContaminant()
@ eRefGeneTrackingStatus_INFERRED
@ eRefGeneTrackingStatus_VALIDATED
@ eRefGeneTrackingStatus_WGS
@ eRefGeneTrackingStatus_PREDICTED
@ eRefGeneTrackingStatus_Error
@ eRefGeneTrackingStatus_NotSet
@ eRefGeneTrackingStatus_PROVISIONAL
@ eRefGeneTrackingStatus_PIPELINE
@ eRefGeneTrackingStatus_REVIEWED
void ResetRefGeneTrackingCollaboratorURL()
CUser_object & SetCategory(ECategory category)
format a user object as a given type.
void SetRefGeneTrackingAssembly(const TRefGeneTrackingAccessions &acc_list)
void ResetRefGeneTrackingGenerated()
void RemoveUnverifiedMisassembled()
ECategory
enums for implicit typing of user objects
void x_AddUnverifiedType(const string &val)
void ResetRefGeneTrackingGenomicSource()
void SetRefGeneTrackingStatus(ERefGeneTrackingStatus status)
void RemoveUnverifiedContaminant()
void SetRefGeneTrackingCollaborator(const string &collaborator)
void SetRefGeneTrackingIdenticalTo(const CRefGeneTrackingAccession &accession)
const string & x_GetRefGeneTrackingField(const string &field_name) const
bool RemoveNamedField(const string &field_name, NStr::ECase ecase=NStr::eCase)
void SetRefGeneTrackingGenomicSource(const string &genomic_source)
EObjectType
Object Type.
@ eObjectType_RefGeneTracking
@ eObjectType_StructuredComment
@ eObjectType_AutodefOptions
@ eObjectType_ValidationSuppression
bool IsUnverifiedMisassembled() const
void GetLabel(string *label, ELabelContent mode=eContent) const
Append a label to label.
void SetRefGeneTrackingGenerated(bool val=true)
bool HasField(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Verify that a named field exists.
void SetFileTrackUploadId(const string &upload_id)
vector< CConstRef< CRefGeneTrackingAccession > > TRefGeneTrackingAccessions
const string & GetRefGeneTrackingGenomicSource() const
void x_RemoveUnreviewedType(const string &val)
CUser_object & AddField(const string &label, const string &value, EParseField parse=eParse_String)
add a data field to the user object that holds a given value
~CUser_object(void)
destructor
Definition: User_object.cpp:62
bool IsUnverifiedOrganism() const
bool GetRefGeneTrackingGenerated() const
void ResetRefGeneTrackingCollaborator()
ERefGeneTrackingStatus GetRefGeneTrackingStatus() const
bool x_IsUnreviewedType(const string &val) const
ELabelContent
enum controlling what to return for a label this mirrors a request inside of feature::GetLabel()
EExperiment
sub-category experiment
EExperiment GetExperimentType(void) const
sub-category accessors:
bool IsUnverifiedContaminant() const
TRefGeneTrackingAccessions GetRefGeneTrackingAssembly() const
void x_RemoveUnverifiedType(const string &val)
void SetFileTrackURL(const string &url)
void x_AddUnreviewedType(const string &val)
bool IsUnverifiedFeature() const
void UpdateNcbiCleanup(int version)
void RemoveUnverifiedOrganism()
CUser_object(void)
constructor
void AddUnverifiedMisassembled()
const CUser_object & GetExperiment(void) const
bool IsUnreviewedUnannotated() const
CConstRef< CRefGeneTrackingAccession > GetRefGeneTrackingIdenticalTo() const
CUser_field & SetField(const string &str, const string &delim=".", const string &obj_subtype=kEmptyStr, NStr::ECase use_case=NStr::eCase)
Access a named field in this user object.
CRef< CUser_field > SetFieldRef(const string &str, const string &delim=".", const string &obj_subtype=kEmptyStr, NStr::ECase use_case=NStr::eCase)
EParseField
how to interpret the value in the AddField() conversion functions below.
Definition: User_object.hpp:60
const CUser_field & GetField(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Access a named field in this user object.
Definition: User_object.cpp:71
void ResetRefGeneTrackingIdenticalTo()
CUser_object & SetExperiment(EExperiment category)
format a user object as a given type.
void x_SetRefGeneTrackingField(const string &field_name, const string &value)
EObjectType GetObjectType() const
void AddUnverifiedFeature()
#define true
Definition: bool.h:35
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
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 NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
#define ZERO_GI
Definition: ncbimisc.hpp:1088
string
Definition: cgiapp.hpp:687
#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 Empty(void) const THROWS_NONE
Check if CConstRef is empty – not pointing to any object which means having a null value.
Definition: ncbiobj.hpp:1385
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
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
ECase
Which type of string comparison.
Definition: ncbistr.hpp:1204
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2508
int Year(void) const
Get year.
Definition: ncbitime.hpp:2265
int Day(void) const
Get day.
Definition: ncbitime.hpp:2271
int Month(void) const
Get month.
Definition: ncbitime.hpp:2268
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
static const char label[]
const TStr & GetStr(void) const
Get the variant data.
bool IsSetData(void) const
the object itself Check if a value has been assigned to Data data member.
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
bool IsSetType(void) const
type of object within class Check if a value has been assigned to Type data member.
const TData & GetData(void) const
Get the Data member data.
TClass & SetClass(void)
Assign a value to Class data member.
const TFields & GetFields(void) const
Get the variant data.
TBool GetBool(void) const
Get the variant data.
bool IsFields(void) const
Check if variant Fields is selected.
bool IsInt(void) const
Check if variant Int is selected.
bool IsSetClass(void) const
endeavor which designed this object Check if a value has been assigned to Class data member.
const TClass & GetClass(void) const
Get the Class member data.
bool IsStr(void) const
Check if variant Str is selected.
TType & SetType(void)
Assign a value to Type data member.
bool IsSetLabel(void) const
field label Check if a value has been assigned to Label data member.
TData & SetData(void)
Assign a value to Data data member.
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
void SetLabel(TLabel &value)
Assign a value to Label data member.
TInt GetInt(void) const
Get the variant data.
TStr & SetStr(void)
Select the variant.
Definition: Object_id_.hpp:304
virtual void Reset(void)
Reset the whole object.
const TData & GetData(void) const
Get the Data member data.
const TObject & GetObject(void) const
Get the variant data.
void ResetType(void)
Reset Type data member.
void ResetData(void)
Reset Data data member.
void SetData(TData &value)
Assign a value to Data data member.
const TLabel & GetLabel(void) const
Get the Label member data.
const TType & GetType(void) const
Get the Type member data.
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
bool IsBool(void) const
Check if variant Bool is selected.
void ResetData(void)
Reset Data data member.
vector< CRef< CUser_field > > TData
@ e_Object
for using other definitions
static int version
Definition: mdb_load.c:29
constexpr bool empty(list< Ts... >) noexcept
mdb_mode_t mode
Definition: lmdb++.h:38
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const char * tag
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
Modified on Mon May 27 04:36:07 2024 by modify_doxy.py rev. 669887