class Bio::HMMER::HMMER3::TabularReport

Attributes

format[R]
hits[R]

Public Class Methods

new(hmmer_output, format = nil) click to toggle source
# File lib/bio/appl/hmmer/hmmer3/tabular_report.rb, line 20
def initialize(hmmer_output, format = nil)
  
  @hits = Array.new
  @line_number = 0
  @format = format
  if hmmer_output.kind_of?(String)
    str = StringIO.new(hmmer_output)
    str.each_line() { |line| parse_line(line) }
  elsif hmmer_output.kind_of?(IO)
    hmmer_output.each_line() { |line| parse_line(line) }
  else
    raise "Unexpected hmmer_output class: excpected String or IO, found #{hmmer_output.class}"
  end
end

Private Instance Methods

looks_like_per_domain_result?(line) click to toggle source
# File lib/bio/appl/hmmer/hmmer3/tabular_report.rb, line 64
def looks_like_per_domain_result?(line)
  line =~ /^(\S*)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s*(.*)/
end
parse_line(line) click to toggle source
# File lib/bio/appl/hmmer/hmmer3/tabular_report.rb, line 40
def parse_line(line)
  @line_number += 1
  if line  =~ /^#.+this\s+domain/
    @format = :domtblout
  elsif line =~ /^#.+best\s+1\s+domain/
    @format = :tblout
  elsif line =~ /\S/ && line !~ /^#/
    if @format == nil
      if looks_like_per_domain_result?(line)
        @format = :domtblout
      else
        @format = :tblout
      end
    end
    if @format == :domtblout
      @hits << PerDomainHit.new(line, @line_number)
    elsif @format == :tblout
      @hits << PerSequenceHit.new(line, @line_number)
    else
      raise ArgumentError, "attempt to parse hmmscan/hmmsearch output style other than \"domtblout\" or \"tblout\""
    end
  end
end