Class: Bio::Fasta::Report

Inherits:
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


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
# 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
  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.


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

def entry_overrun
  @entry_overrun
end

#hitsObject (readonly)

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


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

def hits
  @hits
end

#listObject (readonly)

Returns the 'The best scores are' lines as a String.


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

def list
  @list
end

#logObject (readonly)

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


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

def log
  @log
end

#programObject (readonly)

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


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

def program
  @program
end

#query_defObject (readonly)

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


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

def query_def
  @query_def
end

#query_lenObject (readonly)

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


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

def query_len
  @query_len
end

Instance Method Details

#eachObject

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


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

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'.


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

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'.


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

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