[Bio] / FigKernelScripts / km_pick_best_hit_in_peg.pl Repository:
ViewVC logotype

View of /FigKernelScripts/km_pick_best_hit_in_peg.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Thu Oct 6 19:09:49 2016 UTC (3 years, 1 month ago) by olson
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +18 -6 lines
Some readability / documentation changes.

use strict;
use Data::Dumper;

use Getopt::Long;
my $no_scores = 0;

my $usage = "usage: km_pick_best_hit_in_peg [-n]\n";

my $rc  = GetOptions('n'   => \$no_scores);
if (! $rc)
{ 
    print STDERR $usage; exit ;
}

use SeedUtils;
while (defined($_ = <STDIN>) && ($_ ne "---------------------\n")) { }
my $last = <STDIN>;
while ($last && ($last =~ /^(\S+)/))
{
    my $peg = $1;
    my %funcsW;
    my %funcs;
    my $z_sc = -100;
    #
    # Row format: 0 contig, 1 beg, 2 end, 3 strand, 4 frame, 5 hits, 6 func, 7 weighted-score, 8 funcIdx
    #
    #                    0     1    2    3    4    5      6            7       8     9
    #                  $1                         $2     $3            $4        $5 $6
    while (($last =~ /^(\S+)\t\S+\t\S+\t\S+\t\S+\t(\d+)\t(\S[^\t]*\S)\t(\S+)\t\S+(\t(\S+))?/) && ($peg eq $1))
    {
	my $hits = $2;
	my $func = $3;
	my $weighted_score = $4;
	my $hit_zsc = $6;
	
	$funcsW{$func} += $weighted_score;
	$funcs{$func} += $hits;
	$z_sc       = ($hit_zsc > $z_sc) ? $hit_zsc : $z_sc;
	$last = <STDIN>;
    }
    my @funcs = sort { $funcsW{$b} <=> $funcsW{$a} } keys(%funcs);
    my $best_func = $funcs[0];

    if ($no_scores)
    {
	print "$peg\t$best_func\n";
    }
    else
    {
	print "$peg\t$best_func\t$funcs{$best_func}\t$funcsW{$best_func}\t$z_sc\n";
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3