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

Go to the SVN repository for this file.

1 /* $Id: unit_test_score_builder.cpp 102803 2024-07-18 17:09:15Z mozese2 $
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: Vyacheslav Chetvernin
27 *
28 * File Description:
29 * Score unit test.
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 
36 #include <corelib/ncbiapp.hpp>
37 #include <corelib/test_boost.hpp>
38 
39 #include <serial/serial.hpp>
40 #include <serial/objistr.hpp>
43 
57 
60 #include <objmgr/scope.hpp>
61 
62 #include <common/test_assert.h> /* This header must go last */
63 
66 
67 
68 
70 {
71  descrs->AddFlag("print_exp", "Print expected values instead of testing");
72 }
73 
74 
75 bool DumpExpected(void)
76 {
77  return CNcbiApplication::Instance()->GetArgs()["print_exp"];
78 }
79 
80 
82 {
83  static bool s_Initialized = false;
85  if ( !s_Initialized ) {
87  s_Initialized = true;
88  }
89  CRef<CScope> scope(new CScope(*objmgr));
90  scope->AddDefaults();
91  return scope;
92 }
93 
94 
95 // Helper function for loading alignments. Returns number of alignments loaded
96 // into the container. The expected format is:
97 // <int-number-of-alignments>
98 // <Seq-align>+
100  CAlnContainer& aligns,
101  size_t limit = 0)
102 {
103  size_t num_aligns = 0;
104  while ( !in.eof() ) {
105  try {
106  CRef<CSeq_align> align(new CSeq_align);
107  in >> MSerial_AsnText >> *align;
108  align->Validate(true);
109  aligns.insert(*align);
110  num_aligns++;
111  if (limit > 0 && num_aligns >= limit) break;
112  }
113  catch (CIOException&) {
114  break;
115  }
116  }
117  return num_aligns;
118 }
119 
120 
121 BOOST_AUTO_TEST_CASE(TestAltStartIdentity)
122 {
123  string buf = " \
124 Seq-align ::= { \
125  type disc, \
126  dim 2, \
127  segs spliced { \
128  product-id gi 487489526, \
129  genomic-id gi 556503834, \
130  genomic-strand minus, \
131  product-type protein, \
132  exons { \
133  { \
134  product-start protpos { \
135  amin 0, \
136  frame 1 \
137  }, \
138  product-end protpos { \
139  amin 259, \
140  frame 3 \
141  }, \
142  genomic-start 1642491, \
143  genomic-end 1643270, \
144  parts { \
145  diag 780 \
146  } \
147  } \
148  }, \
149  product-length 260 \
150  } \
151 } ";
152 
153  CNcbiIstrstream istrs(buf);
154  unique_ptr<CObjectIStream> istr(CObjectIStream::Open(eSerial_AsnText, istrs));
155  CSeq_align align;
156  *istr >> align;
157  BOOST_CHECK_NO_THROW(align.Validate(true));
158 
159  CRef<CScope> scope_ref = GetScope();
160  CScope& scope = *scope_ref;
161  CScoreBuilderBase score_builder;
162  int value;
163  score_builder.AddScore(scope, align, CSeq_align::eScore_IdentityCount);
165  BOOST_CHECK_EQUAL(value, 780);
166  score_builder.AddScore(scope, align, CSeq_align::eScore_MismatchCount);
168  BOOST_CHECK_EQUAL(value, 0);
169  score_builder.AddScore(scope, align, CSeq_align::eScore_PercentIdentity_Gapped);
170  int dbl_value;
171  BOOST_CHECK(align.GetNamedScore(CSeq_align::eScore_PercentIdentity_Gapped, dbl_value));
172  BOOST_CHECK_CLOSE(dbl_value, 100.0, DBL_EPSILON);
173 }
CSeq_align container.
const_iterator insert(const CSeq_align &seq_align)
Insert new CSeq_align into the list.
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:264
CScope –.
Definition: scope.hpp:92
void AddScore(CScope &scope, CSeq_align &align, CSeq_align::EScoreType score)
@ eScore_PercentIdentity_Gapped
Definition: Seq_align.hpp:163
@ eScore_IdentityCount
Definition: Seq_align.hpp:145
@ eScore_MismatchCount
Definition: Seq_align.hpp:154
bool GetNamedScore(const string &id, int &score) const
Get score.
Definition: Seq_align.cpp:563
void Validate(bool full_test=false) const
Definition: Seq_align.cpp:649
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:305
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
char * buf
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define DBL_EPSILON
size of the next series term that indicates convergence in the log and polygamma functions
Definition: ncbi_math.c:61
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
std::istream & in(std::istream &in_, double &x_)
static bool s_Initialized
The Object manager core.
Utility stuff for more convenient using of Boost.Test library.
USING_SCOPE(objects)
bool DumpExpected(void)
size_t LoadAligns(CNcbiIstream &in, CAlnContainer &aligns, size_t limit=0)
CRef< CScope > GetScope(void)
BOOST_AUTO_TEST_CASE(TestAltStartIdentity)
NCBITEST_INIT_CMDLINE(descrs)
Modified on Fri Sep 20 14:57:43 2024 by modify_doxy.py rev. 669887