1 /* $Id: local_blast.hpp 631502 2021-05-19 13:46:48Z ivanov $
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, Kevin Bealer
27 *
28 */
29
30 /** @file local_blast.hpp
31 * Main class to perform a BLAST search on the local machine.
32 */
33
34 #ifndef ALGO_BLAST_API___LOCAL_BLAST_HPP
35 #define ALGO_BLAST_API___LOCAL_BLAST_HPP
36
37 #include <algo/blast/api/prelim_stage.hpp>
38 #include <algo/blast/api/traceback_stage.hpp>
39 #include <algo/blast/api/blast_seqinfosrc.hpp>
40
41 /** @addtogroup AlgoBlast
42 *
43 * @{
44 */
45 class CBlastFilterTest;
46
47 BEGIN_NCBI_SCOPE
48 BEGIN_SCOPE(blast)
49
50 /// Returns the optimal chunk size for a given task
51 /// @param program BLAST task [in]
52 NCBI_XBLAST_EXPORT
53 size_t
54 SplitQuery_GetChunkSize(EProgram program);
55
56 /// Class to perform a BLAST search on local BLAST databases
57 /// Note that PHI-BLAST can be run using this class also, one only need to
58 /// configure it as a regular blastp or blastn search and set the pattern in
59 /// the CBlastOptionsHandle object
60 /// @todo should RPS-BLAST be moved out of this object?
61 class NCBI_XBLAST_EXPORT CLocalBlast : public CObject, public CThreadable
62 {
63 public:
64 /// Constructor with database description
65 /// @param query_factory query sequence(s) [in]
66 /// @param opts_handle BLAST options handle [in]
67 /// @param dbinfo description of BLAST database to search [in]
68 CLocalBlast(CRef<IQueryFactory> query_factory,
69 CRef<CBlastOptionsHandle> opts_handle,
70 const CSearchDatabase& dbinfo);
71
72 /// Constructor with subject adapter (@sa CLocalDbAdapter)
73 /// @param query_factory query sequence(s) [in]
74 /// @param opts_handle BLAST options handle [in]
75 /// @param db subject adapter [in]
76 CLocalBlast(CRef<IQueryFactory> query_factory,
77 CRef<CBlastOptionsHandle> opts_handle,
78 CRef<CLocalDbAdapter> db);
79
80 /// Constructor with database description
81 /// @param query_factory query sequence(s) [in]
82 /// @param opts_handle BLAST options handle [in]
83 /// @param seqsrc BlastSeqSrc object to search [in]
84 /// @param seqInfoSrc user-specified IBlastSeqInfoSrc [in]
85 CLocalBlast(CRef<IQueryFactory> query_factory,
86 CRef<CBlastOptionsHandle> opts_handle,
87 BlastSeqSrc* seqsrc,
88 CRef<IBlastSeqInfoSrc> seqInfoSrc);
89
90 /// Executes the search
91 CRef<CSearchResultSet> Run();
92
93 /// Set a function callback to be invoked by the CORE of BLAST to allow
94 /// interrupting a BLAST search in progress.
95 /// @param fnptr pointer to callback function [in]
96 /// @param user_data user data to be attached to SBlastProgress structure
97 /// [in]
98 /// @return the previously set TInterruptFnPtr (NULL if none was
99 /// provided before)
SetInterruptCallback(TInterruptFnPtr fnptr,void * user_data=NULL)100 TInterruptFnPtr SetInterruptCallback(TInterruptFnPtr fnptr,
101 void* user_data = NULL) {
102 _ASSERT(m_PrelimSearch);
103 return m_PrelimSearch->SetInterruptCallback(fnptr, user_data);
104 }
105
106 /// Retrieve any error/warning messages that occurred during the search
107 TSearchMessages GetSearchMessages() const;
108
109 /// Retrieve the number of extensions performed during the search
110 Int4 GetNumExtensions();
111
112 /// Get the diagnostics structure (deep copy, needs to be deleted by caller)
113 BlastDiagnostics* GetDiagnostics();
114
115 // set batch number
SetBatchNumber(int batch_num)116 void SetBatchNumber( int batch_num ) {
117 m_batch_num_str = string("B") + NStr::NumericToString( batch_num );
118 }
119
120 private:
121 /// Query factory from which to obtain the query sequence data
122 CRef<IQueryFactory> m_QueryFactory;
123
124 /// Options to use
125 CRef<CBlastOptions> m_Opts;
126
127 /// Internal core data structures which are used in the preliminary and
128 /// traceback stages of the search
129 CRef<SInternalData> m_InternalData;
130
131 /// Object which runs the preliminary stage of the search
132 CRef<CBlastPrelimSearch> m_PrelimSearch;
133
134 /// Object which runs the traceback stage of the search
135 CRef<CBlastTracebackSearch> m_TbackSearch;
136
137 /// Local DB adaptor (if one was) passed to constructor.
138 CRef<CLocalDbAdapter> m_LocalDbAdapter;
139
140 /// User-specified IBlastSeqInfoSrc implementation
141 /// (may be used for non-standard databases, etc.)
142 CRef<IBlastSeqInfoSrc> m_SeqInfoSrc;
143
144 /// Warnings and error messages
145 TSearchMessages m_Messages;
146
147 // current batch number
148 std::string m_batch_num_str;
149
150 friend class ::CBlastFilterTest;
151 friend class CBl2Seq;
152 };
153
154 inline TSearchMessages
GetSearchMessages() const155 CLocalBlast::GetSearchMessages() const
156 {
157 return m_Messages;
158 }
159
160 END_SCOPE(BLAST)
161 END_NCBI_SCOPE
162
163 /* @} */
164
165 #endif /* ALGO_BLAST_API___LOCAL_BLAST__HPP */
166