import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) def test_rnaseq_env_bin_can_be_overridden(monkeypatch, tmp_path): from apps.cli import rnaseq_env custom_bin = tmp_path / "rnaseq" / "bin" monkeypatch.setenv("PLANTAI_RNASEQ_BIN", str(custom_bin)) assert rnaseq_env.rnaseq_bin() == custom_bin assert rnaseq_env.rnaseq_tool("salmon") == str(custom_bin / "salmon") assert rnaseq_env.rnaseq_rscript() == str(custom_bin / "Rscript") def test_rnar_rscript_uses_rnaR_environment(monkeypatch, tmp_path): from apps.cli import rnaseq_env conda_base = tmp_path / "miniconda3" monkeypatch.delenv("PLANTAI_RNAR_BIN", raising=False) monkeypatch.setenv("PLANTAI_CONDA_BASE", str(conda_base)) assert rnaseq_env.rnar_rscript() == str(conda_base / "envs" / "rnaR" / "bin" / "Rscript") def test_wgcna_script_caps_wgcna_and_blas_threads(tmp_path): from apps.cli import run_rnaseq_wgcna as wgcna script = tmp_path / "run_wgcna.R" wgcna.write_r_script(script, threads=12) text = script.read_text(encoding="utf-8") assert "wgcna_threads <- 12" in text assert "allowWGCNAThreads(nThreads = wgcna_threads)" in text assert "OMP_NUM_THREADS" in text assert "OPENBLAS_NUM_THREADS" in text def test_annotation_interproscan_uses_rnaseq_path(monkeypatch, tmp_path): from apps.cli import run_annotation rnaseq_bin = tmp_path / "miniconda3" / "envs" / "rnaseq" / "bin" monkeypatch.setenv("PLANTAI_RNASEQ_BIN", str(rnaseq_bin)) captured = {} class Result: returncode = 0 stdout = "" stderr = "" def fake_run(cmd, **kwargs): captured["cmd"] = cmd captured["env"] = kwargs.get("env") return Result() monkeypatch.setattr(run_annotation.subprocess, "run", fake_run) run_annotation.run_interproscan( tmp_path / "proteins.fa", tmp_path / "out", tmp_path / "interproscan.sh", 4, "Pfam", tmp_path / "tmp", ) assert captured["env"] is not None assert str(rnaseq_bin) in captured["env"]["PATH"].split(":")