NCBI C++ ToolKit
blast_scope_src.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef ALGO_BLAST_BLASTINPUT___BLAST_SCOPE_SRC__HPP
2 #define ALGO_BLAST_BLASTINPUT___BLAST_SCOPE_SRC__HPP
3 
4 /* $Id: blast_scope_src.hpp 74834 2016-09-29 12:32:30Z camacho $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Christiam Camacho
30  *
31  * ===========================================================================
32  */
33 
34 /** @file blast_scope_src.hpp
35  * Declares CBlastScopeSource class to create properly configured CScope
36  * objects to invoke the BLAST database data loader first and fall back on to
37  * the Genbank data loader if the former fails (this is configurable at
38  * runtime).
39  */
40 
44 
47  class CScope;
49 BEGIN_SCOPE(blast)
50 
51 /// Configuration structure for the CBlastScopeSource
52 /// @note the choice of data loaders to use to configure the scope as well as
53 /// the BLAST database(s) to search if the BLAST database data loader is used
54 /// can be configured in the NCBI configuration file, BLAST section.
55 /// For details, refer to the section 'Configuring BLAST' in the BLAST+ user
56 /// manual
58 
59  /// Default protein BLAST database to use for the BLAST DB data loaders
60  static const char* kDefaultProteinBlastDb;
61  /// Default nucleotide BLAST database to use for the BLAST DB data loaders
62  static const char* kDefaultNucleotideBlastDb;
63 
64  /// Configuration options for the BlastScopeSource
65  enum EConfigOpts {
66  /// Use the local BLAST database loader first, if this fails, use the
67  /// remote BLAST database data loader
68  eUseBlastDbDataLoader = (0x1 << 0),
69  /// Use the Genbank data loader
70  eUseGenbankDataLoader = (0x1 << 1),
71  /// Do not add any data loaders
72  eUseNoDataLoaders = (0x1 << 2),
73  eDefault = (eUseBlastDbDataLoader | eUseGenbankDataLoader)
74  };
75 
76  /// Constructor which relies on the configuration file to set the BLAST
77  /// database to use
78  /// @param load_proteins is this object going to load/read proteins only
79  /// [in]
80  /// @param options configuration options [in]
81  SDataLoaderConfig(bool load_proteins, EConfigOpts options = eDefault)
82  {
83  x_Init(options, kEmptyStr, load_proteins);
84  }
85 
86  /// Constructor which allows the specification of a BLAST database to use
87  /// to initialize the BLAST DB data loader, without the option to override
88  /// this at runtime via the configuration file
89  /// @param dbname name of BLAST database [in]
90  /// @param protein_data is this object going to load/read proteins only
91  /// [in]
92  /// @param options configuration options [in]
93  SDataLoaderConfig(const string& dbname, bool protein_data,
94  EConfigOpts options = eDefault)
95  {
96  x_Init(options, dbname, protein_data);
97  }
98 
99  /// Configures the BLAST database data loader to optimize the retrieval of
100  /// *entire* large sequences.
101  /// @note This option only has effect upon a BLAST database data loader's
102  /// first initialization. If this setting should change on the same BLAST
103  /// database, the data loader must be revoked from the object manager (this
104  /// can be achieved with CBlastScopeSource::RevokeBlastDbDataLoader()).
105  /// @param value TRUE to turn on, FALSE to turn off
107  m_UseFixedSizeSlices = !value;
108  }
109 
110  /// Determine whether either of the data loaders should be used
111  bool UseDataLoaders() const { return m_UseBlastDbs || m_UseGenbank; }
112 
113  /// Use the BLAST database data loaders
115  /// Name of the BLAST database to use (non-empty if m_UseBlastDbs is true)
117 
118  /// Is this intended to load protein sequences
120 
121  /// Use the Genbank data loader
123 
124  /// Equality operator
125  bool operator==(const SDataLoaderConfig& rhs) const;
126  /// Inequality operator
127  bool operator!=(const SDataLoaderConfig& rhs) const;
128 
129  /// Argument to configure BLAST database data loader
131 private:
132  /// Initialization method
133  /// @param options configuration options [in]
134  /// @param dbname name of BLAST database [in]
135  /// @param load_proteins is this object going to load/read proteins only
136  /// [in]
137  void x_Init(EConfigOpts options, const string& dbname, bool load_proteins);
138 
139  /// Load the DATA_LOADERS configuration value from the config file
140  void x_LoadDataLoadersConfig(const CNcbiRegistry& registry);
141 
142  /// Load the BLAST database configured to search for the blastdb
143  /// DATA_LOADERS option from the config file
144  void x_LoadBlastDbDataLoaderConfig(const CNcbiRegistry& registry);
145 };
146 
147 
148 /// Class whose purpose is to create CScope objects which have data loaders
149 /// added with different priorities, so that the BLAST database data loader is
150 /// used first, then the Genbank data loader. By default, this object tries to
151 /// initialize the local BLAST database data loader first, if this cannot be
152 /// initialized, the remote BLAST database loader is initialized; then the
153 /// Genbank data loader is initialized.
154 /// The selection of data loaders can be configured via the SDataLoaderConfig
155 /// object and the DATA_LOADERS entry of the BLAST section of an NCBI
156 /// configuration file, the latter setting trumping the selection of the
157 /// SDataLoaderConfig object.
158 /// @note all data loaders are registered as non-default data loaders
160 {
161 public:
162  /// Convenience typedef
164 
165  /// Constructor which only registers the Genbank data loader
166  /// @param load_proteins is this object going to load/read proteins only
167  /// [in]
168  CBlastScopeSource(bool load_proteins = true,
169  CObjectManager* objmgr = NULL);
170 
171  /// Constructor with explicit data loader configuration object
173  CObjectManager* objmgr = NULL);
174 
175  /// Constructor which registers the specified BLAST database handle and
176  /// Genbank data loaders
178  CObjectManager* objmgr = NULL);
179 
180  /// Create a new, properly configured CScope
181  CRef<objects::CScope> NewScope();
182 
183  /// Add the data loader configured in the object to the provided scope.
184  /// Use when the scope already has some sequences loaded in it
185  /// @param scope scope to add the data loaders to [in|out]
186  /// @throw Null pointer exception if scope is NULL
187  void AddDataLoaders(CRef<objects::CScope> scope);
188 
189  /// Removes the BLAST database data loader from the object manager.
190  void RevokeBlastDbDataLoader();
191 
192  /// Retrieves the BLAST database data loader name initialized by this
193  /// instance
194  string GetBlastDbLoaderName() const { return m_BlastDbLoaderName; }
195 
196 private:
197  /// Our reference to the object manager
199  /// The configuration for this object
201  /// Name of the BLAST database data loader
203  /// Name of the Genbank data loader
205 
206  /// Initializes the BLAST database data loader
207  /// @param dbname name of the BLAST database [in]
208  /// @param dbtype molecule type of the database above [in]
209  void x_InitBlastDatabaseDataLoader(const string& dbname, EDbType dbtype);
210  /// Initializes the BLAST database data loader
211  /// @param db_handle Handle to a BLAST database [in]
212  void x_InitBlastDatabaseDataLoader(CRef<CSeqDB> db_handle);
213  /// Initialize the Genbank data loader
214  void x_InitGenbankDataLoader();
215 
216  /// Data loader priority for BLAST database data loader (if multiple BLAST
217  /// database data loaders are registered, they are added in decreasing
218  /// priority)
219  static const int kBlastDbLoaderPriority = 80;
220  /// Data loader priority for Genbank data loader
221  static const int kGenbankLoaderPriority = 99;
222 };
223 
224 END_SCOPE(blast)
226 
227 #endif /* ALGO_BLAST_BLASTINPUT___BLAST_SCOPE_SRC__HPP */
bool operator!=(const _Ht_iterator< _Val, _Nonconst_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__x, const _Ht_iterator< _Val, _Const_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__y)
Definition: _hashtable.h:173
Data loader implementation that uses the blast databases.
Defines to provide correct exporting from BLAST DLL in Windows.
EDbType
Describes the type of blast database to use.
Definition: bdbloader.hpp:57
Class whose purpose is to create CScope objects which have data loaders added with different prioriti...
string m_GbLoaderName
Name of the Genbank data loader.
string GetBlastDbLoaderName() const
Retrieves the BLAST database data loader name initialized by this instance.
string m_BlastDbLoaderName
Name of the BLAST database data loader.
CRef< objects::CObjectManager > m_ObjMgr
Our reference to the object manager.
SDataLoaderConfig m_Config
The configuration for this object.
CBlastDbDataLoader::EDbType EDbType
Convenience typedef.
CNcbiRegistry –.
Definition: ncbireg.hpp:913
CObjectManager –.
CObject –.
Definition: ncbiobj.hpp:180
CScope –.
Definition: scope.hpp:92
static CMemoryRegistry registry
Definition: cn3d_tools.cpp:81
char value[7]
Definition: config.c:431
bool operator==(const CEquivRange &A, const CEquivRange &B)
@ eDefault
Definition: ncbi_types.h:112
#define NULL
Definition: ncbistd.hpp:225
#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
#define NCBI_BLASTINPUT_EXPORT
Definition: ncbi_export.h:336
char * dbname(DBPROCESS *dbproc)
Get name of current database.
Definition: dblib.c:6929
The Object manager core.
Configuration structure for the CBlastScopeSource.
bool m_UseGenbank
Use the Genbank data loader.
static const char * kDefaultProteinBlastDb
Default protein BLAST database to use for the BLAST DB data loaders.
string m_BlastDbName
Name of the BLAST database to use (non-empty if m_UseBlastDbs is true)
bool UseDataLoaders() const
Determine whether either of the data loaders should be used.
static const char * kDefaultNucleotideBlastDb
Default nucleotide BLAST database to use for the BLAST DB data loaders.
SDataLoaderConfig(bool load_proteins, EConfigOpts options=eDefault)
Constructor which relies on the configuration file to set the BLAST database to use.
void OptimizeForWholeLargeSequenceRetrieval(bool value=true)
Configures the BLAST database data loader to optimize the retrieval of *entire* large sequences.
bool m_UseBlastDbs
Use the BLAST database data loaders.
bool m_UseFixedSizeSlices
Argument to configure BLAST database data loader.
EConfigOpts
Configuration options for the BlastScopeSource.
bool m_IsLoadingProteins
Is this intended to load protein sequences.
SDataLoaderConfig(const string &dbname, bool protein_data, EConfigOpts options=eDefault)
Constructor which allows the specification of a BLAST database to use to initialize the BLAST DB data...
Modified on Sat Mar 02 10:54:45 2024 by modify_doxy.py rev. 669887