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

Go to the SVN repository for this file.

1 /* $Id: RNA_ref.cpp 99064 2023-02-08 19:14:27Z ucko $
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 the following specifications:
34  * 'seqfeat.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
43 
44 // generated classes
45 
47 
48 BEGIN_objects_SCOPE // namespace ncbi::objects::
49 
50 // destructor
52 {
53 }
54 
55 
57  { CRNA_ref::eType_premsg, "precursor_RNA" },
58  { CRNA_ref::eType_mRNA, "mRNA" },
59  { CRNA_ref::eType_tRNA, "tRNA" },
60  { CRNA_ref::eType_rRNA, "rRNA" },
61  { CRNA_ref::eType_snRNA, "snRNA" },
62  { CRNA_ref::eType_scRNA, "scRNA" },
63  { CRNA_ref::eType_snoRNA, "snoRNA" },
64  { CRNA_ref::eType_ncRNA, "ncRNA" },
65  { CRNA_ref::eType_tmRNA, "tmRNA" },
66  { CRNA_ref::eType_miscRNA, "misc_RNA" },
67  { CRNA_ref::eType_other, "misc_RNA" }
68 };
69 
72 
74 {
75  const char* rna_type_name = "";
76  TRnaTypeMap::const_iterator rna_type_it = sc_RnaTypeMap.find(rna_type);
77  if ( rna_type_it != sc_RnaTypeMap.end() ) {
78  rna_type_name = rna_type_it->second;
79  }
80  return rna_type_name;
81 }
82 
83 static const char* sc_TrnaList[] = {
84  "tRNA-Gap",
85  "tRNA-Ala",
86  "tRNA-Asx",
87  "tRNA-Cys",
88  "tRNA-Asp",
89  "tRNA-Glu",
90  "tRNA-Phe",
91  "tRNA-Gly",
92  "tRNA-His",
93  "tRNA-Ile",
94  "tRNA-Xle",
95  "tRNA-Lys",
96  "tRNA-Leu",
97  "tRNA-Met",
98  "tRNA-Asn",
99  "tRNA-Pyl",
100  "tRNA-Pro",
101  "tRNA-Gln",
102  "tRNA-Arg",
103  "tRNA-Ser",
104  "tRNA-Thr",
105  "tRNA-Sec",
106  "tRNA-Val",
107  "tRNA-Trp",
108  "tRNA-OTHER",
109  "tRNA-Tyr",
110  "tRNA-Glx",
111  "tRNA-TERM"
112 };
113 
114 static CTempString s_AaName(int aa)
115 {
116  int idx = 255;
117 
118  if (aa != '*') {
119  idx = aa - 64;
120  } else {
121  idx = 27;
122  }
123 
124  if (idx > 0 && idx < ArraySize(sc_TrnaList)) {
125  return sc_TrnaList [idx];
126  }
127  return kEmptyStr;
128 }
129 
130 
132 {
133  int aa = 0;
134  if ( trna.IsSetAa() ) {
135  if (trna.GetAa().IsNcbieaa()) {
136  aa = trna.GetAa().GetNcbieaa();
137  } else if (trna.GetAa().IsIupacaa()) {
138  aa = trna.GetAa().GetIupacaa();
139  }
140  }
141 
142  return s_AaName(aa);
143 }
144 
145 string CRNA_ref::GetRnaProductName(void) const
146 {
147  if (!IsSetExt()) {
148  return kEmptyStr;
149  }
150 
151  if (GetExt().IsName()) {
152  return GetExt().GetName();
153  } else if (GetExt().IsGen() && GetExt().GetGen().IsSetProduct()) {
154  return GetExt().GetGen().GetProduct();
155  } else if (GetExt().IsTRNA()) {
156  return s_GetTrnaProduct(GetExt().GetTRNA());
157  }
158 
159  return kEmptyStr;
160 }
161 
162 
163 static void s_SetTrnaProduct(CTrna_ext& trna, const string& product, string& remainder)
164 {
165  remainder = kEmptyStr;
166  if (NStr::IsBlank(product)) {
167  trna.ResetAa();
168  return;
169  }
170 
171  string test = product;
172  if (!NStr::StartsWith(product, "tRNA-")) {
173  test = "tRNA-" + test;
174  }
175 
176  if (NStr::StartsWith(test, "tRNA-TERM", NStr::eNocase)
177  || NStr::StartsWith(test, "tRNA-STOP", NStr::eNocase)) {
178  trna.SetAa().SetNcbieaa(42);
179  if (test.length() > 9) {
180  remainder = test.substr(9);
181  NStr::TruncateSpacesInPlace(remainder);
182  }
183  } else {
184  remainder = product;
185  bool found_three_letter_code = false;
186  for (int i = 0; i < ArraySize(sc_TrnaList); ++i) {
188  trna.SetAa().SetNcbieaa(i + 64);
189  remainder = test.substr(CTempString(sc_TrnaList[i]).length());
190  found_three_letter_code = true;
191  break;
192  }
193  }
194  if (!found_three_letter_code && test.length() > 5) {
195  int ch = test.c_str()[5];
196  int after = test.c_str()[6];
197  if (!isalpha(after)) {
198  if (isalpha(ch)) {
199  int aa = 65 + ch - 'A';
200  trna.SetAa().SetNcbieaa(aa);
201  remainder = test.substr(6);
202  } else if (ch == '*') {
203  trna.SetAa().SetNcbieaa(42);
204  remainder = test.substr(6);
205  }
206  }
207  }
208  }
209  if (remainder.length() == 5 && NStr::StartsWith(remainder, "(") && NStr::EndsWith(remainder, ")")) {
210  string codon = remainder.substr(1, 3);
211  codon = NStr::ToUpper(codon);
212  NStr::ReplaceInPlace(codon, "U", "T");
213  // will parse a single codon recognized
214  CRef<CTrna_ext> ext(new CTrna_ext());
215  if (CTrna_ext::ParseDegenerateCodon(*ext, codon)) {
216  trna.ResetCodon();
217  ITERATE(CTrna_ext::TCodon, c, ext->GetCodon()) {
218  trna.SetCodon().push_back(*c);
219  }
220  remainder = kEmptyStr;
221  }
222  }
223 }
224 
225 void CRNA_ref::SetRnaProductName(const string& product, string& remainder)
226 {
227  remainder = kEmptyStr;
228  switch (GetType()) {
232  if (NStr::IsBlank(product)) {
233  ResetExt();
234  } else {
235  SetExt().SetName(product);
236  }
237  break;
239  s_SetTrnaProduct(SetExt().SetTRNA(), product, remainder);
240  break;
241  default:
242  if (NStr::IsBlank(product)) {
243  SetExt().SetGen().ResetProduct();
244  if (!GetExt().GetGen().IsSetClass() && !GetExt().GetGen().IsSetQuals()) {
245  ResetExt();
246  }
247  } else {
248  SetExt().SetGen().SetProduct(product);
249  }
250  break;
251  }
252 }
253 
254 END_objects_SCOPE // namespace ncbi::objects::
255 
257 
258 /* Original file checksum: lines: 65, chars: 1885, CRC32: 6e6c3f8a */
DEFINE_STATIC_ARRAY_MAP(TRnaTypeMap, sc_RnaTypeMap, sc_rna_type_map)
static const SStaticPair< CRNA_ref::EType, const char * > sc_rna_type_map[]
Definition: RNA_ref.cpp:56
static const char * sc_TrnaList[]
Definition: RNA_ref.cpp:83
static CTempString s_GetTrnaProduct(const CTrna_ext &trna)
Definition: RNA_ref.cpp:131
static void s_SetTrnaProduct(CTrna_ext &trna, const string &product, string &remainder)
Definition: RNA_ref.cpp:163
static CTempString s_AaName(int aa)
Definition: RNA_ref.cpp:114
CStaticPairArrayMap< CRNA_ref::EType, const char * > TRnaTypeMap
Definition: RNA_ref.cpp:70
User-defined methods of the data storage class.
string GetRnaProductName(void) const
Definition: RNA_ref.cpp:145
~CRNA_ref(void)
Definition: RNA_ref.cpp:51
static string GetRnaTypeName(const CRNA_ref::EType rna_type)
Definition: RNA_ref.cpp:73
void SetRnaProductName(const string &product, string &remainder)
Definition: RNA_ref.cpp:225
CRef –.
Definition: ncbiobj.hpp:618
class CStaticArrayMap<> is an array adaptor that provides an STLish interface to statically-defined a...
Definition: static_map.hpp:105
TBase::const_iterator const_iterator
Definition: static_map.hpp:109
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
static bool ParseDegenerateCodon(CTrna_ext &tRNA, const string &codon)
Definition: Trna_ext.cpp:65
#define test(a, b, c, d, e)
Definition: numeric.c:170
constexpr size_t ArraySize(const Element(&)[Size])
Definition: ncbimisc.hpp:1532
#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 BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
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
size_type length(void) const
Return the length of the represented array.
Definition: tempstr.hpp:320
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
static string & ToUpper(string &str)
Convert string to upper case – string& version.
Definition: ncbistr.cpp:424
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
TName & SetName(void)
Select the variant.
Definition: RNA_ref_.hpp:491
TType GetType(void) const
Get the Type member data.
Definition: RNA_ref_.hpp:529
const TAa & GetAa(void) const
Get the Aa member data.
Definition: Trna_ext_.hpp:603
void ResetAa(void)
Reset Aa data member.
Definition: Trna_ext_.cpp:130
bool IsSetAa(void) const
Check if a value has been assigned to Aa data member.
Definition: Trna_ext_.hpp:591
bool IsIupacaa(void) const
Check if variant Iupacaa is selected.
Definition: Trna_ext_.hpp:483
bool IsNcbieaa(void) const
Check if variant Ncbieaa is selected.
Definition: Trna_ext_.hpp:510
EType
type of RNA feature
Definition: RNA_ref_.hpp:95
bool IsSetExt(void) const
generic fields for ncRNA, tmRNA, miscRNA Check if a value has been assigned to Ext data member.
Definition: RNA_ref_.hpp:604
TCodon & SetCodon(void)
Assign a value to Codon data member.
Definition: Trna_ext_.hpp:630
TNcbieaa GetNcbieaa(void) const
Get the variant data.
Definition: Trna_ext_.hpp:516
TIupacaa GetIupacaa(void) const
Get the variant data.
Definition: Trna_ext_.hpp:489
list< int > TCodon
Definition: Trna_ext_.hpp:306
void SetAa(TAa &value)
Assign a value to Aa data member.
Definition: Trna_ext_.cpp:135
void ResetCodon(void)
Reset Codon data member.
Definition: Trna_ext_.cpp:147
const TGen & GetGen(void) const
Get the variant data.
Definition: RNA_ref_.cpp:156
void ResetExt(void)
Reset Ext data member.
Definition: RNA_ref_.cpp:206
const TName & GetName(void) const
Get the variant data.
Definition: RNA_ref_.hpp:484
TGen & SetGen(void)
Select the variant.
Definition: RNA_ref_.cpp:162
const TProduct & GetProduct(void) const
Get the Product member data.
Definition: RNA_gen_.hpp:306
const TExt & GetExt(void) const
Get the Ext member data.
Definition: RNA_ref_.hpp:616
void SetProduct(const TProduct &value)
Assign a value to Product data member.
Definition: RNA_gen_.hpp:315
TExt & SetExt(void)
Assign a value to Ext data member.
Definition: RNA_ref_.cpp:216
void ResetProduct(void)
Reset Product data member.
Definition: RNA_gen_.cpp:57
@ eType_scRNA
will become ncRNA, with RNA-gen.class = scRNA
Definition: RNA_ref_.hpp:102
@ eType_snoRNA
will become ncRNA, with RNA-gen.class = snoRNA
Definition: RNA_ref_.hpp:103
@ eType_ncRNA
non-coding RNA; subsumes snRNA, scRNA, snoRNA
Definition: RNA_ref_.hpp:104
@ eType_snRNA
will become ncRNA, with RNA-gen.class = snRNA
Definition: RNA_ref_.hpp:101
int i
int isalpha(Uchar c)
Definition: ncbictype.hpp:61
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
Modified on Wed Apr 17 13:08:33 2024 by modify_doxy.py rev. 669887