Skip to content

Commit 6066c29

Browse files
committed
prepare-blast module behaviour resolve
1 parent f4523fb commit 6066c29

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

src/PROBESt/prepare_blast.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ def prepare_bases_if_needed(
222222
true_base: Path to true base (BLAST database or FASTA directory).
223223
false_bases: List of paths to false bases (BLAST databases or FASTA directories).
224224
output_dir: Output directory for created BLAST databases.
225-
contig_table_path: Path for the contig names output file.
225+
contig_table_path: Path for the contig names TSV (genome id, sseqid). When
226+
bases are built from FASTA directories, true and all false bases append
227+
into this file, matching repeated ``prep_db.sh -c`` usage.
226228
tmp_dir: Optional temporary directory for intermediate files.
227229
script_path: Path to the directory containing prep_db.sh script.
228230
@@ -231,38 +233,43 @@ def prepare_bases_if_needed(
231233
"""
232234
blast_db_dir = os.path.join(output_dir, ".blast_db")
233235
os.makedirs(blast_db_dir, exist_ok=True)
234-
236+
237+
# One contig table for all JIT-prepared bases (same as repeated prep_db.sh -c file).
238+
shared_contig_table = (
239+
contig_table_path
240+
if os.path.dirname(contig_table_path)
241+
else os.path.join(blast_db_dir, contig_table_path)
242+
)
243+
235244
# Process true base
236245
if is_fasta_directory(true_base):
237246
dir_name = os.path.basename(true_base.rstrip('/'))
238247
processed_true_base = os.path.join(blast_db_dir, f"true_{dir_name}")
239-
true_contig_table = contig_table_path if os.path.dirname(contig_table_path) else os.path.join(blast_db_dir, contig_table_path)
240-
248+
241249
print(f"Preparing BLAST database from FASTA directory: {true_base}")
242250
prepare_blast_database(
243251
fasta_dir=true_base,
244252
output_db_path=processed_true_base,
245-
contig_table_path=true_contig_table,
253+
contig_table_path=shared_contig_table,
246254
tmp_dir=tmp_dir,
247255
script_path=script_path
248256
)
249257
print(f"Created BLAST database: {processed_true_base}")
250258
else:
251259
processed_true_base = true_base
252-
260+
253261
# Process false bases
254262
processed_false_bases = []
255263
for i, false_base in enumerate(false_bases):
256264
if is_fasta_directory(false_base):
257265
dir_name = os.path.basename(false_base.rstrip('/'))
258266
processed_false_base = os.path.join(blast_db_dir, f"false_{i}_{dir_name}")
259-
false_contig_table = os.path.join(blast_db_dir, f"contigs_false_{i}.tsv")
260-
267+
261268
print(f"Preparing BLAST database from FASTA directory: {false_base}")
262269
prepare_blast_database(
263270
fasta_dir=false_base,
264271
output_db_path=processed_false_base,
265-
contig_table_path=false_contig_table,
272+
contig_table_path=shared_contig_table,
266273
tmp_dir=tmp_dir,
267274
script_path=script_path
268275
)

tests/test_pipeline_general_integration.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _require_blast_tools():
4343

4444
@pytest.mark.integration
4545
def test_pipeline_general_fish_from_test_sh(tmp_path):
46-
"""Mirror test.sh: small general run with visualization and AI enabled."""
46+
"""Mirror `test.sh` snippet: small general run (AI enabled by default, visualize disabled)."""
4747
_require_blast_tools()
4848

4949
output = tmp_path / "output"
@@ -67,10 +67,6 @@ def test_pipeline_general_fish_from_test_sh(tmp_path):
6767
"5",
6868
"-N",
6969
"3",
70-
"--visualize",
71-
"True",
72-
"--AI",
73-
"True",
7470
]
7571

7672
result = subprocess.run(
@@ -87,5 +83,5 @@ def test_pipeline_general_fish_from_test_sh(tmp_path):
8783

8884
assert (output / "modeling_results.tsv").is_file()
8985
assert (output / "output_dedegenerated.fa").is_file()
90-
assert (output / "visualizations").is_dir()
91-
assert any((output / "visualizations").iterdir())
86+
# Visualizations are only created when `--visualize` is enabled.
87+
assert not (output / "visualizations").exists()

0 commit comments

Comments
 (0)