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

Go to the SVN repository for this file.

1 /* $Id: Feat_qual_choice.cpp 94996 2021-09-27 14:11:38Z grichenk $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: J. Chen
27  *
28  * File Description:
29  * GetQualFromFeatureAnyType
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'macro.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 
43 // generated classes
44 
46 
47 BEGIN_objects_SCOPE // namespace ncbi::objects::
48 
49 // destructor
51 {
52 }
53 
54 string CFeat_qual_choice :: x_GetLegalQualName(vector <EFeat_qual_legal>& v_qual, EFeat_qual_legal qual) const
55 {
56  ITERATE (vector <EFeat_qual_legal>, it, v_qual) {
57  if (qual == *it) {
58  string name = ENUM_METHOD_NAME(EFeat_qual_legal)()->FindName(qual, true);
59  if (name == "name") {
60  return ("region");
61  }
62  else if (name == "product") {
63  return ("name");
64  }
65  else if (name == "gene") {
66  return ("locus");
67  }
68  else if ( name == "locus-tag") {
69  return("locus_tag");
70  }
71  return name;
72  }
73  }
74  return kEmptyStr;
75 };
76 
77 void CFeat_qual_choice :: x_GetTwoFieldSubfield(string& str, int subfield) const
78 {
79  if (str.empty() || subfield > 2) {
80  str = kEmptyStr;
81  }
82  if (subfield) {
83  size_t pos = str.find(':');
84  if (pos == string::npos) {
85  if (subfield != 1) {
86  str = kEmptyStr;
87  }
88  }
89  else {
90  if (subfield == 1) {
91  str.substr(0, pos);
92  }
93  else {
94  str = str.substr(pos+1);
95  }
96  }
97  }
98 };
99 
100 string CFeat_qual_choice :: x_GetFirstGBQualMatch(const vector <CRef <CGb_qual> >& quals, const string& qual_name, int subfield, const CString_constraint& str_cons) const
101 {
102  string str;
103  ITERATE (vector <CRef <CGb_qual> >, it, quals) {
104  if (NStr::EqualNocase( (*it)->GetQual(), qual_name)) {
105  str = (*it)->GetVal();
106  if (subfield) {
107  x_GetTwoFieldSubfield(str, subfield);
108  }
109  if (str.empty() || !str_cons.Match(str)) {
110  str = kEmptyStr;
111  }
112  else {
113  break;
114  }
115  }
116  }
117  return str;
118 };
119 
120 string CFeat_qual_choice :: GetFirstStringMatch(const list <string>& strs, const CString_constraint& str_cons)
121 {
122  ITERATE (list <string>, sit, strs) {
123  if ( !(*sit).empty() && str_cons.Match(*sit)) {
124  return (*sit);
125  }
126  }
127  return kEmptyStr;
128 };
129 
130 string CFeat_qual_choice :: GetFirstStringMatch(const vector <string>& strs, const CString_constraint& str_cons)
131 {
132  ITERATE (vector <string>, sit, strs) {
133  if ( !(*sit).empty() && str_cons.Match(*sit)) {
134  return (*sit);
135  }
136  }
137  return kEmptyStr;
138 };
139 
141 {
142  string str;
143  if (feat.CanGetQual()) {
144  ITERATE (vector <CRef <CGb_qual> >, it, feat.GetQual()) {
145  str = (*it)->GetVal();
146  if (!str.empty() && str_cons.Match(str)) {
147  return str;
148  }
149  else str = kEmptyStr;
150  }
151  }
152  return str;
153 };
154 
155 END_objects_SCOPE // namespace ncbi::objects::
156 
158 
159 /* Original file checksum: lines: 57, chars: 1741, CRC32: 81a34e90 */
User-defined methods of the data storage class.
static string GetFirstStringMatch(const list< string > &strs, const CString_constraint &str_cons)
void x_GetTwoFieldSubfield(string &str, int subfield) const
string x_GetFirstGBQualMatch(const vector< CRef< CGb_qual > > &quals, const string &qual_name, int subfield, const CString_constraint &str_cons) const
string x_GetLegalQualName(vector< EFeat_qual_legal > &v_qual, EFeat_qual_legal qual) const
string x_GetFirstGBQualMatchConstraintName(const CSeq_feat &feat, const CString_constraint &str_cons) const
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
bool Match(const CMatchString &str) const
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define ENUM_METHOD_NAME(EnumName)
Definition: serialbase.hpp:994
#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 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
EFeat_qual_legal
Access to EFeat_qual_legal's attributes (values, names) as defined in spec.
bool CanGetQual(void) const
Check if it is safe to call GetQual method.
Definition: Seq_feat_.hpp:1141
const TQual & GetQual(void) const
Get the Qual member data.
Definition: Seq_feat_.hpp:1147
Modified on Sun Apr 21 03:40:26 2024 by modify_doxy.py rev. 669887