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

Go to the SVN repository for this file.

1 /* $Id: showdefline_unit_test.cpp 99204 2023-02-27 15:02:25Z fongah2 $
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: Jian Ye
27 *
28 * File Description:
29 * Unit test module to test CShowBlastDefline
30 *
31 * ===========================================================================
32 */
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbiexpt.hpp>
35 #include <corelib/ncbiutil.hpp>
36 #include <corelib/ncbistre.hpp>
37 
38 #include <objmgr/util/sequence.hpp>
39 #include <objmgr/bioseq_handle.hpp>
42 
45 
46 #include "blast_test_util.hpp"
47 #define NCBI_BOOST_NO_AUTO_TEST_MAIN
48 #include <corelib/test_boost.hpp>
49 
50 using namespace std;
51 using namespace ncbi;
52 using namespace ncbi::objects;
53 using namespace ncbi::align_format;
54 using namespace TestUtil;
55 
56 BOOST_AUTO_TEST_SUITE(showdefline)
57 
59 
61  CScope& scope,
62  size_t line_length = 65,
63  size_t deflines_to_show = align_format::kDfltArgNumDescriptions,
64  bool translated_nuc_alignment = false,
65  CRange<TSeqPos>* master_range = NULL)
66  : CShowBlastDefline(seqalign, scope, line_length,
67  deflines_to_show, translated_nuc_alignment,
68  master_range)
69  {}
70 
72  {
73  CNcbiIfstream is("data/showdefline-cppunit.aln");
74  unique_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, is));
76  *in >> *san;
77 
78  const CSeq_annot::TData& data = san->GetData();
79  const CSeq_annot::TData::TAlign& align= data.GetAlign();
80 
82  seqalign->Set() = align;
83 
84  const string kDbName("nr");
86 
87  TestUtil::CBlastOM tmp_data_loader(kDbName, kDbType, location);
88 
89  CRef<CScope> scope = tmp_data_loader.NewScope();
90 
91  CShowBlastDeflineTest sbd(*seqalign, *scope);
92  int options = 0;
93  options += CShowBlastDefline::eHtml|
95  sbd.SetOption(options);
96 
97  int i = 0;
98  ITERATE(CSeq_align_set::Tdata, iter, seqalign->Get()){
99  unique_ptr<CShowBlastDefline::SScoreInfo>
100  si(sbd.x_GetScoreInfo(**iter, 1));
101  unique_ptr<CShowBlastDefline::SDeflineInfo>
102  dl(sbd.x_GetDeflineInfo(si->id, si->use_this_seqid, 1));
103  CShowBlastDeflineTest::TestData(dl.get(), si.get(), i);
104  i++;
105  if (i > 1) {
106  break;
107  }
108  }
110  }
111 
114  int index)
115  {
116  string defline[] = {"adenosine deaminase [Rattus norvegicus]",
117  "adenosine deaminase isoform 1 [Mus musculus]"};
118  string evalue_string[] = {"0.0", "0.0"};
119  string bit_string[] = {"734", "677"};
120  int sum_n[] = {1, 1};
121 
122  string id_url[] = {"<a title=\"Show report for NP_569083.1\" href=\"https://www.ncbi.nlm.nih.gov/nucleotide/NP_569083.1?report=genbank&log$=nucltop&blast_rank=1&RID=\" >",
123  "<a title=\"Show report for NP_001258981.1\" href=\"https://www.ncbi.nlm.nih.gov/nucleotide/NP_001258981.1?report=genbank&log$=nucltop&blast_rank=1&RID=\" >" };
124  string score_url[] = {"<a href=#NP_569083.1>", "<a href=#NP_001258981.1>"};
125  bool is_new[] = {false, false};
126  bool was_checked[] = {false, false};
127  BOOST_REQUIRE(dl->defline.find(defline[index])!= NPOS);
128  BOOST_REQUIRE_EQUAL(dl->id_url, id_url[index]);
129  BOOST_REQUIRE_EQUAL(dl->score_url, score_url[index]);
130  BOOST_REQUIRE_EQUAL(dl->is_new, is_new[index]);
131  BOOST_REQUIRE_EQUAL(dl->was_checked, was_checked[index]);
132 
133  BOOST_REQUIRE_EQUAL(si->evalue_string, evalue_string[index]);
134  BOOST_REQUIRE_EQUAL(si->bit_string, bit_string[index]);
135  BOOST_REQUIRE_EQUAL(si->sum_n, sum_n[index]);
136  }
137 };
138 
139 BOOST_AUTO_TEST_CASE(LocalDeflineInfo)
140 {
141  CShowBlastDeflineTest::GetDeflineInfo(CBlastOM::eLocal);
142 }
143 
144 BOOST_AUTO_TEST_CASE(RemoteDeflineInfo)
145 {
146  CShowBlastDeflineTest::GetDeflineInfo(CBlastOM::eRemote);
147 }
Declares class to display one-line descriptions at the top of the BLAST report.
BOOST_AUTO_TEST_SUITE_END() static int s_GetSegmentFlags(const CBioseq &bioseq)
EDbType
Describes the type of blast database to use.
Definition: bdbloader.hpp:57
@ eProtein
protein database
Definition: bdbloader.hpp:59
CScope –.
Definition: scope.hpp:92
This class displays the defline for BLAST result.
Definition: showdefline.hpp:67
SScoreInfo * x_GetScoreInfo(const objects::CSeq_align &aln, int blast_rank)
Internal function to return score info.
SDeflineInfo * x_GetDeflineInfo(CConstRef< objects::CSeq_id > id, list< string > &use_this_seqid, int blast_rank)
Internal function to return defline info.
void SetOption(int option)
options per DisplayOption
Class which registers the BLAST database and Genbank data loaders as a non-default data loaders with ...
ncbi::CRef< ncbi::objects::CScope > NewScope()
Create a new scope with the default set to the BLAST database data loader for the BLAST database spec...
static const char si[8][64]
Definition: des.c:146
Blast defline related defines.
const size_t kDfltArgNumDescriptions
Default number of one-line descriptions to display in the traditional BLAST report.
static const char location[]
Definition: config.c:97
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
@ 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
void RevokeAllDataLoaders(void)
Revoke all registered data loaders, even if they were still used.
CObjectManager & GetObjectManager(void)
Get object manager controlling this scope.
Definition: scope.cpp:89
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
#define NPOS
Definition: ncbistr.hpp:133
Tdata & Set(void)
Assign a value to data member.
list< CRef< CSeq_align > > Tdata
const Tdata & Get(void) const
Get the member data.
list< CRef< CSeq_align > > TAlign
Definition: Seq_annot_.hpp:194
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
int i
Magic spell ;-) needed for some weird compilers... very empiric.
Defines NCBI C++ exception handling.
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
Useful/utility classes and methods.
std::istream & in(std::istream &in_, double &x_)
Utilities to develop and debug unit tests for BLAST.
BOOST_AUTO_TEST_SUITE(psiblast_iteration)
BOOST_AUTO_TEST_CASE(LocalDeflineInfo)
static void GetDeflineInfo(CBlastOM::ELocation location)
static void TestData(CShowBlastDefline::SDeflineInfo *dl, CShowBlastDefline::SScoreInfo *si, int index)
CShowBlastDeflineTest(const CSeq_align_set &seqalign, CScope &scope, size_t line_length=65, size_t deflines_to_show=align_format::kDfltArgNumDescriptions, bool translated_nuc_alignment=false, CRange< TSeqPos > *master_range=NULL)
Data Representing each defline.
Utility stuff for more convenient using of Boost.Test library.
Modified on Fri Sep 20 14:57:10 2024 by modify_doxy.py rev. 669887