forked from Axolotl233/Simple_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phase.kobas2gokegg.pl
61 lines (57 loc) · 1.13 KB
/
Phase.kobas2gokegg.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
55
56
57
58
59
60
61
#! perl
use warnings;
use strict;
use Getopt::Long;
my (@fs,$prefix,$out);
GetOptions(
'in=s' => \@fs,
'out=s' => \$out,
'prefix=s' => \$prefix
);
if(scalar @fs == 0){
print STDERR "USAGE : perl $0 --in kobas.res1 --in kobas.res2 [--out]\n";
exit;
}
$out //= "kobas";
my $go_out = "$out.go.tsv";
my $kegg_out = "$out.kegg.tsv";
my @kegg;
my %go;
for my $f (@fs){
open IN,'<',$f or die "$!";
Kegg:while(<IN>){
next if /^#/;
next unless length;
if(/^-/){
last Kegg;
}else{
push @kegg,$_;
}
}
#my $c = "////";
$/="////";
while(<IN>){
my @info = split/\n/;
my $gene;
for my $e (@info){
next if /\/^/;
next if /\s^/;
if($e =~ /Query:/){
$gene = (split/\t/,$e)[1];
}elsif($e =~ /(GO:\d+)/){
push @{$go{$gene}} , $1;
}
}
}
$/="\n";
}
open O,'>',$kegg_out;
print O @kegg;
close O;
open O,'>',$go_out;
for my $k (sort {$a cmp $b} keys %go){
print O "$k\t";
print O join"\t",@{$go{$k}};
print O "\n";
}
close O;