forked from Axolotl233/Simple_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blast.grep.result.pl
57 lines (53 loc) · 1.09 KB
/
Blast.grep.result.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
#! perl
use warnings;
use strict;
use Getopt::Long;
my $gene = shift or die "need gene\n";
my $blast = shift or die "need blast\n";
my $max = shift;
$max //= 1;
my %blast = %{&blast_load($blast)};
open IN,'<',$gene;
while(<IN>){
chomp;
if(exists $blast{$_}){
print join "\n",@{$blast{$_}};
print "\n";
}
}
sub blast_load{
my $f = shift @_;
my %h;
open IN,'<', $f or die "$!";
while(<IN>){
chomp;
my @l = split/\t/;
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}};
#print $a[1][0];exit;
@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{$k}} , $n;
}
}else{
for(my $i = 0;$i <= ($num-1);$i++){
my $n = @{$a[$i]}[0];
push @{$p{$k}} , $n;
}
}
}
return %p;
}