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

Go to the SVN repository for this file.

1 /* ===========================================================================
2  *
3  * PUBLIC DOMAIN NOTICE
4  * National Center for Biotechnology Information
5  *
6  * This software/database is a "United States Government Work" under the
7  * terms of the United States Copyright Act. It was written as part of
8  * the author's official duties as a United States Government employee and
9  * thus cannot be copyrighted. This software/database is freely available
10  * to the public for use. The National Library of Medicine and the U.S.
11  * Government have not placed any restriction on its use or reproduction.
12  *
13  * Although all reasonable efforts have been taken to ensure the accuracy
14  * and reliability of the software and data, the NLM and the U.S.
15  * Government do not and cannot warrant the performance or results that
16  * may be obtained by using this software or data. The NLM and the U.S.
17  * Government disclaim all warranties, express or implied, including
18  * warranties of performance, merchantability or fitness for any particular
19  * purpose.
20  *
21  * Please cite the author in any work or product based on this material.
22  *
23  * ===========================================================================
24  *
25  * Author: Christiam Camacho
26  *
27  */
28 
29 /** @file local_db_adapter.cpp
30  * Defines class which provides internal BLAST database representations to the
31  * internal BLAST APIs
32  */
33 
34 #include <ncbi_pch.hpp>
36 #include <algo/blast/api/objmgr_query_data.hpp> // for CObjMgr_QueryFactory
37 #include <algo/blast/api/seqsrc_multiseq.hpp> // for MultiSeqBlastSeqSrcInit
38 #include <algo/blast/api/seqsrc_seqdb.hpp> // for SeqDbBlastSeqSrcInit
39 #include <algo/blast/api/seqinfosrc_seqdb.hpp> // for CSeqDbSeqInfoSrc
40 #include <algo/blast/api/seqinfosrc_seqvec.hpp> // for CSeqVecSeqInfoSrc
42 #include "seqsrc_query_factory.hpp" // for QueryFactoryBlastSeqSrcInit
43 #include "psiblast_aux_priv.hpp" // for CPsiBlastValidate
44 #include "seqinfosrc_bioseq.hpp" // for CBioseqInfoSrc
45 
46 /** @addtogroup AlgoBlast
47  *
48  * @{
49  */
50 
52 BEGIN_SCOPE(blast)
53 
55  : m_SeqSrc(0), m_SeqInfoSrc(0), m_DbName(dbinfo.GetDatabaseName()), m_DbScanMode(false)
56 {
57  m_DbInfo.Reset(new CSearchDatabase(dbinfo));
58 }
59 
62  bool dbscan_mode)
63  : m_SeqSrc(0), m_SeqInfoSrc(0), m_SubjectFactory(subject_sequences),
64  m_OptsHandle(opts_handle), m_DbName(kEmptyStr), m_DbScanMode(dbscan_mode)
65 {
66  if (subject_sequences.Empty()) {
67  NCBI_THROW(CBlastException, eInvalidArgument,
68  "Missing subject sequence data");
69  }
70  if (opts_handle.Empty()) {
71  NCBI_THROW(CBlastException, eInvalidArgument, "Missing options");
72  }
73  if (opts_handle->GetOptions().GetProgram() == ePSIBlast) {
74  CPsiBlastValidate::QueryFactory(subject_sequences, *opts_handle,
76  }
77 
78  CObjMgr_QueryFactory* objmgr_qf = NULL;
79  if ( (objmgr_qf = dynamic_cast<CObjMgr_QueryFactory*>(&*m_SubjectFactory)) )
80  {
81  m_Subjects = objmgr_qf->GetTSeqLocVector();
82  _ASSERT(!m_Subjects.empty());
83  }
84 }
85 
87  CRef<IBlastSeqInfoSrc> seqInfoSrc)
88  : m_SeqSrc(seqSrc), m_SeqInfoSrc(seqInfoSrc), m_DbName(kEmptyStr), m_DbScanMode(false)
89 {
90 }
91 
93 {
94  if (m_SeqSrc) {
96  }
97 }
98 
99 void
101 {
102  if (m_SeqSrc) {
104  }
105 }
106 
107 /// Checks if the BlastSeqSrc initialization succeeded
108 /// @throws CBlastException if BlastSeqSrc initialization failed
109 static void
111 {
112  if ( !seqsrc ) {
113  return;
114  }
115 
116  char* error_str = BlastSeqSrcGetInitError(seqsrc);
117  if (error_str) {
118  string msg(error_str);
119  sfree(error_str);
120  NCBI_THROW(CBlastException, eSeqSrcInit, msg);
121  }
122 }
123 
126 {
127  if ( ! m_SeqSrc ) {
128  if (m_DbInfo.NotEmpty()) {
130  } else if (m_SubjectFactory.NotEmpty() && m_OptsHandle.NotEmpty()) {
131  const EBlastProgramType program =
133  if ( !m_Subjects.empty() ) {
134  //m_SeqSrc = QueryFactoryBlastSeqSrcInit(m_Subjects, program);
136  } else {
138  program);
139  }
140  _ASSERT(m_SeqSrc);
141  } else {
142  abort();
143  }
145  _ASSERT(m_SeqSrc);
146  }
147  return m_SeqSrc;
148 }
149 
152 {
153  if ( !m_SeqInfoSrc ) {
154  if (m_DbInfo.NotEmpty()) {
156  dynamic_cast<CSeqDbSeqInfoSrc *>(&*m_SeqInfoSrc)
157  ->SetFilteringAlgorithmId(m_DbInfo->GetFilteringAlgorithm());
158  } else if (m_SubjectFactory.NotEmpty() && m_OptsHandle.NotEmpty()) {
160  if ( !m_Subjects.empty() ) {
162  } else {
163  CRef<IRemoteQueryData> subj_data
165  CRef<CBioseq_set> subject_bioseqs(subj_data->GetBioseqSet());
166  bool is_prot = Blast_SubjectIsProtein(p) ? true : false;
167  m_SeqInfoSrc = new CBioseqSeqInfoSrc(*subject_bioseqs, is_prot);
168  }
169  } else {
170  abort();
171  }
173  }
174  return m_SeqInfoSrc;
175 }
176 
177 bool
179 {
180  bool retval = false;
181  if (m_DbInfo) {
182  retval = m_DbInfo->IsProtein();
183  } else if (m_OptsHandle) {
185  retval = Blast_SubjectIsProtein(p) ? true : false;
186  } else if (m_SeqSrc) {
187  retval = BlastSeqSrcGetIsProt(m_SeqSrc) ? true : false;
188  } else {
189  // Data type provided in a constructor, but not handled here
190  abort();
191  }
192  return retval;
193 }
194 
195 string
197 {
199 }
200 
201 
202 END_SCOPE(Blast)
204 
205 /* @} */
#define sfree(x)
Safe free a pointer: belongs to a higher level header.
Definition: blast_def.h:112
Boolean Blast_SubjectIsProtein(EBlastProgramType p)
Returns true if the subject is protein.
Definition: blast_program.c:50
EBlastProgramType
Defines the engine's notion of the different applications of the BLAST algorithm.
Definition: blast_program.h:72
Boolean BlastSeqSrcGetIsProt(const BlastSeqSrc *seq_src)
Find if the Blast Sequence Source contains protein or nucleotide sequences.
Definition: blast_seqsrc.c:243
char * BlastSeqSrcGetInitError(const BlastSeqSrc *seq_src)
Function to retrieve NULL terminated string containing the description of an initialization error or ...
Definition: blast_seqsrc.c:159
BlastSeqSrc * BlastSeqSrcFree(BlastSeqSrc *seq_src)
Frees the BlastSeqSrc structure by invoking the destructor function set by the user-defined construct...
Definition: blast_seqsrc.c:112
void BlastSeqSrcResetChunkIterator(BlastSeqSrc *seq_src)
Reset the internal "bookmark" of the last chunk for iteration provided by this object.
Definition: blast_seqsrc.c:436
@ ePSIBlast
PSI Blast.
Definition: blast_types.hpp:67
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
Implementation of the IBlastSeqInfoSrc interface to encapsulate retrieval of sequence identifiers and...
Defines BLAST error codes (user errors included)
Interface to create a BlastSeqSrc suitable for use in CORE BLAST from a a variety of BLAST database/s...
NCBI C++ Object Manager dependant implementation of IQueryFactory.
Blast Search Subject.
Implementation of the IBlastSeqInfoSrc interface to encapsulate retrieval of sequence identifiers and...
Implementation of the IBlastSeqInfoSrc interface to encapsulate retrieval of sequence identifiers and...
Abstract base class to encapsulate retrieval of sequence identifiers.
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.
bool IsProtein() const
Returns true if this object represents protein or nucleotide sequences.
CConstRef< CBlastOptionsHandle > m_OptsHandle
Options to be used when instantiating the subject sequences.
CRef< CSearchDatabase > m_DbInfo
Object containing BLAST database description.
BlastSeqSrc * QueryFactoryBlastSeqSrcInit(CRef< IQueryFactory > query_factory, EBlastProgramType program)
Initialize the sequence source structure from a query factory.
int GetFilteringAlgorithm() const
Accessor for the filtering algorithm ID.
static void s_CheckForBlastSeqSrcErrors(const BlastSeqSrc *seqsrc)
Checks if the BlastSeqSrc initialization succeeded.
CRef< CSeqDB > GetSeqDb() const
Obtain a reference to the database.
TSeqLocVector GetTSeqLocVector()
Retrieves the TSeqLocVector used to construct this object or a conversion of the CBlastQueryVector pr...
string GetFilteringAlgorithmKey()
Retrieve the database filtering id from key.
CRef< IBlastSeqInfoSrc > m_SeqInfoSrc
Pointer to the IBlastSeqInfoSrc.
string GetFilteringAlgorithmKey() const
Accessor for the filtering algorithm key.
BlastSeqSrc * MakeSeqSrc()
Retrieves or constructs the BlastSeqSrc.
bool IsProtein() const
Determine whether this database contains protein sequences or not.
virtual ~CLocalDbAdapter()
Destructor.
TSeqLocVector m_Subjects
This is initialized ONLY if the m_SubjectFactory is of type CObjMgr_QueryFactory, case in which it's ...
BlastSeqSrc * MultiSeqBlastSeqSrcInit(TSeqLocVector &seq_vector, EBlastProgramType program, bool dbscan_mode=false)
Initialize the sequence source structure.
EBlastProgramType GetProgramType() const
Returns the CORE BLAST notion of program type.
static BlastSeqSrc * CreateBlastSeqSrc(const CSearchDatabase &db)
Create a BlastSeqSrc from a CSearchDatabase (uses CSeqDB)
CRef< IQueryFactory > m_SubjectFactory
IQueryFactory containing the subject sequences.
EProgram GetProgram() const
Accessors/Mutators for individual options.
const CBlastOptions & GetOptions() const
Return the object which this object is a handle for.
virtual CRef< objects::CBioseq_set > GetBioseqSet()=0
Accessor for the CBioseq_set.
IBlastSeqInfoSrc * MakeSeqInfoSrc()
Retrieves or constructs the IBlastSeqInfoSrc.
void ResetBlastSeqSrcIteration()
This method should be called so that if the implementation has an internal "bookmark" of the chunks o...
CRef< IRemoteQueryData > MakeRemoteQueryData()
Creates and caches an IRemoteQueryData.
Definition: query_data.cpp:61
bool m_DbScanMode
Specifies that bl2seq search run in database scan mode (not pairwise)
CLocalDbAdapter(const CSearchDatabase &dbinfo)
Constructor.
BlastSeqSrc * m_SeqSrc
Pointer to the BlastSeqSrc this object owns and manages.
#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
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
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 NotEmpty(void) const THROWS_NONE
Check if CConstRef is not empty – pointing to an object and has a non-null value.
Definition: ncbiobj.hpp:1392
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 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
#define kEmptyStr
Definition: ncbistr.hpp:123
Declares class which provides internal BLAST database representations to the internal BLAST APIs.
void abort()
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 a concrete strategy for the IBlastSeqInfoSrc interface for sequence identifiers retrieval fro...
Defines a concrete strategy for the IBlastSeqInfoSrc interface for sequence identifiers retrieval fro...
Defines a concrete strategy for the IBlastSeqInfoSrc interface for sequence identifiers retrieval fro...
Implementation of the BlastSeqSrc interface for a vector of sequence locations.
Implementation of the BlastSeqSrc interface for a query factory.
Implementation of the BlastSeqSrc interface using the C++ BLAST databases API.
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
Complete type definition of Blast Sequence Source ADT.
Definition: blast_seqsrc.c:43
#define _ASSERT
#define const
Definition: zconf.h:230
Modified on Thu Feb 22 17:11:29 2024 by modify_doxy.py rev. 669887