-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathblast2krona.pl
executable file
·68 lines (60 loc) · 1.46 KB
/
blast2krona.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
#!/usr/bin/perl
# Script: blast2krona.pl
# Description: Takes BLAST results and creates a Krona data file
# Author: Steven Ahrendt
# email: [email protected]
# Date: 02.19.2014
##################################
use warnings;
use strict;
use Getopt::Long;
use Bio::SearchIO;
use Data::Dumper;
#####-----Global Variables-----#####
my $input;
my ($help,$verb);
my %results;
my %tax_hierarchy;
my $taxfile = "/rhome/sahrendt/bigdata/Genomes/tax_hierarchy";
GetOptions ('i|input=s' => \$input,
'h|help' => \$help,
'v|verbose' => \$verb);
my $usage = "Usage: blast2krona.pl -i input\nOutput to STDOUT\n";
die $usage if $help;
die "No input.\n$usage" if (!$input);
#####-----Main-----#####
open(TAX,"<$taxfile");
while(my $line = <TAX>)
{
next if ($line =~ /^#/);
chomp $line;
my @data = split(/\t/,$line);
$tax_hierarchy{$data[0]} = $data[1];
}
#print Dumper \%tax_hierarchy;
my $blast_io = Bio::SearchIO->new(-file => $input,
-format => "blasttable");
while(my $result = $blast_io->next_result)
{
while( my $hit = $result->next_hit )
{
# print $hit->name,"\n";
my $species = (split(/\|/,$hit->name))[0];
$results{$species}++;
}
}
foreach my $key (sort keys %results)
{
print $results{$key},"\t";
if($key =~ /Npar/)
{
$key = "Npar";
}
my $tmp = $tax_hierarchy{$key};
# print $tmp,"\n";
$tmp =~ s/;/\t/g;
print $tmp,"\n";
}
warn "Done.\n";
exit(0);
#####-----Subroutines-----#####