lib/bio/nwk.rb in bio-nwk-0.1.0 vs lib/bio/nwk.rb in bio-nwk-0.1.1

- old
+ new

@@ -118,9 +118,37 @@ index = tip.name tip.name = @index2tip[index] end end + def getAlldistances() + distances = Array.new + each_edge do |node0, node1, edge| + next if node0 == root or node1 == root + distances << edge.distance + end + return(distances) + end + + def normalizeBranchLength!() + min, max = getAlldistances().minmax + each_edge do |node0, node1, edge| + edge.distance = (edge.distance-min+1e-10).to_f/(max-min) + end + end + + def normalizeBranchLengthGainAndLoss!() + min, max = getAlldistances().select{|i|i>=0}.minmax + each_edge do |node0, node1, edge| + edge.distance = (edge.distance-min+1e-10).to_f/(max-min) + 1 if edge.distance >= 0 + end + + min, max = getAlldistances().select{|i|i<0}.minmax + each_edge do |node0, node1, edge| + edge.distance = (edge.distance-min+1e-10).to_f/(max-min) if edge.distance < 0 + end + end + private def translate # TRANSLATE # 1 Hamster, puts "\tTRANSLATE"