Skip to content

Commit 4f333b4

Browse files
authored
Enhance run_bigscape for BiG-SCAPE v2 compatibility (#349)
* Enhance run_bigscape to convert underscores to hyphens for BiG-SCAPE v2 compatibility * Fix BiG-SCAPE v2 database file naming in DatasetArranger * Fix formatting * Update BiG-SCAPE installation script for compatibility and versioning improvements * Update BiG-SCAPE v2 script path to remove version suffix * Add importlib-resources to BiG-SCAPE installation dependencies * Add scikit-learn to BiG-SCAPE installation dependencies
1 parent eedcc84 commit 4f333b4

4 files changed

Lines changed: 68 additions & 12 deletions

File tree

bin/install-nplinker-deps

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,16 @@ echo "🔥 Start installing BigScape ..."
142142
chmod 664 domains_color_file.tsv
143143
chmod 775 Annotated_MIBiG_reference
144144
ln -sf $LIB_PATH/BiG-SCAPE/bigscape.py $PY_PATH/bin
145+
# Patch ArrowerSVG.py for Biopython compatibility (feature.strand -> feature.location.strand)
146+
sed -i.bak 's/feature\.strand/feature.location.strand/g' ArrowerSVG.py && rm -f ArrowerSVG.py.bak
145147
cd ..
146-
# blob size limit to remove large files left in history
147-
[[ -d BiG-SCAPE-v2 ]] || git clone -b dev --filter=blob:limit=10m https://github.com/medema-group/BiG-SCAPE.git BiG-SCAPE-v2
148+
[[ -d BiG-SCAPE-v2 ]] || git clone https://github.com/medema-group/BiG-SCAPE.git BiG-SCAPE-v2
148149
cd BiG-SCAPE-v2
149-
git config --ad advice.detatchedHead false
150-
git checkout v2.0.0-beta.5 # feb 12, 2025
151-
pip install click sqlalchemy pyhmmer tqdm matplotlib requests
152-
chmod 754 bigscape.py
153-
ln -sf $LIB_PATH/BiG-SCAPE-v2/bigscape.py $PY_PATH/bin/bigscape-v2.py
150+
git config --add advice.detachedHead false
151+
git fetch --tags
152+
git checkout v2.0.2 # Feb 3, 2026
153+
pip install -q click sqlalchemy "pyhmmer>=0.12.0" tqdm matplotlib requests sortedcontainers pyyaml importlib-metadata importlib-resources scikit-learn
154+
pip install -q .
154155
cd ..
155156

156157

src/nplinker/arranger.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,11 @@ def _run_bigscape(self) -> None:
333333
):
334334
shutil.copy(f, self.bigscape_dir)
335335
elif version == "2":
336-
shutil.copy(
337-
self.bigscape_running_output_dir / "data_sqlite.db",
338-
self.bigscape_dir,
336+
# BiG-SCAPE v2 names the DB as <output_dir_name>.db
337+
bigscape_db = (
338+
self.bigscape_running_output_dir / f"{self.bigscape_running_output_dir.name}.db"
339339
)
340+
shutil.copy(bigscape_db, self.bigscape_dir / "data_sqlite.db")
340341
else:
341342
raise ValueError(f"Invalid BiG-SCAPE version: {version}")
342343

src/nplinker/genomics/bigscape/runbigscape.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_bigscape(
6868
if version == "1":
6969
bigscape_py_path = "bigscape.py"
7070
elif version == "2":
71-
bigscape_py_path = "bigscape-v2.py"
71+
bigscape_py_path = "bigscape"
7272
else:
7373
raise ValueError("Invalid BiG-SCAPE version number. Expected: '1' or '2'.")
7474

@@ -109,7 +109,13 @@ def run_bigscape(
109109

110110
# append the user supplied params, if any
111111
if len(extra_params) > 0:
112-
args.extend(extra_params.split(" "))
112+
params = extra_params.split(" ")
113+
# BiG-SCAPE v2 uses Click which requires hyphens in option names,
114+
# while v1 used argparse which accepted both. Convert underscores
115+
# to hyphens in option names for v2 compatibility.
116+
if version == "2":
117+
params = [p.replace("_", "-") if p.startswith("-") else p for p in params]
118+
args.extend(params)
113119

114120
logger.info(f"BiG-SCAPE command: {args}")
115121
result = subprocess.run(args, stdout=sys.stdout, stderr=sys.stderr)

tests/unit/genomics/test_runbigscape.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
2+
import subprocess
23
import pytest
34
from nplinker.genomics import bigscape
5+
from nplinker.genomics.bigscape import runbigscape
46
from .. import DATA_DIR
57

68

@@ -68,3 +70,49 @@ def test_bad_parameters(tmp_path, version):
6870
)
6971

7072
assert "BiG-SCAPE" in e.value.args[0]
73+
74+
75+
def test_v2_converts_underscores_to_hyphens(tmp_path, monkeypatch):
76+
"""Test that underscores in option names are converted to hyphens for BiG-SCAPE v2."""
77+
calls = []
78+
79+
def fake_run(args, **kwargs):
80+
calls.append(args)
81+
return subprocess.CompletedProcess(args, returncode=0)
82+
83+
monkeypatch.setattr(runbigscape.subprocess, "run", fake_run)
84+
85+
bigscape.run_bigscape(
86+
antismash_path=tmp_path,
87+
output_path=tmp_path,
88+
extra_params="--mibig_version 3.1 --include_singletons --gcf_cutoffs 0.30",
89+
version="2",
90+
)
91+
92+
# Second call is the actual BiG-SCAPE run (first is the -h check)
93+
actual_args = calls[1]
94+
assert "--mibig-version" in actual_args
95+
assert "--include-singletons" in actual_args
96+
assert "--gcf-cutoffs" in actual_args
97+
assert "--mibig_version" not in actual_args
98+
99+
100+
def test_v1_preserves_underscores(tmp_path, monkeypatch):
101+
"""Test that underscores in option names are preserved for BiG-SCAPE v1."""
102+
calls = []
103+
104+
def fake_run(args, **kwargs):
105+
calls.append(args)
106+
return subprocess.CompletedProcess(args, returncode=0)
107+
108+
monkeypatch.setattr(runbigscape.subprocess, "run", fake_run)
109+
110+
bigscape.run_bigscape(
111+
antismash_path=tmp_path,
112+
output_path=tmp_path,
113+
extra_params="--mibig_version 3.1",
114+
version="1",
115+
)
116+
117+
actual_args = calls[1]
118+
assert "--mibig_version" in actual_args

0 commit comments

Comments
 (0)