librostlab-blast  1.0.1
blast-result.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Laszlo Kajan, Technical University of Munich, Germany
3 
4  This file is part of librostlab.
5 
6  librostlab is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef ROSTLAB_BLAST_RESULT_H
20 #define ROSTLAB_BLAST_RESULT_H
21 #include <stdint.h>
22 #include <sstream>
23 #include <string>
24 #include <vector>
25 
26 namespace rostlab {
27 
28 namespace blast {
29 
31 struct round {
33  size_t oneline_idx;
35  size_t oneline_cnt;
37  size_t hit_idx;
39  size_t hit_cnt;
44  static const size_t noidx = static_cast<size_t>(-1);
45  public:
46  round( size_t __oneline_idx = 0, size_t __oneline_cnt = 0, size_t __hit_idx = 0, size_t __hit_cnt = 0, size_t __oneline_new_idx = noidx, size_t __oneline_new_cnt = 0 ) : oneline_idx( __oneline_idx), oneline_cnt(__oneline_cnt), hit_idx( __hit_idx ), hit_cnt(__hit_cnt), oneline_new_idx(__oneline_new_idx), oneline_new_cnt(__oneline_new_cnt){}
47  virtual ~round(){}
48 };
49 
51 
52 struct hsp {
54 
55  typedef enum ECompoAdjustModes {
61  } ECompoAdjustModes; // ncbi-tools6-6.1.20090809/algo/blast/composition_adjustment/composition_constants.h:51 // a copy is made so we do not have to depend on that library only for this
62  public:
63  double bit_score;
64  size_t raw_score;
65  double e_value;
67  size_t identities;
68  size_t positives;
69  size_t gaps;
71  std::string q_strand;
73  std::string s_strand;
75 
76  int8_t q_frame;
78 
79  int8_t s_frame;
81  size_t q_start;
83  std::string q_ali;
85  size_t q_end;
87  std::string match_line;
89  size_t s_start;
91  std::string s_ali;
93  size_t s_end;
94  public:
95  hsp( double __bit_score = 0, size_t __raw_score = 0 ) : bit_score(__bit_score), raw_score(__raw_score), e_value(0), method(eNoCompositionBasedStats), identities(0), positives(0), gaps(0), q_frame(32), s_frame(32),
96  q_start(0), q_end(0), s_start(0), s_end(0){}
97  virtual ~hsp(){}
98 
100 
106  inline static std::string
108  {
109  switch( __m )
110  {
112  return "Composition-based stats"; break;
114  return "Compositional matrix adjust"; break;
115  default:
116  std::stringstream ss; ss << __m; return ss.str();
117  }
118  }
120 
121  inline static ECompoAdjustModes
122  methfromstr( std::string __m )
123  {
124  if( __m.size() > 0 && __m[ __m.size()-1 ] == '.' ) __m.resize( __m.size()-1 );
125  // 1
126  // 012345678901
127  // Composition-based stats
128  // Compositional matrix adjust
129  if( __m.size() >= 12 )
130  {
131  if( __m[11] == '-' ) return eCompositionBasedStats;
132  if( __m[11] == 'a' ) return eCompositionMatrixAdjust;
133  }
135  }
136 };
137 
139 
140 struct hit {
141  std::string name;
142  std::string desc;
144  size_t length;
145  std::vector<hsp> hsps;
146  public:
147  hit( const std::string& __name = "", const std::string& __desc = "", size_t __length = 0 ) : name(__name), desc(__desc), length(__length) {}
148  virtual ~hit(){}
149 };
150 
152 struct oneline {
153  std::string name;
154  std::string desc;
156  double bit_score;
157  double e_value;
158  oneline( const std::string& __name = "", const std::string& __desc = "", double __bit_score = 0, double __e_value = 0 ) : name(__name), desc(__desc), bit_score(__bit_score), e_value(__e_value){}
159  oneline( const hit& __h ) : name(__h.name), desc(__h.desc), bit_score(__h.hsps.at(0).bit_score), e_value(__h.hsps.at(0).e_value){}
160  virtual ~oneline(){}
161 };
162 
164 struct result {
165  bool empty;
166  std::string blast_version;
167  std::vector<std::string>
170  std::vector<rostlab::blast::round>
173  std::string q_name;
175  std::string q_desc;
177  size_t q_length;
179  std::string db_name;
181  size_t db_nseq;
183  size_t db_nletter;
185  std::vector<rostlab::blast::oneline>
188  bool converged;
190  std::vector<rostlab::blast::hit>
193  std::string tail;
194  public:
195  result() : empty(true), q_length(0), db_nseq(0), db_nletter(0), converged(false) {}
196  virtual ~result(){}
197 
199 
200  operator bool() const { return !empty; }
201 };
202 
203 } // namespace blast
204 
205 // methods declaration - needs to be done before aux_funtions inclusion in
206 // order to properly resolve template scoping with gcc-12.
207 inline std::ostream& operator<<(std::ostream&, const rostlab::blast::round&);
208 inline std::ostream& operator<<(std::ostream&, const rostlab::blast::oneline&);
209 inline std::ostream& operator<<(std::ostream&, const rostlab::blast::hsp&);
210 inline std::ostream& operator<<(std::ostream&, const rostlab::blast::hit&);
211 inline std::ostream& operator<<(std::ostream&, const rostlab::blast::result&);
212 } // namespace rostlab
213 
214 #include <rostlab/aux_functions.h>
215 
216 namespace rostlab {
218 inline
219 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::round& __r )
220 {
221  __os << "ol_idx = " << __r.oneline_idx << ", ol_cnt = " << __r.oneline_cnt << ", hit_idx = " << __r.hit_idx << ", hit_cnt = " << __r.hit_cnt << ", ol_new_idx = " << __r.oneline_new_idx << ", ol_new_cnt = " << __r.oneline_new_cnt;
222  return __os;
223 }
224 
226 inline
227 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::oneline& __r )
228 {
229  __os << "n = " << __r.name << " d = " << __r.desc << ": " << __r.bit_score << " bits, " << __r.e_value << " E";
230  return __os;
231 }
232 
234 inline
235 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::hsp& __r )
236 {
237  __os << "bits = " << __r.bit_score << ", raw = " << __r.raw_score << ", E = " << __r.e_value << ", method = " << blast::hsp::methodstr(__r.method) << ", ident = " << __r.identities <<
238  ", pos = " << __r.positives << ", gaps = " << __r.gaps << ", q_strand = " << __r.q_strand << ", s_strand = " << __r.s_strand << ", q_frame = " << (int)__r.q_frame <<
239  ", s_frame = " << (int)__r.s_frame << ", q_start = " << __r.q_start << ", q_ali = " << __r.q_ali << ", q_end = " << __r.q_end << ", match_line = " << __r.match_line <<
240  ", s_start = " << __r.s_start << ", s_ali = " << __r.s_ali << ", s_end = " << __r.s_end;
241  return __os;
242 }
243 
245 inline
246 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::hit& __r )
247 {
248  __os << "n = " << __r.name << " d = " << __r.desc << " Length = " << __r.length << " " << __r.hsps;
249  return __os;
250 }
251 
253 inline
254 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::result& __r )
255 {
256  __os << __r.blast_version << "\n\nreferences: " << __r.references << "\n\nrounds: " << __r.rounds << "\n\nn = " << __r.q_name << " d = " << __r.q_desc << " (" << __r.q_length <<
257  " letters)\n\nDatabase: " << __r.db_name << " " << __r.db_nseq << " sequences; " << __r.db_nletter << " total letters\n\none-line desc: " << __r.onelines << "\n\n" <<
258  ( __r.converged ? "CONVERGED!\n\n" : "" ) << "hits: " << __r.hits << "\n\n" << __r.tail;
259  return __os;
260 }
261 
262 } // namespace rostlab
263 
264 #endif // ROSTLAB_BLAST_RESULT_H
265 // vim:et:ts=4:ai:
std::ostream & operator<<(std::ostream &, const rostlab::blast::round &)
Stream output operator for blast::round.
Definition: blast-result.h:219
hit(const std::string &__name="", const std::string &__desc="", size_t __length=0)
Definition: blast-result.h:147
size_t length
Full length of subject sequence.
Definition: blast-result.h:144
std::vector< hsp > hsps
Definition: blast-result.h:145
High-scoring segment pair.
Definition: blast-result.h:52
std::string s_strand
Subject strand [Plus|Minus].
Definition: blast-result.h:73
static std::string methodstr(const ECompoAdjustModes __m)
Translate method code to string.
Definition: blast-result.h:107
size_t s_end
Subject end (1-based).
Definition: blast-result.h:93
int8_t q_frame
Query frame.
Definition: blast-result.h:76
size_t q_end
Query end (1-based).
Definition: blast-result.h:85
std::string q_ali
Query alignment string.
Definition: blast-result.h:83
static ECompoAdjustModes methfromstr(std::string __m)
Translate method description to mode code.
Definition: blast-result.h:122
size_t s_start
Subject start (1-based).
Definition: blast-result.h:89
std::string match_line
Match line.
Definition: blast-result.h:87
int8_t s_frame
Subject frame.
Definition: blast-result.h:79
size_t q_start
Query start (1-based).
Definition: blast-result.h:81
ECompoAdjustModes
An collection of constants that specify all permissible modes of composition adjustment.
Definition: blast-result.h:55
std::string s_ali
Subject alignment string.
Definition: blast-result.h:91
std::string q_strand
Query strand [Plus|Minus].
Definition: blast-result.h:71
ECompoAdjustModes method
Definition: blast-result.h:66
hsp(double __bit_score=0, size_t __raw_score=0)
Definition: blast-result.h:95
One-line description.
Definition: blast-result.h:152
double bit_score
Bit score.
Definition: blast-result.h:156
oneline(const hit &__h)
Definition: blast-result.h:159
oneline(const std::string &__name="", const std::string &__desc="", double __bit_score=0, double __e_value=0)
Definition: blast-result.h:158
Blast result for one query.
Definition: blast-result.h:164
std::string q_name
Query name.
Definition: blast-result.h:173
std::vector< rostlab::blast::oneline > onelines
Vector of all one-line descriptions.
Definition: blast-result.h:186
bool converged
Indicates that the search has converged.
Definition: blast-result.h:188
std::string tail
Tail part of blast result as a long string.
Definition: blast-result.h:193
std::vector< rostlab::blast::hit > hits
Vector of all hits.
Definition: blast-result.h:191
size_t db_nseq
Number of sequences in database.
Definition: blast-result.h:181
std::vector< std::string > references
Definition: blast-result.h:168
size_t db_nletter
Number of letters in database.
Definition: blast-result.h:183
std::string blast_version
Definition: blast-result.h:166
std::string q_desc
Query description.
Definition: blast-result.h:175
std::vector< rostlab::blast::round > rounds
Vector of iterated blast round information.
Definition: blast-result.h:171
std::string db_name
Database name.
Definition: blast-result.h:179
size_t q_length
Query length.
Definition: blast-result.h:177
Data specific to an iterated blast round.
Definition: blast-result.h:31
round(size_t __oneline_idx=0, size_t __oneline_cnt=0, size_t __hit_idx=0, size_t __hit_cnt=0, size_t __oneline_new_idx=noidx, size_t __oneline_new_cnt=0)
Definition: blast-result.h:46
size_t oneline_idx
Index of first one-line description of this round in vector of all one-line descriptions.
Definition: blast-result.h:33
size_t oneline_cnt
Count of one-line descriptions in round.
Definition: blast-result.h:35
size_t oneline_new_idx
Index of first one-line description of sequences not found previously in this round....
Definition: blast-result.h:41
size_t oneline_new_cnt
Count of one-line descriptions for sequences not found previously.
Definition: blast-result.h:43
size_t hit_cnt
Count of hits in round.
Definition: blast-result.h:39
static const size_t noidx
Definition: blast-result.h:44
size_t hit_idx
Index of first hit of this round in vector of all hits.
Definition: blast-result.h:37