[BioRuby] newick tree

Naohisa GOTO ngoto at gen-info.osaka-u.ac.jp
Thu Jan 22 04:56:18 UTC 2009


Hi,

If you want only leaf nodes (= OTUs in normal phylogenetic tree),

  t = Bio::Newick.new("(A,(B,C),D)")
  tree = t.tree
  tree.leaves
  # => [(Node:"B"), (Node:"D"), (Node:"C"), (Node:"A")]

Naohisa Goto
ngoto at gen-info.osaka-u.ac.jp / ng at bioruby.org

On Thu, 22 Jan 2009 12:39:50 +1000
Ben Woodcroft <donttrustben at gmail.com> wrote:

> I had the same problem - managed to solve it, but it wasn't the best. It
> used something like this:
> 
> count = 0
> tree.each_node do |node|
>   #I get internal nodes here - not sure how else to skip
>   next if node.name.nil? or node.name.length == 0
> 
>   count += 1
> end
> count
> 
> 2009/1/22 Tomoaki NISHIYAMA <tomoakin at kenroku.kanazawa-u.ac.jp>
> 
> > Hi,
> >
> > I have not used the Newick feature of bioruby but the behavior
> > you showed seems doing quite right.
> > What is your expectation? Or, what do you want?
> >
> > (A,(B,C),D)
> > represents the following tree, which have 4 terminal and 2 internal nodes.
> >
> > +------A
> > |
> > |   +---B
> > |   |
> > +---+
> > |   |
> > |   +---C
> > |
> > +-----D
> >
> > The two internal nodes have no label and referred as (Node:43c98a8)
> > (Node:43c91f0) in the representation.
> >
> > --
> > Tomoaki NISHIYAMA
> >
> > Advanced Science Research Center,
> > Kanazawa University,
> > 13-1 Takara-machi,
> > Kanazawa, 920-0934, Japan
> >
> >
> >
> > On 2009/01/22, at 8:11, K. Patil wrote:
> >
> >  Hi,
> >>
> >> I was trying some simple methods for the Newick tree. I did the following,
> >>
> >>  t = Bio::Newick.new("(A,(B,C),D)")
> >>> t.tree.nodes
> >>>
> >> =>[(Node:43c98a8), (Node:"A"), (Node:"B"), (Node:"D"), (Node:43c91f0),
> >> (Node:"C")]
> >>
> >>> t.tree.number_of_nodes
> >>>
> >> => 6
> >>
> >> Am I doing something wrong? I am using bioruby version 1.2.1 in ruby 1.8.
> >> Any suggestions are welcome.
> >>
> >> Cheers,
> >> Kaustubh
> >>
> >>
> >>
> >> _______________________________________________
> >> BioRuby mailing list
> >> BioRuby at lists.open-bio.org
> >> http://lists.open-bio.org/mailman/listinfo/bioruby
> >>
> >>
> > _______________________________________________
> > BioRuby mailing list
> > BioRuby at lists.open-bio.org
> > http://lists.open-bio.org/mailman/listinfo/bioruby
> >
> 
> 
> 
> -- 
> FYI: My email addresses at unimelb, uq and gmail all redirect to the same
> place.
> _______________________________________________
> BioRuby mailing list
> BioRuby at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioruby





More information about the BioRuby mailing list