Class: NewickString
- Inherits:
-
Object
- Object
- NewickString
- Defined in:
- lib/rnewick.rb
Instance Attribute Summary collapse
-
#str ⇒ Object
readonly
Returns the value of attribute str.
Instance Method Summary collapse
-
#branch_lengths ⇒ Object
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?.
- #clean ⇒ Object
-
#initialize(str) ⇒ NewickString
constructor
A new instance of NewickString.
- #multifurcations ⇒ Object
- #numtaxa ⇒ Object
- #rawtopology ⇒ Object
- #str_with_numeric_branch_lengths ⇒ Object
- #str_with_scaled_branch_lengths(factor) ⇒ Object
- #support_values ⇒ Object
- #taxanames ⇒ Object
- #treelength ⇒ Object
Constructor Details
#initialize(str) ⇒ NewickString
Returns a new instance of NewickString.
12 13 14 |
# File 'lib/rnewick.rb', line 12 def initialize(str) @str=String.new(str) end |
Instance Attribute Details
#str ⇒ Object (readonly)
Returns the value of attribute str.
11 12 13 |
# File 'lib/rnewick.rb', line 11 def str @str end |
Instance Method Details
#branch_lengths ⇒ Object
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?
22 23 24 |
# 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 ⇒ Object
51 52 53 54 55 |
# 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 ⇒ Object
18 19 20 21 |
# 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 ⇒ Object
48 49 50 |
# File 'lib/rnewick.rb', line 48 def numtaxa @str.count(",").to_i + 1 end |
#rawtopology ⇒ Object
42 43 44 |
# File 'lib/rnewick.rb', line 42 def rawtopology @str.gsub(/[0-9]+\.[0-9]+/,'').gsub(':','') end |
#str_with_numeric_branch_lengths ⇒ Object
32 33 34 35 36 37 38 |
# 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) ⇒ Object
25 26 27 28 29 30 31 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/rnewick.rb', line 15 def support_values @str.gsub("0.0;","").scan(/\[([0-9]+)\]/).map{|n| n[0].to_i} end |
#taxanames ⇒ Object
45 46 47 |
# File 'lib/rnewick.rb', line 45 def taxanames self.rawtopology.gsub("(", " ").gsub(")", " ").gsub(",", " ").gsub(";", " ").strip.split end |
#treelength ⇒ Object
39 40 41 |
# File 'lib/rnewick.rb', line 39 def treelength self.branch_lengths.inject(0){|acc,i| acc+i} end |