Class: Bio::HMMER::Report

Inherits:
Object show all
Defined in:
lib/bio/appl/hmmer/report.rb

Overview

A parser class for a search report by hmmsearch or hmmpfam program in the HMMER package.

Examples

Examples
 #for multiple reports in a single output file (example.hmmpfam)
 Bio::HMMER.reports(File.read("example.hmmpfam")) do |report|
   report.program['name']
   report.parameter['HMM file']
   report.query_info['Query sequence']
   report.hits.each do |hit|
     hit.accession
     hit.description
     hit.score
     hit.evalue
     hit.hsps.each do |hsp|
       hsp.accession
       hsp.domain
       hsp.evalue
       hsp.midline
   end
 end

References

Defined Under Namespace

Classes: Hit, Hsp

Constant Summary

DELIMITER =

Delimiter of each entry for Bio::FlatFile support.

RS = "\n//\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Report

Parses a HMMER search report (by hmmpfam or hmmsearch program) and reutrns a Bio::HMMER::Report object.

Examples

hmmpfam_report = Bio::HMMER::Report.new(File.read("hmmpfam.out"))

hmmsearch_report = Bio::HMMER::Report.new(File.read("hmmsearch.out"))


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/bio/appl/hmmer/report.rb', line 156

def initialize(data)

  # The input data is divided into six data fields, i.e. header,
  # query infomation, hits, HSPs, alignments and search statistics.
  # However, header and statistics data don't necessarily exist.
  subdata, is_hmmsearch = get_subdata(data)

  # if header exists, parse it
  if subdata["header"]
    @program, @parameter = parse_header_data(subdata["header"])
  else
    @program, @parameter = [{}, {}]
  end

  @query_info = parse_query_info(subdata["query"])
  @hits       = parse_hit_data(subdata["hit"])
  @hsps       = parse_hsp_data(subdata["hsp"], is_hmmsearch)

  if @hsps != []
    # split alignment subdata into an array of alignments
    aln_ary = subdata["alignment"].split(/^\S+.*?\n/).slice(1..-1)

    # append alignment information to corresponding Hsp
    aln_ary.each_with_index do |aln, i|
      @hsps[i].set_alignment(aln)
    end
  end

  # assign each Hsp object to its parent Hit
  hits_hash = {}
  @hits.each do |hit|
    hits_hash[hit.accession] = hit
  end
  @hsps.each do |hsp|
    if hits_hash.has_key?(hsp.accession)
      hits_hash[hsp.accession].append_hsp(hsp)
    end
  end

  # parse statistics (for hmmsearch)
  if is_hmmsearch
    @histogram, @statistical_detail, @total_seq_searched, \
    @whole_seq_top_hits, @domain_top_hits = \
    parse_stat_data(subdata["statistics"])
  end

end

Instance Attribute Details

#domain_top_hitsObject (readonly)

statistics by hmmsearch. Keys are 'Total memory', 'Satisfying E cutoff' and 'Total hits'.



144
145
146
# File 'lib/bio/appl/hmmer/report.rb', line 144

def domain_top_hits
  @domain_top_hits
end

#histogramObject (readonly)

statistics by hmmsearch.



132
133
134
# File 'lib/bio/appl/hmmer/report.rb', line 132

def histogram
  @histogram
end

#hitsObject (readonly)

Returns the value of attribute hits



123
124
125
# File 'lib/bio/appl/hmmer/report.rb', line 123

def hits
  @hits
end

#hspsObject (readonly)

Returns an Array of Bio::HMMER::Report::Hsp objects. Under special circumstances, some HSPs do not have parent Hit objects. If you want to access such HSPs, use this method.



129
130
131
# File 'lib/bio/appl/hmmer/report.rb', line 129

def hsps
  @hsps
end

#parameterObject (readonly)

A hash contains parameters used. Valid keys are 'HMM file' and 'Sequence file'.



116
117
118
# File 'lib/bio/appl/hmmer/report.rb', line 116

def parameter
  @parameter
end

#programObject (readonly)

A Hash contains program information used. Valid keys are 'name', 'version', 'copyright' and 'license'.



112
113
114
# File 'lib/bio/appl/hmmer/report.rb', line 112

def program
  @program
end

#query_infoObject (readonly)

A hash contains the query information. Valid keys are 'query sequence', 'Accession' and 'Description'.



120
121
122
# File 'lib/bio/appl/hmmer/report.rb', line 120

def query_info
  @query_info
end

#statistical_detailObject (readonly)

statistics by hmmsearch. Keys are 'mu', 'lambda', 'chi-sq statistic' and 'P(chi-square)'.



135
136
137
# File 'lib/bio/appl/hmmer/report.rb', line 135

def statistical_detail
  @statistical_detail
end

#total_seq_searchedObject (readonly)

statistics by hmmsearch.



138
139
140
# File 'lib/bio/appl/hmmer/report.rb', line 138

def total_seq_searched
  @total_seq_searched
end

#whole_seq_top_hitsObject (readonly)

statistics by hmmsearch. Keys are 'Total memory', 'Satisfying E cutoff' and 'Total hits'.



141
142
143
# File 'lib/bio/appl/hmmer/report.rb', line 141

def whole_seq_top_hits
  @whole_seq_top_hits
end

Instance Method Details

#eachObject Also known as: each_hit

Iterates each hit (Bio::HMMER::Report::Hit).



206
207
208
209
210
# File 'lib/bio/appl/hmmer/report.rb', line 206

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