[Bio] / FigKernelScripts / k-class-representative_n_tree_tips.pl Repository:
ViewVC logotype

View of /FigKernelScripts/k-class-representative_n_tree_tips.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Fri Apr 17 20:59:22 2015 UTC (4 years, 7 months ago) by jdavis
Branch: MAIN
CVS Tags: HEAD
adding k-class-representative_n_tree_tips.pl

#! /usr/bin/env perl
use strict;
use gjonewicklib;
use Data::Dumper;
use Getopt::Long;

my $usage = "k-class-representative_n_tree_tips.pl -n (number of tips to keep) -i distance to increment <tree > list of tips
             -n is the number of tips you want to try to get
             -i is the distance that you wish to increment by
                if you do not specify -i, it will be the smallest tip distance
             ";

my ($n, $help, $incr);
my $opts = GetOptions('n=i'    => \$n,
                      'h'      => \$help,
                      'i=s'    => \$incr);
if ($help){die "$usage\n";}
if (! $n){die "you must enter a -n  number of tips"}; 

my $TREE = \*STDIN; 
my $treestr = join( "", <$TREE> ); 
my $tree1 = &gjonewicklib::parse_newick_tree_str( $treestr ); 
my %tip_dists = newick_tip_distances( $tree1 );
my @dists;
foreach my $key (sort { $tip_dists{$a} <=> $tip_dists{$b}} keys %tip_dists )
{
    push @dists, $tip_dists{$key};
}

my $smallest = $dists[0];
my $biggest = $dists[-1];
my @rep_tips; 
my $inc = $smallest;

if ($incr)
{
	$inc = $incr;
}

my $new_dist = $biggest;
my %opts;
my @old_tips;

while (((scalar @rep_tips)  <= $n ) && ($new_dist >= 0))
{
    @old_tips = @rep_tips;
    $opts{dist} = $new_dist; 
    @rep_tips = &gjonewicklib::representative_tips($tree1, \%opts); 
    $new_dist -= $inc;
    
    my $size = scalar @rep_tips;
    print STDERR  "Size = $size\tnewdist = $new_dist\n"; 

}
foreach (@old_tips){print "$_\n";}

#my $newtree = &gjonewicklib::newick_subtree( $tree1, @rep_tips); 
#&gjonewicklib::writeNewickTree($newtree); 






MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3