class Bio::Blast::Default::Report::HSP

Bio::Blast::Default::Report::HSP holds information about the hsp (high-scoring segment pair).

Attributes

align_len[R]

aligned length

bit_score[R]

bit score

evalue[R]

e-value

gaps[R]

Gaps (number of gaps)

hit_frame[R]

frame of the hit

hit_from[R]

start position of the hit (the first position is 1)

hit_strand[R]

strand of the hit (“Plus” or “Minus” or nil)

hit_to[R]

end position of the hit (including its position)

hseq[R]

hit sequence (with gaps) of the alignment of the hsp

identity[R]

Identity (number of identical nucleotides or amino acids)

midline[R]

middle line of the alignment of the hsp

percent_gaps[R]

percent of gaps

percent_identity[R]

percent of identical nucleotides or amino acids

percent_positive[R]

percent of positive hit amino acids or nucleotides

positive[R]

Positives (number of positive hit amino acids or nucleotides)

qseq[R]

query sequence (with gaps) of the alignment of the hsp

query_frame[R]

frame of the query

query_from[R]

start position of the query (the first position is 1)

query_strand[R]

strand of the query (“Plus” or “Minus” or nil)

query_to[R]

end position of the query (including its position)

score[R]

score

stat_method[R]

statistical method for calculating evalue and/or score (nil or a string) (note that composition-based statistics for blastp or tblastn were enabled by default after NCBI BLAST 2.2.17)

Public Class Methods

new(data) click to toggle source

Creates new HSP object. It is designed to be called only internally from the Bio::Blast::Default::Report::Hit class. Users should not call the method directly.

    # File lib/bio/appl/blast/format0.rb
960 def initialize(data)
961   @f0score = data.shift
962   @f0alignment = []
963   while r = data[0] and /^(Query|Sbjct)\:/ =~ r
964     @f0alignment << data.shift
965   end
966 end

Private Class Methods

method_after_parse_alignment(*names) click to toggle source

Defines attributes which call parse_alignment before accessing.

     # File lib/bio/appl/blast/format0.rb
1191 def self.method_after_parse_alignment(*names)
1192   names.each do |x|
1193     module_eval("def #{x}; parse_alignment; @#{x}; end")
1194   end
1195 end
method_after_parse_score(*names) click to toggle source

Defines attributes which call parse_score before accessing.

     # File lib/bio/appl/blast/format0.rb
1055 def self.method_after_parse_score(*names)
1056   names.each do |x|
1057     module_eval("def #{x}; parse_score; (defined? @#{x}) ? @#{x} : nil; end")
1058   end
1059 end

Private Instance Methods

parse_alignment() click to toggle source

Parses alignments.

     # File lib/bio/appl/blast/format0.rb
1121 def parse_alignment
1122   unless defined?(@parse_alignment)
1123     qpos1 = nil
1124     qpos2 = nil
1125     spos1 = nil
1126     spos2 = nil
1127     qseq = []
1128     sseq = []
1129     mseq = []
1130     pos_st = nil
1131     len_seq = 0
1132     nextline = :q
1133     @f0alignment.each do |x|
1134       sc = StringScanner.new(x)
1135       while sc.rest?
1136         #p pos_st, len_seq
1137         #p nextline.to_s
1138         if r = sc.skip(/Query\: *(\d+) */) then
1139           pos_st = r
1140           pos1 = sc[1]
1141           len_seq = sc.skip(/[^ ]*/)
1142           seq = sc[0]
1143           sc.skip(/ *(\d+) *\n/)
1144           pos2 = sc[1]
1145           raise ScanError unless nextline == :q
1146           qpos1 = pos1.to_i unless qpos1
1147           qpos2 = pos2.to_i
1148           qseq << seq
1149           nextline = :m
1150         elsif r = sc.scan(/Sbjct\: *(\d+) *.+ +(\d+) *\n/) then
1151           pos1 = sc[1]
1152           pos2 = sc[2]
1153           raise ScanError unless pos_st
1154           raise ScanError unless len_seq
1155           seq = r[pos_st, len_seq]
1156           if nextline == :m then
1157             mseq << (' ' * len_seq)
1158           end
1159           spos1 = pos1.to_i unless spos1
1160           spos2 = pos2.to_i
1161           sseq << seq
1162           nextline = :q
1163         elsif r = sc.scan(/ {6}.+/) then
1164           raise ScanError unless nextline == :m
1165           mseq << r[pos_st, len_seq]
1166           sc.skip(/\n/)
1167           nextline = :s
1168         elsif r = sc.skip(/pattern +\d+.+/) then
1169           # PHI-BLAST
1170           # do nothing
1171           sc.skip(/\n/)
1172         else
1173           raise ScanError
1174         end
1175       end #while
1176     end #each
1177     #p qseq, sseq, mseq
1178     @qseq = qseq.join('')
1179     @hseq = sseq.join('')
1180     @midline = mseq.join('')
1181     @query_from = qpos1
1182     @query_to   = qpos2
1183     @hit_from = spos1
1184     @hit_to   = spos2
1185     @parse_alignment = true
1186   end #unless
1187 end
parse_score() click to toggle source

