[Bioperl-l] distances between leaf nodes
Arnau Montagud
beornk at gmail.com
Fri Dec 17 16:05:47 UTC 2010
Hello, I am new to Bioperl and looking for a solution to this specific
problem, I found this mailing list.
I am trying to know distances between all the leaves of a given
extended newick tree. Thanks to your script I can have a vector
(@dists) with all the distances, but I would like to know from what
pair of nodes are those distances from (!).
Thanks!
My current script is:
use Bio::TreeIO;
$tree = Bio::TreeIO->new(
-file=>'tree',
-format=>'nhx'
)->next_tree;
my @nodes = $tree->get_leaf_nodes;
my @dists;
while (my $l = shift @nodes) {
foreach my $m (@nodes) {
push @dists, $tree->distance( -nodes => [$l, $m] );
}
}
foreach (@dists) {
print "$_\n";
}
On 12 mar, 16:45, "Mark A. Jensen" <maj at fortinbras.us> wrote:
> 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 pairwisedistances.
>
>
>
>
>
>
>
>
>
> ----- 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]distancesbetweenleafnodes
>
> > 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 thedistancesbetweenall
> > theleafnodes. I copied examples of the code from
> >http://www.bioperl.org/wiki/HOWTO:Treesbut 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 rootnodes.
>
> > 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 "Distancebetweentrees 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
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.orghttp://lists.open-bio.org/mailman/listinfo/bioperl-l
More information about the Bioperl-l
mailing list