Skip to content

Instantly share code, notes, and snippets.

@Buttonwood
Created May 13, 2014 03:17
Show Gist options
  • Save Buttonwood/c27f8f92fd1d1932780c to your computer and use it in GitHub Desktop.
Save Buttonwood/c27f8f92fd1d1932780c to your computer and use it in GitHub Desktop.
A short script for function annotation table statistics!
#=============================================================================
# FileName: stat_func.pl
# Desc:
# Author: tanhao
# Email: tanhao2013@gmail.com
# HomePage: http://buttonwood.github.io
# Version: 0.0.1
# LastChange: 2014-05-13 10:06:14
# History:
#=============================================================================
use Data::Dumper;
#my (%cog, %kegg, %swiss, %nr, %go);
use Getopt::Long;
my ($c,$s,$n,$k,$g,$help);
GetOptions(
"cog:s" => \$c,
"kegg:s" => \$k,
"swiss:s" => \$s,
"nr:s" => \$n,
"go:s" => \$g,
"help:s" => \$help
);
if(defined($help) || (!defined($c) && !defined($k) && !defined($s) && !defined($n) && !defined($g))){
die("Usage:\n\tperl $0 -cog cog.best -kegg kegg.best -swiss swiss.best ... \n");
}
my %hash;
&hash_id($c, \%hash, 15, "COG") if($c);
&hash_id($k, \%hash, 15, "KEGG") if($k);
&hash_id($s, \%hash, 5, "SWISS") if($s);
&hash_id($n, \%hash, 15, "NR") if($n);
&hash_id($g, \%hash, 15, "GO") if($g);
#print Dumper(\%hash);
my @genes = map { $_->[0] }
sort{ $a->[1] <=> $b->[1] }
map { [$_, (split /\_/)[1]] } keys(%hash);
my @func = ("COG","KEGG","SWISS","NR","GO");
foreach my $x (@genes){
print $x;
foreach my $y (@func){
if(exists $hash{$x}{$y}){
print "\t",$hash{$x}{$y};
}else{
print "\t*";
}
}
print "\n";
}
sub hash_id{
my ($file, $h_r, $clm, $tag) = @_;
open(IN,"<$file")or die("$file wrong! Plead check\n$!");
while(<IN>){
next if (/Query\_id/);
my @t = split;
if($clm == 5){
my @a = split(/\|/, $t[4]);
$h_r->{$t[0]}->{$tag} = $a[1];
}else{
$h_r->{$t[0]}->{$tag} = $t[14];
}
}
close IN;
}
########### Float like a butterfly! Stand like a buttonwood! ###########
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment