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

Go to the SVN repository for this file.

1 /* $Id: seq_c_compat_unit_test.cpp 91356 2020-10-16 15:25:33Z 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: Aaron Ucko, NCBI
27  *
28  * File Description:
29  * Unit test to confirm C-Toolkit-compatible formatting and parsing of
30  * Seq-locs and the like.
31  *
32  * ===========================================================================
33  */
34 
35 #include <ncbi_pch.hpp>
36 
38 #include <serial/objectinfo.hpp>
39 #include <serial/objistrasn.hpp>
41 
42 #include <sequtil.h>
43 
44 #include <corelib/test_boost.hpp>
45 #include <boost/test/parameterized_test.hpp>
46 #include <common/test_assert.h> /* This header must go last */
47 
50 
51 #if defined(NCBI_COMPILER_MSVC) && defined(NCBI_DLL_BUILD)
53 {
55 }
56 
58 {
59 }
60 #else
61 static AsnTypePtr s_SeqIdATP;
62 
64 {
65  CONNECT_Init();
66  SeqLocAsnLoad();
67  s_SeqIdATP = AsnFind(const_cast<char*>("Seq-id")); // avoid warnings
68 }
69 
70 static const char* const kRepresentativeIDs[] = {
71  "local id 123",
72  "local str \"foo|\"\"bar\"\"\"",
73  "gibbsq 123",
74  "gibbmt 123",
75  "giim { id 123, db \"foo\", release \"bar\" }",
76  // NB: release and version not used together below due to a minor
77  // discrepancy whose resolution remains to be determined.
78  "genbank { name \"AMU12345\", accession \"U12345\", release \"foo\" }",
79  "embl { name \"MTBH37RV\", accession \"AL123456\", version 2 }",
80  "pir { name \"S16356\" }",
81  "swissprot { name \"RS22_SALTY\", accession \"Q7CQJ0\","
82  " release \"reviewed\" }",
83  "swissprot { name \"Q9ORT2_9HIV1\", accession \"Q90RT2\","
84  " release \"unreviewed\" }",
85  "swissprot { accession \"Q7CQJ0\", release \"reviewed\", version 1 }",
86  "patent { seqid 1, cit { country \"US\", id number \"RE33188\" } }",
87  // "patent { seqid 7, cit { country \"EP\", id app-number \"0238993\" } }",
88  "other { accession \"NM_000170\", version 1 }",
89  "general { db \"EcoSeq\", tag str \"EcoAce\" }",
90  "general { db \"taxon\", tag id 9606 }",
91  "general { db \"dbSNP\", tag str \"rs31251_allelePos=201totallen=401"
92  "|taxid=9606|snpClass=1|alleles=?|mol=?|build=?\" }",
93  "gi 1234",
94  "ddbj { accession \"N00068\" }",
95  "prf { accession \"0806162C\" }",
96  "pdb { mol \"1GAV\" }",
97  "pdb { mol \"1GAV\", chain 0 }",
98  "pdb { mol \"1GAV\", chain 33 }", // !
99  "pdb { mol \"1GAV\", chain 88 }", // X
100  // "pdb { mol \"1GAV\", chain 120 }", // x
101  // "pdb { mol \"1GAV\", chain 124 }", // |
102  "tpg { accession \"BK003456\" }",
103  "tpe { accession \"BN000123\" }",
104  "tpd { accession \"FAA00017\" }",
105  "gpipe { accession \"GPC_123456789\", version 1 }",
106  "named-annot-track { accession \"AT_123456789\", version 1 }"
107 };
108 static const size_t kNumRepresentativeIDs
109 = sizeof(kRepresentativeIDs)/sizeof(*kRepresentativeIDs);
110 
112 {
113  static void Delete(SeqIdPtr sip) { SeqIdFree(sip); }
114 };
116 
118  eFastaShort = PRINTID_FASTA_SHORT,
119  eTextAccVer = PRINTID_TEXTID_ACC_VER,
120  eTextAccOnly = PRINTID_TEXTID_ACC_ONLY,
121  eReport = PRINTID_REPORT
122 };
123 
124 static string s_IdLabel(const TAutoSeqId& c_id, EIDLabelType type)
125 {
126  CharPtr c_label = SeqIdWholeLabel(c_id.get(), type);
128  Nlm_MemFree(c_label);
129  return result;
130 }
131 
132 static string s_IdLabel(const CSeq_id& cxx_id, EIDLabelType type)
133 {
134  string label;
138 
139  switch (type) {
140  case eFastaShort: gl_type = CSeq_id::eFasta; break;
141  case eTextAccOnly: flags &= ~CSeq_id::fLabel_Version; break;
142  case eReport: flags &= ~CSeq_id::fLabel_GeneralDbIsContent; break;
143  default: break;
144  }
145  cxx_id.GetLabel(&label, gl_type, flags);
147  return label;
148 }
149 
150 static void s_TestIdFormatting(const char* s)
151 {
152  size_t len = strlen(s);
153  CObjectIStreamAsn ois(s, len);
154  CSeq_id cxx_id;
155  AsnIoMemPtr aimp = AsnIoMemOpen
156  (const_cast<char*>("r"),
157  reinterpret_cast<BytePtr>(const_cast<char*>(s)), len);
158  AsnIoPtr aip = AsnIoNew((ASNIO_IN | ASNIO_TEXT), NULL, aimp,
159  AsnIoMemRead, AsnIoMemWrite);
160  TAutoSeqId c_id;
161 
162  ois.Read(&cxx_id, CSeq_id::GetTypeInfo(), CObjectIStream::eNoFileHeader);
163  aip->read_id = TRUE;
164  c_id = SeqIdAsnRead(aip, s_SeqIdATP);
165 
166  BOOST_CHECK_EQUAL(s_IdLabel(c_id, eFastaShort),
167  s_IdLabel(cxx_id, eFastaShort));
168  BOOST_CHECK_EQUAL(s_IdLabel(c_id, eTextAccVer),
169  s_IdLabel(cxx_id, eTextAccVer));
170  BOOST_CHECK_EQUAL(s_IdLabel(c_id, eTextAccOnly),
171  s_IdLabel(cxx_id, eTextAccOnly));
172  BOOST_CHECK_EQUAL(s_IdLabel(c_id, eReport), s_IdLabel(cxx_id, eReport));
173 
174  AsnIoClose(aip);
175  AsnIoMemClose(aimp);
176 }
177 
180 #endif
AutoPtr –.
Definition: ncbimisc.hpp:401
CObjectIStreamAsn –.
Definition: objistrasn.hpp:54
static uch flags
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:469
#define NULL
Definition: ncbistd.hpp:225
#define BytePtr
Definition: ncbistd.hpp:143
#define CharPtr
Definition: ncbistd.hpp:125
NLM_EXTERN void *LIBCALL Nlm_MemFree(void *ptr)
Definition: ct_ncbimem.cpp:298
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2040
int TLabelFlags
Definition: Seq_id.hpp:625
ELabelType
return the label for a given string
Definition: Seq_id.hpp:603
@ fLabel_Version
Show the version.
Definition: Seq_id.hpp:615
@ fLabel_GeneralDbIsContent
For type general, use the database name as the tag and the (text or numeric) key as the content.
Definition: Seq_id.hpp:618
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:605
@ eFasta
Tagged ID in NCBI's traditional FASTA style.
Definition: Seq_id.hpp:607
void Read(const CObjectInfo &object)
Read object of know type.
Definition: objistr.cpp:952
static CTempString TruncateSpaces_Unsafe(const CTempString str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
Definition: ncbistr.cpp:3191
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
@ eTrunc_End
Truncate trailing spaces only.
Definition: ncbistr.hpp:2241
void NcbiTestSetGlobalDisabled(void)
Disable execution of all tests in current configuration.
void CONNECT_Init(const IRWRegistry *reg=0, CRWLock *lock=0, TConnectInitFlags flag=eConnectInit_OwnNothing, FSSLSetup ssl=0)
Init [X]CONNECT library with the specified "reg" and "lock" (ownership for either or both can be deta...
static const char label[]
int len
#define TRUE
bool replacment for C indicating true.
Definition: ncbi_std.h:97
static const size_t kNumRepresentativeIDs
USING_SCOPE(objects)
static AsnTypePtr s_SeqIdATP
BOOST_AUTO_PARAM_TEST_CASE(s_TestIdFormatting, kRepresentativeIDs+0, kRepresentativeIDs+kNumRepresentativeIDs)
static string s_IdLabel(const TAutoSeqId &c_id, EIDLabelType type)
AutoPtr< SeqId, SSeqIdDeleter > TAutoSeqId
NCBITEST_AUTO_INIT()
static void s_TestIdFormatting(const char *s)
static const char *const kRepresentativeIDs[]
static void Delete(SeqIdPtr sip)
Definition: type.c:6
Utility stuff for more convenient using of Boost.Test library.
else result
Definition: token2.c:20
BOOST_AUTO_TEST_CASE(TestUsingArg)
Modified on Mon Jun 17 05:09:37 2024 by modify_doxy.py rev. 669887