Class: Bio::Fasta::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/appl/fasta/format10.rb

Overview

Summarized results of the fasta execution results.

Defined Under Namespace

Classes: FastaFormat10Splitter, Hit, Program

Constant Summary collapse

FLATFILE_SPLITTER =

Splitter for Bio::FlatFile

FastaFormat10Splitter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Report

Returns a new instance of Report.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/bio/appl/fasta/format10.rb', line 69

def initialize(data)
  # Split outputs containing multiple query sequences' results
  chunks = data.split(/^(\s*\d+\>\>\>.*)/, 3)
  if chunks.size >= 3 then
    if chunks[0].strip.empty? then
      qdef_line = chunks[1]
      data = chunks[1..2].join('')
      overruns = chunks[3..-1]
    elsif /^\>\>\>/ =~ chunks[0] then
      qdef_line = nil
      data = chunks.shift
      overruns = chunks
    else
      qdef_line = chunks[1]
      data = chunks[0..2].join('')
      overruns = chunks[3..-1]
    end
    @entry_overrun = overruns.join('')
    if qdef_line and
        /^ *\d+\>\>\>([^ ]+) .+ \- +(\d+) +(nt|aa)\s*$/ =~ qdef_line then
      @query_def = $1
      @query_len = $2.to_i
    end
  end

  # header lines - brief list of the hits
  if list_start = data.index("\nThe best scores are") then
    data = data[(list_start + 1)..-1]
    data.sub!(/(.*?)\n\n>>>/m, '')
    @list = $1
    data.sub!(/>>><<<(.*)$/m, '')
  else
    if list_start = data.index(/\n!!\s+/) then
      data = data[list_start..-1]
      data.sub!(/\n!!\s+/, '')
      data.sub!(/.*/) { |x| @list = x; '' }
    else
      data = data.sub(/.*/) { |x| @list = x; '' }
    end
  end

  # body lines - fasta execution result
  program, *hits = data.split(/\n>>/)

  # trailing lines - log messages of the execution
  @log = hits.pop
  @log.sub!(/.*<\n/m, '')
  @log.strip!

  # parse results
  @program = Program.new(program)
  @hits = []

  hits.each do |x|
    @hits.push(Hit.new(x))
  end
end

Instance Attribute Details

#entry_overrunObject (readonly)

piece of next entry. Bio::FlatFile uses it.



128
129
130
# File 'lib/bio/appl/fasta/format10.rb', line 128

def entry_overrun
  @entry_overrun
end

#hitsObject (readonly)

Returns an Array of Bio::Fasta::Report::Hit objects.



147
148
149
# File 'lib/bio/appl/fasta/format10.rb', line 147

def hits
  @hits
end

#listObject (readonly)

Returns the ‘The best scores are’ lines as a String.



137
138
139
# File 'lib/bio/appl/fasta/format10.rb', line 137

def list
  @list
end

#logObject (readonly)

Returns the trailing lines including library size, execution date, fasta function used, and fasta versions as a String.



141
142
143
# File 'lib/bio/appl/fasta/format10.rb', line 141

def log
  @log
end

#programObject (readonly)

Returns a Bio::Fasta::Report::Program object.



144
145
146
# File 'lib/bio/appl/fasta/format10.rb', line 144

def program
  @program
end

#query_defObject (readonly)

Query definition. For older reports, the value may be nil.



131
132
133
# File 'lib/bio/appl/fasta/format10.rb', line 131

def query_def
  @query_def
end

#query_lenObject (readonly)

Query sequence length. For older reports, the value may be nil.



134
135
136
# File 'lib/bio/appl/fasta/format10.rb', line 134

def query_len
  @query_len
end

Instance Method Details

#eachObject

Iterates on each Bio::Fasta::Report::Hit object.



150
151
152
153
154
# File 'lib/bio/appl/fasta/format10.rb', line 150

def each
  @hits.each do |x|
    yield x
  end
end

#lap_over(length_min = 0) ⇒ Object

Returns an Array of Bio::Fasta::Report::Hit objects having longer overlap length than ‘length_min’.



168
169
170
171
172
173
174
# File 'lib/bio/appl/fasta/format10.rb', line 168

def lap_over(length_min = 0)
  list = []
  @hits.each do |x|
    list.push(x) if x.overlap > length_min
  end
  return list
end

#threshold(evalue_max = 0.1) ⇒ Object

Returns an Array of Bio::Fasta::Report::Hit objects having better evalue than ‘evalue_max’.



158
159
160
161
162
163
164
# File 'lib/bio/appl/fasta/format10.rb', line 158

def threshold(evalue_max = 0.1)
  list = []
  @hits.each do |x|
    list.push(x) if x.evalue < evalue_max
  end
  return list
end