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

Go to the SVN repository for this file.

1 /* $Id: flat_qual_slots.cpp 95791 2021-12-23 15:35:42Z stakhovv $
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: Michael Kornbluh
27 *
28 * File Description:
29 * Simple function(s) to support flat file qual slots, such as
30 * enum-to-string function(s).
31 *
32 * ===========================================================================
33 */
34 
35 #include <ncbi_pch.hpp>
36 
38 
39 #include <util/static_map.hpp>
40 
41 using namespace std;
42 
45 
48 {
49 #ifdef TYPICAL_FQ
50 # error TYPICAL_FQ should not be defined yet
51 #endif
52 
53 // Usually, it's the same as the enum name minus the "eSQ_" prefix, but not always.
54 #define TYPICAL_FQ(x) { eFQ_##x, #x }
55 
56  typedef SStaticPair<EFeatureQualifier, const char*> TFeatQualToName;
57  static const TFeatQualToName kFeatQualToNames[] = {
58  TYPICAL_FQ(none),
59  TYPICAL_FQ(allele),
60  TYPICAL_FQ(anticodon),
61  TYPICAL_FQ(artificial_location),
62  TYPICAL_FQ(bond),
63  TYPICAL_FQ(bond_type),
64  TYPICAL_FQ(bound_moiety),
65  TYPICAL_FQ(calculated_mol_wt),
66  { eFQ_cds_product, "product" },
67  TYPICAL_FQ(circular_RNA),
68  TYPICAL_FQ(citation),
69  TYPICAL_FQ(clone),
70  TYPICAL_FQ(coded_by),
71  TYPICAL_FQ(codon),
72  TYPICAL_FQ(codon_start),
73  TYPICAL_FQ(compare),
74  TYPICAL_FQ(cons_splice),
75  TYPICAL_FQ(cyt_map),
76  TYPICAL_FQ(db_xref),
77  TYPICAL_FQ(derived_from),
78  TYPICAL_FQ(direction),
79  TYPICAL_FQ(EC_number),
80  TYPICAL_FQ(encodes),
81  TYPICAL_FQ(estimated_length),
82  TYPICAL_FQ(evidence),
83  TYPICAL_FQ(experiment),
84  TYPICAL_FQ(exception),
85  TYPICAL_FQ(exception_note),
86  TYPICAL_FQ(figure),
87  TYPICAL_FQ(frequency),
88  TYPICAL_FQ(function),
89  TYPICAL_FQ(gap_type),
90  TYPICAL_FQ(gen_map),
91  TYPICAL_FQ(gene),
92  TYPICAL_FQ(gene_desc),
93  { eFQ_gene_allele, "allele" },
94  { eFQ_gene_map, "map" },
95  TYPICAL_FQ(gene_syn),
96  { eFQ_gene_syn_refseq, "synonym" },
97  TYPICAL_FQ(gene_note),
98  { eFQ_gene_xref, "db_xref" },
99  { eFQ_go_component, "GO_component" },
100  { eFQ_go_function, "GO_function" },
101  { eFQ_go_process, "GO_process" },
102  TYPICAL_FQ(heterogen),
103  { eFQ_illegal_qual, "illegal" },
104  TYPICAL_FQ(inference),
105  TYPICAL_FQ(insertion_seq),
106  TYPICAL_FQ(label),
107  TYPICAL_FQ(linkage_evidence),
108  TYPICAL_FQ(locus_tag),
109  TYPICAL_FQ(map),
110  TYPICAL_FQ(maploc),
111  TYPICAL_FQ(mobile_element),
112  TYPICAL_FQ(mobile_element_type),
113  TYPICAL_FQ(mod_base),
114  TYPICAL_FQ(modelev),
115  TYPICAL_FQ(mol_wt),
116  TYPICAL_FQ(ncRNA_class),
117  TYPICAL_FQ(nomenclature),
118  TYPICAL_FQ(non_std_residue),
120  TYPICAL_FQ(old_locus_tag),
121  TYPICAL_FQ(operon),
122  TYPICAL_FQ(organism),
123  TYPICAL_FQ(partial),
124  TYPICAL_FQ(PCR_conditions),
125  TYPICAL_FQ(peptide),
126  TYPICAL_FQ(phenotype),
127  TYPICAL_FQ(product),
128  TYPICAL_FQ(product_quals),
129  { eFQ_prot_activity, "function" },
130  TYPICAL_FQ(prot_comment),
131  { eFQ_prot_EC_number, "EC_number" },
132  TYPICAL_FQ(prot_note),
133  TYPICAL_FQ(prot_method),
134  TYPICAL_FQ(prot_conflict),
135  TYPICAL_FQ(prot_desc),
136  TYPICAL_FQ(prot_missing),
137  { eFQ_prot_name, "name" },
138  TYPICAL_FQ(prot_names),
139  TYPICAL_FQ(protein_id),
140  TYPICAL_FQ(pseudo),
141  TYPICAL_FQ(pseudogene),
142  TYPICAL_FQ(pyrrolysine),
143  TYPICAL_FQ(pyrrolysine_note),
144  TYPICAL_FQ(rad_map),
145  TYPICAL_FQ(region),
146  TYPICAL_FQ(region_name),
147  TYPICAL_FQ(recombination_class),
148  TYPICAL_FQ(regulatory_class),
149  TYPICAL_FQ(replace),
150  TYPICAL_FQ(ribosomal_slippage),
151  TYPICAL_FQ(rpt_family),
152  TYPICAL_FQ(rpt_type),
153  TYPICAL_FQ(rpt_unit),
154  TYPICAL_FQ(rpt_unit_range),
155  TYPICAL_FQ(rpt_unit_seq),
156  TYPICAL_FQ(rrna_its),
157  TYPICAL_FQ(satellite),
158  TYPICAL_FQ(sec_str_type),
159  TYPICAL_FQ(selenocysteine),
160  TYPICAL_FQ(selenocysteine_note),
161  TYPICAL_FQ(seqfeat_note),
162  TYPICAL_FQ(site),
163  TYPICAL_FQ(site_type),
164  TYPICAL_FQ(standard_name),
165  TYPICAL_FQ(tag_peptide),
166  TYPICAL_FQ(trans_splicing),
167  TYPICAL_FQ(transcription),
168  TYPICAL_FQ(transcript_id),
169  { eFQ_transcript_id_note, "tscpt_id_note" },
170  TYPICAL_FQ(transl_except),
171  TYPICAL_FQ(transl_table),
172  TYPICAL_FQ(translation),
173  TYPICAL_FQ(transposon),
174  TYPICAL_FQ(trna_aa),
175  TYPICAL_FQ(trna_codons),
176  TYPICAL_FQ(UniProtKB_evidence),
177  TYPICAL_FQ(usedin),
178  TYPICAL_FQ(xtra_prod_quals)
179 #undef TYPICAL_FQ
180  };
181  typedef const CStaticPairArrayMap<EFeatureQualifier, const char*> TFeatQualToNameMap;
182  DEFINE_STATIC_ARRAY_MAP(TFeatQualToNameMap, kFeatQualToNameMap, kFeatQualToNames);
183 
184  _ASSERT( kFeatQualToNameMap.size() == eFQ_NUM_SOURCE_QUALIFIERS );
185 
186  TFeatQualToNameMap::const_iterator find_iter =
187  kFeatQualToNameMap.find(eFeatureQualifier);
188  if( find_iter != kFeatQualToNameMap.end() ) {
189  return find_iter->second;
190  }
191 
192  return "UNKNOWN_FEAT_QUAL";
193 }
194 
196 {
197 #ifdef TYPICAL_SQ
198 # error TYPICAL_SQ should not be defined yet
199 #endif
200 
201 // Usually, it's the same as the enum name minus the "eSQ_" prefix, but not always.
202 #define TYPICAL_SQ(x) { eSQ_##x, #x }
203 
204  typedef SStaticPair<ESourceQualifier, const char*> TSourceQualToName;
205  static const TSourceQualToName kSourceQualToNames[] = {
206  TYPICAL_SQ(none),
207  TYPICAL_SQ(acronym),
208  TYPICAL_SQ(altitude),
209  TYPICAL_SQ(anamorph),
210  TYPICAL_SQ(authority),
211  TYPICAL_SQ(bio_material),
212  TYPICAL_SQ(biotype),
213  TYPICAL_SQ(biovar),
214  TYPICAL_SQ(breed),
215  TYPICAL_SQ(cell_line),
216  TYPICAL_SQ(cell_type),
217  TYPICAL_SQ(chemovar),
218  TYPICAL_SQ(chromosome),
219  TYPICAL_SQ(citation),
220  TYPICAL_SQ(clone),
221  TYPICAL_SQ(clone_lib),
222  TYPICAL_SQ(collected_by),
223  TYPICAL_SQ(collection_date),
224  TYPICAL_SQ(common),
225  TYPICAL_SQ(common_name),
226  TYPICAL_SQ(country),
227  TYPICAL_SQ(cultivar),
228  TYPICAL_SQ(culture_collection),
229  TYPICAL_SQ(db_xref),
230  { eSQ_org_xref, "db_xref" },
231  TYPICAL_SQ(dev_stage),
232  TYPICAL_SQ(dosage),
233  TYPICAL_SQ(ecotype),
234  { eSQ_endogenous_virus_name, "endogenous_virus" },
235  TYPICAL_SQ(environmental_sample),
236  TYPICAL_SQ(extrachrom),
237  TYPICAL_SQ(focus),
238  TYPICAL_SQ(forma),
239  TYPICAL_SQ(forma_specialis),
240  TYPICAL_SQ(frequency),
241  TYPICAL_SQ(fwd_primer_name),
242  TYPICAL_SQ(fwd_primer_seq),
243  TYPICAL_SQ(gb_acronym),
244  TYPICAL_SQ(gb_anamorph),
245  TYPICAL_SQ(gb_synonym),
246  TYPICAL_SQ(genotype),
247  TYPICAL_SQ(germline),
248  TYPICAL_SQ(group),
249  TYPICAL_SQ(haplogroup),
250  TYPICAL_SQ(haplotype),
251  TYPICAL_SQ(identified_by),
252  { eSQ_insertion_seq_name, "insertion_seq" },
253  TYPICAL_SQ(isolate),
254  TYPICAL_SQ(isolation_source),
255  TYPICAL_SQ(lab_host),
256  TYPICAL_SQ(label),
257  TYPICAL_SQ(lat_lon),
258  TYPICAL_SQ(linkage_group),
259  TYPICAL_SQ(macronuclear),
260  TYPICAL_SQ(mating_type),
261  TYPICAL_SQ(map),
262  TYPICAL_SQ(metagenome_source),
263  TYPICAL_SQ(metagenomic),
264  TYPICAL_SQ(mobile_element),
265  TYPICAL_SQ(mol_type),
266  TYPICAL_SQ(old_lineage),
267  TYPICAL_SQ(old_name),
268  TYPICAL_SQ(organism),
269  TYPICAL_SQ(organelle),
270  TYPICAL_SQ(orgmod_note),
271  TYPICAL_SQ(pathovar),
272  TYPICAL_SQ(PCR_primers),
273  TYPICAL_SQ(pcr_primer_note),
274  { eSQ_plasmid_name, "plasmid" },
275  { eSQ_plastid_name, "plastid" },
276  TYPICAL_SQ(pop_variant),
277  TYPICAL_SQ(rearranged),
278  TYPICAL_SQ(rev_primer_name),
279  TYPICAL_SQ(rev_primer_seq),
280  TYPICAL_SQ(segment),
281  TYPICAL_SQ(seqfeat_note),
282  TYPICAL_SQ(sequenced_mol),
283  TYPICAL_SQ(serogroup),
284  TYPICAL_SQ(serotype),
285  TYPICAL_SQ(serovar),
286  TYPICAL_SQ(sex),
287  { eSQ_spec_or_nat_host, "host" },
288  TYPICAL_SQ(specimen_voucher),
289  TYPICAL_SQ(strain),
290  { eSQ_subclone, "sub_clone" },
291  TYPICAL_SQ(subgroup),
292  TYPICAL_SQ(sub_species),
293  { eSQ_substrain, "sub_strain" },
294  TYPICAL_SQ(subtype),
295  TYPICAL_SQ(subsource_note),
296  TYPICAL_SQ(synonym),
297  TYPICAL_SQ(teleomorph),
298  TYPICAL_SQ(tissue_lib),
299  TYPICAL_SQ(tissue_type),
300  TYPICAL_SQ(transgenic),
301  { eSQ_transposon_name, "transposon" },
302  TYPICAL_SQ(type),
303  TYPICAL_SQ(type_material),
304  TYPICAL_SQ(unstructured),
305  TYPICAL_SQ(usedin),
306  TYPICAL_SQ(variety),
307  TYPICAL_SQ(whole_replicon),
308  { eSQ_zero_orgmod, "?" },
309  { eSQ_one_orgmod, "?" },
310  { eSQ_zero_subsrc, "?" },
311  TYPICAL_SQ(submitter_seqid)
312 #undef TYPICAL_SQ
313  };
314  typedef const CStaticPairArrayMap<ESourceQualifier, const char*> TSourceQualToNameMap;
315  DEFINE_STATIC_ARRAY_MAP(TSourceQualToNameMap, kSourceQualToNameMap, kSourceQualToNames);
316 
317  _ASSERT( kSourceQualToNameMap.size() == eSQ_NUM_SOURCE_QUALIFIERS );
318 
319  TSourceQualToNameMap::const_iterator find_iter =
320  kSourceQualToNameMap.find(eSourceQualifier);
321  if( find_iter != kSourceQualToNameMap.end() ) {
322  return find_iter->second;
323  }
324 
325  return "UNKNOWN_SOURCE_QUAL";
326 }
327 
330 {
331  switch( eOrgModSubtype )
332  {
333  // In most (but not all) cases, the orgmod subtype
334  // corresponds directly to the sourcequal. For those
335  // easy cases, we use this CASE_ORGMOD macro
336 #ifdef CASE_ORGMOD
337 # error CASE_ORGMOD should NOT be already defined here.
338 #endif
339 
340 #define CASE_ORGMOD(x) case COrgMod::eSubtype_##x: return eSQ_##x;
341  CASE_ORGMOD(strain);
342  CASE_ORGMOD(substrain);
343  CASE_ORGMOD(type);
344  CASE_ORGMOD(subtype);
345  CASE_ORGMOD(variety);
346  CASE_ORGMOD(serotype);
347  CASE_ORGMOD(serogroup);
348  CASE_ORGMOD(serovar);
349  CASE_ORGMOD(cultivar);
350  CASE_ORGMOD(pathovar);
351  CASE_ORGMOD(chemovar);
352  CASE_ORGMOD(biovar);
353  CASE_ORGMOD(biotype);
354  CASE_ORGMOD(group);
355  CASE_ORGMOD(subgroup);
356  CASE_ORGMOD(isolate);
357  CASE_ORGMOD(common);
358  CASE_ORGMOD(acronym);
359  CASE_ORGMOD(dosage);
361  CASE_ORGMOD(sub_species);
362  CASE_ORGMOD(specimen_voucher);
363  CASE_ORGMOD(authority);
364  CASE_ORGMOD(forma);
365  CASE_ORGMOD(forma_specialis);
366  CASE_ORGMOD(ecotype);
367  CASE_ORGMOD(culture_collection);
368  CASE_ORGMOD(bio_material);
369  CASE_ORGMOD(type_material);
370  CASE_ORGMOD(synonym);
371  CASE_ORGMOD(anamorph);
372  CASE_ORGMOD(teleomorph);
373  CASE_ORGMOD(breed);
374  CASE_ORGMOD(gb_acronym);
375  CASE_ORGMOD(gb_anamorph);
376  CASE_ORGMOD(gb_synonym);
377  CASE_ORGMOD(metagenome_source);
378  CASE_ORGMOD(old_lineage);
379  CASE_ORGMOD(old_name);
380 #undef CASE_ORGMOD
382  default: return eSQ_none;
383  }
384 }
385 
388 {
389  switch( eSubSourceSubtype ) {
390  // Generally, there is a direct, obvious correspondence
391  // between subsource subtypes and sourcequals.
392 #ifdef DO_SS
393 # error DO_SS should NOT have already been defined here.
394 #endif
395 
396 #define DO_SS(x) case CSubSource::eSubtype_##x: return eSQ_##x;
397  DO_SS(chromosome);
398  DO_SS(map);
399  DO_SS(clone);
400  DO_SS(subclone);
401  DO_SS(haplotype);
402  DO_SS(genotype);
403  DO_SS(sex);
404  DO_SS(cell_line);
405  DO_SS(cell_type);
406  DO_SS(tissue_type);
407  DO_SS(clone_lib);
408  DO_SS(dev_stage);
409  DO_SS(frequency);
410  DO_SS(germline);
411  DO_SS(rearranged);
412  DO_SS(lab_host);
413  DO_SS(pop_variant);
414  DO_SS(tissue_lib);
415  DO_SS(plasmid_name);
416  DO_SS(transposon_name);
417  DO_SS(insertion_seq_name);
418  DO_SS(plastid_name);
419  DO_SS(country);
420  DO_SS(segment);
421  DO_SS(endogenous_virus_name);
422  DO_SS(transgenic);
423  DO_SS(environmental_sample);
424  DO_SS(isolation_source);
425  DO_SS(lat_lon);
426  DO_SS(altitude);
427  DO_SS(collection_date);
428  DO_SS(collected_by);
429  DO_SS(identified_by);
430  DO_SS(fwd_primer_seq);
431  DO_SS(rev_primer_seq);
432  DO_SS(fwd_primer_name);
433  DO_SS(rev_primer_name);
434  DO_SS(metagenomic);
435  DO_SS(mating_type);
436  DO_SS(linkage_group);
437  DO_SS(haplogroup);
438  DO_SS(whole_replicon);
439 #undef DO_SS
441  default: return eSQ_none;
442  }
443 }
444 
447 
class CStaticArrayMap<> is an array adaptor that provides an STLish interface to statically-defined a...
Definition: static_map.hpp:105
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTempString GetStringOfSourceQual(ESourceQualifier eSourceQualifier)
Given a ESourceQualifier, this returns the qualifier name.
#define CASE_ORGMOD(x)
ESourceQualifier GetSourceQualOfOrgMod(COrgMod::ESubtype eOrgModSubtype)
Translate an org-mod subtype into a sourcequalifier.
#define DO_SS(x)
ESourceQualifier GetSourceQualOfSubSource(CSubSource::ESubtype eSubSourceSubtype)
Translate a subsource subtype into a sourcequalifier.
CTempString GetStringOfFeatQual(EFeatureQualifier eFeatureQualifier)
Given a EFeatureQualifier, this returns the qualifier name.
#define TYPICAL_FQ(x)
#define TYPICAL_SQ(x)
ESourceQualifier
@ eSQ_spec_or_nat_host
@ eSQ_none
@ eSQ_one_orgmod
@ eSQ_transposon_name
@ eSQ_org_xref
@ eSQ_plasmid_name
@ eSQ_orgmod_note
@ eSQ_zero_orgmod
@ eSQ_zero_subsrc
@ eSQ_plastid_name
@ eSQ_insertion_seq_name
@ eSQ_subclone
@ eSQ_substrain
@ eSQ_NUM_SOURCE_QUALIFIERS
@ eSQ_subsource_note
@ eSQ_endogenous_virus_name
EFeatureQualifier
@ eFQ_NUM_SOURCE_QUALIFIERS
@ eFQ_cds_product
@ eFQ_gene_syn_refseq
@ eFQ_prot_activity
@ eFQ_gene_xref
@ eFQ_transcript_id_note
@ eFQ_go_function
@ eFQ_gene_allele
@ eFQ_prot_name
@ eFQ_go_component
@ eFQ_prot_EC_number
@ eFQ_go_process
@ eFQ_illegal_qual
@ eFQ_gene_map
#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 const char label[]
@ eSubtype_other
ASN5: old-name (254) will be added to next spec.
Definition: OrgMod_.hpp:125
@ eSubtype_nat_host
natural host of this specimen
Definition: OrgMod_.hpp:104
ESERV_Site site
static BOOL number
Definition: pcregrep.c:193
#define DEFINE_STATIC_ARRAY_MAP(Type, Var, Array)
Definition: static_set.hpp:888
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
Definition: type.c:6
#define _ASSERT
Modified on Tue Apr 30 06:42:35 2024 by modify_doxy.py rev. 669887