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

Go to the SVN repository for this file.

1 /* $Id: pssm_test_util.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: Christiam Camacho
27  *
28  */
29 
30 /** @file psiblast_test_util.cpp
31  * Utilities to develop and debug unit tests for BLAST
32  */
33 
34 
35 #include <ncbi_pch.hpp>
36 
37 #define BLAST_SECONDARY_SOURCE 1
38 
39 #include <corelib/test_boost.hpp>
40 #include "blast_test_util.hpp"
41 #include "pssm_test_util.hpp"
42 
43 
44 using namespace std;
45 using namespace ncbi;
46 using namespace ncbi::blast;
47 
48 /// @param query protein sequence in ncbistdaa with sentinel bytes
49 /// @param query_size length of the query sequence (w/o including sentinel
50 // bytes)
52  Uint4 query_size)
53 {
54  const EBlastProgramType kProgramType = eBlastTypeBlastp;
55  const double kScaleFactor = 1.0;
56  Blast_Message* errors = NULL;
57  short status = 0;
58 
59  // Setup the scoring options
61  status = BlastScoringOptionsNew(kProgramType, &opts);
62  BOOST_REQUIRE(status == 0);
63 
64  // Setup the sequence block structure
65  CBLAST_SequenceBlk query_blk;
66  status = BlastSeqBlkNew(&query_blk);
67  BOOST_REQUIRE(status == 0);
68  status = BlastSeqBlkSetSequence(query_blk, query, query_size);
69  BOOST_REQUIRE(status == 0);
70  // don't delete the sequences upon exit!
71  query_blk->sequence_allocated = FALSE;
72  query_blk->sequence_start_allocated = FALSE;
73 
74  const Uint1 kNullByte = GetSentinelByte(eBlastEncodingProtein);
75  BOOST_REQUIRE(query_blk.Get() != NULL);
76  BOOST_REQUIRE(query_blk->sequence[0] != kNullByte);
77  BOOST_REQUIRE(query_blk->sequence[query_blk->length - 1] != kNullByte);
78  BOOST_REQUIRE(query_blk->sequence_start[0] == kNullByte);
79  BOOST_REQUIRE(query_blk->sequence_start[query_blk->length + 1] ==
80  kNullByte);
81 
82  // Setup the query info structure
83  CBlastQueryInfo query_info(TestUtil::CreateProtQueryInfo(query_size));
84 
85  BlastScoreBlk* retval = NULL;
86  status = BlastSetup_ScoreBlkInit(query_blk,
87  query_info,
88  opts,
89  kProgramType,
90  &retval,
92  &errors,
94  if (status) {
95  throw runtime_error(errors->message);
96  }
97  BOOST_REQUIRE(retval->kbp_ideal);
98 
99  /*********************************************************************/
100 
101  return retval;
102 }
Int2 BlastScoringOptionsNew(EBlastProgramType program, BlastScoringOptions **options)
Allocate memory for BlastScoringOptions and fill with default values.
EBlastProgramType
Defines the engine's notion of the different applications of the BLAST algorithm.
Definition: blast_program.h:72
@ eBlastTypeBlastp
Definition: blast_program.h:73
Int2 BlastSetup_ScoreBlkInit(BLAST_SequenceBlk *query_blk, const BlastQueryInfo *query_info, const BlastScoringOptions *scoring_options, EBlastProgramType program_number, BlastScoreBlk **sbpp, double scale_factor, Blast_Message **blast_message, GET_MATRIX_PATH get_path)
Initializes the score block structure.
Definition: blast_setup.c:456
Int2 BlastSeqBlkSetSequence(BLAST_SequenceBlk *seq_blk, const Uint1 *sequence, Int4 seqlen)
Stores the sequence in the sequence block structure.
Definition: blast_util.c:147
Int2 BlastSeqBlkNew(BLAST_SequenceBlk **retval)
Allocates a new sequence block structure.
Definition: blast_util.c:133
Wrapper class for BLAST_SequenceBlk .
Definition: blast_aux.hpp:309
Wrapper class for BlastQueryInfo .
Definition: blast_aux.hpp:311
Wrapper class for BlastScoringOptions .
Definition: blast_aux.hpp:334
BLAST_SequenceBlk * Get() const
Definition: blast_aux.hpp:309
char * BlastFindMatrixPath(const char *matrix_name, Boolean is_prot)
Returns the path to a specified matrix.
Uint1 GetSentinelByte(EBlastEncoding encoding) THROWS((CBlastException))
Convenience function to centralize the knowledge of which sentinel bytes we use for supported encodin...
@ eBlastEncodingProtein
NCBIstdaa.
#define NULL
Definition: ncbistd.hpp:225
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
static const int kScaleFactor
Definition: hyperclust.cpp:176
BlastQueryInfo * CreateProtQueryInfo(unsigned int query_size)
Creates and initializes a BlastQueryInfo structure for a single protein sequence.
Magic spell ;-) needed for some weird compilers... very empiric.
#define FALSE
bool replacment for C indicating false.
Definition: ncbi_std.h:101
Utilities to develop and debug unit tests for BLAST.
BlastScoreBlk * InitializeBlastScoreBlk(const unsigned char *query, Uint4 query_size)
Utilities to develop and debug unit tests that deal with PSSM computation.
Uint1 * sequence_start
Start of sequence, usually one byte before sequence as that byte is a NULL sentinel byte.
Definition: blast_def.h:244
Boolean sequence_allocated
TRUE if memory has been allocated for sequence.
Definition: blast_def.h:251
Int4 length
Length of sequence.
Definition: blast_def.h:246
Uint1 * sequence
Sequence used for search (could be translation).
Definition: blast_def.h:243
Boolean sequence_start_allocated
TRUE if memory has been allocated for sequence_start.
Definition: blast_def.h:253
Structure used for scoring calculations.
Definition: blast_stat.h:177
Blast_KarlinBlk * kbp_ideal
Ideal values (for query with average database composition).
Definition: blast_stat.h:216
Structure to hold the a message from the core of the BLAST engine.
Definition: blast_message.h:70
char * message
User message to be saved.
Definition: blast_message.h:73
static string query
Utility stuff for more convenient using of Boost.Test library.
Modified on Tue Apr 16 20:11:11 2024 by modify_doxy.py rev. 669887