|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +echo "== csubst command tests ==" |
| 5 | + |
| 6 | +which csubst |
| 7 | +csubst --version || true |
| 8 | + |
| 9 | +# --- ヘルプ確認(存在チェック) --- |
| 10 | +csubst -h | grep -E '\bdataset\b' >/dev/null |
| 11 | +csubst -h | grep -E '\banalyze\b' >/dev/null |
| 12 | +csubst -h | grep -E '\bsite\b' >/dev/null |
| 13 | +csubst -h | grep -E '\bsimulate\b' >/dev/null |
| 14 | +csubst analyze -h | grep -- '--alignment_file' >/dev/null |
| 15 | +csubst site -h | grep -- '--alignment_file' >/dev/null |
| 16 | +csubst simulate -h | grep -- '--alignment_file' >/dev/null |
| 17 | + |
| 18 | +# --- 作業ディレクトリ(smoke と共通) --- |
| 19 | +WORKDIR="${RUNNER_TEMP:-$(mktemp -d)}/csubst_smoke" |
| 20 | +mkdir -p "$WORKDIR" |
| 21 | +cd "$WORKDIR" |
| 22 | + |
| 23 | +# 最小データが無い場合は生成 |
| 24 | +if [ ! -s alignment.fa ]; then |
| 25 | + csubst dataset --name PGK |
| 26 | +fi |
| 27 | +test -s alignment.fa && test -s tree.nwk && test -s foreground.txt |
| 28 | + |
| 29 | +# 便利関数:新規ファイル検出 |
| 30 | +newer_than() { find . -maxdepth 1 -type f -newer "$1" -printf "%f\n" || true; } |
| 31 | + |
| 32 | +# --- analyze(既定=ECM系) --- |
| 33 | +rm -f alignment.fa.{iqtree,log,rate,state,treefile} || true |
| 34 | +MARKER=$(mktemp); sleep 1; touch "$MARKER" |
| 35 | +env PYTHONOPTIMIZE=1 OMP_NUM_THREADS=1 csubst analyze \ |
| 36 | + --alignment_file alignment.fa \ |
| 37 | + --rooted_tree_file tree.nwk \ |
| 38 | + --foreground foreground.txt \ |
| 39 | + --threads 1 |
| 40 | +# 生成物(TSV)が増えたか |
| 41 | +NEW_TSV=($(find . -maxdepth 1 -type f -name "csubst_*.tsv" -newer "$MARKER" -print)) |
| 42 | +[ ${#NEW_TSV[@]} -ge 1 ] || { echo "ERROR: analyze 後に TSV が増えていない"; exit 1; } |
| 43 | +echo "OK: analyze(created): ${NEW_TSV[*]}" |
| 44 | + |
| 45 | +# --- analyze(GY 分岐) --- |
| 46 | +rm -f alignment.fa.{iqtree,log,rate,state,treefile} || true |
| 47 | +MARKER=$(mktemp); sleep 1; touch "$MARKER" |
| 48 | +env PYTHONOPTIMIZE=1 OMP_NUM_THREADS=1 csubst analyze \ |
| 49 | + --alignment_file alignment.fa \ |
| 50 | + --rooted_tree_file tree.nwk \ |
| 51 | + --foreground foreground.txt \ |
| 52 | + --iqtree_model GY+F3x4+R2 \ |
| 53 | + --threads 1 |
| 54 | +NEW_TSV=($(find . -maxdepth 1 -type f -name "csubst_*.tsv" -newer "$MARKER" -print)) |
| 55 | +[ ${#NEW_TSV[@]} -ge 1 ] || { echo "ERROR: analyze(GY) 後に TSV が増えていない"; exit 1; } |
| 56 | +echo "OK: analyze(GY)(created): ${NEW_TSV[*]}" |
| 57 | + |
| 58 | +# --- site(サイト別計算:最小オプション) --- |
| 59 | +rm -f alignment.fa.{iqtree,log,rate,state,treefile} || true |
| 60 | +MARKER=$(mktemp); sleep 1; touch "$MARKER" |
| 61 | +# ※ site も内部で祖先状態を使うため、念のため assert 無効化を局所適用 |
| 62 | +env PYTHONOPTIMIZE=1 OMP_NUM_THREADS=1 csubst site \ |
| 63 | + --alignment_file alignment.fa \ |
| 64 | + --rooted_tree_file tree.nwk \ |
| 65 | + --foreground foreground.txt \ |
| 66 | + --threads 1 |
| 67 | +NEW_SITE_TSV=($(find . -maxdepth 1 -type f -name "csubst_site*.tsv" -newer "$MARKER" -print)) |
| 68 | +# ファイル名が将来変わっても拾えるよう、site 実行直後に新規 TSV があるかも見る |
| 69 | +[ ${#NEW_SITE_TSV[@]} -ge 1 ] || NEW_SITE_TSV=($(find . -maxdepth 1 -type f -name "*.tsv" -newer "$MARKER" -print)) |
| 70 | +[ ${#NEW_SITE_TSV[@]} -ge 1 ] || { echo "ERROR: site 実行で TSV が作られていない"; exit 1; } |
| 71 | +echo "OK: site(created): ${NEW_SITE_TSV[*]}" |
| 72 | + |
| 73 | +# --- simulate(シミュレーション:デフォルト) --- |
| 74 | +MARKER=$(mktemp); sleep 1; touch "$MARKER" |
| 75 | +# simulate は多くの場合 IQ-TREE を起動しないので速いはず。安全のため threads=1。 |
| 76 | +env PYTHONOPTIMIZE=1 csubst simulate \ |
| 77 | + --alignment_file alignment.fa \ |
| 78 | + --rooted_tree_file tree.nwk \ |
| 79 | + --foreground foreground.txt \ |
| 80 | + --threads 1 |
| 81 | +NEW_SIM=($(find . -maxdepth 1 -type f \( -name "*.fa" -o -name "*.fasta" -o -name "*.phy" \) -newer "$MARKER" -print)) |
| 82 | +[ ${#NEW_SIM[@]} -ge 1 ] || { echo "ERROR: simulate 実行で配列ファイルが作られていない"; exit 1; } |
| 83 | +echo "OK: simulate(created): ${NEW_SIM[*]}" |
| 84 | + |
| 85 | +# --- 体裁の最小チェック(TSV ヘッダ & 非空) --- |
| 86 | +TSV_PICK="${NEW_TSV[0]}" |
| 87 | +[ -n "${TSV_PICK:-}" ] && [ -s "$TSV_PICK" ] && grep $'\t' "$TSV_PICK" >/dev/null || true |
| 88 | + |
| 89 | +# --- アーティファクト収集 --- |
| 90 | +ART="$WORKDIR/_artifacts_cmd" |
| 91 | +mkdir -p "$ART" |
| 92 | +# 直近の生成物をざっくり集める |
| 93 | +for f in csubst_*.tsv alignment.fa.{iqtree,log,rate,state,treefile} *.fa *.fasta *.phy; do |
| 94 | + [ -f "$f" ] && cp -v "$f" "$ART" || true |
| 95 | +done |
| 96 | + |
| 97 | +echo "Command tests OK" |
0 commit comments