/
countBlastTaxids.pl
55 lines (45 loc) · 1.17 KB
/
countBlastTaxids.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
#!/usr/bin/perl -w
use strict;
# countBlastTaxids.pl [.blast] [categories.dmp] > out.tsv
# Requires tabular blast file with staxid
my ($dmp, $blast) = @ARGV;
my %hash;
open DMP, $dmp;
while (<DMP>) {
chomp;
my @line = split '\t', $_;
my ($cat, $id) = ($line[0], $line[2]);
# print $cat, "\t", $id, "\n";
$hash{$id} = $cat;
}
close DMP;
my @domains = ('A', 'B', 'E', 'V', 'U');
my %count;
open BLAST, $blast;
while (<BLAST>) {
chomp;
my @line = split '\t', $_;
my ($query,$taxids) = ($line[0], $line[-1]);
my @taxids = split ';', $taxids;
my $taxid = $taxids[0];
# print $query, "\t", $taxa[0], "\n";
foreach my $dom (@domains) {
if (exists $hash{$taxid}) {
$count{$query}{$dom}++ if ($hash{$taxid} =~ /$dom/);
}
else {print STDERR "$query:\t$taxid is not available in categories.dmp\n"}
}
}
close BLAST;
print "CDS", "\t";
foreach my $dom (@domains) {print $dom, "\t"}
print "\n";
foreach my $query (keys %count) {
print $query, "\t";
foreach my $dom (@domains) {
if (exists $count{$query}{$dom}) {print $count{$query}{$dom}}
else {print "0"}
print "\t";
}
print "\n";
}