Module: Dphil::PAUP
- Defined in:
- lib/dphil/paup.rb
Overview
PAUP* Log Processor
Constant Summary collapse
- BRANCH_REGEXP =
/^Branch lengths and linkages.*?\n\-{40,}\n(.*?)\n\-{40,}\n^Sum.*?(^Tree length =.*?)\n\n/m
- CHGLIST_REGEXP =
/^Character change lists:.*?\n\-{40,}\n(.*?)\n\n/m
Class Method Summary collapse
Class Method Details
.parse_trees(infile) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dphil/paup.rb', line 8 def self.parse_trees(infile) infile = File.(infile) return STDERR.puts("File #{infile} not found.") unless File.exist?(infile) data = File.read(infile).to_s.split(/^Tree ([0-9]+)\:$/) return data if data.empty? hash = { preamble: data.shift.strip } trees = {} data.each_slice(2) do |k, v| next trees[:remainder] = k if v.nil? branches = v.match(BRANCH_REGEXP)&.captures changes = v.match(CHGLIST_REGEXP)&.captures arr = [] arr.concat(i[lengths stats].zip(branches)) unless branches.nil? arr << [:changes, changes[0]] unless branches.nil? trees[k.to_i] = arr.to_h end hash.merge(trees) end |