-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_key_word_in_annotation.pl
54 lines (52 loc) · 914 Bytes
/
search_key_word_in_annotation.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl -w
use strict;
use warnings;
use Getopt::Long;
use File::Basename;
my($go,$key,$out);
GetOptions(
"h|?" => \&USAGE,
"go:s" => \$go,
"k:s" => \$key,
"o:s" => \$out,
);
&USAGE unless (defined $go or defined $key or defined $key);
if(!defined $out){
$out ||="Result.list";
}
open(OUT,">$out");
open(IN,"$key") or die $!;
my @key=();
while(<IN>){
chomp;
push @key,$_;
}
close IN;
open(IN,"$go") or die "$!";
my %anno=();
while(<IN>){
chomp;
next if(/\#/);
my ($gene,$left)=(split /\s+/,$_,3)[0,2];
$anno{$gene}=$left;
}
close IN;
foreach my $kw(@key){
if($kw =~m/^\#/){
next;
}
foreach my $gene(sort{$a cmp $b} keys %anno){
if($anno{$gene}=~m/$kw/i){
print OUT $gene,"\t",$anno{$gene},"\n";
}
}
}
close OUT;
sub USAGE{
my $usage=<<"USAGE";
usege:
perl $0 -go <go.anno> -k <file with key> -o <default:Result>
USAGE
print $usage,"\n";
exit;
}