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

Go to the SVN repository for this file.

1 /* $Id: effsearchspace_calc.cpp 100101 2023-06-15 14:10:29Z merezhuk $
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 effsearchspace_calc.cpp
31 /// Defines auxiliary class to calculate the effective search space
32 
33 #include <ncbi_pch.hpp>
34 
38 #include "blast_memento_priv.hpp"
39 
40 /** @addtogroup AlgoBlast
41  *
42  * @{
43  */
44 
46 BEGIN_SCOPE(blast)
47 
48 /// Memento class to save, null out, and restore the filtering options of the
49 /// CBlastOptionsMemento object passed to its constructor
50 /// This prevents side effects (like filtering the query sequence) to occur
51 /// during calculation of the effective search space
53 {
54 public:
55  /// Parametrized constructor
56  /// @param opts_memento snapshopt of the BLAST options [in]
58  : m_OptsMemento(opts_memento), m_FilterString(0), m_FilterOpts(0)
59  {
60  m_FilterString = opts_memento->m_QueryOpts->filter_string;
61  m_FilterOpts = opts_memento->m_QueryOpts->filtering_options;
62  opts_memento->m_QueryOpts->filter_string = NULL;
64  eEmpty);
65  }
66 
67  /// Destructor
69  {
70  m_OptsMemento->m_QueryOpts->filter_string = m_FilterString;
71  SBlastFilterOptionsFree(m_OptsMemento->m_QueryOpts->filtering_options);
72  m_OptsMemento->m_QueryOpts->filtering_options = m_FilterOpts;
73  }
74 
75 private:
76  CBlastOptionsMemento* m_OptsMemento; /**< snapshopt of BLAST options */
77  char* m_FilterString; /**< original filtering string
78  specified in m_OptsMemento */
79  SBlastFilterOptions* m_FilterOpts; /**< original filtering options
80  specified in m_OptsMemento */
81 };
82 
84  (CRef<IQueryFactory> query_factory,
85  const CBlastOptions& options,
86  Int4 db_num_seqs,
87  Int8 db_num_bases,
88  BlastScoreBlk* sbp)
89  : m_QueryFactory(query_factory), m_Program(options.GetProgramType())
90 {
91  bool delete_sbp = false;
92  CRef<ILocalQueryData> local_data =
94  m_QueryInfo = local_data->GetQueryInfo();
95 
96  unique_ptr<CBlastOptionsMemento> opts_memento
97  (const_cast<CBlastOptionsMemento*>(options.CreateSnapshot()));
98  {{
99  TSearchMessages messages;
100 
102  fm(const_cast<CBlastOptionsMemento*>(opts_memento.get()));
103  if (sbp == NULL)
104  {
105  sbp = CSetupFactory::CreateScoreBlock(opts_memento.get(), local_data, NULL, messages);
106  delete_sbp = true;
107  }
108  _ASSERT(!messages.HasMessages());
109  }}
110 
111  CBlastEffectiveLengthsParameters eff_len_params;
112 
113  /* Initialize the effective length parameters with real values of
114  database length and number of sequences */
115  BlastEffectiveLengthsParametersNew(opts_memento->m_EffLenOpts,
116  db_num_bases, db_num_seqs,
117  &eff_len_params);
118 
119  Int2 status =
120  BLAST_CalcEffLengths(m_Program, opts_memento->m_ScoringOpts,
121  eff_len_params, sbp, m_QueryInfo, NULL);
122 
123  if (delete_sbp == true)
124  sbp = BlastScoreBlkFree(sbp);
125 
126  if (status) {
127  NCBI_THROW(CBlastException, eCoreBlastError,
128  "BLAST_CalcEffLengths failed");
129  }
130 }
131 
132 Int8
134 {
135  _ASSERT((Int4)query_index < m_QueryInfo->num_queries);
136  return BlastQueryInfoGetEffSearchSpace(m_QueryInfo, m_Program, static_cast<Int4>(query_index));
137 }
138 
139 Int8
141 {
142  _ASSERT((Int4)ctx_index <= m_QueryInfo->last_context);
143  return m_QueryInfo->contexts[ctx_index].eff_searchsp;
144 }
145 
147 {
148  return m_QueryInfo;
149 }
150 
151 END_SCOPE(blast)
153 
154 /* @} */
155 
Classes that capture the state of the BLAST options (or subsets of options) and restore them later (u...
SBlastFilterOptions * SBlastFilterOptionsFree(SBlastFilterOptions *filter_options)
Frees SBlastFilterOptions and all subservient structures.
@ eEmpty
no filtering at all.
Int2 SBlastFilterOptionsNew(SBlastFilterOptions **filter_options, EFilterOptions type)
Allocates memory for SBlastFilterOptions and.
Int2 BlastEffectiveLengthsParametersNew(const BlastEffectiveLengthsOptions *options, Int8 db_length, Int4 num_seqs, BlastEffectiveLengthsParameters **parameters)
Allocate memory for BlastEffectiveLengthsParameters.
Int8 BlastQueryInfoGetEffSearchSpace(const BlastQueryInfo *qinfo, EBlastProgramType program, Int4 query_index)
Retrieve a query sequence's search space.
Utilities initialize/setup BLAST.
Int2 BLAST_CalcEffLengths(EBlastProgramType program_number, const BlastScoringOptions *scoring_options, const BlastEffectiveLengthsParameters *eff_len_params, const BlastScoreBlk *sbp, BlastQueryInfo *query_info, Blast_Message **blast_message)
Function to calculate effective query length and db length as well as effective search space.
Definition: blast_setup.c:699
BlastScoreBlk * BlastScoreBlkFree(BlastScoreBlk *sbp)
Deallocates BlastScoreBlk as well as all associated structures.
Definition: blast_stat.c:965
Wrapper class for BlastEffectiveLengthsParameters .
Definition: blast_aux.hpp:340
Defines BLAST error codes (user errors included)
Class that allows the transfer of data structures from the CBlastOptionsLocal class to either the BLA...
Encapsulates ALL the BLAST algorithm's options.
Memento class to save, null out, and restore the filtering options of the CBlastOptionsMemento object...
typedef for the messages for an entire BLAST search, which could be comprised of multiple query seque...
Declares auxiliary class to calculate the effective search space.
bool HasMessages() const
Definition: blast_aux.cpp:1002
CBlastOptionsMemento * m_OptsMemento
snapshopt of BLAST options
const CBlastOptionsMemento * CreateSnapshot() const
Create a snapshot of the state of this object for internal use of its data structures (BLAST C++ APIs...
CRef< IQueryFactory > m_QueryFactory
source of query sequence(s)
EBlastProgramType m_Program
BLAST program.
~CFilteringMemento()
Destructor.
Int8 GetEffSearchSpaceForContext(size_t ctx_index) const
Retrieve the effective search space calculated for a given query context.
SBlastFilterOptions * m_FilterOpts
original filtering options specified in m_OptsMemento
CRef< ILocalQueryData > MakeLocalQueryData(const CBlastOptions *opts)
Creates and caches an ILocalQueryData.
Definition: query_data.cpp:52
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.
virtual BlastQueryInfo * GetQueryInfo()=0
Accessor for the BlastQueryInfo structure.
BlastQueryInfo * GetQueryInfo() const
Retrieve the BlastQueryInfo structure that stores the effective search spaces for all queries.
CFilteringMemento(CBlastOptionsMemento *opts_memento)
Parametrized constructor.
BlastQueryInfo * m_QueryInfo
struct to store eff. search spaces
CEffectiveSearchSpaceCalculator(CRef< IQueryFactory > query_factory, const CBlastOptions &options, Int4 db_num_seqs, Int8 db_num_bases, BlastScoreBlk *sbp=NULL)
Constructor.
QuerySetUpOptions * m_QueryOpts
char * m_FilterString
original filtering string specified in m_OptsMemento
Int8 GetEffSearchSpace(size_t query_index=0) const
Retrieve the effective search space calculated for a given query.
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
Int8 eff_searchsp
Effective search space for this context.
The query related information.
BlastContextInfo * contexts
Information per context.
Structure used for scoring calculations.
Definition: blast_stat.h:177
char * filter_string
DEPRECATED, filtering options above.
SBlastFilterOptions * filtering_options
structured options for all filtering offered from algo/blast/core for BLAST.
All filtering options.
#define _ASSERT
Modified on Wed Apr 17 13:08:07 2024 by modify_doxy.py rev. 669887