class Bio::Spidey::Report::Hit

Hit object of Spidey result. Similar to Bio::Blast::Report::Hit but lacks many methods.

Public Class Methods

new(data, d0) click to toggle source

Creates a new Hit object. It is designed to be called internally from Bio::Spidey::Report::* classes. Users shall not call it directly.

# File lib/bio/appl/spidey/report.rb, line 290
def initialize(data, d0)
  @data = data
  @d0 = d0
end

Public Instance Methods

align() click to toggle source

Returns alignments. Returns an Array of arrays. This would be a Bio::Spidey specific method.

# File lib/bio/appl/spidey/report.rb, line 465
def align
  unless defined?(@align); parse_align; end
  @align
end
complement?() click to toggle source

Returns true if the result reports 'Reverse complement'. Otherwise, return false or nil. This would be a Bio::Spidey specific method.

# File lib/bio/appl/spidey/report.rb, line 330
def complement?
  unless defined?(@complement); parse_strand; end
  @complement
end
definition()
Alias for: target_def
each() { |segmentpair| ... } click to toggle source

Iterates over each exon of the hit. Yields Bio::Spidey::Report::SegmentPair object.

# File lib/bio/appl/spidey/report.rb, line 555
def each(&x) #:yields: segmentpair
  exons.each(&x)
end
exons() click to toggle source

Returns exons of the hit. Returns an array of Bio::Spidey::Report::SegmentPair object.

# File lib/bio/appl/spidey/report.rb, line 437
def exons
  unless defined?(@exons); parse_segmentpairs; end
  @exons
end
Also aliased as: hsps
genomic() click to toggle source

Returns sequence informations of the 'Genomic'. Returns a Bio::Spidey::Report::SeqDesc object. This would be a Bio::Spidey specific method.

# File lib/bio/appl/spidey/report.rb, line 373
def genomic
  unless defined?(@genomic)
    @genomic = SeqDesc.parse(@d0.find { |x| /^Genomic\:/ =~ x })
  end
  @genomic
end
hit_id()
Alias for: target_id
hsps()
Alias for: exons
introns() click to toggle source

Returns introns of the hit. Some of them would contain untranscribed regions. Returns an array of Bio::Spidey::Report::SegmentPair objects. (Note that intron data is not always available according to run-time options of the program.)

# File lib/bio/appl/spidey/report.rb, line 447
def introns
  unless defined?(@introns); parse_segmentpairs; end
  @introns
end
len()
Alias for: target_len
missing_mrna_ends() click to toggle source

Returns missing mRNA ends of the hit.

# File lib/bio/appl/spidey/report.rb, line 363
def missing_mrna_ends
  unless defined?(@missing_mrna_ends)
    @missing_mrna_ends = field_fetch('Missing mRNA ends', @d0)
  end
  @missing_mrna_ends
end
mrna() click to toggle source

Returns sequence informations of the mRNA. Returns a Bio::Spidey::Report::SeqDesc object. This would be a Bio::Spidey specific method.

# File lib/bio/appl/spidey/report.rb, line 383
def mrna
  unless defined?(@mrna)
    @mrna = SeqDesc.parse(@d0.find { |x| /^mRNA\:/ =~ x })
  end
  @mrna
end
number_of_exons() click to toggle source

Returns number of exons in the hit.

# File lib/bio/appl/spidey/report.rb, line 336
def number_of_exons
  unless defined?(@number_of_exons)
    @number_of_exons = field_fetch('Number of exons', @d0).to_i
  end
  @number_of_exons
end
number_of_splice_sites() click to toggle source

Returns number of splice sites of the hit.

# File lib/bio/appl/spidey/report.rb, line 344
def number_of_splice_sites
  unless defined?(@number_of_splice_sites)
    @number_of_splice_sites = 
      field_fetch('Number of splice sites', @d0).to_i
  end
  @number_of_splice_sites
end
percent_identity() click to toggle source

Returns overall percent identity of the hit.

# File lib/bio/appl/spidey/report.rb, line 353
def percent_identity
  unless defined?(@percent_identity)
    x = field_fetch('overall percent identity', @d0)
    @percent_identity = 
      (/([\d\.]+)\s*\%/ =~ x.to_s) ? $1 : nil
  end
  @percent_identity
end
query_def() click to toggle source

Definition of the mRNA (query). Same as Bio::Spidey::Report#query_def.

# File lib/bio/appl/spidey/report.rb, line 536
def query_def;  mrna.definition; end
query_id() click to toggle source

Identifier of the mRNA (query). Same as Bio::Spidey::Report#query_id.

# File lib/bio/appl/spidey/report.rb, line 532
def query_id;   mrna.entry_id;   end
query_len() click to toggle source

Length of the mRNA (query) sequence. Same as Bio::Spidey::Report#query_len.

