1 /* $Id: RNA_ref.cpp 499355 2016-04-25 19:42:55Z dicuccio $
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
41 #include <objects/seqfeat/RNA_ref.hpp>
42 #include <objects/seqfeat/Trna_ext.hpp>
43
44 // generated classes
45
46 BEGIN_NCBI_SCOPE
47
48 BEGIN_objects_SCOPE // namespace ncbi::objects::
49
50 // destructor
~CRNA_ref(void)51 CRNA_ref::~CRNA_ref(void)
52 {
53 }
54
55
56 static const SStaticPair<CRNA_ref::EType, const char*> sc_rna_type_map[] = {
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
70 typedef CStaticPairArrayMap<CRNA_ref::EType, const char*> TRnaTypeMap;
71 DEFINE_STATIC_ARRAY_MAP(TRnaTypeMap, sc_RnaTypeMap, sc_rna_type_map);
72
GetRnaTypeName(const CRNA_ref::EType rna_type)73 string CRNA_ref::GetRnaTypeName (const CRNA_ref::EType rna_type)
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
s_AaName(int aa)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
s_GetTrnaProduct(const CTrna_ext & trna)131 static CTempString s_GetTrnaProduct(const CTrna_ext& trna)
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
GetRnaProductName(void) const145 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
s_SetTrnaProduct(CTrna_ext & trna,const string & product,string & remainder)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 (size_t i = 0; i < ArraySize(sc_TrnaList); ++i) {
187 if (NStr::StartsWith(test, sc_TrnaList[i], NStr::eNocase)) {
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
SetRnaProductName(const string & product,string & remainder)225 void CRNA_ref::SetRnaProductName(const string& product, string& remainder)
226 {
227 remainder = kEmptyStr;
228 switch (GetType()) {
229 case CRNA_ref::eType_rRNA:
230 case CRNA_ref::eType_mRNA:
231 case CRNA_ref::eType_premsg:
232 if (NStr::IsBlank(product)) {
233 ResetExt();
234 } else {
235 SetExt().SetName(product);
236 }
237 break;
238 case CRNA_ref::eType_tRNA:
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
256 END_NCBI_SCOPE
257
258 /* Original file checksum: lines: 65, chars: 1885, CRC32: 6e6c3f8a */
259