forked from NBISweden/ProtExcluder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblastformatProt.pl
executable file
·87 lines (77 loc) · 1.87 KB
/
blastformatProt.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
85
86
87
#! /usr/bin/perl
$usage = "blastformatProt.pl blastx_output_file score_cutoff identity_cutoff\nwhere the latter two are optional (default 0)\n";
# to reformat blastx ouput
if (@ARGV < 1) {die "$usage";}
if (@ARGV > 1) {$score_cutoff = $ARGV[1];}
else {$score_cutoff = 0;}
if (@ARGV > 2) {$iden_cutoff = $ARGV[2];}
else {$iden_cutoff = 0;}
open(BLT, "$ARGV[0]") || die "Can not open BLAST output $ARGV[0].\n$usage";
$score = -1;
while (<BLT>) {
if (/^Query=\s+(\S+)/) {
$query_current = $1;
$ct = "q";
}
elsif (/^>\s(\S+)/) {
$sbjct_current = $1;
$ct = "sb";
}
elsif (/^Length=(\d+)/) {
if ($ct eq "q") {
$q_len_current = $1;
}
elsif ($ct eq "sb") {
$sb_len_current = $1;
}
}
elsif (/^\s+Score =\s*(\d+)/) {
if (&filter) {
&report;
}
$head_q_boolean = 1;
$head_s_boolean = 1;
$query = $query_current;
$q_len = $q_len_current;
$sb_len = $sb_len_current;
$sbjct = $sbjct_current;
$score = $1;
}
elsif (/^\s+Identities =\s+(\d+)\/(\d+)/) {
$iden = $1/$2*100;
}
elsif (/^Query\s+(\d+)\s+(\S+)\s+(\d+)/) {
if ($head_q_boolean) {
$head_query = $1;
$head_q_boolean = 0;
}
$tail_query = $3;
}
elsif (/^Sbjct\s+(\d+)\s+(\S+)\s+(\d+)/) {
if ($head_s_boolean) {
$head_sbjct = $1;
$head_s_boolean = 0;
}
$tail_sbjct = $3;
}
}
close BLT;
if (&filter) {
&report;
}
sub filter {
if ($score > 0 && $score > $score_cutoff && $iden > $iden_cutoff) {
return 1;
}
return 0;
}
sub report {
if ($head_query < $tail_query) {
printf("%06d %03d %05d %05d %-5d %-30s %05d %05d %05d %-30s +\n", $score, $iden, $head_query,
$tail_query, $q_len, $query, $head_sbjct, $tail_sbjct, $sb_len, $sbjct);
}
else {
printf("%06d %03d %05d %05d %-5d %-30s %05d %05d %05d %-30s C\n", $score, $iden, $tail_query,
$head_query, $q_len, $query, $head_sbjct, $tail_sbjct, $sb_len, $sbjct);
}
}