[Bioperl-l] comparing phylogenies.
Jason Stajich
jason.stajich at duke.edu
Mon Nov 8 10:41:54 EST 2004
On Nov 4, 2004, at 10:27 AM, Zara Ghazoui wrote:
> Hi Jason,
>
> I am not sure if the method below would work in my case for comparing
> phylogenies.
>
> So
> - Make a list of node names in Tree A which into a clade with 70%
> support (based on the code I posted before).
> - Then find these nodes in Tree B (find_node method).
> - Find their LCA (get_lca method).
> - Then walk back down from the LCA (an internal node) and get all the
> tips (get_all_Descendents + the grep code posted below).
> - Check if there are any other taxa in the clade thus violating your
> requirement of identical clades.
>
> Post your code that does parts of what you want and we can help point.
> Please post to the list so other people can learn from it too.
>
>
> The reason being is that when I get all the descendents of the LCA in
> Tree B for a particular node, I will just get all the taxa provided
> that this particular node is an edge. Therefore the taxa would be the
> same since I have used the same species to build my 2 single gene
> phylogenies (TreeA and TreeB).
>
> So I though instead of looking up all the nodes from Tree A in Tree B,
> I 'll only look up the leafnodes. Also instead of going all the way
> down to the LCA in tree B,
> maybe I can just compare the descendents of the parents of that
> particular leafnode in Tree A and Tree B. However I think this will
> only work for comparing the groupings that form the leaves of my tree.
> So is there any way of doing this process recursively starting from
> the leaves i.e. Find leafnode X in Tree B, look up its sister groups
> (the descendents of its parent) + compare with the sister groups of
> leafnode X in TreeA. If similar move up Tree B doing this same
> process all the way to LCA in Tree B but if different then break
> saying these groupings are different.
>
I think this should work to get the sister group:
my @sister_group = grep {$_->is_Leaf && $node->internal_id !=
$_->internal_id } $node->ancestor->get_all_Descendents
internal_id is only relevant for within-tree comparisons.
$_->is_Leaf insures you are only building lists which are leaf nodes.
>
> Thanks lot for your help in advance.
>
> Zara
>
>
>
>
>
>
>
>
>
> #!/usr/bin/perl
> use Bio::TreeIO;
> use Array::Compare ;
>
> my $inputA = new Bio::TreeIO(-file =>
> "/biol/people/zg105/ProSeqFasta/
> AgroBradRpalusMesoSinoBrumelCauloRleg_stuff/aligned_files/test/
> 1.phb",-format => "newick");
> my $treeA = $inputA->next_tree;
>
> my $inputB = new Bio::TreeIO (-file =>
> "/biol/people/zg105/ProSeqFasta/
> AgroBradRpalusMesoSinoBrumelCauloRleg_stuff/aligned_files/test/
> 10.phb",-format => "newick");
> my $treeB = $inputB ->next_tree;
>
> my $array_comp = Array::Compare->new;
> my @TreeA_leaves = grep {$_-> is_Leaf() && $_->ancestor->bootstrap >
> 700 } $treeA->get_nodes;
>
> for my $TreeAleaf (@TreeA_leaves) {
> my $TreeAleaf_parent = $TreeAleaf ->ancestor;
> my @TreeA_parent_descendents = $TreeAleaf_parent
> ->get_all_Descendents();
> my $TreeAleafname = $TreeAleaf ->id;
> print ("Node in TreeA is $TreeAleafname \n");
> for my $TreeA_parent_descendent (@TreeA_parent_descendents){
> $TreeA_DescendentName = $TreeA_parent_descendent ->id ;
> push (@TreeA_DescendentNames ,$TreeA_DescendentName);
> print ("Descendents of this node in TreeA are
> $TreeA_DescendentName\n");
> }
>
> my @TreeB_leaves = grep {$_-> is_Leaf() && $_->ancestor->bootstrap
> > 700 } $treeB->get_nodes;
> for my $TreeBleaf (@TreeB_leaves){
> if ($TreeBleaf ->id eq $TreeAleafname ){
> my $TreeBleaf_parent = $TreeBleaf ->ancestor;
> my @TreeB_parent_descendents =
> $TreeBleaf_parent->get_all_Descendents();
> for my $TreeB_parent_descendent (@TreeB_parent_descendents){
> $TreeB_DescendentName = $TreeB_parent_descendent ->id ;
> push (@TreeB_DescendentNames ,$TreeA_DescendentName);
> print ("Descendents of this node in TreeB are
> $TreeB_DescendentName \n");
> unless( grep{ $_->id eq $TreeB_DescendentName}
> @DescendentANames) {
> print ("The trees are different\n");
> }
> }
> }
> }
> }
>
> Well I'm only going to help if you try some of this out on your own
> first and post what you've tried.
>
> $tree->get_lca(-nodes => \@nodes) will find the least common ancestor
> ($node) = $tree->find_node($name) will find a particular node based
> on its name
>
> So
> - Make a list of node names in Tree A which into a clade with 70%
> support (based on the code I posted before).
> - Then find these nodes in Tree B (find_node method).
> - Find their LCA (get_lca method).
> - Then walk back down from the LCA (an internal node) and get all the
> tips (get_all_Descendents + the grep code posted below).
> - Check if there are any other taxa in the clade thus violating your
> requirement of identical clades.
>
> Post your code that does parts of what you want and we can help point.
> Please post to the list so other people can learn from it too.
>
> -jason
>
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>
>
--
Jason Stajich
jason.stajich at duke.edu
http://www.duke.edu/~jes12/
More information about the Bioperl-l
mailing list