Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
339 lines (265 loc) · 14.5 KB
/
Copy pathMakefile
File metadata and controls
339 lines (265 loc) · 14.5 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# Makefile for the project
include Makefile.help
MAKEFLAGS += --no-print-directory
# Makefile containing the project's variables
PROJECT_NAME := BioMate
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
UV ?= uv
BCLCONVERT ?= assets/bcl-convert
BCLCONVERT_NOFILE ?= 65535
BCLCONVERT_MIN_NOFILE ?= 4096
BCLCONVERT_FD_ERROR_PATTERN ?= too many open files|bad file descriptor
SHELL=/bin/bash
# Test assets and variables
NISS = assets/SampleSheet_NoIndex.csv
SISS = assets/SampleSheet_SingleIndex.csv
DISS = assets/SampleSheet_DualIndex.csv
MISS = assets/SampleSheet_MixedIndexes.csv
TEMP_DIR = temp
FLOWCELL_ID = 20261105_LM43899_0385_A12GGASZR5
FLOWCELL_ID_NONE ?= $(FLOWCELL_ID)
FLOWCELL_ID_SINGLE ?= 20261105_LM43896_0386_B98QWERTY6
FLOWCELL_ID_DUAL ?= 20261105_LM43897_0387_C36MNBVCX7
FLOWCELL_ID_MIX ?= 20261105_LM43898_0388_D74LKJHGF8
SEQ_NUM = 100
# Number of undetermined reads written to the Undetermined files of each lane
# with an indexed design (blabber --taint-count); lanes with a no-index design
# are expected to have 0. Used by report_results to verify the bcl-convert output.
TAINT_COUNT ?= 50
RELEASE_DATA = DemuxCasesData.tar.gz
RELEASE_DIR = $(basename $(basename $(RELEASE_DATA)))
TEST_PATH ?= tests
PYTEST_ARGS ?=
.PHONY: check-uv
check-uv:
@command -v $(UV) >/dev/null 2>&1 || { \
echo "Error: '$(UV)' not found in PATH."; \
echo "Install uv (https://docs.astral.sh/uv/) or set UV=/full/path/to/uv."; \
exit 1; \
}
.PHONY: install-uv
## Install uv using the official installer script
install-uv:
@curl -LsSf https://astral.sh/uv/install.sh | sh
.PHONY: check-bclconvert
check-bclconvert:
@command -v $(BCLCONVERT) >/dev/null 2>&1 || { \
echo "Error: '$(BCLCONVERT)' not found."; \
echo "BCL-convert is a proprietary Illumina tool and is not bundled with this repository (its redistribution is prohibited)."; \
echo "Download it from https://support.illumina.com/sequencing/sequencing_software/bcl-convert/downloads.html and place the executable in the assets/ directory, or set BCLCONVERT=/full/path/to/bcl-convert."; \
exit 1; \
}
.PHONY: smoke-bclconvert-fd
smoke-bclconvert-fd:
@for f in $(TEMP_DIR)/bcl-validate.err $(TEMP_DIR)/bcl-convert.err; do \
if [[ -f $$f ]] && grep -Eiq "$(BCLCONVERT_FD_ERROR_PATTERN)" "$$f"; then \
echo "Detected file descriptor-related bcl-convert error in $$f"; \
grep -Ein "$(BCLCONVERT_FD_ERROR_PATTERN)" "$$f" | tail -n 20; \
echo "This usually means bcl-convert ran with too few open files; raise the nofile limit for this session with 'ulimit -Sn $(BCLCONVERT_NOFILE)' and re-run."; \
exit 1; \
fi; \
done; \
echo "No file descriptor-related errors found in bcl-convert logs."
.PHONY: sync
## Sync the project's dependencies with the environment
sync: check-uv
@$(UV) sync --all-extras --all-groups
.PHONY: kernels
## Build the optional Rust kernels (biomate_kernels) into .venv; needs cargo
kernels: check-uv
@[[ -x .venv/bin/python ]] || { echo "Error: no .venv found; run 'make sync' first."; exit 1; }
@command -v cargo >/dev/null 2>&1 || { \
echo "Error: 'cargo' not found in PATH."; \
echo "Install a Rust toolchain (https://rustup.rs/) and retry."; \
exit 1; \
}
@$(UV) pip install --quiet "maturin>=1.5,<2.0"
@cd rust/biomate_kernels && env -u CONDA_PREFIX VIRTUAL_ENV=$(PROJECT_DIR)/.venv \
$(PROJECT_DIR)/.venv/bin/maturin develop --release
@$(PROJECT_DIR)/.venv/bin/python -c "import biomate_kernels; print('biomate_kernels installed, scan format', biomate_kernels.SCAN_FORMAT)"
uv.lock: check-uv
@$(UV) lock
.PHONY: lock
## Create a lockfile for the project's dependencies
lock: uv.lock
.PHONY: upgrade
## Upgrade the project's dependencies
upgrade: check-uv
@$(UV) lock --upgrade
.PHONY: build
## Build the project into distribution archives
build: check-uv
@$(UV) build
.venv/bin/activate: check-uv
@$(UV) venv
.PHONY: venv
## Create a new virtual environment
venv: .venv/bin/activate
.PHONY: singularity
## Create the Singularity image for the project
singularity: remove_singularity singularity.sif
.PHONY: remove_singularity
singularity.sif: singularity.def
@singularity build --fakeroot --fix-perms --force --bind $(PROJECT_DIR):/mnt $@ $< > singularity_build.out 2> singularity_build.err && echo "Singularity image built successfully!" || { echo "Error building Singularity image! Check singularity_build.err for details."; exit 1; }
remove_singularity:
@if [[ -f singularity.sif ]]; then rm singularity.sif; fi
requirements.txt: check-uv uv.lock
@$(UV) export --output-file requirements.txt
.PHONY: export
## Export the project's dependencies to a requirements.txt file
export: requirements.txt
.PHONY: interrogate
## Run interrogate in verbose mode to check for code quality
interrogate: check-uv
@$(UV) run interrogate --verbose
.PHONY: test
## Run the pytest test suite
test: check-uv
@$(UV) run pytest $(TEST_PATH) $(PYTEST_ARGS)
.PHONY: test_verbose
## Run the pytest suite in verbose mode
test_verbose: check-uv
@$(UV) run pytest -v --tb=short $(TEST_PATH) $(PYTEST_ARGS)
.PHONY: test_failed
## Re-run only tests that failed in the previous pytest run
test_failed: check-uv
@$(UV) run pytest --lf -v --tb=short $(TEST_PATH) $(PYTEST_ARGS)
.PHONY: deploy
## Deploy documentation on GitHub
deploy: check-uv
@$(UV) run mkdocs gh-deploy
# The datasets recipe runs the full pipeline (blabber, fastrewind, bcl-convert) for
# every flowcell and packages each flowcell directory in its post-fastrewind
# state. BCL-convert results (temp/Demultiplexed and its logs) are excluded
# from the archive. Every test_* deepcleans temp/ before running, so each
# flowcell directory is staged away right after its test completes, before
# the next test's deepclean wipes it.
.PHONY: datasets
## Build the test datasets: runs the full pipeline for every flowcell and
## packages each flowcell directory (post-fastrewind, BCL-convert results
## excluded) into the datasets archive
datasets:
@rm -rf $(RELEASE_DIR)
@mkdir -p $(RELEASE_DIR)
@$(MAKE) test_none
mv $(TEMP_DIR)/$(FLOWCELL_ID_NONE) $(RELEASE_DIR)/
@$(MAKE) test_single
mv $(TEMP_DIR)/$(FLOWCELL_ID_SINGLE) $(RELEASE_DIR)/
@$(MAKE) test_dual
mv $(TEMP_DIR)/$(FLOWCELL_ID_DUAL) $(RELEASE_DIR)/
@$(MAKE) test_mix
mv $(TEMP_DIR)/$(FLOWCELL_ID_MIX) $(RELEASE_DIR)/
tar -czf $(RELEASE_DATA) $(RELEASE_DIR)
rm -r $(RELEASE_DIR)
@$(MAKE) deepclean
$(TEMP_DIR):
@mkdir -p $(TEMP_DIR)
copy_none: $(TEMP_DIR) $(NISS) clean_samplesheet
@cp $(NISS) $(TEMP_DIR)/SampleSheet.csv && echo "Copied SampleSheet (No Index) to working folder." || { echo "Error copying SampleSheet to working folder!"; exit 1; }
copy_single: $(TEMP_DIR) $(SISS) clean_samplesheet
@cp $(SISS) $(TEMP_DIR)/SampleSheet.csv && echo "Copied SampleSheet (Single Index) to working folder." || { echo "Error copying SampleSheet to working folder!"; exit 1; }
copy_dual: $(TEMP_DIR) $(DISS) clean_samplesheet
@cp $(DISS) $(TEMP_DIR)/SampleSheet.csv && echo "Copied SampleSheet (Dual Indexes) to working folder." || { echo "Error copying SampleSheet to working folder!"; exit 1; }
copy_mix: $(TEMP_DIR) $(MISS) clean_samplesheet
@cp $(MISS) $(TEMP_DIR)/SampleSheet.csv && echo "Copied SampleSheet (Mixed Indexes) to working folder." || { echo "Error copying SampleSheet to working folder!"; exit 1; }
$(TEMP_DIR)/$(FLOWCELL_ID): check-uv $(TEMP_DIR) clean_flowcell
@$(UV) run biomate --verbose blabber --format fastq --sample-sheet $(TEMP_DIR)/SampleSheet.csv --seq-number $(SEQ_NUM) --taint --taint-count $(TAINT_COUNT) --random-seed 42 --output $(TEMP_DIR) --flowcell-id $(FLOWCELL_ID) > $(TEMP_DIR)/blabber.out 2> $(TEMP_DIR)/blabber.err && echo "Blabber module executed successfully!" || { echo "Error executing Blabber module!"; exit 1; }
$(TEMP_DIR)/$(FLOWCELL_ID)/Data $(TEMP_DIR)/$(FLOWCELL_ID)/RunInfo.xml $(TEMP_DIR)/$(FLOWCELL_ID)/RunParameters.xml: check-uv $(TEMP_DIR)/$(FLOWCELL_ID) clean_data
@$(UV) run biomate --verbose fastrewind --input-path $(TEMP_DIR) --output-path $(TEMP_DIR)/$(FLOWCELL_ID) --flowcell-id $(FLOWCELL_ID) --threads 8 > $(TEMP_DIR)/fastrewind.out 2> $(TEMP_DIR)/fastrewind.err && echo "Fastrewind module executed successfully!" || { echo "Error executing Fastrewind module!"; exit 1; }
validate_samplesheet: check-bclconvert $(TEMP_DIR)/$(FLOWCELL_ID)/RunInfo.xml
@ulimit -Sn $(BCLCONVERT_NOFILE) 2>/dev/null || true; \
if [ "$$(ulimit -Sn)" -lt $(BCLCONVERT_MIN_NOFILE) ]; then \
echo "Error: bcl-convert requires at least $(BCLCONVERT_MIN_NOFILE) open files, but the soft nofile limit is only $$(ulimit -Sn) and could not be raised to $(BCLCONVERT_NOFILE) (hard limit: $$(ulimit -Hn))."; \
echo "Raise the limit for this session with 'ulimit -Sn $(BCLCONVERT_NOFILE)' (or permanently via /etc/security/limits.conf) and re-run."; \
exit 1; \
fi; \
echo "BCL-convert soft nofile limit set to $$(ulimit -Sn)"; \
$(BCLCONVERT) --output-directory $(TEMP_DIR)/Demultiplexed --bcl-input-directory $(TEMP_DIR)/$(FLOWCELL_ID) --strict-mode true --bcl-sampleproject-subdirectories true --sample-name-column-enabled true --bcl-output-format demux-autodetect --bcl-validate-sample-sheet-only true > $(TEMP_DIR)/bcl-validate.out 2> $(TEMP_DIR)/bcl-validate.err && echo "BCL-convert SampleSheet validation was successful!" || { echo "Error executing BCL-convert SampleSheet validation!"; exit 1; }
@$(MAKE) smoke-bclconvert-fd
$(TEMP_DIR)/Demultiplexed: check-bclconvert $(TEMP_DIR)/$(FLOWCELL_ID)/RunInfo.xml clean_demux
@ulimit -Sn $(BCLCONVERT_NOFILE) 2>/dev/null || true; \
if [ "$$(ulimit -Sn)" -lt $(BCLCONVERT_MIN_NOFILE) ]; then \
echo "Error: bcl-convert requires at least $(BCLCONVERT_MIN_NOFILE) open files, but the soft nofile limit is only $$(ulimit -Sn) and could not be raised to $(BCLCONVERT_NOFILE) (hard limit: $$(ulimit -Hn))."; \
echo "Raise the limit for this session with 'ulimit -Sn $(BCLCONVERT_NOFILE)' (or permanently via /etc/security/limits.conf) and re-run."; \
exit 1; \
fi; \
echo "BCL-convert soft nofile limit set to $$(ulimit -Sn)"; \
$(BCLCONVERT) --output-directory $(TEMP_DIR)/Demultiplexed --bcl-input-directory $(TEMP_DIR)/$(FLOWCELL_ID) --strict-mode true --bcl-sampleproject-subdirectories true --sample-name-column-enabled true > $(TEMP_DIR)/bcl-convert.out 2> $(TEMP_DIR)/bcl-convert.err && echo "BCL-convert executed successfully!" || { echo "Error executing BCL-convert!"; exit 1; }
@$(MAKE) smoke-bclconvert-fd
.PHONY: report_results
report_results: $(TEMP_DIR)/Demultiplexed results_message
@find $(TEMP_DIR)/Demultiplexed -name "*.fastq.gz" | grep -v -e "Undetermined" -e "_I1_" -e "_I2_" | xargs -r zgrep -c ^@ || true
@find $(TEMP_DIR)/Demultiplexed -name "*.fastq.gz" | grep "Undetermined" | grep -v -e "_I1_" -e "_I2_" | xargs -r zgrep -c ^@ || true
@echo "Verifying undetermined read counts ($(TAINT_COUNT) expected per indexed lane)..."
@for lane in $$(awk -F, '/^\[BCLConvert_Data\]$$/ { s=1; next } /^\[/ { s=0 } s && $$1 ~ /^[0-9]+$$/ { print "L" sprintf("%03d", $$1) }' $(TEMP_DIR)/SampleSheet.csv | sort -u); do \
file=$$(find $(TEMP_DIR)/Demultiplexed -name "Undetermined_S0_$${lane}_R1_*.fastq.gz" | head -n 1); \
if [ -n "$$file" ]; then actual=$$(zgrep -c ^@ "$$file"); else actual=0; fi; \
indexed=$$(awk -F, -v lane="$$lane" '/^\[BCLConvert_Data\]$$/ { d=1; next } /^\[/ { d=0 } d && $$1 ~ /^[0-9]+$$/ && sprintf("L%03d", $$1) == lane && ($$4 != "" || $$5 != "") { found=1; exit } END { print found+0 }' $(TEMP_DIR)/SampleSheet.csv); \
if [ "$$indexed" = "1" ]; then expected=$(TAINT_COUNT); else expected=0; fi; \
if [ "$$actual" != "$$expected" ]; then \
echo "ERROR: lane $$lane has $$actual undetermined R1 reads, expected $$expected."; \
exit 1; \
fi; \
echo " lane $$lane: $$actual/$$expected undetermined R1 reads"; \
done
compare_results: $(TEMP_DIR)/Demultiplexed comparison_message
@FLOWCELL_ID=$(FLOWCELL_ID) bash assets/compare_results.sh && echo "All files pairwise comparisons were successful!" || echo "WARNING: Some pairwise comparisons yield different results!"
## Run the demultiplexing test with the no-index sample sheet
test_none:
@$(MAKE) FLOWCELL_ID=$(FLOWCELL_ID_NONE) deepclean run_message copy_none validate_samplesheet report_results compare_results
## Run the demultiplexing test with the single-index sample sheet
test_single:
@$(MAKE) FLOWCELL_ID=$(FLOWCELL_ID_SINGLE) deepclean run_message copy_single validate_samplesheet report_results compare_results
## Run the demultiplexing test with the dual-index sample sheet
test_dual:
@$(MAKE) FLOWCELL_ID=$(FLOWCELL_ID_DUAL) deepclean run_message copy_dual validate_samplesheet report_results compare_results
## Run the demultiplexing test with the mixed-index sample sheet
test_mix:
@$(MAKE) FLOWCELL_ID=$(FLOWCELL_ID_MIX) deepclean run_message copy_mix validate_samplesheet report_results compare_results
.PHONY: copy_none copy_single copy_dual copy_mix
.PHONY: validate_samplesheet compare_results smoke-bclconvert-fd
.PHONY: test_none test_single test_dual test_mix
.PHONY: cleanup_message
cleanup_message:
@echo "-------------------------------------"
@echo "- Past runs cleanup -----------------"
@echo "-------------------------------------"
.PHONY: run_message
run_message:
@echo "-------------------------------------"
@echo "- Executing tests -------------------"
@echo "-------------------------------------"
.PHONY: results_message
results_message:
@echo "-------------------------------------"
@echo "- Test results ($(SEQ_NUM)) -----------------"
@echo "-------------------------------------"
.PHONY: comparison_message
comparison_message:
@echo "-------------------------------------"
@echo "- Original vs artificial comparison -"
@echo "-------------------------------------"
.PHONY: deepclean
deepclean: cleanup_message clean_samplesheet clean_flowcells clean_data
if [[ -d $(TEMP_DIR) ]]; then rm -r $(TEMP_DIR); fi
.PHONY: clean_samplesheet
clean_samplesheet:
if [[ -f $(TEMP_DIR)/SampleSheet.csv ]]; then rm $(TEMP_DIR)/SampleSheet.csv; fi
.PHONY: clean_flowcell clean_flowcells
clean_flowcell:
if [[ -d $(TEMP_DIR)/$(FLOWCELL_ID) ]]; then rm -r $(TEMP_DIR)/$(FLOWCELL_ID); fi
# Remove every flowcell directory found in the working folder, regardless of
# which FLOWCELL_ID is currently in effect (run folders follow the Illumina
# YYYYMMDD_ naming convention, so the glob never matches other entries).
clean_flowcells:
@if [[ -d $(TEMP_DIR) ]]; then \
for fc in $(TEMP_DIR)/????????_*; do \
if [[ -d $$fc ]]; then rm -r "$$fc"; fi; \
done; \
fi
.PHONY: clean_data
clean_data:
if [[ -d $(TEMP_DIR)/$(FLOWCELL_ID)/Data ]]; then rm -r $(TEMP_DIR)/$(FLOWCELL_ID)/Data; fi
.PHONY: clean_demux
clean_demux:
@if [[ -d $(TEMP_DIR)/Demultiplexed ]]; then rm -r $(TEMP_DIR)/Demultiplexed; fi