-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblast_summary_rRNA.pl
More file actions
129 lines (128 loc) · 4.11 KB
/
Copy pathblast_summary_rRNA.pl
File metadata and controls
129 lines (128 loc) · 4.11 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl -w
###################################
### Summarize Blast Output ###
### Jennifer Meneghin ###
### February 4, 2009 ###
### Updated March 12, 2009 ###
### Updated July 29, 2010 ###
### Updated August 9, 2010 ###
###################################
#-----------------------------------------------------------------------------------------------------------------------------------------
#Deal with passed parameters
#-----------------------------------------------------------------------------------------------------------------------------------------
if ($#ARGV == -1) {
&usage;
}
$in_file = "";
$out_file = "summary.out";
$db_file = "";
$flag = -1;
%my_args = @ARGV;
for $i (sort keys %my_args) {
if ($i eq "-i") {
$in_file = $my_args{$i};
}
elsif ($i eq "-o") {
$out_file = $my_args{$i};
}
elsif ($i eq "-d") {
$db_file = $my_args{$i};
$flag = 0;
}
else {
print "\nUnrecognized argument: $i\n\n";
&usage;
}
}
unless ( open(IN, "$in_file") ) {
print "\nGot a bad input file: $in_file\n\n";
&usage;
}
unless ( open(OUT, ">$out_file") ) {
print "\nGot a bad output file: $out_file\n\n";
&usage;
}
if (length($db_file) > 0) {
unless ( open(DB, "$db_file") ) {
print "\nGot a bad database file: $db_file\n\n";
&usage;
}
}
print "Parameters:\ninput file = $in_file\noutput file = $out_file";
if (length($db_file) > 0) {
print "\ndatabase file = $db_file";
}
print "\n\n";
#---------------------------------------------------------------------------------------------------------------------------
#The main event
#---------------------------------------------------------------------------------------------------------------------------
%genbank_percent = ();
%genbank_count = ();
%genomes = ();
while (<IN>) {
if (/^#/) {
next;
}
chomp;
@fields = split(/\t/);
$genbank_id = $fields[1];
$percent_identity = $fields[2];
if ( $genbank_count{$genbank_id} ) {
$genbank_percent{$genbank_id} = $genbank_percent{$genbank_id} + $percent_identity;
$genbank_count{$genbank_id} = $genbank_count{$genbank_id} + 1;
}
else {
$genbank_percent{$genbank_id} = $percent_identity;
$genbank_count{$genbank_id} = 1;
}
}
if (length($db_file) > 0 && $flag == 0) {
while (<DB>) {
$line = $_;
if ($line =~ /^>/) {
chomp($line);
$id = $line;
$id =~ s/^>(.+?)\s\|\s.+$/$1/g;
if ($genbank_count{$id}) {
$genome = $line;
$genome =~ s/^>.+?\s\|\s(.+)$/$1/g;
$genomes{$id} = $genome;
}
}
}
}
print OUT "ID\tCount\tAvg. % Identity\tGenome\n";
foreach $i (sort by_id keys %genbank_count) {
$average = $genbank_percent{$i} / $genbank_count{$i};
#print "$i\t$genbank_count{$i}\t$average";
print OUT "$i\t$genbank_count{$i}\t$average";
if (length($db_file) > 0) {
#print "\t$genomes{$i}";
print OUT "\t$genomes{$i}";
}
#print "\n";
print OUT "\n";
}
close(IN);
close(OUT);
if (length($db_file) > 0) {
close(DB);
}
sub by_id { $a cmp $b; }
sub usage {
print "BLAST SUMMARY rRNA 2.0\n";
print "Jennifer Meneghin\n";
print "March 12, 2009\n\n";
print "Last updated August 9, 2010\n\n";
print "Usage: blast_summary_rRNA.pl\n\n";
print "Parameters:\n";
print "-i <input file>\t\t\tA BLAST output file in short format\n";
print "-o <output file>\t\tThe new file to create. If not provided, a file called summary.out will be created.\n";
print "-d <database file>\t\tThe database (in fasta format) used in the BLAST (optional).\n";
print "This program takes a blast output file in short format as it's input file,\n";
print "and returns a tab delimmited list of unique database IDs found, the number of times each appeared,\n";
print "and the average percent identity found for each.\n\n";
print "If a database file (in fasta format) is provided, any extra header information (organisim name) will be included.\n";
print "Currently this script assumes the database is ssu-parc.fasta (downloaded from SILVA www.arb-silva.de), lsu-parc.fasta (also from SILVA site), or these two files concatenated together (SILVA.fasta)\n\n";
exit;
}