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

Go to the SVN repository for this file.

1 
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_impl.cpp
31 /// Implements implementation class for PSI-BLAST and PSI-BLAST 2 Sequences
32 
33 #include <ncbi_pch.hpp>
34 #include "psiblast_impl.hpp"
35 #include "psiblast_aux_priv.hpp"
43 
44 // Object includes
49 
50 /** @addtogroup AlgoBlast
51  *
52  * @{
53  */
54 
57 BEGIN_SCOPE(blast)
58 
62 : m_Pssm(pssm), m_Query(0), m_Subject(subject), m_OptsHandle(options),
63  m_ResultType(eDatabaseSearch)
64 {
65  x_Validate();
66  x_ExtractQueryFromPssm();
67  x_CreatePssmScoresFromFrequencyRatios();
68 }
69 
73 : m_Pssm(0), m_Query(query), m_Subject(subject), m_OptsHandle(options),
74  m_ResultType(eDatabaseSearch)
75 {
76  x_Validate();
77 }
78 
79 void
81 {
82  // Validate the options
83  if (m_OptsHandle.Empty()) {
84  NCBI_THROW(CBlastException, eInvalidArgument, "Missing options");
85  }
87 
88  // Either PSSM or a protein query must be provided
89  if (m_Pssm.NotEmpty()) {
91  } else if (m_Query.NotEmpty()) {
93  } else {
94  NCBI_THROW(CBlastException, eInvalidArgument, "Missing query or pssm");
95  }
96 
97  // Validate the subject
98  if (m_Subject.Empty()) {
99  NCBI_THROW(CBlastException, eInvalidArgument,
100  "Missing database or subject sequences");
101  }
102 }
103 
104 void
106 {
107  if ( !m_Pssm->GetPssm().CanGetFinalData() ||
108  !m_Pssm->GetPssm().GetFinalData().CanGetScores() ||
109  m_Pssm->GetPssm().GetFinalData().GetScores().empty() ) {
111  }
112 }
113 
114 void
116 {
117  CConstRef<CBioseq> query_bioseq(&m_Pssm->GetPssm().GetQuery().GetSeq());
118  m_Query.Reset(new CObjMgrFree_QueryFactory(query_bioseq)); /* NCBI_FAKE_WARNING */
119 }
120 
123 {
125  opts(const_cast<CBlastOptions*>(&m_OptsHandle->GetOptions()));
126 
127  // FIXME: Move the following line and initialization of all
128  // BlastSeqSrc/subjects to CBlastPrelimSearch::x_Init
130 
131  // Run the preliminary stage
132  CBlastPrelimSearch prelim_search(m_Query,
133  opts,
134  m_Subject->MakeSeqSrc(),
135  m_Pssm);
136  prelim_search.SetNumberOfThreads(GetNumberOfThreads());
137  CRef<SInternalData> core_data = prelim_search.Run();
138 
139  // Run the traceback stage
141  _ASSERT(seqinfo_src.NotEmpty());
142  TSearchMessages search_messages = prelim_search.GetSearchMessages();
144  core_data,
145  opts,
146  seqinfo_src,
147  search_messages);
150  m_Results = tback.Run();
151 
152  // Save the K&A values be as they might have been modified in the
153  // composition adjustment library
154  if (m_Pssm.NotEmpty()) {
155  CPssm& pssm = m_Pssm->SetPssm();
156  pssm.SetLambda
157  (core_data->m_ScoreBlk->GetPointer()->kbp_gap_psi[0]->Lambda);
158  pssm.SetKappa
159  (core_data->m_ScoreBlk->GetPointer()->kbp_gap_psi[0]->K);
160  pssm.SetH
161  (core_data->m_ScoreBlk->GetPointer()->kbp_gap_psi[0]->H);
162  pssm.SetLambdaUngapped
163  (core_data->m_ScoreBlk->GetPointer()->kbp_psi[0]->Lambda);
164  pssm.SetKappaUngapped
165  (core_data->m_ScoreBlk->GetPointer()->kbp_psi[0]->K);
166  pssm.SetHUngapped
167  (core_data->m_ScoreBlk->GetPointer()->kbp_psi[0]->H);
168  }
169  return m_Results;
170 }
171 
172 void
174 {
175  if (pssm.Empty()) {
176  NCBI_THROW(CBlastException, eInvalidArgument,
177  "Setting empty reference for pssm");
178  }
179  CPsiBlastValidate::Pssm(*pssm, true);
180  m_Pssm.Reset(const_cast<CPssmWithParameters*>(&*pssm));
181 }
182 
183 void
185 {
186  m_ResultType = type;
187 }
188 
191 {
192  return m_Pssm;
193 }
194 
195 END_SCOPE(blast)
197 
198 /* @} */
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
Declares the BLAST exception class.
Defines interface for retrieving sequence identifiers.
EResultType
Specifies the style of Seq-aligns that should be built from the internal BLAST data structures.
@ eDatabaseSearch
Seq-aligns in the style of a database search.
Defines BLAST error codes (user errors included)
Encapsulates ALL the BLAST algorithm's options.
Search class to perform the preliminary stage of the BLAST search.
CConstRef –.
Definition: ncbiobj.hpp:1266
Interface to create a BlastSeqSrc suitable for use in CORE BLAST from a a variety of BLAST database/s...
NCBI C++ Object Manager free implementation of IQueryFactory.
Handle to the protein-protein options to the BLAST algorithm.
Implementation class for PSI-BLAST (database search and 2 sequences).
Definition: Pssm.hpp:55
void SetHUngapped(double val)
Definition: Pssm.cpp:188
void SetH(double val)
Definition: Pssm.cpp:170
void SetLambdaUngapped(double val)
Definition: Pssm.cpp:176
void SetKappa(double val)
Definition: Pssm.cpp:164
void SetKappaUngapped(double val)
Definition: Pssm.cpp:182
void SetLambda(double val)
Definition: Pssm.cpp:158
CRef –.
Definition: ncbiobj.hpp:618
typedef for the messages for an entire BLAST search, which could be comprised of multiple query seque...
static int type
Definition: getdata.c:31
static void QueryFactory(CRef< IQueryFactory > query_factory, const CBlastOptionsHandle &opts_handle, EQueryFactoryType query_factory_type=eQFT_Query)
Function to perform sanity checks on the query factory.
CPsiBlastImpl(CRef< objects::CPssmWithParameters > pssm, CRef< CLocalDbAdapter > subject, CConstRef< CPSIBlastOptionsHandle > options)
Constructor for restarting PSI-BLAST iterations with a previously generated PSSM.
size_t GetNumberOfThreads(void) const
Accessor for the number of threads to use.
virtual void SetNumberOfThreads(size_t nthreads)
Mutator for the number of threads.
void SetResultType(EResultType type)
Set the desired result type.
CRef< SInternalData > Run()
Borrow the internal data and results results.
void x_ExtractQueryFromPssm()
Auxiliary function to get the query sequence data from the ASN.1 PSSM Post-condition: (m_Query....
CRef< CSearchResultSet > Run()
Run the traceback search.
BlastSeqSrc * MakeSeqSrc()
Retrieves or constructs the BlastSeqSrc.
CConstRef< CBlastOptionsHandle > m_OptsHandle
Options to use.
void SetResultType(EResultType type)
Specifies how the Seq-align-set returned as part of the results is formatted.
virtual void SetNumberOfThreads(size_t nthreads)
@inheritDoc
void x_Validate()
Perform sanity checks on input parameters.
CRef< TBlastScoreBlk > m_ScoreBlk
BLAST score block structure.
EResultType m_ResultType
Specifies how the results should be produced.
CRef< IQueryFactory > m_Query
Query sequence (either extracted from PSSM or provided in constructor)
CConstRef< objects::CPssmWithParameters > GetPssm() const
Accessor for the most recently used PSSM.
const CBlastOptions & GetOptions() const
Return the object which this object is a handle for.
IBlastSeqInfoSrc * MakeSeqInfoSrc()
Retrieves or constructs the IBlastSeqInfoSrc.
void PsiBlastComputePssmScores(CRef< objects::CPssmWithParameters > pssm, const CBlastOptions &opts)
Given a PSSM with frequency ratios and options, invoke the PSSM engine to compute the scores.
void ResetBlastSeqSrcIteration()
This method should be called so that if the implementation has an internal "bookmark" of the chunks o...
bool Validate() const
Validate the options contained in this object.
static void Pssm(const objects::CPssmWithParameters &pssm, bool require_scores=false)
Perform validation on the PSSM.
CRef< CSearchResultSet > m_Results
Holds a reference to the results.
void x_CreatePssmScoresFromFrequencyRatios()
Computes the PSSM scores in case these are not available in the PSSM.
void SetPssm(CConstRef< objects::CPssmWithParameters > pssm)
This method allows the same object to be reused when performing multiple iterations.
CRef< CLocalDbAdapter > m_Subject
PSI-BLAST subject abstraction.
CRef< CSearchResultSet > Run()
Run the PSI-BLAST engine for one iteration.
TSearchMessages GetSearchMessages() const
Retrieve any error/warning messages that occurred during the search.
CRef< objects::CPssmWithParameters > m_Pssm
PSSM to be used as query.
#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
bool Empty(void) const THROWS_NONE
Check if CConstRef is empty – not pointing to any object which means having a null value.
Definition: ncbiobj.hpp:1385
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty – pointing to an object and has a non-null value.
Definition: ncbiobj.hpp:726
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define USING_SCOPE(ns)
Use the specified namespace.
Definition: ncbistl.hpp:78
#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...
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
Declarations of auxiliary functions/classes for PSI-BLAST.
Defines implementation class for PSI-BLAST and PSI-BLAST 2 Sequences.
Declares the CPSIBlastOptionsHandle class.
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
static string subject
static string query
Definition: type.c:6
#define _ASSERT
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
Modified on Mon May 13 04:32:55 2024 by modify_doxy.py rev. 669887