Class: BioMummer::DeltaFile
- Inherits:
-
Object
- Object
- BioMummer::DeltaFile
- Defined in:
- lib/bio-mummer/mummer.rb
Constant Summary collapse
- NUCMER =
1
- PROMER =
2
Instance Attribute Summary collapse
-
#alignments ⇒ Object
readonly
Returns the value of attribute alignments.
-
#alternate_filename ⇒ Object
Returns the value of attribute alternate_filename.
-
#reference_filename ⇒ Object
Returns the value of attribute reference_filename.
Class Method Summary collapse
Instance Method Summary collapse
- #format_ok?(io) ⇒ Boolean
-
#initialize(io) ⇒ DeltaFile
constructor
A new instance of DeltaFile.
- #parse(string) ⇒ Object
- #transpose_region(refname, startpos, endpos) ⇒ Object
Constructor Details
#initialize(io) ⇒ DeltaFile
Returns a new instance of DeltaFile.
55 56 57 58 |
# 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 |
Instance Attribute Details
#alignments ⇒ Object (readonly)
Returns the value of attribute alignments.
53 54 55 |
# File 'lib/bio-mummer/mummer.rb', line 53 def alignments @alignments end |
#alternate_filename ⇒ Object
Returns the value of attribute alternate_filename.
52 53 54 |
# File 'lib/bio-mummer/mummer.rb', line 52 def alternate_filename @alternate_filename end |
#reference_filename ⇒ Object
Returns the value of attribute reference_filename.
52 53 54 |
# File 'lib/bio-mummer/mummer.rb', line 52 def reference_filename @reference_filename end |
Class Method Details
.open(filename) ⇒ Object
60 61 62 63 |
# File 'lib/bio-mummer/mummer.rb', line 60 def self.open(filename) io = File.open(filename) self.new(super(io)) end |
Instance Method Details
#format_ok?(io) ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# 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) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# 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 |