Skip to content

Commit 83944fd

Browse files
committed
Support for HAMAP.hmm.gz
1 parent 851237b commit 83944fd

5 files changed

Lines changed: 58 additions & 23 deletions

File tree

bin/prokka

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use Bio::Tools::GuessSeqFormat;
4646
my @CMDLINE = ($0, @ARGV);
4747
my $OPSYS = $^O;
4848
my $EXE = $FindBin::RealScript;
49-
my $VERSION = "1.15.5";
49+
my $VERSION = "1.15.6";
5050
my $AUTHOR = 'Torsten Seemann <torsten.seemann@gmail.com>';
5151
my $URL = 'https://github.com/tseemann/prokka';
5252
my $PROKKA_PMID = '24642063';
@@ -1659,8 +1659,15 @@ sub setup_db {
16591659
}
16601660

16611661
check_tool('hmmpress');
1662-
for my $hmm (<$dbdir/hmm/*.hmm>) {
1662+
for my $hmm (<$dbdir/hmm/*.{hmm,hmm.gz}>) {
16631663
msg("Pressing HMM database: $hmm");
1664+
# We may need to uncompress first
1665+
if ($hmm =~ m/^(.*?)\.gz$/) {
1666+
msg("Uncompressing: $hmm");
1667+
my $hmm_u = $1;
1668+
runcmd("gzip -dc \Q$hmm\E > \Q$hmm_u\E");
1669+
$hmm = $hmm_u;
1670+
}
16641671
runcmd("hmmpress \Q$hmm\E");
16651672
}
16661673

bin/prokka-genbank_to_fasta_db

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ while (my $seq = $in->next_seq) {
4141

4242
next unless $f->length >= $minlen;
4343

44-
next if !$pseudo and $f->has_tag('pseudo');
44+
next if !$pseudo and ($f->has_tag('pseudo') or $f->has_tag('pseudogene'));
4545

4646
my $prod = TAG($f, 'product') || $blank;
4747

@@ -54,7 +54,7 @@ while (my $seq = $in->next_seq) {
5454
$id = TAG($f, $idtag);
5555
last if $id;
5656
}
57-
$id or die "\nFeature #$counter does not have any of these tags: @TRYIDTAG";
57+
$id or die "\nFeature #$counter does not have any of these tags: @TRYIDTAG".Dumper($f);
5858
$counter++;
5959
print STDERR "[$counter] ", $seq->display_id, " | $id | $prod\n" if $verbose;
6060

bin/prokka-hamap_to_hmm

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,44 @@ use Bio::SeqIO;
66
use Data::Dumper;
77
use File::Temp qw(tempdir);
88

9-
my(@Options, $verbose, $datadir, $hypo, $sep, $blank, $pseudo, $minlen);
9+
my(@Options, $verbose, $datadir, $hypo, $sep, $blank,
10+
$pseudo, $minlen, $seeds, $index, $rules);
1011
setOptions();
1112

1213
$datadir or die "please specify HAMAP --datadir";
1314
-d $datadir or die "--datadir $datadir is not a valid folder";
15+
$seeds or die "need --seeds .tgz file";
16+
$index or die "need --index .dat file";
17+
$rules or die "need --rules .dat file";
1418

1519
my $dir = tempdir(CLEANUP=>1);
1620
print STDERR "Using $dir as temp folder.\n";
1721

22+
1823
my %DESC;
19-
my $ali_fh = get_file("alignment_id.dat", "alignment /gene /product info");
24+
my $ali_fh = get_file($index, "alignment /gene /product info");
2025
while (<$ali_fh>) {
26+
#0 MF_00001
27+
#1 MF_00001
28+
#2 28
29+
#3 PYRB
30+
#4 pyrB
31+
#5 Aspartate carbamoyltransferase [pyrB]
2132
chomp;
2233
my @x = split m/\t/;
23-
next if $x[5] =~ m/UPF\d+|homolog|[@<\[]/;
34+
$x[5] =~ s/\s\[\w+\]$//;
35+
next if $x[5] =~ m/UPF\d+|homolog/;
2436
$x[5] =~ s/^probable\s+//gi;
2537
$DESC{ $x[0] } = "$sep$x[4]$sep$x[5]";
2638
}
27-
printf STDERR "Accepted descriptions for %d families\n", scalar keys %DESC;
39+
printf STDERR "Accepted descriptions for %d families\n", scalar keys %DESC;;
2840

29-
my $fam_fh = get_file("hamap_families.dat", "alignment /EC_number");
41+
my $fam_fh = get_file($rules, "alignment /EC_number");
3042
my($AC,$EC,$Bac);
3143
while (<$fam_fh>) {
3244
chomp;
3345
if (m{^//}) {
34-
#print STDERR "AC=$AC EC=$EC Bac=$Bac\n";
46+
print STDERR "AC=$AC EC=$EC Bac=$Bac\n";
3547
if ($AC and $EC and exists $DESC{$AC}) {
3648
$DESC{$AC} = $EC.$DESC{$AC};
3749
}
@@ -53,7 +65,7 @@ while (<$fam_fh>) {
5365
}
5466
printf STDERR "%d models made it through filtering\n", scalar keys %DESC;
5567

56-
my $aln_file = "$datadir/hamap_seed_alignments.tar.gz";
68+
my $aln_file = $seeds;
5769
if (-r $aln_file) {
5870
print STDERR "Extracting $aln_file.\n";
5971
system("tar -C $dir --strip-components 1 -zxf $aln_file")==0 or die "ERROR: $?";
@@ -83,23 +95,24 @@ else {
8395
}
8496

8597
my $dest = 'HAMAP.hmm';
86-
print STDERR "Combining into $dest\n";
87-
system("cat $dir/*.hmm > $dest");
88-
98+
print STDERR "Combining into $dest.ascii\n";
99+
system("cat $dir/*.hmm > $dest.ascii");
100+
print STDERR "Converting to binary $dest\m";
101+
system("hmmconvert -b $dest.ascii > $dest.hmm");
89102

90103
print STDERR "Done.\n";
91104

92105
#----------------------------------------------------------------------
93106

94107
sub get_file {
95108
my($pattern, $desc) = @_;
96-
my($first) = glob("$datadir/$pattern");
109+
my($first) = glob("$pattern");
97110
if ($first and -r $first) {
98111
print STDERR "Found $desc: $first\n";
99112
open my $fh, '<', $first;
100113
return $fh;
101114
}
102-
die "Problem finding $pattern in $datadir ($desc)";
115+
die "Problem finding '$pattern'";
103116
}
104117

105118
#----------------------------------------------------------------------
@@ -111,7 +124,10 @@ sub setOptions {
111124
@Options = (
112125
{OPT=>"help", VAR=>\&usage, DESC=>"This help"},
113126
{OPT=>"verbose!", VAR=>\$verbose, DEFAULT=>0, DESC=>"Verbose progress"},
114-
{OPT=>"datadir=s", VAR=>\$datadir, DEFAULT=>'', DESC=>"Path to downloaded HAMAP folder (ftp://ftp.expasy.org/databases/hamap/)" },
127+
{OPT=>"datadir=s", VAR=>\$datadir, DEFAULT=>'hamap_seed_alignments', DESC=>"Path to downloaded HAMAP folder (ftp://ftp.expasy.org/databases/hamap/)" },
128+
{OPT=>"seeds=s", VAR=>\$seeds, DEFAULT=>'hamap_seed_alignments.tar.gz', DESC=>"Seed alignments .tgz" },
129+
{OPT=>"index=s", VAR=>\$index, DEFAULT=>'rules_index.dat', DESC=>"Index file" },
130+
{OPT=>"rules=s", VAR=>\$rules, DEFAULT=>'hamap_rules.dat', DESC=>"Rules file" },
115131
{OPT=>"sep=s", VAR=>\$sep, DEFAULT=>'~~~', DESC=>"Separator between EC/gene/product" },
116132
{OPT=>"blank=s", VAR=>\$blank, DEFAULT=>'', DESC=>"Replace empty EC/gene/product with this"},
117133
# {OPT=>"pseudo!", VAR=>\$pseudo, DEFAULT=>0, DESC=>"Include /pseudo genes"},

db/hmm/HAMAP.hmm

-95.3 MB
Binary file not shown.

update-dbs/Makefile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22

33
DIR := ../db/kingdom
4+
DIR_HMM := ../db/hmm
45
DIR_B := $(DIR)/Bacteria
56
DIR_A := $(DIR)/Archaea
67
DIR_V := $(DIR)/Viruses
@@ -14,19 +15,32 @@ CP := cp -vf
1415

1516
.PHONY: install all
1617

17-
18-
ALL := AMR sprot_b sprot_v sprot_a
18+
ALL := AMR sprot_b sprot_v sprot_a HAMAP.hmm.gz
1919

2020
all: $(ALL)
2121

2222
install : $(ALL)
23-
$(CP) AMR $(DIR_B)/AMR
23+
$(CP) HAMAP.hmm.gz $(DIR_HMM)/
24+
$(CP) AMR $(DIR_B)/
2425
$(CP) sprot_b $(DIR_B)/sprot
2526
$(CP) sprot_a $(DIR_A)/sprot
2627
$(CP) sprot_v $(DIR_V)/sprot
2728
# $(CP) sprot_m $(DIR_M)/sprot
28-
2929

30+
HAMAP.hmm.gz : HAMAP.hmm
31+
pigz -9 < $< > $@
32+
33+
HAMAP.hmm : hamap_rules.dat rules_index.dat hamap_seed_alignments.tar.gz
34+
../bin/prokka-hamap_to_hmm
35+
36+
hamap_rules.dat :
37+
wget https://ftp.expasy.org/databases/hamap/hamap_rules.dat
38+
39+
rules_index.dat :
40+
wget https://ftp.expasy.org/databases/hamap/rules_index.dat
41+
42+
hamap_seed_alignments.tar.gz :
43+
wget https://ftp.expasy.org/databases/hamap/hamap_seed_alignments.tar.gz
3044

3145
AMR: AMRProt.fa
3246
./AMRprot-to-AMR.pl $< > $@
@@ -54,5 +68,3 @@ uniprot_sprot_virsues.dat.gz :
5468

5569
clean :
5670
rm -f $(ALL)
57-
58-

0 commit comments

Comments
 (0)