Parses scores, identities, positives, gaps, and so on.

     # File lib/bio/appl/blast/format0.rb
 969 def parse_score
 970   unless defined?(@parse_score)
 971     sc = StringScanner.new(@f0score)
 972     while sc.rest?
 973       sc.skip(/\s*/)
 974       if sc.skip(/Expect(?:\(\d+\))? *\= *([e\+\-\.\d]+)/) then
 975         ev = sc[1].to_s
 976         ev = '1' + ev if ev[0] == ?e
 977         @evalue = ev.to_f
 978       elsif sc.skip(/Score *\= *([e\+\-\.\d]+) *bits *\( *([e\+\-\.\d]+) *\)/) then
 979         bs = sc[1]
 980         bs = '1' + bs if bs[0] == ?e
 981         @bit_score = bs.to_f
 982         @score = sc[2].to_i
 983       elsif sc.skip(/(Identities|Positives|Gaps) *\= (\d+) *\/ *(\d+) *\(([\.\d]+) *\% *\)/) then
 984         alen = sc[3].to_i
 985         @align_len = alen unless defined?(@align_len)
 986         raise ScanError if alen != @align_len
 987         case sc[1]
 988         when 'Identities'
 989           @identity = sc[2].to_i
 990           @percent_identity = sc[4].to_i
 991         when 'Positives'
 992           @positive = sc[2].to_i
 993           @percent_positive = sc[4].to_i
 994         when 'Gaps'
 995           @gaps = sc[2].to_i
 996           @percent_gaps = sc[4].to_i
 997         else
 998           raise ScanError
 999         end
1000       elsif sc.skip(/Strand *\= *(Plus|Minus) *\/ *(Plus|Minus)/) then
1001         @query_strand = sc[1]
1002         @hit_strand = sc[2]
1003         if sc[1] == sc[2] then
1004           @query_frame = 1
1005           @hit_frame = 1
1006         elsif sc[1] == 'Plus' then # Plus/Minus
1007           # complement sequence against xml(-m 7)
1008           # In xml(-m 8), -1=>Plus, 1=>Minus ???
1009           #@query_frame = -1
1010           #@hit_frame = 1
1011           @query_frame = 1
1012           @hit_frame = -1
1013         else # Minus/Plus
1014           @query_frame = -1
1015           @hit_frame = 1
1016         end
1017       elsif sc.skip(/Frame *\= *([\-\+]\d+)( *\/ *([\-\+]\d+))?/) then
1018         @query_frame = sc[1].to_i
1019         if sc[2] then
1020           @hit_frame = sc[3].to_i
1021         end
1022       elsif sc.skip(/Score *\= *([e\+\-\.\d]+) +\(([e\+\-\.\d]+) *bits *\)/) then
1023         #WU-BLAST
1024         @score = sc[1].to_i
1025         bs = sc[2]
1026         bs = '1' + bs if bs[0] == ?e
1027         @bit_score = bs.to_f
1028       elsif sc.skip(/P *\= * ([e\+\-\.\d]+)/) then
1029         #WU-BLAST
1030         @p_sum_n = nil
1031         pv = sc[1]
1032         pv = '1' + pv if pv[0] == ?e
1033         @pvalue = pv.to_f
1034       elsif sc.skip(/Sum +P *\( *(\d+) *\) *\= *([e\+\-\.\d]+)/) then
1035         #WU-BLAST
1036         @p_sum_n = sc[1].to_i
1037         pv = sc[2]
1038         pv = '1' + pv if pv[0] == ?e
1039         @pvalue = pv.to_f
1040       elsif sc.skip(/Method\:\s*(.+)/) then
1041         # signature of composition-based statistics method
1042         # for example, "Method: Composition-based stats."
1043         @stat_method = sc[1]
1044       else
1045         raise ScanError
1046       end
1047       sc.skip(/\s*\,?\s*/)
1048     end
1049     @parse_score = true
1050   end
1051 end