1 /* $Id: unit_test_get_label.cpp 627205 2021-03-10 19:12:27Z ivanov $
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: Colleen Bollin, NCBI
27 *
28 * File Description:
29 * Sample unit tests file for main stream test developing.
30 *
31 * This file represents basic most common usage of Ncbi.Test framework based
32 * on Boost.Test framework. For more advanced techniques look into another
33 * sample - unit_test_alt_sample.cpp.
34 *
35 * ===========================================================================
36 */
37
38 #include <ncbi_pch.hpp>
39
40 #include <corelib/ncbi_system.hpp>
41
42 // This macro should be defined before inclusion of test_boost.hpp in all
43 // "*.cpp" files inside executable except one. It is like function main() for
44 // non-Boost.Test executables is defined only in one *.cpp file - other files
45 // should not include it. If NCBI_BOOST_NO_AUTO_TEST_MAIN will not be defined
46 // then test_boost.hpp will define such "main()" function for tests.
47 //
48 // Usually if your unit tests contain only one *.cpp file you should not
49 // care about this macro at all.
50 //
51 //#define NCBI_BOOST_NO_AUTO_TEST_MAIN
52
53
54 // This header must be included before all Boost.Test headers if there are any
55 #include <corelib/test_boost.hpp>
56
57 #include <objects/seqset/Seq_entry.hpp>
58 #include <objmgr/object_manager.hpp>
59 #include <objmgr/scope.hpp>
60 #include <objmgr/bioseq_ci.hpp>
61 #include <objmgr/feat_ci.hpp>
62 #include <objmgr/seq_vector.hpp>
63 #include <objmgr/util/feature.hpp>
64 #include <objects/seq/seqport_util.hpp>
65 #include <objects/seq/Seq_inst.hpp>
66 #include <objects/seq/Seq_ext.hpp>
67 #include <objects/seq/Seq_literal.hpp>
68 #include <objects/seq/Delta_seq.hpp>
69 #include <objects/seq/Delta_ext.hpp>
70 #include <objects/general/Object_id.hpp>
71 #include <objects/seqfeat/Cdregion.hpp>
72 #include <objects/misc/sequence_macros.hpp>
73
74 USING_NCBI_SCOPE;
75 USING_SCOPE(objects);
76
77 extern const char* sc_TestEntry; //
78
79
CheckOneFeatureType(CBioseq_Handle bsh,CSeqFeatData::ESubtype subtype,const string & content,const string & ftype,const string & both)80 void CheckOneFeatureType
81 (CBioseq_Handle bsh,
82 CSeqFeatData::ESubtype subtype,
83 const string& content,
84 const string& ftype,
85 const string& both)
86 {
87 CFeat_CI f(bsh, subtype);
88
89 string label = kEmptyStr;
90
91 feature::GetLabel(*(f->GetSeq_feat()), &label, feature::fFGL_Content, &(bsh.GetScope()));
92 BOOST_CHECK_EQUAL(label, content);
93 label = kEmptyStr;
94
95 feature::GetLabel(*(f->GetSeq_feat()), &label, feature::fFGL_Type, &(bsh.GetScope()));
96 BOOST_CHECK_EQUAL(label, ftype);
97 label = kEmptyStr;
98
99 feature::GetLabel(*(f->GetSeq_feat()), &label, feature::fFGL_Both, &(bsh.GetScope()));
100 if (label != both) {
101 cout << "error: '" << label << "' != '" << both << "'" << endl;
102 }
103 BOOST_CHECK_EQUAL(label, both);
104 }
105
BOOST_AUTO_TEST_CASE(Test_feature_GetLabel)106 BOOST_AUTO_TEST_CASE(Test_feature_GetLabel)
107 {
108 CSeq_entry entry;
109 {{
110 CNcbiIstrstream istr(sc_TestEntry);
111 istr >> MSerial_AsnText >> entry;
112 }}
113
114 CScope scope(*CObjectManager::GetInstance());
115 CSeq_entry_Handle seh = scope.AddTopLevelSeqEntry(entry);
116 CBioseq_CI nuc_bsh(seh, CSeq_inst::eMol_na);
117
118 CheckOneFeatureType(*nuc_bsh, CSeqFeatData::eSubtype_misc_feature,
119 "/rpt_family=repeat family /rpt_type=inverted /rpt_type=tandem /rpt_unit_range=4..7 /rpt_unit_seq=aatt; tumour",
120 "[misc_feature]",
121 "[misc_feature]: /rpt_family=repeat family /rpt_type=inverted /rpt_type=tandem /rpt_unit_range=4..7 /rpt_unit_seq=aatt; tumour");
122 CheckOneFeatureType(*nuc_bsh, CSeqFeatData::eSubtype_cdregion,
123 "neuronal thread protein AD7c-NTP",
124 "CDS",
125 "CDS: neuronal thread protein AD7c-NTP");
126
127 CBioseq_CI prot_bsh(seh, CSeq_inst::eMol_aa);
128 CheckOneFeatureType(*prot_bsh, CSeqFeatData::eSubtype_prot,
129 "neuronal thread protein AD7c-NTP",
130 "Prot",
131 "Prot: neuronal thread protein AD7c-NTP");
132
133 CheckOneFeatureType(*prot_bsh, CSeqFeatData::eSubtype_preprotein,
134 "proprotein", "proprotein", "proprotein: ");
135 CheckOneFeatureType(*prot_bsh, CSeqFeatData::eSubtype_mat_peptide_aa,
136 "mat_peptide", "mat_peptide", "mat_peptide: ");
137 CheckOneFeatureType(*prot_bsh, CSeqFeatData::eSubtype_sig_peptide_aa,
138 "sig_peptide", "sig_peptide", "sig_peptide: ");
139 CheckOneFeatureType(*prot_bsh, CSeqFeatData::eSubtype_transit_peptide_aa,
140 "transit_peptide", "transit_peptide", "transit_peptide: ");
141 }
142
143
144
145 //////////////////////////////////////////////////////////////////////////////
146
147 const char* sc_TestEntry ="\
148 Seq-entry ::= set {\
149 class nuc-prot,\
150 seq-set {\
151 seq {\
152 id {\
153 genbank {\
154 name \"AF010144\",\
155 accession \"AF010144\",\
156 version 1\
157 },\
158 gi 3002526\
159 },\
160 inst {\
161 repr raw,\
162 mol rna,\
163 length 1442,\
164 seq-data iupacna \"TTTTTTTTTTTGAGATGGAGTTTTCGCTCTTGTTGCCCAGGCTGGAGTGCAA\
165 TGGCGCAATCTCAGCTCACCGCAACCTCCGCCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCCTCCCCAGTAGCTGG\
166 GATTACAGGCATGTGCACCCACGCTCGGCTAATTTTGTATTTTTTTTTAGTAGAGATGGAGTTTCTCCATGTTGGTCA\
167 GGCTGGTCTCGAACTCCCGACCTCAGATGATCCCTCCGTCTCGGCCTCCCAAAGTGCTAGATACAGGACTGGCCACCA\
168 TGCCCGGCTCTGCCTGGCTAATTTTTGTGGTAGAAACAGGGTTTCACTGATGTGCCCAAGCTGGTCTCCTGAGCTCAA\
169 GCAGTCCACCTGCCTCAGCCTCCCAAAGTGCTGGGATTACAGGCGTGCAGCCGTGCCTGGCCTTTTTATTTTATTTTT\
170 TTTAAGACACAGGTGTCCCACTCTTACCCAGGATGAAGTGCAGTGGTGTGATCACAGCTCACTGCAGCCTTCAACTCC\
171 TGAGATCAAGCATCCTCCTGCCTCAGCCTCCCAAGTAGCTGGGACCAAAGACATGCACCACTACACCTGGCTAATTTT\
172 TATTTTTATTTTTAATTTTTTGAGACAGAGTCTCAACTCTGTCACCCAGGCTGGAGTGCAGTGGCGCAATCTTGGCTC\
173 ACTGCAACCTCTGCCTCCCGGGTTCAAGTTATTCTCCTGCCCCAGCCTCCTGAGTAGCTGGGACTACAGGCGCCCACC\
174 ACGCCTAGCTAATTTTTTTGTATTTTTAGTAGAGATGGGGTTCACCATGTTCGCCAGGTTGATCTTGATCTCTGGACC\
175 TTGTGATCTGCCTGCCTCGGCCTCCCAAAGTGCTGGGATTACAGGCGTGAGCCACCACGCCCGGCTTATTTTTAATTT\
176 TTGTTTGTTTGAAATGGAATCTCACTCTGTTACCCAGGCTGGAGTGCAATGGCCAAATCTCGGCTCACTGCAACCTCT\
177 GCCTCCCGGGCTCAAGCGATTCTCCTGTCTCAGCCTCCCAAGCAGCTGGGATTACGGGCACCTGCCACCACACCCCGC\
178 TAATTTTTGTATTTTCATTAGAGGCGGGGTTTCACCATATTTGTCAGGCTGGTCTCAAACTCCTGACCTCAGGTGACC\
179 CACCTGCCTCAGCCTTCCAAAGTGCTGGGATTACAGGCGTGAGCCACCTCACCCAGCCGGCTAATTTAGATAAAAAAA\
180 TATGTAGCAATGGGGGGTCTTGCTATGTTGCCCAGGCTGGTCTCAAACTTCTGGCTTCATGCAATCCTTCCAAATGAG\
181 CCACAACACCCAGCCAGTCACATTTTTTAAACAGTTACATCTTTATTTTAGTATACTAGAAAGTAATACAATAAACAT\
182 GTCAAACCTGCAAATTCAGTAGTAACAGAGTTCTTTTATAACTTTTAAACAAAGCTTTAGAGCA\"\
183 },\
184 annot { { data ftable {\
185 {\
186 data imp { key \"misc_feature\" },\
187 comment \"tumour\",\
188 location int { from 0, to 374, id gi 3002526 },\
189 qual {\
190 {qual \"rpt_family\", val \"repeat family\"},\
191 {qual \"rpt_type\", val \"inverted\"},\
192 {qual \"rpt_type\", val \"tandem\"},\
193 {qual \"rpt_unit_range\", val \"4..7\"},\
194 {qual \"rpt_unit_seq\", val \"aatt\"}\
195 }\
196 }\
197 } } }\
198 },\
199 seq {\
200 id {\
201 genbank {\
202 accession \"AAC08737\",\
203 version 1\
204 },\
205 gi 3002527\
206 },\
207 inst {\
208 repr raw,\
209 mol aa,\
210 length 375,\
211 topology not-set,\
212 seq-data ncbieaa \"MEFSLLLPRLECNGAISAHRNLRLPGSSDSPASASPVAGITGMCTHARLILY\
213 FFLVEMEFLHVGQAGLELPTSDDPSVSASQSARYRTGHHARLCLANFCGRNRVSLMCPSWSPELKQSTCLSLPKCWDY\
214 RRAAVPGLFILFFLRHRCPTLTQDEVQWCDHSSLQPSTPEIKHPPASASQVAGTKDMHHYTWLIFIFIFNFLRQSLNS\
215 VTQAGVQWRNLGSLQPLPPGFKLFSCPSLLSSWDYRRPPRLANFFVFLVEMGFTMFARLILISGPCDLPASASQSAGI\
216 TGVSHHARLIFNFCLFEMESHSVTQAGVQWPNLGSLQPLPPGLKRFSCLSLPSSWDYGHLPPHPANFCIFIRGGVSPY\
217 LSGWSQTPDLR\"\
218 },\
219 annot {\
220 {\
221 data ftable {\
222 {\
223 data prot { processed preprotein },\
224 location int { from 0, to 374, id gi 3002527 }\
225 },\
226 {\
227 data prot { processed mature },\
228 location int { from 0, to 374, id gi 3002527 }\
229 },\
230 {\
231 data prot { processed signal-peptide },\
232 location int { from 0, to 374, id gi 3002527 }\
233 },\
234 {\
235 data prot { processed transit-peptide },\
236 location int { from 0, to 374, id gi 3002527 }\
237 },\
238 {\
239 data prot {\
240 name {\
241 \"neuronal thread protein AD7c-NTP\"\
242 }\
243 },\
244 location int {\
245 from 0,\
246 to 374,\
247 strand plus,\
248 id gi 3002527\
249 }\
250 }\
251 }\
252 }\
253 }\
254 }\
255 },\
256 annot {\
257 {\
258 data ftable {\
259 {\
260 data cdregion {\
261 frame one,\
262 code {\
263 id 1\
264 }\
265 },\
266 product whole gi 3002527,\
267 location int {\
268 from 14,\
269 to 1141,\
270 strand plus,\
271 id gi 3002526\
272 }\
273 }\
274 }\
275 }\
276 }\
277 }";
278