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

Go to the SVN repository for this file.

1 /* $Id: unit_test_entrezgene.cpp 100826 2023-09-15 16:42:12Z wallinc $
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: Craig Wallin, NCBI
27  *
28  * File Description:
29  *
30  * Unit test for CEntrezgene
31  *
32  * ===========================================================================
33  */
34 
35 #include <ncbi_pch.hpp>
36 
37 #include <corelib/ncbiapp.hpp>
38 #include <corelib/test_boost.hpp>
39 
46 
48 
51 
52 // Read a public Entrezgene record.
53 
54 static void s_GetObject(const string& gene_id, CEntrezgene& eg_obj)
55 {
56  LOG_POST(Note << "Looking up GeneID " << gene_id);
58  CEFetch_Request req(ctx);
59  req.SetDatabase("gene");
60  req.GetId().AddId(gene_id);
61  string eg_str;
62  // A very limited and simple retry.
63  try {
64  SleepMilliSec(333); // per e-utils guidelines
65  req.Read(&eg_str);
66  CNcbiIstrstream istr(eg_str);
67  istr >> MSerial_AsnText >> eg_obj;
68  } catch(...) {
69  // simple retry, only retry once
70  SleepMilliSec(30000); // maybe enough time, maybe not
71  req.Read(&eg_str);
72  CNcbiIstrstream istr(eg_str);
73  istr >> MSerial_AsnText >> eg_obj;
74  }
75 }
76 
77 BOOST_AUTO_TEST_CASE(s_TestDescription)
78 {
79  CEntrezgene eg_obj;
80 
81  // Data comes from gene desc
82  s_GetObject("2778", eg_obj);
83  BOOST_CHECK_EQUAL(eg_obj.GetDescription(), "GNAS complex locus");
84 
85  // Data comes from prot desc
86  s_GetObject("4514", eg_obj);
87  BOOST_CHECK_EQUAL(eg_obj.GetDescription(), "cytochrome c oxidase subunit III");
88 
89  // Data comes from prot name
90  s_GetObject("4508", eg_obj);
91  BOOST_CHECK_EQUAL(eg_obj.GetDescription(), "ATP synthase F0 subunit 6");
92 
93  // Data comes from rna ext name
94  s_GetObject("4549", eg_obj);
95  BOOST_CHECK_EQUAL(eg_obj.GetDescription(), "s-rRNA");
96 
97  // Data comes from gene type
98  s_GetObject("4511", eg_obj);
99  BOOST_CHECK_EQUAL(eg_obj.GetDescription(), "tRNA-Cys");
100 }
101 
102 BOOST_AUTO_TEST_CASE(s_TestNomenclature)
103 {
104  CEntrezgene eg_obj;
106 
107  // Data comes from formal-name element.
108  s_GetObject("4535", eg_obj);
109  BOOST_CHECK_EQUAL(eg_obj.GetGene().IsSetFormal_name(), true);
110  nomen = eg_obj.GetNomenclature();
111  BOOST_CHECK_EQUAL(nomen->GetStatus(), CGene_nomenclature::eStatus_official);
112  BOOST_CHECK_EQUAL(nomen->GetSymbol(), "MT-ND1");
113  BOOST_CHECK_EQUAL(nomen->GetName(), "mitochondrially encoded NADH dehydrogenase 1");
114  BOOST_CHECK_EQUAL(nomen->GetSource().GetDb(), "HGNC");
115  BOOST_CHECK_EQUAL(nomen->GetSource().GetTag().GetStr(), "HGNC:7455");
116 
117  // Interim symbol and name, from general comment elements.
118  s_GetObject("121110513", eg_obj);
119  BOOST_CHECK_EQUAL(eg_obj.GetGene().IsSetFormal_name(), false);
120  nomen = eg_obj.GetNomenclature();
121  BOOST_CHECK_EQUAL(nomen->GetStatus(), CGene_nomenclature::eStatus_interim);
122  BOOST_CHECK_EQUAL(nomen->GetSymbol(), "TRNASTOP-UCA");
123  BOOST_CHECK_EQUAL(nomen->GetName(), "transfer RNA opal suppressor (anticodon UCA)");
124  // TODO: check source field when it becomes available
125 
126  // Official symbol and name, from general comment elements.
127  s_GetObject("1", eg_obj);
128  BOOST_CHECK_EQUAL(eg_obj.GetGene().IsSetFormal_name(), false);
129  nomen = eg_obj.GetNomenclature();
130  BOOST_CHECK_EQUAL(nomen->GetStatus(), CGene_nomenclature::eStatus_official);
131  BOOST_CHECK_EQUAL(nomen->GetSymbol(), "A1BG");
132  BOOST_CHECK_EQUAL(nomen->GetName(), "alpha-1-B glycoprotein");
133  // TODO: check source field when it becomes available
134 
135  // None available in the data.
136  s_GetObject("107547967", eg_obj);
137  BOOST_CHECK_EQUAL(eg_obj.GetGene().IsSetFormal_name(), false);
138  nomen = eg_obj.GetNomenclature();
139  BOOST_CHECK_EQUAL(nomen->GetStatus(), CGene_nomenclature::eStatus_unknown);
140 }
141 
142 BOOST_AUTO_TEST_CASE(s_TestFindComment)
143 {
144  CEntrezgene eg_obj;
145  CRef<CGene_commentary> comment;
146 
147  s_GetObject("1", eg_obj);
148  // Comment not found.
149  comment = eg_obj.FindComment("Nonesuch");
150  BOOST_CHECK_EQUAL(true, comment.Empty());
151  // Comment found.
152  comment = eg_obj.FindComment("RefSeq Status");
153  BOOST_CHECK_EQUAL(true, comment.NotEmpty());
154  if (comment) {
155  BOOST_CHECK_EQUAL(true, comment->IsSetLabel());
156  if (comment->IsSetLabel()) {
157  BOOST_CHECK_EQUAL("REVIEWED", comment->GetLabel());
158  }
159  }
160 }
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CEFetch_Request.
Definition: efetch.hpp:59
CEUtils_ConnContext.
Definition: eutils.hpp:65
string GetDescription() const
Definition: Entrezgene.cpp:173
CRef< CGene_commentary > FindComment(const string &heading) const
Definition: Entrezgene.cpp:212
CRef< CGene_nomenclature > GetNomenclature() const
Definition: Entrezgene.cpp:65
CS_CONTEXT * ctx
Definition: t0006.c:12
#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 SetDatabase(const string &database)
Setting new database disconnects the request.
Definition: eutils.cpp:281
void AddId(const string &id)
Add a single id to the list.
Definition: eutils.hpp:235
const CEUtils_IdGroup & GetId(void) const
Group of ids to retrieve.
Definition: efetch.hpp:68
void Read(string *content)
Read the whole stream into the string.
Definition: eutils.cpp:274
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty – pointing to an object and has a non-null value.
Definition: ncbiobj.hpp:726
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
const TGene & GetGene(void) const
Get the Gene member data.
bool IsSetFormal_name(void) const
Check if a value has been assigned to Formal_name data member.
Definition: Gene_ref_.hpp:828
const TSource & GetSource(void) const
Get the Source member data.
const TSymbol & GetSymbol(void) const
Get the Symbol member data.
TStatus GetStatus(void) const
Get the Status member data.
const TName & GetName(void) const
Get the Name member data.
const TTag & GetTag(void) const
Get the Tag member data.
Definition: Dbtag_.hpp:267
const TDb & GetDb(void) const
Get the Db member data.
Definition: Dbtag_.hpp:220
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
where both of them are integers Note
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Utility stuff for more convenient using of Boost.Test library.
USING_SCOPE(objects)
static void s_GetObject(const string &gene_id, CEntrezgene &eg_obj)
BOOST_AUTO_TEST_CASE(s_TestDescription)
Modified on Sat Dec 02 09:20:02 2023 by modify_doxy.py rev. 669887