class NewickString
Attributes
str[R]
Public Class Methods
new(str)
click to toggle source
# File lib/rnewick.rb, line 12 def initialize(str) @str=String.new(str) end
Public Instance Methods
branch_lengths()
click to toggle source
# File lib/rnewick.rb, line 22 def branch_lengths @str.gsub("0.0;","").scan(/:([0-9]+\.[0-9]+)/).map{|n| n[0].to_f} end
clean()
click to toggle source
# File lib/rnewick.rb, line 51 def clean newstr = @str.gsub('(,)',"").gsub('(,(','((').gsub('),)','))') newstr = newstr.gsub('(,)',"").gsub('(,(','((').gsub('),)','))') newstr.gsub(',)',")").gsub('(,','(').gsub("e-06","") end
multifurcations()
click to toggle source
# File lib/rnewick.rb, line 18 def multifurcations # TODO find the multifurcations and show their support (guess it is 100 cause bifurcations were lower than 50) # maybe try to resolve them on the fly? end
numtaxa()
click to toggle source
# File lib/rnewick.rb, line 48 def numtaxa @str.count(",").to_i + 1 end
rawtopology()
click to toggle source
# File lib/rnewick.rb, line 42 def rawtopology @str.gsub(/[0-9]+\.[0-9]+/,'').gsub(':','') end
str_with_numeric_branch_lengths()
click to toggle source
# File lib/rnewick.rb, line 32 def str_with_numeric_branch_lengths newt = @str.gsub(/:([0-9]+\.[0-9]+)e-([0-9]+)/) do |bl| newval = bl.gsub(":","").to_f ":" + "%.9f" % newval end newt end
str_with_scaled_branch_lengths(factor)
click to toggle source
# File lib/rnewick.rb, line 25 def str_with_scaled_branch_lengths(factor) newt = @str.gsub(/:([0-9]+\.[0-9]+)/) do |bl| newval = bl.gsub(":","").to_f * factor ":" + "%.9f" % newval end newt end
support_values()
click to toggle source
# File lib/rnewick.rb, line 15 def support_values @str.gsub("0.0;","").scan(/\[([0-9]+)\]/).map{|n| n[0].to_i} end
taxanames()
click to toggle source
# File lib/rnewick.rb, line 45 def taxanames self.rawtopology.gsub("(", " ").gsub(")", " ").gsub(",", " ").gsub(";", " ").strip.split end
treelength()
click to toggle source
# File lib/rnewick.rb, line 39 def treelength self.branch_lengths.inject(0){|acc,i| acc+i} end