Skip to content

Commit e4b55dd

Browse files
committed
build(docker): build kraken2 from git
1 parent f9a4eb1 commit e4b55dd

1 file changed

Lines changed: 13 additions & 123 deletions

File tree

Dockerfile

Lines changed: 13 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,54 @@
1-
# stage: build the Rust binary
21
FROM rust:slim AS builder
32

43
COPY . /nohuman
4+
55
WORKDIR /nohuman
66

77
RUN apt update \
88
&& apt install -y musl-tools libssl-dev pkg-config \
99
&& cargo build --release \
1010
&& strip target/release/nohuman
1111

12-
# stage: build and patch Kraken2
1312
FROM ubuntu:24.04 AS kraken
1413

14+
# for easy upgrade later. ARG variables only persist during build time.
1515
ARG K2VER="2.17"
1616

17-
# install dependencies (include git so we can apply patches)
17+
# install dependencies and cleanup apt garbage
1818
RUN apt-get update && apt-get -y --no-install-recommends install \
1919
wget \
2020
ca-certificates \
2121
zlib1g-dev \
2222
make \
2323
g++ \
24+
git \
2425
libgoogle-perftools-dev \
2526
rsync \
2627
cpanminus \
27-
ncbi-blast+ \
28-
git \
29-
&& rm -rf /var/lib/apt/lists/* && apt-get autoclean
28+
ncbi-blast+ && \
29+
rm -rf /var/lib/apt/lists/* && apt-get autoclean
3030

3131
# perl module required for kraken2-build
3232
RUN cpanm Getopt::Std
3333

34-
# Download Kraken2, apply patches (both Makefile+install_kraken2.sh and scripts/k2),
35-
# then install into the container. We initialize a temporary git repo to allow git apply.
36-
RUN wget https://github.com/DerrickWood/kraken2/archive/v${K2VER}.tar.gz \
37-
&& tar -xzf v${K2VER}.tar.gz \
38-
&& rm -rf v${K2VER}.tar.gz \
39-
&& cd kraken2-${K2VER} \
40-
&& git init . \
41-
&& git add . \
42-
&& git commit -m "orig kraken2" >/dev/null 2>&1 || true \
43-
&& cat > /tmp/0001-src-Makefile.patch <<'PATCH'
44-
diff --git a/src/Makefile b/src/Makefile
45-
index df902f3..39be19e 100644
46-
--- a/src/Makefile
47-
+++ b/src/Makefile
48-
@@ -1,17 +1,17 @@
49-
-CXX ?= g++
50-
+CXX ?= $(CXX)
51-
KRAKEN2_SKIP_FOPENMP ?= -fopenmp
52-
-CXXFLAGS = $(KRAKEN2_SKIP_FOPENMP) -Wall -std=c++11 -O3 -fPIC
53-
-CXXFLAGS += -DLINEAR_PROBING
54-
-CFLAGS = -Wall -std=c99 -O0 -g3
55-
+CXXFLAGS = $(KRAKEN2_SKIP_FOPENMP) -Wall -std=c++14 -O3 -fPIC
56-
+CXXFLAGS += -DLINEAR_PROBING $(LDFLAGS)
57-
+CFLAGS = -Wall -std=c11 -O3 -g3
58-
59-
.PHONY: all clean install
60-
61-
-PROGS = estimate_capacity build_db classify dump_table lookup_accession_numbers k2mask blast_to_fasta libtax
62-
+PROGS = estimate_capacity build_db classify dump_table lookup_accession_numbers k2mask blast_to_fasta libtax.so
63-
64-
all: $(PROGS)
65-
66-
install: $(PROGS)
67-
- cp $(PROGS) "$(KRAKEN2_DIR)/"
68-
+ install -v -m 0755 $(PROGS) "$(KRAKEN2_DIR)"
69-
70-
clean:
71-
rm -f *.o $(PROGS)
72-
@@ -61,5 +61,5 @@ blast_to_fasta: blast_to_fasta.o blast_defline.o blast_utils.o
73-
74-
libtax.o: libtax.cc
75-
76-
-libtax: taxonomy.o mmap_file.o libtax.o
77-
+libtax.so: taxonomy.o mmap_file.o libtax.o
78-
$(CXX) $(CXXFLAGS) -shared -o libtax.so taxonomy.o mmap_file.o libtax.o
79-
diff --git a/install_kraken2.sh b/install_kraken2.sh
80-
index 248b553..5a9a7eb 100755
81-
--- a/install_kraken2.sh
82-
+++ b/install_kraken2.sh
83-
@@ -28,10 +28,10 @@ fi
84-
# Perl cmd used to canonicalize dirname - "readlink -f" doesn't work
85-
# on OS X.
86-
export KRAKEN2_DIR
87-
-KRAKEN2_DIR=$(perl -MCwd=abs_path -le 'print abs_path(shift)' "$1")
88-
+KRAKEN2_DIR="${PREFIX}/share/${PKG_NAME}-${PKG_VERSION}/libexec"
89-
90-
mkdir -p "$KRAKEN2_DIR"
91-
-make -C src install
92-
+make -C src install CXX="$CXX" CC="$CC" -j"$CPU_COUNT"
93-
for file in scripts/*
94-
do
95-
destination_file="$KRAKEN2_DIR/$(basename "$file")"
96-
PATCH
97-
RUN cat > /tmp/0002-k2.patch <<'PATCH'
98-
diff --git a/scripts/k2 b/scripts/k2
99-
old mode 100755
100-
new mode 100644
101-
index 04160c2..7d5a574
102-
--- a/scripts/k2
103-
+++ b/scripts/k2
104-
@@ -431,7 +431,7 @@ def download_and_process_blast_volumes(args):
105-
) as pool:
106-
with open("manifest.txt", "r") as in_file:
107-
tarballs = in_file.readlines()
108-
- f = functools.partial(
109-
+ wrapped_func = functools.partial(
110-
wrap_with_globals, extract_blast_db_files,
111-
LOG.get_queue(), LOG.get_level(),
112-
SCRIPT_PATHNAME
113-
@@ -442,7 +442,7 @@ def download_and_process_blast_volumes(args):
114-
)
115-
for tarball in tarballs:
116-
tarball = os.path.abspath(tarball)
117-
- f = pool.submit(extract_blast_db_files, tarball.strip())
118-
+ f = pool.submit(wrapped_func, tarball.strip())
119-
extraction_futures.append(f)
120-
for future in concurrent.futures.as_completed(extraction_futures):
121-
result = future.result()
122-
@@ -4214,12 +4214,17 @@ def merge_classification_output_parallel(
123-
input = list(zip(file1.readlines(), file2.readlines()))
124-
input_len = len(input)
125-
partition_ranges = list(range(0, input_len, int(input_len / args.threads)))
126-
- partition_ranges[-1] = input_len
127-
+ partition_ranges.append(input_len)
128-
job_number = 0
129-
futures = []
130-
+ wrapped_func = functools.partial(
131-
+ wrap_with_globals, merge_classification_output2,
132-
+ LOG.get_queue(), LOG.get_level(),
133-
+ SCRIPT_PATHNAME
134-
+ )
135-
for start, end in zip(partition_ranges, partition_ranges[1:]):
136-
future = pool.submit(
137-
- merge_classification_output2, taxonomy_pathname,
138-
+ wrapped_func, taxonomy_pathname,
139-
input[start:end], job_number, use_names, args,
140-
save_seq_names, final
141-
)
142-
PATCH
143-
RUN git apply /tmp/0001-src-Makefile.patch \
144-
&& git apply /tmp/0002-k2.patch \
145-
&& ./install_kraken2.sh /bin \
146-
&& cp -v scripts/* /bin/ 2>/dev/null || true \
147-
&& cp -v src/estimate_capacity src/build_db src/classify src/dump_table src/lookup_accession_numbers src/k2mask src/blast_to_fasta /bin/ 2>/dev/null || true \
148-
&& test -f src/libtax.so && cp -v src/libtax.so /usr/lib/ 2>/dev/null || true
34+
# DL Kraken2, unpack, and install
35+
RUN git clone "https://github.com/DerrickWood/kraken2.git" && \
36+
cd kraken2 && \
37+
git checkout f885f832c9863704638dece6c29f0fa4bc19a2e3 && \
38+
./install_kraken2.sh /bin
39+
14940

150-
# final image
15141
FROM ubuntu:24.04
15242

15343
COPY --from=builder /nohuman/target/release/nohuman /bin/
15444
COPY --from=kraken /bin/kraken2* /bin/
15545

15646
RUN nohuman --version && \
15747
nohuman --check
158-
15948
# print help and versions
16049
RUN kraken2 --help && \
16150
kraken2-build --help && \
16251
kraken2 --version
16352

53+
16454
ENTRYPOINT [ "nohuman" ]

0 commit comments

Comments
 (0)