Sha256: 9c7689c4afe300b407d1cdd879ce5131f1a1c8c1df1f419fe8e1d46ae3b35842
Contents?: true
Size: 1.94 KB
Versions: 31
Compression:
Stored size: 1.94 KB
Contents
#!/usr/bin/env ruby # NOTE make sure the newick has no spaces for jsPhyloXML # NOTE for Archaeopteryx, you need <name>#{boot}</name> to show # bootsraps, but for jsPhyloXML, just the confidence is needed require "set" require "bio" def leaf? tree, node tree.children(node).empty? end newick = ARGV.first treeio = Bio::FlatFile.open(Bio::Newick, newick) newick = treeio.next_entry $tree = newick.tree $xml_start = %q{<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd" xmlns="http://www.phyloxml.org"> <phylogeny rooted="false"> <clade> } $xml_end = %q{</clade> </phylogeny> </phyloxml> } def leaf? tree, node tree.descendents(node).count.zero? end def make_xml_string descendents, start_node while (node = descendents.shift) unless $already_added.include? node if leaf? $tree, node # TODO this will raise something if no dist, rescue it dist = $tree.distance(start_node, node) $xml_start << "<clade> <name>#{node.name}</name> <branch_length>#{dist}</branch_length> </clade>\n" $already_added << node $prev_node = node else boot = node.bootstrap if boot boot_xml = %Q{<confidence type="bootstrap">#{boot}</confidence>} else boot_xml = "" end # TODO this will raise something if no dist, rescue it dist = $tree.distance(start_node, node) $xml_start << "<clade> <branch_length>#{dist}</branch_length> #{boot_xml}" STDERR.puts "LOG -- recurse" make_xml_string $tree.descendents(node), node $xml_start << "</clade>\n" $already_added << node end end end end $already_added = Set.new STDERR.puts $tree.nodes.inspect start_node = $tree.root $descendents = $tree.descendents(start_node) STDERR.puts $descendents.inspect make_xml_string $descendents, start_node puts $xml_start puts "#{$xml_end}"
Version data entries
31 entries across 31 versions & 1 rubygems