1 /* $Id: local_db_adapter.hpp 591152 2019-08-12 11:18:21Z fongah2 $
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 local_db_adapter.hpp
31 * Declares class which provides internal BLAST database representations to the
32 * internal BLAST APIs
33 */
34
35 #ifndef ALGO_BLAST_API___LOCAL_DB_ADAPTER_HPP
36 #define ALGO_BLAST_API___LOCAL_DB_ADAPTER_HPP
37
38 #include <algo/blast/core/blast_seqsrc.h>
39 #include <algo/blast/api/uniform_search.hpp> // for CSearchDatabase
40 #include <objtools/blast/seqdb_reader/seqdb.hpp> // for CSeqDB
41 #include <algo/blast/api/sseqloc.hpp> // for TSeqLocVector
42
43 /** @addtogroup AlgoBlast
44 *
45 * @{
46 */
47
48 // Forward declaration
49 struct BlastSeqSrc;
50
51 BEGIN_NCBI_SCOPE
52 BEGIN_SCOPE(blast)
53
54 // Forward declaration
55 class IBlastSeqInfoSrc;
56
57 /// Interface to create a BlastSeqSrc suitable for use in CORE BLAST from a
58 /// a variety of BLAST database/subject representations
59 class NCBI_XBLAST_EXPORT CLocalDbAdapter : public CObject
60 {
61 public:
62 /// Constructor
63 /// @param dbinfo
64 /// Description of BLAST database
65 CLocalDbAdapter(const CSearchDatabase& dbinfo);
66
67 /// Constructor
68 /// @param subject_sequences
69 /// Set of sequences which should be used as subjects
70 /// @param opts_handle
71 /// Options to be used (needed to create the ILocalQueryData)
72 /// @param dbscan_mode Database search mode (as opposed to pairwise)
73 CLocalDbAdapter(CRef<IQueryFactory> subject_sequences,
74 CConstRef<CBlastOptionsHandle> opts_handle,
75 bool dbscan_mode=false);
76
77 /// Constructor taking custom BlastSeqSrc and IBlastSeqInfoSrc objects
78 /// @param seqSrc
79 /// Custom BlastSeqSrc implementation provided by the user
80 /// @param seqInfoSrc
81 /// Custom IBlastSeqInfoSrc implementation provided by the user
82 CLocalDbAdapter(BlastSeqSrc* seqSrc,
83 CRef<IBlastSeqInfoSrc> seqInfoSrc);
84
85 /// Destructor
86 virtual ~CLocalDbAdapter();
87
88 /// This method should be called so that if the implementation has an
89 /// internal "bookmark" of the chunks of the database it has assigned to
90 /// different threads, this can be reset at the start of a PSI-BLAST
91 /// iteration (or when reusing the same object to iterate over the
92 /// database/subjects when the query is split).
93 /// This method should be called before calling MakeSeqSrc() to
94 /// ensure proper action on retrieving the BlastSeqSrc (in some cases it
95 /// might cause a re-construction of the underlying BlastSeqSrc
96 /// implementation). Note that in some cases, this operation might not apply
97 void ResetBlastSeqSrcIteration();
98
99 /// Retrieves or constructs the BlastSeqSrc
100 /// @note ownership of the constructed object is handled by this class
101 BlastSeqSrc* MakeSeqSrc();
102
103 /// Retrieves or constructs the IBlastSeqInfoSrc
104 /// @note ownership of the constructed object is handled by this class
105 IBlastSeqInfoSrc* MakeSeqInfoSrc();
106
107 /// Retrieve the database filtering algorithm
108 /// @returns -1 if not none was used, otherwise the filtering algorithm ID
109 int GetFilteringAlgorithm();
110
111 /// Retrieve the database filtering id from key
112 /// @returns kEmptyStr if not none was found, otherwise the filtering algorithm key
113 string GetFilteringAlgorithmKey();
114
115
116 /// Returns true if this object represents protein or nucleotide sequences
117 bool IsProtein() const;
118
119 /// Returns the database name if appropriate, else kEmptyStr for subject
120 /// sequences
GetDatabaseName() const121 string GetDatabaseName() const { return m_DbName; }
122
123 /// Returns true if this object represents a BLAST database
IsBlastDb() const124 bool IsBlastDb() const { return m_DbName != kEmptyStr; }
125
126 /// Returns true if this is not a database but is database scanning mode
IsDbScanMode() const127 bool IsDbScanMode() const { return m_DbScanMode; }
128
GetSearchDatabase()129 CRef<CSearchDatabase> GetSearchDatabase() {return m_DbInfo;}
130 private:
131 /// Pointer to the BlastSeqSrc this object owns and manages
132 BlastSeqSrc* m_SeqSrc;
133
134 /// Pointer to the IBlastSeqInfoSrc
135 CRef<IBlastSeqInfoSrc> m_SeqInfoSrc;
136
137 /// Object containing BLAST database description
138 CRef<CSearchDatabase> m_DbInfo;
139
140 /// IQueryFactory containing the subject sequences
141 CRef<IQueryFactory> m_SubjectFactory;
142
143 /// Options to be used when instantiating the subject sequences
144 CConstRef<CBlastOptionsHandle> m_OptsHandle;
145
146 /// This is initialized ONLY if the m_SubjectFactory is of type
147 /// CObjMgr_QueryFactory, case in which it's not empty. This is needed to
148 /// handle delta sequences as input and it uses the object manager APIs
149 TSeqLocVector m_Subjects;
150
151 /// This is initialized ONLY if this object represents a BLAST database
152 const string m_DbName;
153
154 /// Specifies that bl2seq search run in database scan mode (not pairwise)
155 bool m_DbScanMode;
156
157 /// Prohibit copy-constructor
158 CLocalDbAdapter(const CLocalDbAdapter&);
159 /// Prohibit assignment operator
160 CLocalDbAdapter & operator=(const CLocalDbAdapter&);
161 };
162
163 inline int
GetFilteringAlgorithm()164 CLocalDbAdapter::GetFilteringAlgorithm()
165 {
166 return (m_DbInfo.Empty() ? -1 : m_DbInfo->GetFilteringAlgorithm());
167 }
168
169 END_SCOPE(BLAST)
170 END_NCBI_SCOPE
171
172 /* @} */
173
174 #endif /* ALGO_BLAST_API___LOCAL_DB_ADAPTER__HPP */
175
176