刚刚接触Perl,高手来帮帮忙!
刚刚接触Perl,高手来帮帮忙!
open RESULT,">Result.txt";
my $geneseq_ref=FastaSquece('myva');
open WHOG ,"<whog";
my %alphabet_catalogy;
my %tree_hash;
my %cog_catalogy;
my %gene_species;
my %cog_des;
my $cog;
my $alphabet;
my $des;
my $species;
while(<WHOG>){
if(/^(\S+)\s+(\S+)\s+(.+)/){
$cog=$2;
$des=$3;
($alphabet)=$1;
$cog_des{$cog}=$des;
$tree_hash{$cog}=$alphabet;
push @{$alphabet_catalogy{$alphabet}},$cog;
}elsif(/^\s+(\S.+)/){
my $line=$1;
my @array=split /\s+/,$line;
if($line=~/:/){
$species=shift @array;
chop $species;
}
foreach my $gene(@array){
push @{$cog_catalogy{$cog}{$species}},$gene;
$tree_hash{$gene}=$cog;
$gene_species{$gene}=$species;
}
}
}
close WHOG;
undef $cog; undef $alphabet; undef $des; undef $species;
if($ARGV[0] ne 0){
print RESULT Rootsearch($ARGV[0])."\n";
foreach my $cog(@{$alphabet_catalogy{$ARGV[0]}}){
print RESULT "->->$cog:$cog_des{$cog}\n";
COG_Gene($cog);
}
}elsif($ARGV[1] ne 0){
print RESULT Rootsearch($ARGV[1]).":$cog_des{$cog}\n";
COG_Gene($ARGV[1]);
}elsif($ARGV[2] ne 0){
print RESULT Rootsearch($ARGV[2])."\n";
print RESULT $$geneseq_ref{$ARGV[2]};
}
exit;
sub FastaSquece{
my $file=shift;
open(FASTA,$file)|| die "$!";
my $gene;
my $seq;
my %gene2seq;
local $/='>';
while(<FASTA>){
next if(/^>/);
chomp;
($gene)=$_=~/^(\S+)/;
$seq=~s/\s+//g;
$gene2seq{$gene}=">$_";
}
local $/='\n';
close FASTA;
return \%gene2seq;
}
sub Rootsearch{
my $query=shift;
my $result=$query;
while(1){
if($query=~/^\[/){
$result='::'.$result;
last;
}
if(exists $tree_hash{$query}){
$result=$tree_hash{$query}."->".$result;
$query=$tree_hash{$query};
}else{
warn "Something seems to be wrong!;\n";
}
}
return $result;
}
sub COG_Gene{
my $cog_query=shift;
if(exists $cog_catalogy{$cog_query}){
foreach my $species (keys %{$cog_catalogy{$cog_query}}){
print RESULT "\n$species\n";
foreach my $gene(@{$cog_catalogy{$cog_query}{$species}}){
print RESULT $$geneseq_ref{$gene};
}
}
}else{
warn "NO such COG Num.\n";
}
}
这个是别人给我的一对生物信息学中的COG数据库查询的代码,麻烦高手解释下,或者加个注释