Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: supertree construction in perl

by thomas895 (Chaplain)
on Oct 08, 2012 at 07:24 UTC ( #997756=note: print w/replies, xml ) Need Help??

in reply to supertree construction in perl

I always wished I could see into your mind, OP, and figure out your exact problem, and then just searh your $knowledge for the required backstory. But I can't, and you're going to have to use more general terms here so that programmers can understand. Assume we are the normal, entry-level class on your subject in a suburban high school. Assume we're just teenagers(which I in fact am, but I'm speaking metaphorically here), and know next to nothing about the subject. Assume you are the teacher, and someone has written "How do I post a question effectively?" on the blackboard.
Even simple, one-sentence explanations of a concept(as in, what does the data look like in some steps of the process?) can go a long way. I looked at the textbook-thing you linked to, but it's just words-words-words-sciencey-word-words-words-words to me. Maybe it's because I'm just a 15-year-old who is fascinated by his chemistry textbook. Who knows? I'm still a few years away from college.

As for your code, I think you need to choose better variable names. I have great difficulty reading code that just looks like random characters(people often ask me, "thomas, why do you use Perl?"). I hope this isn't supposed to end up as an obfuscation. You will eventually forget the meaning of those names, and then your code becomes a confusing mess. Avoid "a" and "b" aa variable names unless that is in context with sort.
DEBUG() seems to be an empty subroutine. Is that what you intended?

P.S.: Ignore the first part if you want. I'm tired, which causes my writeups to become long and ramble-y. I'll probably remove it tomorrow, after thinking "why would I write that?"

confess( "I offer no guarantees on my code." );

Replies are listed 'Best First'.
Re^2: supertree construction in perl
by zing (Beadle) on Oct 08, 2012 at 08:34 UTC
    Hi Thomas, Yes you are very true. So I have edited the code properly this time and introduces proper variable names and indentation.
    #This program read the triplets from file named "data" and returns the #supertree. # ___DATA(triplets)____ #b c a #a c d #d e b #### NOTE ::: SuperTree part hasnt been incorporated yet. use strict; use warnings; use Data::Dumper; use Graph; use Data::Dump qw/ pp /; ####READ IN THE INPUT DATA ######## my @triplets; # Get all the triplets while (<>) { push @triplets, [ split ]; } #Make a deep copy of @triplets my @triplet_deep_copy = map { [@$_] } @triplets; #####AUXILIARY GRAPH G(L) ####### # In order to generate the G(L) first of all extract first two column +s of @triplets into another matrix my @auxiliary_edges=@triplets; splice(@$_, 2, 1) foreach @auxiliary_edges; print "----EDGE LIST TO BUILD AUXILIARY GRAPH-----\n"; print Dumper \@auxiliary_edges; ##### CONNECTED COMPONENTS ########## my $auxiliary_graph = Graph->new( undirected => 1 ); my @from; my @to; for (my $p = 0; $p <= 2; $p++) { $from[$p]=$triplets[$p][0]; } for (my $q = 0; $q <= 2; $q++) { $to[$q]=$triplets[$q][1]; } for (my $r = 0; $r <= 2; $r++) { $auxiliary_graph->add_edge($from[$r], $to[$r]); } my @subgraphs = $auxiliary_graph->connected_components; # Subgraphs my $V = $auxiliary_graph->vertices; # Number of taxa my $connected_components=scalar @subgraphs; #Get the number of connect +ed components ###### FINDING THE TRIPLETS WHICH ARE SUBSET(OR INDUCED BY) OF EACH OF + THE CONNECTED COMPONENTS###### Main(@auxiliary_edges); exit(0); sub induced { my $trip = shift; my @matches; for my $QT ( @_ ) { for my $triplet ( @$trip ) { my %seen; # my %Pie; undef @seen{@$QT}; delete @seen{@$triplet}; if ( keys( %seen ) <= ( @$QT - @$triplet ) ) { push @matches, $triplet; } } ## end for my $triplet ( @$trip ) } ## end for my $QT ( @_ ) return @matches; }## end sub induced sub Main { my $tree = Graph->new( undirected => 1 ); my $dad='u'; $tree->add_vertex($dad); for my $one (@subgraphs) { my @matches = induced( \@triplet_deep_copy, $one ); print "\nTriplet induced by subgraph ", pp( $one => { MATCHES => + \@matches } ), "\n\n"; } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997756]
and the pool shimmers...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2018-05-27 23:31 GMT
Find Nodes?
    Voting Booth?