# File lib/bio/appl/spidey/report.rb, line 528
def query_len;  mrna.len;        end
segmentpairs() click to toggle source

Returns segment pairs (exons and introns) of the hit. Each segment pair is a Bio::Spidey::Report::SegmentPair object. Returns an array of Bio::Spidey::Report::SegmentPair objects. (Note that intron data is not always available according to run-time options of the program.)

# File lib/bio/appl/spidey/report.rb, line 457
def segmentpairs
  unless defined?(@segmentparis); parse_segmentpairs; end
  @segmentpairs
end
strand() click to toggle source

Returns strand information of the hit. Returns 'plus', 'minus', or nil. This would be a Bio::Spidey specific method.

# File lib/bio/appl/spidey/report.rb, line 322
def strand
  unless defined?(@strand); parse_strand; end
  @strand
end
target_def() click to toggle source

Definition of the genomic (target) sequence.

# File lib/bio/appl/spidey/report.rb, line 545
def target_def; genomic.definition; end
Also aliased as: definition
target_id() click to toggle source

Identifier of the genomic (target) sequence.

# File lib/bio/appl/spidey/report.rb, line 542
def target_id;  genomic.entry_id;   end
Also aliased as: hit_id
target_len() click to toggle source

The genomic (target) sequence length.

# File lib/bio/appl/spidey/report.rb, line 539
def target_len; genomic.len;        end
Also aliased as: len

Private Instance Methods

field_fetch(t, ary) click to toggle source

Fetches fields.

# File lib/bio/appl/spidey/report.rb, line 296
def field_fetch(t, ary)
  reg = Regexp.new(/^#{Regexp.escape(t)}\:\s*(.+)\s*$/)
  if ary.find { |x| reg =~ x }
    $1.strip
  else
    nil
  end
end
parse_align() click to toggle source

Parses alignments.

# File lib/bio/appl/spidey/report.rb, line 508
def parse_align
  r = []
  data = @data
  while !data.empty?
    a = []
    while x = data.shift and !(x =~ /^(Genomic|Exon\s*\d+)\:/)
      a.push x
    end
    r.push parse_align_lines(a) unless a.empty?
  end
  @align = r
end
parse_align_lines(data) click to toggle source

Parses alignment lines.

# File lib/bio/appl/spidey/report.rb, line 471
def parse_align_lines(data)
  misc = [ [], [], [], [] ]
  data.each do |x|
    a = x.split(/\r?\n/)
    if g = a.shift then
      misc[0] << g
      (1..3).each do |i|
        if y = a.shift then
          if y.length < g.length
            y << ' ' * (g.length - y.length)
          end
          misc[i] << y
        else
          misc[i] << ' ' * g.length
        end
      end
    end
  end
  misc.collect! { |x| x.join('') }
  left = []
  if /\A +/ =~ misc[2] then
    len = $&.size
    left = misc.collect { |x| x[0, len] }
    misc.each { |x| x[0, len] = '' }
  end
  right = []
  if / +\z/ =~ misc[2] then
    len = $&.size
    right = misc.collect { |x| x[(-len)..-1] }
    misc.each { |x| x[(-len)..-1] = '' }
  end
  body = misc
  [ left, body, right ]
end
parse_segmentpairs() click to toggle source

Parses segment pairs.

# File lib/bio/appl/spidey/report.rb, line 391
def parse_segmentpairs
  aln = self.align.dup
  ex = []
  itr = []
  segpairs = []
  cflag  = self.complement?
  strand = self.strand
  if strand == 'minus' then
    d_to = 1;  d_from = -1
  else
    d_to = -1; d_from = 1
  end
  @d0.each do |x|
    #p x
    if x =~ /^Exon\s*\d+(\(.*\))?\:/ then
      if a = aln.shift then
        y = SegmentPair.parse(x, strand, cflag, a[1])
        ex << y
        if a[0][0].to_s.length > 0 then
          to = y.genomic.from + d_to
          i0 = SegmentPair.new_intron(nil, to, strand, a[0])
          itr << i0
          segpairs << i0
        end
        segpairs << y
        if a[2][0].to_s.length > 0 then
          from = y.genomic.to + d_from
          i2 = SegmentPair.new_intron(from, nil, strand, a[2])
          itr << i2
          segpairs << i2
        end
      else
        y = SegmentPair.parse(x, strand, cflag, [])
        ex << y
        segpairs << y
      end
    end
  end
  @exons = ex
  @introns = itr
  @segmentpairs = segpairs
end
parse_strand() click to toggle source

Parses information about strand.

# File lib/bio/appl/spidey/report.rb, line 307
def parse_strand
  x = field_fetch('Strand', @d0)
  if x =~ /^(.+)Reverse +complement\s*$/ then
    @strand = $1.strip
    @complement = true
  else
    @strand = x
    @complement = nil
  end
end