class NewickFile
Attributes
newickStrings[R]
Public Class Methods
new(filename)
click to toggle source
# File lib/rnewick.rb, line 59 def initialize(filename) @newickStrings = File.open(filename).readlines.map{|line| NewickString.new(line)} @filename = filename end
Public Instance Methods
remove_taxa(taxa, pruned_tree, verbose = false)
click to toggle source
# File lib/rnewick.rb, line 73 def remove_taxa(taxa, pruned_tree, verbose = false) # assume nw_prune and nw_reroot are in the PATH nw_pruner = "nw_prune" nw_unrooter = "nw_reroot" #required_utils = [nw_pruner, nw_unrooter] required_utils = [nw_pruner] required_utils.each do |nw_util| raise "#{nw_util} from newick utilities not available" unless binary_available(nw_util) end # prune a list of taxa and unroot resulting tree with these nice and fast newick utilities # on the first tree of the file or all of them? #system "#{nw_pruner} #{@filename} #{taxa.join ' '} | #{nw_unrooter} -d - > #{pruned_tree}" system "#{nw_pruner} #{@filename} #{taxa.join ' '} > #{pruned_tree}" puts "removed #{taxa.join ','} and saved in #{pruned_tree}" if verbose end
save_each_newick_as(newfile_basename, ending)
click to toggle source
# File lib/rnewick.rb, line 66 def save_each_newick_as(newfile_basename, ending) @newickStrings.each_with_index do |newick, i| File.open(newfile_basename + "_#{i}.#{ending}" , "w") do |f| f.puts newick.str end end end
size()
click to toggle source
# File lib/rnewick.rb, line 63 def size @newickStrings.size end