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

Go to the SVN repository for this file.

1 /* $Id: unit_test_import_feattable.cpp 46089 2021-01-21 21:05:49Z 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: Andrea Asztalos
27 * File Description:
28 * Unit tests for importing feature tables
29 */
30 
31 #include <ncbi_pch.hpp>
32 
33 #include <objmgr/scope.hpp>
35 #include <objmgr/bioseq_ci.hpp>
36 #include <objmgr/util/sequence.hpp>
37 
38 // This header must be included before all Boost.Test headers if there are any
39 #include <corelib/test_boost.hpp>
42 
45 
47 {
48 }
49 
51 {
52 }
53 
54 CRef<CSeq_entry> ReadEntryFromFile(const string& fname)
55 {
56  CRef<CSeq_entry> entry(new CSeq_entry);
57 
58  try {
59  CNcbiIfstream istr(fname.c_str());
60  unique_ptr<CObjectIStream> os(CObjectIStream::Open(eSerial_AsnText, istr));
61  *os >> *entry;
62  }
63  catch (const CException& e) {
64  LOG_POST(Error << e.ReportAll());
65  return CRef<CSeq_entry>();
66  }
67  return entry;
68 }
69 
70 CRef<CSeq_annot> ReadAnnotFromFile(const string& fname)
71 {
72  CRef<CSeq_annot> annot(new CSeq_annot);
73  try {
74  CNcbiIfstream istr(fname.c_str());
75  unique_ptr<CObjectIStream> os(CObjectIStream::Open(eSerial_AsnText, istr));
76  *os >> *annot;
77  }
78  catch (const CException& e) {
79  LOG_POST(Error << e.ReportAll());
80  return CRef<CSeq_annot>();
81  }
82  return annot;
83 }
84 
85 template<class T>
86 string MakeAsn(const T& object)
87 {
89  str << MSerial_AsnText << object;
91 }
92 
93 
95 {
96  CImportFeatTable importer(seh);
98 
99  CSeq_id_Handle ftb_idh;
100  auto it = annot.GetData().GetFtable().front();
101  const CSeq_loc& loc = it->GetLocation();
102  ftb_idh = CSeq_id_Handle::GetHandle(*loc.GetId());
103 
104 
105  CBioseq_CI b_iter(seh, CSeq_inst::eMol_na);
107  seqid_map[ftb_idh] = seq_idh;
108  unsigned int startingLocusTagNumber = 1;
109  unsigned int startingFeatureId = 1;
110  string locus_tag;
111  bool euk = false;
112  CIRef<IEditCommand> cmd = importer.TestImport(annot, seqid_map, startingLocusTagNumber, startingFeatureId, locus_tag, euk);
113  if (cmd)
114  cmd->Execute();
115 }
116 
117 void ImportFeatTblTesting(const string& entry_file, const string& annot_file, const string& output_file)
118 {
119  CRef<CSeq_entry> entry = ReadEntryFromFile(entry_file);
121  scope->AddDefaults();
122 
123  CSeq_entry_Handle orig_seh = scope->AddTopLevelSeqEntry(*entry);
124  BOOST_REQUIRE(orig_seh);
125 
126  CRef<CSeq_annot> annot = ReadAnnotFromFile(annot_file);
127 
128  DoImportFTable(orig_seh, *annot);
129 
131  CConstRef<CSeq_entry> updated_entry = orig_seh.GetCompleteSeq_entry();
132  //cout << MSerial_AsnText << updated_entry.GetObject() << endl;
133  BOOST_CHECK_EQUAL(MakeAsn(*output), MakeAsn(*updated_entry));
134 }
135 
136 // Keep both the genbank accession number and the general tag of the protein ids
137 BOOST_AUTO_TEST_CASE(Test_GB_7376)
138 {
139  ImportFeatTblTesting("FeatTableData/gb_7376.asn", "FeatTableData/gb_7376_tbl.txt", "FeatTableData/gb_7376_imported.asn");
140 }
141 
142 //Keep general protein ids general, don't convert them into local ids
143 BOOST_AUTO_TEST_CASE(Test_GB_7453)
144 {
145  ImportFeatTblTesting("FeatTableData/gb_7453.asn", "FeatTableData/gb_7453_tbl.txt", "FeatTableData/gb_7453_imported.asn");
146 }
147 
148 // Use proper protein id for tRNA anticodon location
149 BOOST_AUTO_TEST_CASE(Test_GB_7668)
150 {
151  ImportFeatTblTesting("FeatTableData/gb_7376.asn", "FeatTableData/gb_7668_tbl.txt", "FeatTableData/gb_7668_imported.asn");
152 }
153 
154 // Remove orig_protein_id qualifiers
155 BOOST_AUTO_TEST_CASE(Test_GB_7030)
156 {
157  ImportFeatTblTesting("FeatTableData/gb_7030.asn", "FeatTableData/gb_7030_tbl.txt", "FeatTableData/gb_7030_imported.asn");
158 }
159 
160 BOOST_AUTO_TEST_CASE(Test_GB_8265)
161 {
162  ImportFeatTblTesting("FeatTableData/gb_8265.asn", "FeatTableData/gb_8265_tbl.txt", "FeatTableData/gb_8265_imported.asn");
163 }
164 
165 BOOST_AUTO_TEST_CASE(Test_GB_8871)
166 {
167  ImportFeatTblTesting("FeatTableData/gb_8871.asn", "FeatTableData/gb_8871_tbl.txt", "FeatTableData/gb_8871_imported.asn");
168 }
169 
170 BOOST_AUTO_TEST_CASE(Test_GB_8922)
171 {
172  ImportFeatTblTesting("FeatTableData/gb_8922.asn", "FeatTableData/gb_8922_tbl.txt", "FeatTableData/gb_8922_imported.asn");
173 }
174 
175 BOOST_AUTO_TEST_CASE(Test_GB_8265_withoutproteinid)
176 {
177  ImportFeatTblTesting("FeatTableData/gb_8265.asn", "FeatTableData/gb_8265_withoutproteinid_tbl.txt", "FeatTableData/gb_8265_withoutproteinid_imported.asn");
178 }
179 
180 BOOST_AUTO_TEST_CASE(Test_GB_8265_pseudocds)
181 {
182  ImportFeatTblTesting("FeatTableData/gb_8265.asn", "FeatTableData/gb_8265_pseudocds_tbl.txt", "FeatTableData/gb_8265_pseudocds_imported.asn");
183 }
184 
185 BOOST_AUTO_TEST_CASE(Test_GB_9054)
186 {
187  // if protein_ids are local ids, the import does not take place
188  ImportFeatTblTesting("FeatTableData/gb_8265.asn", "FeatTableData/gb_8265_withgbid_tbl.txt", "FeatTableData/gb_8265_withgbid_imported.asn");
189 }
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CIRef< IEditCommand > TestImport(const objects::CSeq_annot &orig_annot, TFeatSeqIDMap &ftbl_seqid_map, unsigned int &startingLocusTagNumber, unsigned int &startingFeatureId, const string &locus_tag, bool euk)
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CScope –.
Definition: scope.hpp:92
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define T(s)
Definition: common.h:230
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
Definition: ncbiexpt.cpp:370
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_Seq_id_BestRank
use CSeq_id::BestRank() as the scoring function
Definition: sequence.hpp:107
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CSeq_entry_Handle AddTopLevelSeqEntry(CSeq_entry &top_entry, TPriority pri=kPriority_Default, EExist action=eExist_Default)
Add seq_entry, default priority is higher than for defaults or loaders Add object to the score with p...
Definition: scope.cpp:522
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
const TFtable & GetFtable(void) const
Get the variant data.
Definition: Seq_annot_.hpp:621
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
The Object manager core.
static SQLCHAR output[256]
Definition: print.c:5
static const char * str(char *buf, int n)
Definition: stats.c:84
Utility stuff for more convenient using of Boost.Test library.
void DoImportFTable(CSeq_entry_Handle &seh, const CSeq_annot &annot)
CRef< CSeq_annot > ReadAnnotFromFile(const string &fname)
CRef< CSeq_entry > ReadEntryFromFile(const string &fname)
USING_SCOPE(objects)
string MakeAsn(const T &object)
BOOST_AUTO_TEST_CASE(Test_GB_7376)
void ImportFeatTblTesting(const string &entry_file, const string &annot_file, const string &output_file)
Modified on Thu Nov 30 04:55:48 2023 by modify_doxy.py rev. 669887