[Bioperl-l] distances between leaf nodes

Mark A. Jensen maj at fortinbras.us
Fri Mar 12 15:45:15 UTC 2010


along with Jason's comment then you'll need to
loop through the node pairs by hand:

my @leaves = $tree->get_leaf_nodes;
my @dists;
while (my $l = shift @leaves) {
  foreach my $m (@leaves) {
    push @dists, $tree->distance( -nodes => [$l, $m] );
  }
}

should give you all n(n-1)/2 pairwise distances.

----- Original Message ----- 
From: "Jeffrey Detras" <jdetras at gmail.com>
To: <bioperl-l at bioperl.org>
Sent: Friday, March 05, 2010 1:17 AM
Subject: [Bioperl-l] distances between leaf nodes


> Hi,
>
> I am new at using the Bio::TreeIO module specifically using the newick
> format for a phylogenetic analysis. The sample_tree attached is
> Newick-formatted tree. My objective is to get all the distances between all
> the leaf nodes. I copied examples of the code from
> http://www.bioperl.org/wiki/HOWTO:Trees but it does not tell me much (to my
> knowledge) so that I understand how to assign the right array value for the
> nodes/leaves. The message would say must provide 2 root nodes.
>
> Here is what I have right now:
>
> #!/usr/bin/perl -w
> use strict;
>
> my $treefile = 'sample_tree';
> use Bio::TreeIO;
> my $treeio = Bio::TreeIO->new(-format => 'newick',
>                                 -file => $treefile);
>
> while (my $tree = $treeio->next_tree) {
>         my @leaves = $tree->get_leaf_nodes;
>         for (my $dist = $tree->distance(-nodes => \@leaves)){
>                 print "Distance between trees is $dist\n";
>         }
> }
>
> Thanks,
> Jeff
>


--------------------------------------------------------------------------------


> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l 




More information about the Bioperl-l mailing list