librostlab-blast
1.0.0
|
00001 /* 00002 Copyright (C) 2011 Laszlo Kajan, Technical University of Munich, Germany 00003 00004 This file is part of librostlab. 00005 00006 librostlab is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Lesser General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 #ifndef ROSTLAB_BLAST_RESULT_H 00020 #define ROSTLAB_BLAST_RESULT_H 00021 #include <stdint.h> 00022 #include <sstream> 00023 #include <string> 00024 #include <vector> 00025 #include <rostlab/aux_functions.h> 00026 00027 namespace rostlab { 00028 00029 namespace blast { 00030 00032 struct round { 00034 size_t oneline_idx; 00036 size_t oneline_cnt; 00038 size_t hit_idx; 00040 size_t hit_cnt; 00042 size_t oneline_new_idx; 00044 size_t oneline_new_cnt; 00045 static const size_t noidx = static_cast<size_t>(-1); 00046 public: 00047 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){} 00048 virtual ~round(){} 00049 }; 00050 00052 00053 struct hsp { 00055 00056 typedef enum ECompoAdjustModes { 00057 eNoCompositionBasedStats = 0, 00058 eCompositionBasedStats = 1, 00059 eCompositionMatrixAdjust = 2, 00060 eCompoForceFullMatrixAdjust = 3, 00061 eNumCompoAdjustModes 00062 } 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 00063 public: 00064 double bit_score; 00065 size_t raw_score; 00066 double e_value; 00067 ECompoAdjustModes method; 00068 size_t identities; 00069 size_t positives; 00070 size_t gaps; 00072 std::string q_strand; 00074 std::string s_strand; 00076 00077 int8_t q_frame; 00079 00080 int8_t s_frame; 00082 size_t q_start; 00084 std::string q_ali; 00086 size_t q_end; 00088 std::string match_line; 00090 size_t s_start; 00092 std::string s_ali; 00094 size_t s_end; 00095 public: 00096 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), 00097 q_start(0), q_end(0), s_start(0), s_end(0){} 00098 virtual ~hsp(){} 00099 00101 00107 inline static std::string 00108 methodstr( const ECompoAdjustModes __m ) 00109 { 00110 switch( __m ) 00111 { 00112 case eCompositionBasedStats: 00113 return "Composition-based stats"; break; 00114 case eCompositionMatrixAdjust: 00115 return "Compositional matrix adjust"; break; 00116 default: 00117 std::stringstream ss; ss << __m; return ss.str(); 00118 } 00119 } 00121 00122 inline static ECompoAdjustModes 00123 methfromstr( std::string __m ) 00124 { 00125 if( __m.size() > 0 && __m[ __m.size()-1 ] == '.' ) __m.resize( __m.size()-1 ); 00126 // 1 00127 // 012345678901 00128 // Composition-based stats 00129 // Compositional matrix adjust 00130 if( __m.size() >= 12 ) 00131 { 00132 if( __m[11] == '-' ) return eCompositionBasedStats; 00133 if( __m[11] == 'a' ) return eCompositionMatrixAdjust; 00134 } 00135 return eNoCompositionBasedStats; 00136 } 00137 }; 00138 00140 00141 struct hit { 00142 std::string name; 00143 std::string desc; 00145 size_t length; 00146 std::vector<hsp> hsps; 00147 public: 00148 hit( const std::string& __name = "", const std::string& __desc = "", size_t __length = 0 ) : name(__name), desc(__desc), length(__length) {} 00149 virtual ~hit(){} 00150 }; 00151 00153 struct oneline { 00154 std::string name; 00155 std::string desc; 00157 double bit_score; 00158 double e_value; 00159 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){} 00160 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){} 00161 virtual ~oneline(){} 00162 }; 00163 00165 struct result { 00166 bool empty; 00167 std::string blast_version; 00168 std::vector<std::string> 00169 references; 00171 std::vector<rostlab::blast::round> 00172 rounds; 00174 std::string q_name; 00176 std::string q_desc; 00178 size_t q_length; 00180 std::string db_name; 00182 size_t db_nseq; 00184 size_t db_nletter; 00186 std::vector<rostlab::blast::oneline> 00187 onelines; 00189 bool converged; 00191 std::vector<rostlab::blast::hit> 00192 hits; 00194 std::string tail; 00195 public: 00196 result() : empty(true), q_length(0), db_nseq(0), db_nletter(0), converged(false) {} 00197 virtual ~result(){} 00198 00200 00201 operator bool() const { return !empty; } 00202 }; 00203 00204 } // namespace blast 00205 00207 inline 00208 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::round& __r ) 00209 { 00210 __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; 00211 return __os; 00212 } 00213 00215 inline 00216 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::oneline& __r ) 00217 { 00218 __os << "n = " << __r.name << " d = " << __r.desc << ": " << __r.bit_score << " bits, " << __r.e_value << " E"; 00219 return __os; 00220 } 00221 00223 inline 00224 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::hsp& __r ) 00225 { 00226 __os << "bits = " << __r.bit_score << ", raw = " << __r.raw_score << ", E = " << __r.e_value << ", method = " << blast::hsp::methodstr(__r.method) << ", ident = " << __r.identities << 00227 ", pos = " << __r.positives << ", gaps = " << __r.gaps << ", q_strand = " << __r.q_strand << ", s_strand = " << __r.s_strand << ", q_frame = " << (int)__r.q_frame << 00228 ", 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 << 00229 ", s_start = " << __r.s_start << ", s_ali = " << __r.s_ali << ", s_end = " << __r.s_end; 00230 return __os; 00231 } 00232 00234 inline 00235 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::hit& __r ) 00236 { 00237 __os << "n = " << __r.name << " d = " << __r.desc << " Length = " << __r.length << " " << __r.hsps; 00238 return __os; 00239 } 00240 00242 inline 00243 std::ostream& operator<<( std::ostream& __os, const rostlab::blast::result& __r ) 00244 { 00245 __os << __r.blast_version << "\n\nreferences: " << __r.references << "\n\nrounds: " << __r.rounds << "\n\nn = " << __r.q_name << " d = " << __r.q_desc << " (" << __r.q_length << 00246 " letters)\n\nDatabase: " << __r.db_name << " " << __r.db_nseq << " sequences; " << __r.db_nletter << " total letters\n\none-line desc: " << __r.onelines << "\n\n" << 00247 ( __r.converged ? "CONVERGED!\n\n" : "" ) << "hits: " << __r.hits << "\n\n" << __r.tail; 00248 return __os; 00249 } 00250 00251 } // namespace rostlab 00252 00253 #endif // ROSTLAB_BLAST_RESULT_H 00254 // vim:et:ts=4:ai: