Loading...
Searching...
No Matches
blast-result.h
Go to the documentation of this file.
/*
Copyright (C) 2011 Laszlo Kajan, Technical University of Munich, Germany
This file is part of librostlab.
librostlab is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ROSTLAB_BLAST_RESULT_H
#define ROSTLAB_BLAST_RESULT_H
#include <stdint.h>
#include <sstream>
#include <string>
#include <vector>
namespace rostlab {
namespace blast {
struct round {
size_t oneline_idx;
size_t oneline_cnt;
size_t hit_idx;
size_t hit_cnt;
size_t oneline_new_idx;
size_t oneline_new_cnt;
static const size_t noidx = static_cast<size_t>(-1);
public:
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){}
virtual ~round(){}
};
struct hsp {
typedef enum ECompoAdjustModes {
eNoCompositionBasedStats = 0,
eCompositionBasedStats = 1,
eCompositionMatrixAdjust = 2,
eCompoForceFullMatrixAdjust = 3,
eNumCompoAdjustModes
} 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
public:
double bit_score;
size_t raw_score;
double e_value;
ECompoAdjustModes method;
size_t identities;
size_t positives;
size_t gaps;
std::string q_strand;
std::string s_strand;
int8_t q_frame;
int8_t s_frame;
size_t q_start;
std::string q_ali;
size_t q_end;
std::string match_line;
size_t s_start;
std::string s_ali;
size_t s_end;
public:
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),
q_start(0), q_end(0), s_start(0), s_end(0){}
virtual ~hsp(){}
inline static std::string
methodstr( const ECompoAdjustModes __m )
{
switch( __m )
{
case eCompositionBasedStats:
return "Composition-based stats"; break;
case eCompositionMatrixAdjust:
return "Compositional matrix adjust"; break;
default:
std::stringstream ss; ss << __m; return ss.str();
}
}
inline static ECompoAdjustModes
methfromstr( std::string __m )
{
if( __m.size() > 0 && __m[ __m.size()-1 ] == '.' ) __m.resize( __m.size()-1 );
// 1
// 012345678901
// Composition-based stats
// Compositional matrix adjust
if( __m.size() >= 12 )
{
if( __m[11] == '-' ) return eCompositionBasedStats;
if( __m[11] == 'a' ) return eCompositionMatrixAdjust;
}
return eNoCompositionBasedStats;
}
};
struct hit {
std::string name;
std::string desc;
size_t length;
std::vector<hsp> hsps;
public:
hit( const std::string& __name = "", const std::string& __desc = "", size_t __length = 0 ) : name(__name), desc(__desc), length(__length) {}
virtual ~hit(){}
};
struct oneline {
std::string name;
std::string desc;
double bit_score;
double e_value;
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){}
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){}
virtual ~oneline(){}
};
struct result {
bool empty;
std::string blast_version;
std::vector<std::string>
references;
std::vector<rostlab::blast::round>
rounds;
std::string q_name;
std::string q_desc;
size_t q_length;
std::string db_name;
size_t db_nseq;
size_t db_nletter;
std::vector<rostlab::blast::oneline>
onelines;
bool converged;
std::vector<rostlab::blast::hit>
hits;
std::string tail;
public:
result() : empty(true), q_length(0), db_nseq(0), db_nletter(0), converged(false) {}
virtual ~result(){}
operator bool() const { return !empty; }
};
} // namespace blast
// methods declaration - needs to be done before aux_funtions inclusion in
// order to properly resolve template scoping with gcc-12.
inline std::ostream& operator<<(std::ostream&, const rostlab::blast::round&);
inline std::ostream& operator<<(std::ostream&, const rostlab::blast::oneline&);
inline std::ostream& operator<<(std::ostream&, const rostlab::blast::hsp&);
inline std::ostream& operator<<(std::ostream&, const rostlab::blast::hit&);
inline std::ostream& operator<<(std::ostream&, const rostlab::blast::result&);
} // namespace rostlab
#include <rostlab/aux_functions.h>
namespace rostlab {
inline
std::ostream& operator<<( std::ostream& __os, const rostlab::blast::round& __r )
{
__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;
return __os;
}
inline
std::ostream& operator<<( std::ostream& __os, const rostlab::blast::oneline& __r )
{
__os << "n = " << __r.name << " d = " << __r.desc << ": " << __r.bit_score << " bits, " << __r.e_value << " E";
return __os;
}
inline
std::ostream& operator<<( std::ostream& __os, const rostlab::blast::hsp& __r )
{
__os << "bits = " << __r.bit_score << ", raw = " << __r.raw_score << ", E = " << __r.e_value << ", method = " << blast::hsp::methodstr(__r.method) << ", ident = " << __r.identities <<
", pos = " << __r.positives << ", gaps = " << __r.gaps << ", q_strand = " << __r.q_strand << ", s_strand = " << __r.s_strand << ", q_frame = " << (int)__r.q_frame <<
", 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 <<
", s_start = " << __r.s_start << ", s_ali = " << __r.s_ali << ", s_end = " << __r.s_end;
return __os;
}
inline
std::ostream& operator<<( std::ostream& __os, const rostlab::blast::hit& __r )
{
__os << "n = " << __r.name << " d = " << __r.desc << " Length = " << __r.length << " " << __r.hsps;
return __os;
}
inline
std::ostream& operator<<( std::ostream& __os, const rostlab::blast::result& __r )
{
__os << __r.blast_version << "\n\nreferences: " << __r.references << "\n\nrounds: " << __r.rounds << "\n\nn = " << __r.q_name << " d = " << __r.q_desc << " (" << __r.q_length <<
" letters)\n\nDatabase: " << __r.db_name << " " << __r.db_nseq << " sequences; " << __r.db_nletter << " total letters\n\none-line desc: " << __r.onelines << "\n\n" <<
( __r.converged ? "CONVERGED!\n\n" : "" ) << "hits: " << __r.hits << "\n\n" << __r.tail;
return __os;
}
} // namespace rostlab
#endif // ROSTLAB_BLAST_RESULT_H
// vim:et:ts=4:ai:
rostlab::blast
Definition blast-parser-driver.h:47
rostlab
Definition blast-parser-driver.h:45
rostlab::operator<<
std::ostream & operator<<(std::ostream &, const rostlab::blast::round &)
Stream output operator for blast::round.
Definition blast-result.h:219
rostlab::blast::hit
Blast hit.
Definition blast-result.h:140
rostlab::blast::hit::~hit
virtual ~hit()
Definition blast-result.h:148
rostlab::blast::hit::desc
std::string desc
Definition blast-result.h:142
rostlab::blast::hit::hit
hit(const std::string &__name="", const std::string &__desc="", size_t __length=0)
Definition blast-result.h:147
rostlab::blast::hit::length
size_t length
Full length of subject sequence.
Definition blast-result.h:144
rostlab::blast::hit::hsps
std::vector< hsp > hsps
Definition blast-result.h:145
rostlab::blast::hit::name
std::string name
Definition blast-result.h:141
rostlab::blast::hsp
High-scoring segment pair.
Definition blast-result.h:52
rostlab::blast::hsp::positives
size_t positives
Definition blast-result.h:68
rostlab::blast::hsp::s_strand
std::string s_strand
Subject strand [Plus|Minus].
Definition blast-result.h:73
rostlab::blast::hsp::s_end
size_t s_end
Subject end (1-based).
Definition blast-result.h:93
rostlab::blast::hsp::e_value
double e_value
Definition blast-result.h:65
rostlab::blast::hsp::q_frame
int8_t q_frame
Query frame.
Definition blast-result.h:76
rostlab::blast::hsp::bit_score
double bit_score
Definition blast-result.h:63
rostlab::blast::hsp::q_end
size_t q_end
Query end (1-based).
Definition blast-result.h:85
rostlab::blast::hsp::q_ali
std::string q_ali
Query alignment string.
Definition blast-result.h:83
rostlab::blast::hsp::s_start
size_t s_start
Subject start (1-based).
Definition blast-result.h:89
rostlab::blast::hsp::match_line
std::string match_line
Match line.
Definition blast-result.h:87
rostlab::blast::hsp::gaps
size_t gaps
Definition blast-result.h:69
rostlab::blast::hsp::s_frame
int8_t s_frame
Subject frame.
Definition blast-result.h:79
rostlab::blast::hsp::raw_score
size_t raw_score
Definition blast-result.h:64
rostlab::blast::hsp::q_start
size_t q_start
Query start (1-based).
Definition blast-result.h:81
rostlab::blast::hsp::ECompoAdjustModes
ECompoAdjustModes
An collection of constants that specify all permissible modes of composition adjustment.
Definition blast-result.h:55
rostlab::blast::hsp::eNoCompositionBasedStats
@ eNoCompositionBasedStats
Definition blast-result.h:56
rostlab::blast::hsp::eCompositionMatrixAdjust
@ eCompositionMatrixAdjust
Definition blast-result.h:58
rostlab::blast::hsp::eNumCompoAdjustModes
@ eNumCompoAdjustModes
Definition blast-result.h:60
rostlab::blast::hsp::eCompositionBasedStats
@ eCompositionBasedStats
Definition blast-result.h:57
rostlab::blast::hsp::eCompoForceFullMatrixAdjust
@ eCompoForceFullMatrixAdjust
Definition blast-result.h:59
rostlab::blast::hsp::s_ali
std::string s_ali
Subject alignment string.
Definition blast-result.h:91
rostlab::blast::hsp::~hsp
virtual ~hsp()
Definition blast-result.h:97
rostlab::blast::hsp::identities
size_t identities
Definition blast-result.h:67
rostlab::blast::hsp::q_strand
std::string q_strand
Query strand [Plus|Minus].
Definition blast-result.h:71
rostlab::blast::hsp::method
ECompoAdjustModes method
Definition blast-result.h:66
rostlab::blast::hsp::hsp
hsp(double __bit_score=0, size_t __raw_score=0)
Definition blast-result.h:95
rostlab::blast::oneline
One-line description.
Definition blast-result.h:152
rostlab::blast::oneline::e_value
double e_value
Definition blast-result.h:157
rostlab::blast::oneline::bit_score
double bit_score
Bit score.
Definition blast-result.h:156
rostlab::blast::oneline::name
std::string name
Definition blast-result.h:153
rostlab::blast::oneline::oneline
oneline(const hit &__h)
Definition blast-result.h:159
rostlab::blast::oneline::~oneline
virtual ~oneline()
Definition blast-result.h:160
rostlab::blast::oneline::oneline
oneline(const std::string &__name="", const std::string &__desc="", double __bit_score=0, double __e_value=0)
Definition blast-result.h:158
rostlab::blast::oneline::desc
std::string desc
Definition blast-result.h:154
rostlab::blast::result
Blast result for one query.
Definition blast-result.h:164
rostlab::blast::result::q_name
std::string q_name
Query name.
Definition blast-result.h:173
rostlab::blast::result::onelines
std::vector< rostlab::blast::oneline > onelines
Vector of all one-line descriptions.
Definition blast-result.h:186
rostlab::blast::result::converged
bool converged
Indicates that the search has converged.
Definition blast-result.h:188
rostlab::blast::result::empty
bool empty
Definition blast-result.h:165
rostlab::blast::result::tail
std::string tail
Tail part of blast result as a long string.
Definition blast-result.h:193
rostlab::blast::result::hits
std::vector< rostlab::blast::hit > hits
Vector of all hits.
Definition blast-result.h:191
rostlab::blast::result::db_nseq
size_t db_nseq
Number of sequences in database.
Definition blast-result.h:181
rostlab::blast::result::references
std::vector< std::string > references
Definition blast-result.h:168
rostlab::blast::result::db_nletter
size_t db_nletter
Number of letters in database.
Definition blast-result.h:183
rostlab::blast::result::~result
virtual ~result()
Definition blast-result.h:196
rostlab::blast::result::blast_version
std::string blast_version
Definition blast-result.h:166
rostlab::blast::result::q_desc
std::string q_desc
Query description.
Definition blast-result.h:175
rostlab::blast::result::result
result()
Definition blast-result.h:195
rostlab::blast::result::rounds
std::vector< rostlab::blast::round > rounds
Vector of iterated blast round information.
Definition blast-result.h:171
rostlab::blast::result::db_name
std::string db_name
Database name.
Definition blast-result.h:179
rostlab::blast::result::q_length
size_t q_length
Query length.
Definition blast-result.h:177
rostlab::blast::round
Data specific to an iterated blast round.
Definition blast-result.h:31
rostlab::blast::round::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)
Definition blast-result.h:46
rostlab::blast::round::oneline_idx
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
rostlab::blast::round::oneline_cnt
size_t oneline_cnt
Count of one-line descriptions in round.
Definition blast-result.h:35
rostlab::blast::round::~round
virtual ~round()
Definition blast-result.h:47
rostlab::blast::round::oneline_new_idx
size_t oneline_new_idx
Index of first one-line description of sequences not found previously in this round....
Definition blast-result.h:41
rostlab::blast::round::oneline_new_cnt
size_t oneline_new_cnt
Count of one-line descriptions for sequences not found previously.
Definition blast-result.h:43
rostlab::blast::round::hit_cnt
size_t hit_cnt
Count of hits in round.
Definition blast-result.h:39
rostlab::blast::round::noidx
static const size_t noidx
Definition blast-result.h:44
rostlab::blast::round::hit_idx
size_t hit_idx
Index of first hit of this round in vector of all hits.
Definition blast-result.h:37