1 /* $Id: rps_aux.hpp 579005 2019-01-29 14:28:02Z rackerst $
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 rps_aux.hpp
31 /// Declares auxiliary classes to manage RPS-BLAST related C-structures
32 
33 #ifndef ALGO_BLAST_API__RPS_AUX___HPP
34 #define ALGO_BLAST_API__RPS_AUX___HPP
35 
36 #include <algo/blast/core/blast_export.h>
37 #include <algo/blast/core/blast_aalookup.h> // for BlastRPSLookupTable
38 #include <algo/blast/core/blast_rps.h>
39 
40 /** @addtogroup AlgoBlast
41  *
42  * @{
43  */
44 
45 BEGIN_NCBI_SCOPE
46 BEGIN_SCOPE(blast)
47 
48 // Forward declarations
49 class CBlastRPSAuxInfo;
50 class CRpsAuxFile;
51 class CRpsLookupTblFile;
52 class CRpsPssmFile;
53 class CRpsFreqsFile;
54 class CRpsObsrFile;
55 class CRpsFreqRatiosFile;
56 
57 // The BLAST Engine currently needs the BlastRPSInfo structure for both the
58 // preliminary stage and the traceback search. In practice, the setup code
59 // needs the aux_info field to copy the orig_score_matrix field, gap costs and
60 // scaling factor. The preliminary stage needs its lookup_header and
61 // profile_header fields, and the traceback search needs the profile_header
62 // field and the aux_info's karlin_k field. This suggests that a better
63 // organization might be needed.
64 
65 /// Wrapper class to manage the BlastRPSInfo structure, as currently
66 /// there aren't any allocation or deallocation functions for this structure in
67 /// the CORE of BLAST. This class is meant to be kept in a CRef<>.
68 class NCBI_XBLAST_EXPORT CBlastRPSInfo : public CObject {
69 public:
70 
71     /// Flags for opening database files
72     enum EOpenFlags {
73         // Open lookup table file
74         fLookupTableFile = 1,
75         /// Open pssm file
76         fPssmFile = 2,
77         /// Open auxiliary information file
78         fAuxInfoFile = 4,
79         /// Open residue frequencies file
80         fFrequenciesFile = 8,
81         /// Open file with numbers of independent observations
82         fObservationsFile = 16,
83         /// Open file with frequency ratios
84         fFreqRatiosFile = 32,
85 
86         // The freq ratios file is large and needed only in the traceback.
87         // It may be needed to add closing and loading separate files.
88 
89         /// Flags set for RPS-BLAST
90         fRpsBlast = fLookupTableFile | fPssmFile | fAuxInfoFile,
91 
92         /// Flags set for DELTA-BLAST
93         fDeltaBlast = fFrequenciesFile | fObservationsFile,
94 
95         /// Flags set for RPS-BLAST running in CBS mode
96         fRpsBlastWithCBS = fRpsBlast | fFreqRatiosFile
97     };
98 
99 public:
100     /// Parametrized constructor
101     /// @param rps_dbname name of the RPS-BLAST database
102     CBlastRPSInfo(const string& rps_dbname);
103 
104     /// Parametrized constructor
105     /// @param rps_dbname name of the RPS-BLAST database
106     /// @param flags Flags for which database files to open
107     CBlastRPSInfo(const string& rps_dbname, int flags);
108 
109     /// Destructor
110     ~CBlastRPSInfo();
111 
112     /// Accessor for the underlying C structure (managed by this class)
113     const BlastRPSInfo* operator()() const;
114 
115     /// Returns the scaling factor used to build RPS-BLAST database
116     double GetScalingFactor() const;
117 
118     /// Returns the name of the scoring matrix used to build the RPS-BLAST
119     /// database
120     const char* GetMatrixName() const;
121 
122     // FIXME: the following two methods are an interface that return the
123     // permissible gap costs associated with the matrix used when building the
124     // RPS-BLAST database... these could be removed if some other interface
125     // provided those given the matrix name.
126 
127     /// Returns the gap opening cost associated with the scoring matrix above
128     int GetGapOpeningCost() const;
129 
130     /// Returns the gap extension cost associated with the scoring matrix above
131     int GetGapExtensionCost() const;
132 
133 
134 protected:
135 
136     /// Initialize attributes
137     void x_Init(const string& rps_dbname, int flags);
138 
139 private:
140     /// Prohibit copy-constructor
141     CBlastRPSInfo(const CBlastRPSInfo& rhs);
142     /// Prohibit assignment operator
143     CBlastRPSInfo& operator=(const CBlastRPSInfo& rhs);
144 
145     /// The auxiliary RPS-BLAST file (.aux)
146     CRef<CRpsAuxFile> m_AuxFile;
147     /// The PSSM RPS-BLAST file (.rps)
148     CRef<CRpsPssmFile> m_PssmFile;
149     /// The lookup table RPS-BLAST file (.loo)
150     CRef<CRpsLookupTblFile> m_LutFile;
151 
152     /// Weighted residue frequencies file (.wcounts)
153     /// used by delta-blast
154     CRef<CRpsFreqsFile> m_FreqsFile;
155 
156     /// Number of independent observations file (.obsr)
157     /// used by delta-blast
158     CRef<CRpsObsrFile> m_ObsrFile;
159 
160     /// Frequency ratios file (.freq)
161     /// used for composition based statistics and cobalt
162     CRef<CRpsFreqRatiosFile> m_FreqRatiosFile;
163 
164 
165     /// Pointer which contains pointers to data managed by the data members
166     /// above
167     unique_ptr<BlastRPSInfo> m_RpsInfo;
168 };
169 
170 END_SCOPE(blast)
171 END_NCBI_SCOPE
172 
173 /* @} */
174 
175 #endif  /* ALGO_BLAST_API__RPS_AUX___HPP */
176