librostlab-blast 1.0.1
Loading...
Searching...
No Matches
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
26namespace rostlab {
27
28namespace blast {
29
31struct round {
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
52struct 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
140struct 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
152struct 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
164struct 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;
185 std::vector<rostlab::blast::oneline>
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.
207inline std::ostream& operator<<(std::ostream&, const rostlab::blast::round&);
208inline std::ostream& operator<<(std::ostream&, const rostlab::blast::oneline&);
209inline std::ostream& operator<<(std::ostream&, const rostlab::blast::hsp&);
210inline std::ostream& operator<<(std::ostream&, const rostlab::blast::hit&);
211inline std::ostream& operator<<(std::ostream&, const rostlab::blast::result&);
212} // namespace rostlab
213
214#include <rostlab/aux_functions.h>
215
216namespace rostlab {
218inline
219std::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
226inline
227std::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
234inline
235std::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
245inline
246std::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
253inline
254std::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.
hit(const std::string &__name="", const std::string &__desc="", size_t __length=0)
size_t length
Full length of subject sequence.
std::vector< hsp > hsps
High-scoring segment pair.
std::string s_strand
Subject strand [Plus|Minus].
static std::string methodstr(const ECompoAdjustModes __m)
Translate method code to string.
size_t s_end
Subject end (1-based).
int8_t q_frame
Query frame.
size_t q_end
Query end (1-based).
std::string q_ali
Query alignment string.
static ECompoAdjustModes methfromstr(std::string __m)
Translate method description to mode code.
size_t s_start
Subject start (1-based).
std::string match_line
Match line.
int8_t s_frame
Subject frame.
size_t q_start
Query start (1-based).
ECompoAdjustModes
An collection of constants that specify all permissible modes of composition adjustment.
std::string s_ali
Subject alignment string.
std::string q_strand
Query strand [Plus|Minus].
ECompoAdjustModes method
hsp(double __bit_score=0, size_t __raw_score=0)
One-line description.
double bit_score
Bit score.
oneline(const hit &__h)
oneline(const std::string &__name="", const std::string &__desc="", double __bit_score=0, double __e_value=0)
Blast result for one query.
std::string q_name
Query name.
std::vector< rostlab::blast::oneline > onelines
Vector of all one-line descriptions.
bool converged
Indicates that the search has converged.
std::string tail
Tail part of blast result as a long string.
std::vector< rostlab::blast::hit > hits
Vector of all hits.
size_t db_nseq
Number of sequences in database.
std::vector< std::string > references
size_t db_nletter
Number of letters in database.
std::string q_desc
Query description.
std::vector< rostlab::blast::round > rounds
Vector of iterated blast round information.
std::string db_name
Database name.
size_t q_length
Query length.
Data specific to an iterated blast round.
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)
size_t oneline_idx
Index of first one-line description of this round in vector of all one-line descriptions.
size_t oneline_cnt
Count of one-line descriptions in round.
size_t oneline_new_idx
Index of first one-line description of sequences not found previously in this round....
size_t oneline_new_cnt
Count of one-line descriptions for sequences not found previously.
size_t hit_cnt
Count of hits in round.
static const size_t noidx
size_t hit_idx
Index of first hit of this round in vector of all hits.