class BioMummer::DeltaFile

Constants

NUCMER
PROMER

Attributes

alignments[R]
alternate_filename[RW]
reference_filename[RW]

Public Class Methods

new(io) click to toggle source
# File lib/bio-mummer/mummer.rb, line 55
def initialize(io)
  raise EncodingError, "Not delta format" unless format_ok?(io)
  @alignments = parse(io.read)
end
open(filename) click to toggle source
Calls superclass method
# File lib/bio-mummer/mummer.rb, line 60
def self.open(filename)
  io = File.open(filename)
  self.new(super(io))
end

Public Instance Methods

format_ok?(io) click to toggle source
# File lib/bio-mummer/mummer.rb, line 87
def format_ok?(io)
  line = io.gets.chomp
  unless line.match(/^(\/.*) (\/.*)$/)
    return false
  else
    reference_filename = $1
    alternate_filename = $2
  end

  case io.gets.chomp
  when /NUCMER/
    @format = NUCMER
    return true
  when /PROMER/
    @format = PROMER
    return true
  else
    return false
  end
end
parse(string) click to toggle source
# File lib/bio-mummer/mummer.rb, line 65
def parse(string)
  string.split("\n").slice_before(/^>/).flat_map do |block|
    refname, qryname = block.shift.match(/>(.*) (.*) \d+ \d+/).captures
    block.slice_before(/\d+ \d+ \d+ \d+/).map do |alignment|
      refstart, refstop, qrystart, qrystop = alignment
        .shift
        .match(/(\d+) (\d+) (\d+) (\d+) /)
        .captures
        .map{ |c| c.to_i }
      alignment.pop
      Alignment.new(refname,
                    qryname,
                    refstart,
                    refstop,
                    [qrystart, qrystop].min,
                    [qrystart, qrystop].max,
                    qrystart < qrystop,
                    alignment.map{ |i| i.to_i })
    end
  end
end
transpose_region(refname, startpos, endpos) click to toggle source
# File lib/bio-mummer/mummer.rb, line 108
def transpose_region(refname, startpos, endpos)
  a = alignments.find do |a|
    a.refname == refname && a.refstart <= startpos && a.refstop >= endpos
  end
  if a
    qryname = a.qryname
    qrystart = a.ref_to_query(startpos)
    qrystop = a.ref_to_query(endpos)
    if qrystart.nil? || qrystop.nil?
      return nil
    else
      return [qryname, qrystart, qrystop, a.strand]
    end
  else
    return nil
  end
end