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

Go to the SVN repository for this file.

1 /* $Id: setupfactory_unit_test.cpp 91988 2020-12-17 15:27:07Z 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: Tom Madden
27 *
28 * File Description:
29 * Unit test module to test utilities in setupfactory.c
30 *
31 * ===========================================================================
32 */
33 #include <ncbi_pch.hpp>
34 #include <corelib/test_boost.hpp>
41 
42 #include "blast_memento_priv.hpp"
43 
44 #include "test_objmgr.hpp"
45 
47 USING_SCOPE(blast);
49 
50 
51 BOOST_AUTO_TEST_SUITE(setup_factory)
52 
53 BOOST_AUTO_TEST_CASE(CreateScoreBlockBadReward)
54 {
55 
56  CRef<CSeq_id> qid(new CSeq_id("gi|555"));
57 
60 
62  query.AddQuery(Q1);
64 
65  CBlastNucleotideOptionsHandle options_handle;
66  options_handle.SetMatchReward(1);
67  options_handle.SetMismatchPenalty(-1);
68  CBlastOptions& opts = options_handle.SetOptions();
69 
70  CRef<ILocalQueryData> query_data(qf->MakeLocalQueryData(&opts));
71 
72  unique_ptr<const CBlastOptionsMemento> opts_memento (opts.CreateSnapshot());
73 
74  BlastSeqLoc* blast_seq_loc = NULL;
75  TSearchMessages search_messages;
76 
77  BOOST_CHECK_THROW(CSetupFactory::CreateScoreBlock(opts_memento.get(), query_data, &blast_seq_loc, search_messages),
79 }
80 
81 
82 BOOST_AUTO_TEST_CASE(CreateScoreBlockMaskedSequence)
83 {
84  // This sequence is mostly XXXXXXXXXXXXX
85  CRef<CSeq_id> qid(new CSeq_id("gi|53690285"));
86  TSeqRange range(60, 120);
87 
88  unique_ptr<SSeqLoc> ssloc(
89  CTestObjMgr::Instance().CreateSSeqLoc(*qid, range, eNa_strand_unknown));
90 
91  TSeqLocVector tslv;
92  tslv.push_back(*ssloc.get());
93 
95 
96  CBlastProteinOptionsHandle options_handle;
97  CBlastOptions& opts = options_handle.SetOptions();
98 
99  CRef<ILocalQueryData> query_data(qf->MakeLocalQueryData(&opts));
100 
101  unique_ptr<const CBlastOptionsMemento> opts_memento (opts.CreateSnapshot());
102 
103  BlastSeqLoc* blast_seq_loc = NULL;
104  TSearchMessages search_messages;
105 
106  BlastScoreBlk* sbp = CSetupFactory::CreateScoreBlock(opts_memento.get(), query_data, &blast_seq_loc, search_messages);
107 
108  BOOST_REQUIRE(search_messages.ToString().find(kBlastErrMsg_CantCalculateUngappedKAParams) != string::npos);
109  BOOST_REQUIRE(blast_seq_loc != NULL);
110  BOOST_REQUIRE(sbp != NULL);
111 
112  sbp = BlastScoreBlkFree(sbp);
113  BOOST_REQUIRE(sbp == NULL);
114  blast_seq_loc = BlastSeqLocFree(blast_seq_loc);
115  BOOST_REQUIRE(blast_seq_loc == NULL);
116 }
117 
118 BOOST_AUTO_TEST_CASE(CreateScoreBlockOK)
119 {
120  CRef<CSeq_id> qid(new CSeq_id("gi|129295"));
121 
122  unique_ptr<SSeqLoc> ssloc(
123  CTestObjMgr::Instance().CreateSSeqLoc(*qid, eNa_strand_unknown));
124 
125  TSeqLocVector tslv;
126  tslv.push_back(*ssloc.get());
127 
129 
130  CBlastProteinOptionsHandle options_handle;
131  CBlastOptions& opts = options_handle.SetOptions();
132 
133  CRef<ILocalQueryData> query_data(qf->MakeLocalQueryData(&opts));
134 
135  unique_ptr<const CBlastOptionsMemento> opts_memento (opts.CreateSnapshot());
136 
137  BlastSeqLoc* blast_seq_loc = NULL;
138  TSearchMessages search_messages;
139 
140  BlastScoreBlk* sbp = CSetupFactory::CreateScoreBlock(opts_memento.get(), query_data, &blast_seq_loc, search_messages);
141 
142  BOOST_REQUIRE(search_messages.HasMessages() == false);
143  BOOST_REQUIRE(blast_seq_loc != NULL);
144  BOOST_REQUIRE(sbp != NULL);
145 
146  sbp = BlastScoreBlkFree(sbp);
147  BOOST_REQUIRE(sbp == NULL);
148  blast_seq_loc = BlastSeqLocFree(blast_seq_loc);
149  BOOST_REQUIRE(blast_seq_loc == NULL);
150 }
151 
152 
BlastSeqLoc * BlastSeqLocFree(BlastSeqLoc *loc)
Deallocate all BlastSeqLoc objects in a chain.
Definition: blast_filter.c:737
Classes that capture the state of the BLAST options (or subsets of options) and restore them later (u...
const char * kBlastErrMsg_CantCalculateUngappedKAParams
Definition: blast_message.c:38
Declares the CBlastNucleotideOptionsHandle class.
Declares the CBlastProteinOptionsHandle class.
BlastScoreBlk * BlastScoreBlkFree(BlastScoreBlk *sbp)
Deallocates BlastScoreBlk as well as all associated structures.
Definition: blast_stat.c:965
BOOST_AUTO_TEST_SUITE_END() static int s_GetSegmentFlags(const CBioseq &bioseq)
Defines BLAST error codes (user errors included)
Handle to the nucleotide-nucleotide options to the BLAST algorithm.
Encapsulates ALL the BLAST algorithm's options.
Handle to the protein-protein options to the BLAST algorithm.
Query Vector.
Definition: sseqloc.hpp:276
NCBI C++ Object Manager dependant implementation of IQueryFactory.
CRef< blast::CBlastSearchQuery > CreateBlastSearchQuery(objects::CSeq_id &id, objects::ENa_strand s=objects::eNa_strand_unknown)
static CTestObjMgr & Instance()
Definition: test_objmgr.cpp:69
typedef for the messages for an entire BLAST search, which could be comprised of multiple query seque...
bool HasMessages() const
Definition: blast_aux.cpp:1002
const CBlastOptionsMemento * CreateSnapshot() const
Create a snapshot of the state of this object for internal use of its data structures (BLAST C++ APIs...
void SetMatchReward(int r)
Sets MatchReward.
CRef< ILocalQueryData > MakeLocalQueryData(const CBlastOptions *opts)
Creates and caches an ILocalQueryData.
Definition: query_data.cpp:52
CBlastOptions & SetOptions()
Returns a reference to the internal options class which this object is a handle for.
void SetMismatchPenalty(int p)
Sets MismatchPenalty.
static BlastScoreBlk * CreateScoreBlock(const CBlastOptionsMemento *opts_memento, CRef< ILocalQueryData > query_data, BlastSeqLoc **lookup_segments, TSearchMessages &search_messages, TSeqLocInfoVector *masked_query_regions=NULL, const CBlastRPSInfo *rps_info=NULL)
Initializes the BlastScoreBlk.
string ToString() const
Converts messages to a string, which is returned.
Definition: blast_aux.cpp:1013
#define NULL
Definition: ncbistd.hpp:225
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
range(_Ty, _Ty) -> range< _Ty >
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
BOOST_AUTO_TEST_SUITE(psiblast_iteration)
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
USING_SCOPE(blast)
BOOST_AUTO_TEST_CASE(CreateScoreBlockBadReward)
Definition of SSeqLoc structure.
vector< SSeqLoc > TSeqLocVector
Vector of sequence locations.
Definition: sseqloc.hpp:129
Structure used for scoring calculations.
Definition: blast_stat.h:177
Used to hold a set of positions, mostly used for filtering.
Definition: blast_def.h:204
static string query
Utility stuff for more convenient using of Boost.Test library.
Modified on Fri Sep 20 14:57:02 2024 by modify_doxy.py rev. 669887