forked from Axolotl233/Simple_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blast.swissport2go.pl
84 lines (78 loc) · 1.77 KB
/
Blast.swissport2go.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! perl
use warnings;
use strict;
use Getopt::Long;
use File::Basename;
(my $blast,my $idmapping,my $max,my $out);
GetOptions(
'blast=s' => \$blast,
'idmapping=s' => \$idmapping,
'max=s' => \$max,
'out=s' => \$out
);
$idmapping //= "/data/01/user112/database/nr/idmapping.tb";
$max //= 5;
exit if (! $blast);
my $name = basename $blast;
$out = $name."go.out";
my %blast = %{&blast_load($blast)};
my %o;
open IN,'<',$idmapping or die "$!";
while(<IN>){
chomp;
my @l = split/\t/;
if($l[0] ne ""){
next if $l[7] eq "";
if(exists $blast{$l[0]}){
(my $go = $l[7]) =~ s/\s+//;
my @gos = split/;/,$go;
for my $g (@{$blast{$l[0]}}){
push @{$o{$g}} , @gos;
}
}
}
}
close IN;
open O,'>',"$out" or die "$!";
for my $k(sort {$a cmp $b} keys %o){
my $p = join"\t",@{$o{$k}};
print O "$k\t$p\n";
}
close O;
sub blast_load{
my $f = shift @_;
my %h;
open IN,'<', $f or die "$!";
while(<IN>){
chomp;
my @l = split/\t/;
$l[1] =~ s/(.*?)\..*/$1/;
#print $l[1];exit;
push @{$h{$l[0]}} , [$l[1],$l[-1]];
}
close IN;
%h = &blast_filter(\%h,$max);
return \%h
}
sub blast_filter{
my $ref = shift @_;
my %h = %{$ref};
my %p;
for my $k (keys %h){
my @a = @{$h{$k}};
@a = sort{${$b}[1] <=> ${$a}[1]} @a;
my $num = scalar @a;
if($num >= $max){
for(my $i = 0;$i < ($max-1);$i++){
my $n = @{$a[$i]}[0];
push @{$p{$n}} , $k;
}
}else{
for(my $i = 0;$i < ($num-1);$i++){
my $n = @{$a[$i]}[0];
push @{$p{$n}} , $k;
}
}
}
return %p;
}