Class: Bio::Blat::Report

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

Overview

Bio::Blat::Report is a BLAT report parser class. Its object may contain some Bio::Blat::Report::Hits objects.

In BLAT results, the start position of a sequnece is numbered as 0. On the other hand, in many other homology search programs, the start position of a sequence is numbered as 1. To keep compatibility, the BLAT parser adds 1 to every position number except Bio::Blat::Report::Seqdesc and some Bio::Blat specific methods.

Note that Bio::Blat::Report#query_def, #query_id, #query_len methods simply return first hit’s query_*. If multiple query sequences are given, these values will be incorrect.

Defined Under Namespace

Classes: Hit, SegmentPair, SeqDesc

Constant Summary collapse

DELIMITER =

Delimiter of each entry. Bio::FlatFile uses it. In Bio::Blat::Report, it it nil (1 entry 1 file).

RS = nil
FLATFILE_SPLITTER =

Splitter for Bio::FlatFile

Bio::FlatFile::Splitter::LineOriented

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = '') ⇒ Report

Creates a new Bio::Blat::Report object from BLAT result text (String). You can use Bio::FlatFile to read a file. Currently, results created with options -out=psl (default) or -out=pslx are supported.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bio/appl/blat/report.rb', line 56

def initialize(text = '')
  flag = false
  head = []
  @hits = []
  text.each_line do |line|
    if flag then
      @hits << Hit.new(line)
    else
      # for headerless data
      if /^\d/ =~ line then
        flag = true
        redo
      end
      line = line.chomp
      if /\A\-+\s*\z/ =~ line
        flag = true
      else
        head << line
      end
    end
  end
  @columns = parse_header(head) unless head.empty?
end

Instance Attribute Details

#columnsObject (readonly)

Returns descriptions of columns. Returns an Array. This would be a Bio::Blat specific method.



125
126
127
# File 'lib/bio/appl/blat/report.rb', line 125

def columns
  @columns
end

#hitsObject (readonly)

hits of the result. Returns an Array of Bio::Blat::Report::Hit objects.



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

def hits
  @hits
end

#psl_versionObject (readonly)

version of the psl format (String or nil).



152
153
154
# File 'lib/bio/appl/blat/report.rb', line 152

def psl_version
  @psl_version
end

Instance Method Details

#add_header_line(line) ⇒ Object

Adds a header line if the header data is not yet given and the given line is suitable for header. Returns self if adding header line is succeeded. Otherwise, returns false (the line is not added).



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/bio/appl/blat/report.rb', line 84

def add_header_line(line)
  return false if defined? @columns
  line = line.chomp
  case line
  when /^\d/
    @columns = (defined? @header_lines) ? parse_header(@header_lines) : []
    return false
  when /\A\-+\s*\z/
    @columns = (defined? @header_lines) ? parse_header(@header_lines) : []
    return self
  else
    @header_lines ||= []
    @header_lines.push line
  end
end

#add_line(line) ⇒ Object

Adds a line to the entry if the given line is regarded as a part of the current entry. If the current entry (self) is empty, or the line has the same query name, the line is added and returns self. Otherwise, returns false (the line is not added).



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/bio/appl/blat/report.rb', line 105

def add_line(line)
  if /\A\s*\z/ =~ line then
    return @hits.empty? ? self : false
  end
  hit = Hit.new(line.chomp)
  if @hits.empty? or @hits.first.query.name == hit.query.name then
    @hits.push hit
    return self
  else
    return false
  end
end

#each_hit(&x) ⇒ Object Also known as: each

Iterates over each Bio::Blat::Report::Hit object. Same as hits.each.



496
497
498
# File 'lib/bio/appl/blat/report.rb', line 496

def each_hit(&x) #:yields: hit
  @hits.each(&x)
end

#num_hitsObject

Returns number of hits. Same as hits.size.



492
# File 'lib/bio/appl/blat/report.rb', line 492

def num_hits;     @hits.size;     end

#query_defObject Also known as: query_id

Returns the name of query sequence. CAUTION: query_* methods simply return first hit’s query_*. If multiple query sequences are given, these values will be incorrect.



505
# File 'lib/bio/appl/blat/report.rb', line 505

def query_def; (x = @hits.first) ? x.query_def : nil; end

#query_lenObject

Returns the length of query sequence. CAUTION: query_* methods simply return first hit’s query_*. If multiple query sequences are given, these values will be incorrect.



511
# File 'lib/bio/appl/blat/report.rb', line 511

def query_len; (x = @hits.first) ? x.query_len : nil; end