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

Go to the SVN repository for this file.

1 /* $Id: blastdiag_unit_test.cpp 100942 2023-10-03 17:36:50Z 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: Tom Madden
27 *
28 * File Description:
29 * Unit test for BLAST_DiagTable
30 *
31 * ===========================================================================
32 */
33 #include <ncbi_pch.hpp>
34 #include <corelib/test_boost.hpp>
35 
37 
39 
40 
41 using namespace ncbi;
42 
43 BOOST_AUTO_TEST_SUITE(BlastDiag)
44 
45 BOOST_AUTO_TEST_CASE(testDiagClear) {
46  const Uint4 kQlen=100;
47  const Int4 kWindowSize=20;
48  const Uint4 kFakeReset = 1; // arbitrary non-zero number to init reset
49  const Int4 kFakeLastHit = 40; // arbitrary non-zero number to init last_hit
50  const int kFakeSequenceLength = 100; // arbitrary sequence length
51  BlastInitialWordOptions word_options;
52  BlastInitialWordParameters word_params;
53  Blast_ExtendWord *ewp;
54 
55  word_options.window_size = kWindowSize;
56  word_params.options = &word_options;
57  word_params.container_type = eDiagArray;
58  BOOST_REQUIRE_EQUAL(0, (Int4)BlastExtendWordNew(kQlen, &word_params, &ewp));
59  BLAST_DiagTable* diag_table = ewp->diag_table;
60 
61  for (int i = 0; i < diag_table->diag_array_length; i++)
62  {
63  (diag_table->hit_level_array)[i].flag = kFakeReset;
64  (diag_table->hit_level_array)[i].last_hit = kFakeLastHit;
65  }
66  diag_table->offset = INT4_MAX/4; // a large fake number, should be reset to kWindowSize.
67 
68  Blast_ExtendWordExit(ewp, kFakeSequenceLength);
69 
70  BOOST_REQUIRE_EQUAL(kWindowSize, diag_table->offset);
71  for (int i = 0; i < diag_table->diag_array_length; i++)
72  {
73  BOOST_REQUIRE_EQUAL((Uint4)0, (diag_table->hit_level_array)[i].flag);
74  BOOST_REQUIRE_EQUAL(-kWindowSize, (diag_table->hit_level_array)[i].last_hit);
75  }
76 
77  ewp = BlastExtendWordFree(ewp);
78  BOOST_REQUIRE(ewp == NULL);
79  }
80 
81 // This test is for a full diag that does get reset.
82 BOOST_AUTO_TEST_CASE(testDiagUpdateFull) {
83  const Uint4 kQlen=100;
84  const Int4 kWindowSize=20;
85  const Uint4 kFakeReset = 1; // arbitrary non-zero number to init reset
86  const Int4 kFakeLastHit = 40; // arbitrary non-zero number to init last_hit
87  const int kFakeSequenceLength = 100; // arbitrary sequence length
88  BlastInitialWordOptions word_options;
89  BlastInitialWordParameters word_params;
90  Blast_ExtendWord *ewp;
91 
92  word_options.window_size = kWindowSize;
93  word_params.options = &word_options;
94  word_params.container_type = eDiagArray;
95  BOOST_REQUIRE_EQUAL(0, (Int4)BlastExtendWordNew(kQlen, &word_params, &ewp));
96  BLAST_DiagTable* diag_table = ewp->diag_table;
97 
98  for (int i = 0; i < diag_table->diag_array_length; i++)
99  {
100  (diag_table->hit_level_array)[i].flag = kFakeReset;
101  (diag_table->hit_level_array)[i].last_hit = kFakeLastHit;
102  }
103  diag_table->offset = INT4_MAX/4 + 1000; // a large fake number, should be reset to kWindowSize.
104 
105  Blast_ExtendWordExit(ewp, kFakeSequenceLength);
106 
107  BOOST_REQUIRE_EQUAL(kWindowSize, diag_table->offset);
108  for (int i = 0; i < diag_table->diag_array_length; i++)
109  {
110  BOOST_REQUIRE_EQUAL((Uint4)0, (diag_table->hit_level_array)[i].flag);
111  BOOST_REQUIRE_EQUAL(-kWindowSize, (diag_table->hit_level_array)[i].last_hit);
112  }
113 
114  ewp = BlastExtendWordFree(ewp);
115  BOOST_REQUIRE(ewp == NULL);
116  }
117 
118 // This test is for a not full diag that does not get reset.
119 BOOST_AUTO_TEST_CASE(testDiagUpdateNotFull) {
120  const Uint4 kQlen=100;
121  const Int4 kWindowSize=20;
122  const Uint4 kFakeReset = 1; // arbitrary non-zero number to init reset
123  const Int4 kFakeLastHit = 40; // arbitrary non-zero number to init last_hit
124  const int kFakeSequenceLength = 100; // arbitrary sequence length
125  const int kFakeOffset = 100; // arbitrary small number for test.
126  BlastInitialWordOptions word_options;
127  BlastInitialWordParameters word_params;
128  Blast_ExtendWord *ewp;
129 
130  word_options.window_size = kWindowSize;
131  word_params.options = &word_options;
132  word_params.container_type = eDiagArray;
133  BOOST_REQUIRE_EQUAL(0, (Int4)BlastExtendWordNew(kQlen, &word_params, &ewp));
134  BLAST_DiagTable* diag_table = ewp->diag_table;
135 
136  for (int i = 0; i < diag_table->diag_array_length; i++)
137  {
138  (diag_table->hit_level_array)[i].flag = kFakeReset;
139  (diag_table->hit_level_array)[i].last_hit = kFakeLastHit;
140  }
141  diag_table->offset = kFakeOffset;
142 
143  Blast_ExtendWordExit(ewp, kFakeSequenceLength);
144 
145  BOOST_REQUIRE_EQUAL((kFakeOffset+kFakeSequenceLength+kWindowSize), diag_table->offset);
146  for (int i = 0; i < diag_table->diag_array_length; i++)
147  {
148  BOOST_REQUIRE_EQUAL(kFakeReset, (diag_table->hit_level_array)[i].flag);
149  BOOST_REQUIRE_EQUAL(kFakeLastHit, (diag_table->hit_level_array)[i].last_hit);
150  }
151 
152  ewp = BlastExtendWordFree(ewp);
153  BOOST_REQUIRE(ewp == NULL);
154  }
155 
157 
158 /*
159 * ===========================================================================
160 *
161 * $Log: blastdiag-cppunit.cpp,v $
162 * Revision 1.7 2006/11/21 17:45:30 papadopo
163 * change tests to use ExtendWord sructures only, since BlastDiag structures are local to the engine
164 *
165 * Revision 1.6 2006/09/27 13:45:23 coulouri
166 * Use Blast_ExtendWordExit() instead of BlastDiagUpdate()
167 *
168 * Revision 1.5 2006/07/27 16:24:40 coulouri
169 * remove blast_extend_priv.h
170 *
171 * Revision 1.4 2006/07/27 15:20:10 coulouri
172 * rename bitfield
173 *
174 * Revision 1.3 2006/07/24 16:52:40 coulouri
175 * optimize DiagStruct to reduce size of working set
176 *
177 * Revision 1.2 2005/03/04 17:20:44 bealer
178 * - Command line option support.
179 *
180 * Revision 1.1 2004/12/17 13:27:55 madden
181 * Test for BlastDiagClear/Update
182 *
183 *
184 * ===========================================================================
185 */
Ungapped extension structures that are common to nucleotide and protein extension routines.
Int2 Blast_ExtendWordExit(Blast_ExtendWord *ewp, Int4 subject_length)
Update the word extension structure after scanning of each subject sequence.
Definition: blast_extend.c:162
Blast_ExtendWord * BlastExtendWordFree(Blast_ExtendWord *ewp)
Deallocate memory for the word extension structure.
Definition: blast_extend.c:203
Int2 BlastExtendWordNew(Uint4 query_length, const BlastInitialWordParameters *word_params, Blast_ExtendWord **ewp_ptr)
Initializes the word extension structure.
Definition: blast_extend.c:110
@ eDiagArray
use diagonal structures with array of last hits and levels.
BOOST_AUTO_TEST_CASE(testDiagClear)
BOOST_AUTO_TEST_SUITE_END() static int s_GetSegmentFlags(const CBioseq &bioseq)
Ensure direct dependencies on enough of the core xncbi library to satisfy shared libraries that depen...
#define NULL
Definition: ncbistd.hpp:225
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
int i
Magic spell ;-) needed for some weird compilers... very empiric.
#define INT4_MAX
largest nubmer represented by signed int
Definition: ncbi_std.h:141
BOOST_AUTO_TEST_SUITE(psiblast_iteration)
Structure containing parameters needed for initial word extension.
Definition: blast_extend.h:77
DiagStruct * hit_level_array
Array to hold latest hits and their lengths for all diagonals.
Definition: blast_extend.h:78
Int4 diag_array_length
Smallest power of 2 longer than query length.
Definition: blast_extend.h:81
Int4 offset
"offset" added to query and subject position so that "last_hit" doesn't have to be zeroed out every t...
Definition: blast_extend.h:84
Options needed for initial word finding and processing.
Int4 window_size
Maximal allowed distance between 2 hits in case 2 hits are required to trigger the extension.
Parameter block that contains a pointer to BlastInitialWordOptions and the values derived from it.
BlastInitialWordOptions * options
The original (unparsed) options.
ESeedContainerType container_type
How to store offset pairs for initial seeds?
Structure for keeping initial word extension information.
Definition: blast_extend.h:109
BLAST_DiagTable * diag_table
Diagonal array and related parameters.
Definition: blast_extend.h:110
Utility stuff for more convenient using of Boost.Test library.
Modified on Tue May 21 10:56:18 2024 by modify_doxy.py rev. 669887