Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1250 lines (1177 loc) · 47.9 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·1250 lines (1177 loc) · 47.9 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Conda-friendly installer for the Python SamovaR pipeline.
# Optional R package lives on the GitHub ``r-package`` branch (not in this tree).
#
# Usage:
# ./install.sh Python pipeline only
# ./install.sh full core + every optional extra (reuse if already installed)
# ./install.sh R-package install samovaR from GitHub branch r-package
# ./install.sh OPAL optional CAMI OPAL (https://github.com/CAMI-challenge/OPAL)
# ./install.sh MultiQC optional MultiQC HTML reports
# ./install.sh CAMISIM optional CAMISIM community/read simulator
# ./install.sh NanoSim optional NanoSim in a separate conda env (ONT / hybrid)
# ./install.sh ART optional ART Illumina simulator in a separate conda env
# ./install.sh seqtk optional seqtk (FASTQ subsample / rarefaction)
# ./install.sh MegaHIT optional MegaHIT assembler (sidecar)
# ./install.sh Prodigal optional Prodigal gene caller (sidecar)
# ./install.sh minimap2 optional minimap2 + samtools (sidecar)
# ./install.sh CoverM optional CoverM MAG quantifier (sidecar)
# ./install.sh DAS_Tool optional DAS Tool (sidecar)
# ./install.sh anvio optional anvi'o binner (sidecar)
# ./install.sh CheckM2 optional CheckM2 (sidecar)
# ./install.sh GTDB-Tk optional GTDB-Tk (sidecar; set GTDBTK_DATA_PATH)
# ./install.sh SparseDOSSA2 SparseDOSSA2 (also included in ./install.sh full)
# ./install.sh CAMISIM NanoSim ART several optionals without reinstalling the core
# ./install.sh --rebuild-citations 1 refresh cite/*.bib after install (default)
# ./install.sh --rebuild-citations 0 skip doi.org / R citation() / CLI harvest
#
# Environment:
# SAMOVAR_OFFLINE=1 pip --offline (air-gapped; optional SAMOVAR_WHEELHOUSE)
# SAMOVAR_INSTALL_DEV=1 also install pytest/flake8 extras
# SAMOVAR_INSTALL_FULL=1 same as ./install.sh full
# SAMOVAR_INSTALL_R=1 also install optional R package (same as ./install.sh R-package)
# SAMOVAR_INSTALL_OPAL=1 also install optional CAMI OPAL (same as ./install.sh OPAL)
# SAMOVAR_INSTALL_MULTIQC=1 also install optional MultiQC (same as ./install.sh MultiQC)
# SAMOVAR_INSTALL_CAMISIM=1 also clone optional CAMISIM (same as ./install.sh CAMISIM)
# SAMOVAR_INSTALL_NANOSIM=1 also sidecar-conda NanoSim (same as ./install.sh NanoSim)
# SAMOVAR_INSTALL_ART=1 also sidecar-conda ART (same as ./install.sh ART)
# SAMOVAR_INSTALL_SEQTK=1 also seqtk (same as ./install.sh seqtk)
# SAMOVAR_INSTALL_SPARSEDOSSA2=1 also install SparseDOSSA2 (same as ./install.sh SparseDOSSA2)
# SAMOVAR_CONDA conda/mamba/micromamba executable for sidecar envs
# SAMOVAR_R_REPO default ctlab/samovar
# SAMOVAR_R_BRANCH default r-package
# SAMOVAR_UPDATE_SHELL=1 default: add bin/ to PATH this session and ~/.bashrc
# SAMOVAR_UPDATE_SHELL=0 shared/read-only: skip PATH and ~/.bashrc edits
# SAMOVAR_REBUILD_CITATIONS=0 same as --rebuild-citations 0
# SAMOVAR_CONFIG=/path/to/config.json
# write main config to this file (dir holds env/)
# SAMOVAR_CONFIG_DIR=/dir write $dir/config.json instead of ~/.config/samovar
# SAMOVAR_DATABASE=/path processed genome library (default: $ROOT/genomes)
# SAMOVAR_TAXDUMP=/path NCBI taxdump dir (default: $SAMOVAR_DATABASE/taxdump)
# NCBI_EMAIL / ENTREZ_EMAIL / SAMOVAR_EMAIL
# CI=true non-interactive; NCBI_EMAIL defaults to test@samovar.com
# and shell/PATH edits are skipped
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export SAMOVAR_ROOT="${SAMOVAR_ROOT:-$ROOT}"
cd "$ROOT"
SAMOVAR_VERSION="$(
grep -E '^version[[:space:]]*=' "$ROOT/pyproject.toml" 2>/dev/null \
| head -n1 \
| sed -E 's/^version[[:space:]]*=[[:space:]]*["'\'']([^"'\'']+)["'\''].*/\1/'
)"
SAMOVAR_VERSION="${SAMOVAR_VERSION:-unknown}"
echo ""
echo "Hello from SAMOVAR ${SAMOVAR_VERSION}"
echo "Warning: this tool may be unstable and is under active development."
echo ""
echo "Installing the Python pipeline..."
mkdir -p bin
if ! mkdir -p build 2>/dev/null; then
echo "Warning: cannot write $ROOT/build (read-only checkout); config pointer may be skipped"
fi
# Main config location (default: $XDG_CONFIG_HOME/samovar/config.json).
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
if [ -n "${SAMOVAR_CONFIG:-}" ]; then
# Absolute file path for config.json
case "${SAMOVAR_CONFIG}" in
/*) ;;
~*) SAMOVAR_CONFIG="${SAMOVAR_CONFIG/#\~/$HOME}" ;;
*) SAMOVAR_CONFIG="$(pwd)/${SAMOVAR_CONFIG}" ;;
esac
USER_CFG_DIR="$(dirname "$SAMOVAR_CONFIG")"
elif [ -n "${SAMOVAR_CONFIG_DIR:-}" ]; then
case "${SAMOVAR_CONFIG_DIR}" in
/*) USER_CFG_DIR="${SAMOVAR_CONFIG_DIR}" ;;
~*) USER_CFG_DIR="${SAMOVAR_CONFIG_DIR/#\~/$HOME}" ;;
*) USER_CFG_DIR="$(pwd)/${SAMOVAR_CONFIG_DIR}" ;;
esac
SAMOVAR_CONFIG="${USER_CFG_DIR}/config.json"
else
USER_CFG_DIR="${XDG_CONFIG_HOME}/samovar"
SAMOVAR_CONFIG="${USER_CFG_DIR}/config.json"
fi
export SAMOVAR_CONFIG
export USER_CFG_DIR
mkdir -p "$USER_CFG_DIR"
if [ -n "${CONDA_PREFIX:-}" ] && [ -x "${CONDA_PREFIX}/bin/python" ]; then
PYTHON_PATH="${PYTHON_PATH:-${CONDA_PREFIX}/bin/python}"
elif command -v python3 >/dev/null 2>&1; then
PYTHON_PATH="${PYTHON_PATH:-python3}"
else
PYTHON_PATH="${PYTHON_PATH:-python}"
fi
if ! command -v "$PYTHON_PATH" >/dev/null 2>&1; then
echo "Python 3 is not installed. Create a conda env first, e.g.:"
echo " conda env create -f environment.yml && conda activate samovar"
exit 1
fi
PYTHON_PATH="$(command -v "$PYTHON_PATH" || true)"
PYTHON_PATH="${PYTHON_PATH:-python3}"
PY_BIN="$(cd "$(dirname "$PYTHON_PATH")" && pwd)"
case ":$PATH:" in
*":$PY_BIN:"*) ;;
*) export PATH="$PY_BIN:$PATH" ;;
esac
# remotes::install_github talks to api.github.com and will use a bundled GitHub
# PAT that GitHub has revoked (HTTP 401 "Bad credentials"). Public repos install
# with git clone + remotes::install_local, which never hits that API.
r_install_github_local() {
local repo="$1"
local ref="${2:-}"
local deps="${3:-TRUE}"
local tmp dest dest_esc archive_ref
tmp="$(mktemp -d)"
dest="${tmp}/pkg"
archive_ref="${ref:-HEAD}"
echo "Installing ${repo}${ref:+@${ref}} via git clone (avoids remotes GitHub PAT / API 401) ..."
if [ -n "$ref" ] && [ "$ref" != "HEAD" ]; then
git clone --depth 1 --branch "$ref" --quiet "https://github.com/${repo}.git" "$dest" || true
else
git clone --depth 1 --quiet "https://github.com/${repo}.git" "$dest" || true
fi
if [ ! -f "${dest}/DESCRIPTION" ]; then
echo "git clone failed; trying GitHub source tarball ..."
rm -rf "$dest"
mkdir -p "$tmp"
if curl -fsSL "https://codeload.github.com/${repo}/tar.gz/${archive_ref}" | tar -xz -C "$tmp"; then
dest="$(find "$tmp" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
fi
fi
if [ -z "${dest:-}" ] || [ ! -f "${dest}/DESCRIPTION" ]; then
echo "Could not fetch ${repo} source (need git or curl + a public GitHub tarball)."
rm -rf "$tmp"
return 1
fi
dest_esc="$(printf '%s' "$dest" | sed "s/'/'\\\\''/g")"
if ! R --vanilla -e "library(remotes); remotes::install_local('${dest_esc}', upgrade='never', dependencies=${deps})"; then
rm -rf "$tmp"
return 1
fi
rm -rf "$tmp"
return 0
}
install_samovar_r_package() {
local repo="${SAMOVAR_R_REPO:-ctlab/samovar}"
local branch="${SAMOVAR_R_BRANCH:-r-package}"
local script_dest="$USER_CFG_DIR/annotation_regenerate.R"
if ! command -v R >/dev/null 2>&1; then
echo "R is not on PATH; cannot install the optional samovaR package."
return 1
fi
local info
info="$(R --vanilla -s -e 'if (requireNamespace("samovaR", quietly=TRUE)) { cat("INSTALLED", as.character(packageVersion("samovaR")), find.package("samovaR")) } else cat("MISSING")' 2>/dev/null || true)"
if echo "$info" | grep -q '^INSTALLED'; then
local ver lib
ver="$(echo "$info" | awk '{print $2}')"
lib="$(echo "$info" | awk '{print $3}')"
echo "Warning: samovaR is already installed (version ${ver:-unknown}${lib:+ at $lib})."
echo "Skipping GitHub install. Uninstall the package (not its dependencies) to reinstall from $repo@$branch."
else
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping samovaR install in offline mode."
return 1
fi
echo "Installing samovaR from https://github.com/${repo}/tree/${branch} ..."
R --vanilla -s -e "if (!requireNamespace('remotes', quietly=TRUE)) install.packages('remotes', repos='https://cloud.r-project.org')"
if ! r_install_github_local "$repo" "$branch" "NA"; then
echo "GitHub clone/tarball install failed; trying a local checkout of origin/${branch}..."
local tmp
tmp="$(mktemp -d)"
if git -C "$ROOT" fetch origin "$branch" 2>/dev/null; then
git -C "$ROOT" archive --format=tar "origin/${branch}" | tar -x -C "$tmp"
R --vanilla -s -e "library(remotes); remotes::install_local('${tmp}', upgrade='never', dependencies=NA)"
else
echo "Could not install samovaR from ${repo}@${branch}"
rm -rf "$tmp"
return 1
fi
rm -rf "$tmp"
fi
info="$(R --vanilla -s -e 'if (requireNamespace("samovaR", quietly=TRUE)) { cat("INSTALLED", as.character(packageVersion("samovaR"))) } else cat("MISSING")' 2>/dev/null || true)"
echo "samovaR: $info"
fi
mkdir -p "$USER_CFG_DIR"
export SAMOVAR_R_SCRIPT="$script_dest"
"$PYTHON_PATH" - <<'PY'
import os, shutil, sys
from pathlib import Path
dest = Path(os.environ["SAMOVAR_R_SCRIPT"])
try:
from samovar.table2iss import R_REGENERATE_DRIVER
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_text(R_REGENERATE_DRIVER, encoding="utf-8")
print("R regenerator script:", dest)
except Exception as exc:
print("Warning: could not write R driver:", exc)
sys.exit(0)
try:
from samovar.paths import load_config, write_config
except ImportError:
print(
"Warning: samovar Python package not importable; set SAMOVAR_R_REGENERATE="
+ str(dest)
)
sys.exit(0)
cfg = load_config()
cfg["annotation_regenerate_r"] = str(dest)
cfg["r_path"] = shutil.which("R") or cfg.get("r_path") or ""
write_config(cfg)
print("Updated config annotation_regenerate_r")
PY
return 0
}
install_sparsedossa2() {
if ! command -v R >/dev/null 2>&1 && ! command -v Rscript >/dev/null 2>&1; then
echo "R is not on PATH; cannot install SparseDOSSA2."
echo "See https://github.com/biobakery/SparseDOSSA2 and https://github.com/biobakery/biobakery/wiki/SparseDOSSA2"
return 1
fi
# SparseDOSSA2 Depends (DESCRIPTION): ks, mvtnorm, huge, future.apply, magrittr,
# truncnorm, igraph, Rmpfr. Rmpfr needs system libmpfr/libgmp (apt or conda).
if [ "${SAMOVAR_OFFLINE:-0}" = "0" ]; then
echo "Ensuring SparseDOSSA2 R dependencies ..."
R --vanilla -s -e "if (!requireNamespace('remotes', quietly=TRUE)) install.packages('remotes', repos='https://cloud.r-project.org')" || true
R --vanilla -s -e "
pkgs <- c('ks', 'mvtnorm', 'huge', 'future', 'future.apply', 'magrittr', 'truncnorm', 'igraph', 'Rmpfr')
missing <- pkgs[!vapply(pkgs, requireNamespace, quietly=TRUE, FUN.VALUE=logical(1))]
if (length(missing)) {
message('Installing CRAN deps: ', paste(missing, collapse=', '))
install.packages(missing, repos='https://cloud.r-project.org')
}
" || true
fi
local info
info="$(R --vanilla -s -e 'if (requireNamespace("SparseDOSSA2", quietly=TRUE)) { cat("INSTALLED", as.character(packageVersion("SparseDOSSA2")), find.package("SparseDOSSA2")) } else cat("MISSING")' 2>/dev/null || true)"
if echo "$info" | grep -q '^INSTALLED'; then
echo "SparseDOSSA2 is already installed ($info). Recording table generators and CV scorer in the install config."
elif [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping SparseDOSSA2 install in offline mode."
return 1
else
echo "Installing SparseDOSSA2 from https://github.com/biobakery/SparseDOSSA2 ..."
# Do not swallow stderr: failed Rmpfr/huge builds are the usual GHA failure mode.
# Do not use remotes::install_github: bundled PAT → HTTP 401 on GHA.
if ! r_install_github_local "biobakery/SparseDOSSA2" "" "TRUE"; then
echo "GitHub SparseDOSSA2 install failed."
echo "On Debian/Ubuntu install build deps first:"
echo " sudo apt-get install -y libmpfr-dev libgmp-dev libcurl4-openssl-dev libssl-dev libxml2-dev gfortran"
echo "Or conda: conda install -c conda-forge r-rmpfr r-igraph r-huge r-ks r-mvtnorm r-truncnorm"
echo "Install later with: ./install.sh SparseDOSSA2"
echo "Wiki: https://github.com/biobakery/biobakery/wiki/SparseDOSSA2"
return 1
fi
info="$(R --vanilla -s -e 'if (requireNamespace("SparseDOSSA2", quietly=TRUE)) { cat("INSTALLED", as.character(packageVersion("SparseDOSSA2"))) } else cat("MISSING")' 2>/dev/null || true)"
echo "SparseDOSSA2: $info"
if ! echo "$info" | grep -q '^INSTALLED'; then
echo "SparseDOSSA2 package still missing after install (often Rmpfr without libmpfr-dev)."
return 1
fi
fi
mkdir -p "$USER_CFG_DIR"
local driver_src="$ROOT/src/samovar/sparsedossa2.R"
local driver_dest="$USER_CFG_DIR/sparsedossa2.R"
if [ -f "$driver_src" ]; then
cp -f "$driver_src" "$driver_dest"
echo "SparseDOSSA2 R driver: $driver_dest"
fi
export SAMOVAR_SPARSEDOSSA2_R="$driver_dest"
"$PYTHON_PATH" - <<'PY'
try:
from samovar.sparsedossa2 import register_sparsedossa2_tools
except ImportError as exc:
# Optional-only early path (./install.sh SparseDOSSA2 before pip -e .) may hit this.
print(
"Warning: samovar is not importable yet; R package is installed. "
"Re-run ./install.sh SparseDOSSA2 after the Python package to register tools:",
exc,
)
raise SystemExit(0)
register_sparsedossa2_tools()
print("Updated config: sparsedossa2-fit / sparsedossa2-stool / sparsedossa2-vaginal / sparsedossa2-ibd (table)")
print("Updated config: sparsedossa2-cv (fitCV_SparseDOSSA2 table scorer)")
PY
return 0
}
install_opal() {
if "$PYTHON_PATH" -c "from samovar.paths import discover_opal; raise SystemExit(0 if discover_opal() else 1)" 2>/dev/null; then
echo "OPAL already present; recording it in the install config."
elif [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping OPAL install in offline mode."
return 1
else
echo "Installing optional CAMI OPAL (https://github.com/CAMI-challenge/OPAL) ..."
# cami-opal pins exact numpy/pandas/scipy; those pins fight the SamovaR env
# and can hang pip. Install the package only; scientific stack is already here.
if ! "$PYTHON_PATH" -m pip install "cami-opal" --no-deps "${PIP_OPTS[@]+"${PIP_OPTS[@]}"}"; then
echo "Warning: pip install cami-opal failed. Profiling HTML from OPAL will be skipped."
echo "Install later with: ./install.sh OPAL"
return 1
fi
"$PYTHON_PATH" -m pip install "bokeh>=3" "jinja2>=3" "${PIP_OPTS[@]+"${PIP_OPTS[@]}"}" || true
hash -r 2>/dev/null || true
fi
export PY_BIN
"$PYTHON_PATH" - <<'PY'
import os, shutil, stat, sys
from pathlib import Path
try:
from samovar.paths import discover_opal, load_config, write_config
except ImportError:
print("Warning: samovar is not importable yet; re-run ./install.sh to record opal_path")
raise SystemExit(0)
found = discover_opal()
py_bin = Path(os.environ.get("PY_BIN") or Path(sys.executable).parent)
for extra in (py_bin / "opal.py", Path.home() / ".local" / "bin" / "opal.py"):
if extra.is_file() and (not found):
found = str(extra.resolve())
break
if not found:
print("Warning: cami-opal installed but opal.py was not found on PATH or next to Python.")
print("Add it with: opal_path in ~/.config/samovar/config.json")
raise SystemExit(1)
path = Path(found)
if not os.access(path, os.X_OK):
try:
path.chmod(path.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
except OSError:
pass
cfg = load_config()
cfg["opal_path"] = str(path)
tools = dict(cfg.get("tools") or {})
tools["opal.py"] = str(path)
cfg["tools"] = tools
write_config(cfg)
print("OPAL:", path)
print("Updated config opal_path:", cfg.get("opal_path"))
PY
}
install_multiqc() {
if "$PYTHON_PATH" -c "from samovar.paths import discover_multiqc; import shutil; raise SystemExit(0 if (discover_multiqc() or shutil.which('multiqc')) else 1)" 2>/dev/null; then
echo "MultiQC already present; recording it in the install config."
elif [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping MultiQC install in offline mode."
return 1
else
echo "Installing optional MultiQC (https://seqera.io/multiqc/) ..."
if ! "$PYTHON_PATH" -m pip install "multiqc>=1.21" "${PIP_OPTS[@]+"${PIP_OPTS[@]}"}"; then
echo "Warning: pip install multiqc failed. HTML reports from MultiQC will be skipped."
echo "Install later with: ./install.sh MultiQC"
return 1
fi
hash -r 2>/dev/null || true
fi
export PY_BIN
"$PYTHON_PATH" - <<'PY'
import os, shutil, sys
from pathlib import Path
try:
from samovar.paths import discover_multiqc, load_config, write_config
except ImportError:
print("Warning: samovar is not importable yet; re-run ./install.sh to record multiqc_path")
raise SystemExit(0)
found = discover_multiqc() or shutil.which("multiqc")
py_bin = Path(os.environ.get("PY_BIN") or Path(sys.executable).parent)
for extra in (py_bin / "multiqc", Path.home() / ".local" / "bin" / "multiqc"):
if extra.is_file() and (not found):
found = str(extra.resolve())
break
if not found:
print("Warning: multiqc installed but the CLI was not found on PATH.")
print("Add it with: multiqc_path in ~/.config/samovar/config.json")
raise SystemExit(1)
cfg = load_config()
cfg["multiqc_path"] = str(found)
tools = dict(cfg.get("tools") or {})
tools["multiqc"] = str(found)
cfg["tools"] = tools
write_config(cfg)
print("MultiQC:", found)
print("Updated config multiqc_path:", cfg.get("multiqc_path"))
PY
}
install_camisim() {
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping CAMISIM clone in offline mode."
return 1
fi
echo "Installing optional CAMISIM (https://github.com/CAMI-challenge/CAMISIM) ..."
if ! command -v git >/dev/null 2>&1; then
echo "Warning: git is required to clone CAMISIM."
return 1
fi
export PYTHON_PATH
export SAMOVAR_ROOT="${SAMOVAR_ROOT:-$ROOT}"
"$PYTHON_PATH" - <<'PY'
import os, shutil, subprocess, sys
from pathlib import Path
try:
from samovar.paths import load_config, write_config
except ImportError:
print("Warning: samovar is not importable yet; re-run ./install.sh CAMISIM after the Python package is installed")
raise SystemExit(0)
dest = Path(
os.environ.get("SAMOVAR_CAMISIM")
or (Path(os.environ.get("SAMOVAR_ROOT", ".")) / ".cache" / "CAMISIM")
)
if (dest / "main.nf").is_file() or (dest / "metagenomesimulation.py").is_file():
print("CAMISIM already present:", dest)
else:
dest.parent.mkdir(parents=True, exist_ok=True)
if dest.exists() and not any(dest.iterdir()):
dest.rmdir()
print("Cloning CAMISIM into", dest)
subprocess.check_call(
["git", "clone", "--depth", "1", "https://github.com/CAMI-challenge/CAMISIM", str(dest)]
)
cfg = load_config()
cfg["camisim_path"] = str(dest)
nxt = shutil.which("nextflow") or ""
if nxt:
cfg["nextflow_path"] = nxt
tools = dict(cfg.get("tools") or {})
tools["camisim"] = str(dest)
if nxt:
tools["nextflow"] = nxt
cfg["tools"] = tools
write_config(cfg)
print("CAMISIM:", dest)
print("Nextflow:", nxt or "not found (install nextflow to run CAMISIM 2.0 read simulation)")
print("Updated config camisim_path")
if not nxt:
print("Note: `samovar generate --camisim-mode table` still works (community design + ISS).")
print("Illumina/ONT/wgsim/hybrid need Nextflow + CAMISIM simulators (ART / NanoSim / wgsim).")
print("ONT/hybrid: ./install.sh NanoSim (separate conda env; do not mix with SamovaR Python)")
print("Illumina: ./install.sh ART (optional sidecar; Nextflow can also create ART via conda)")
PY
}
install_nanosim() {
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping NanoSim sidecar env in offline mode."
return 1
fi
echo "Installing optional NanoSim in a separate conda env (Python 3.8; not the SamovaR env) ..."
if ! "$PYTHON_PATH" -m samovar.sidecar nanosim; then
echo "Warning: NanoSim sidecar install failed."
echo "Install later with: ./install.sh NanoSim"
echo "Or: conda create -p \"\$SAMOVAR_ROOT/.cache/samovar/envs/nanosim\" -c conda-forge -c bioconda python=3.8 nanosim=3.2 htseq gffutils numpy=1.23.5 scikit-learn=0.23.2"
echo "Then set tool_envs.nanosim and nanosim_path in ~/.config/samovar/config.json"
return 1
fi
}
install_art() {
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping ART sidecar env in offline mode."
return 1
fi
echo "Installing optional ART (art_illumina) in a separate conda env ..."
if ! "$PYTHON_PATH" -m samovar.sidecar art; then
echo "Warning: ART sidecar install failed."
echo "Install later with: ./install.sh ART"
echo "Or: conda create -p \"\$SAMOVAR_ROOT/.cache/samovar/envs/art\" -c bioconda -c conda-forge art samtools"
echo "Then set tool_envs.art and art_path in ~/.config/samovar/config.json"
return 1
fi
}
install_seqtk() {
if command -v seqtk >/dev/null 2>&1; then
echo "seqtk: $(command -v seqtk)"
return 0
fi
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping seqtk install in offline mode. conda install -c bioconda seqtk"
return 1
fi
local conda_bin="${SAMOVAR_CONDA:-}"
if [ -z "$conda_bin" ]; then
conda_bin="$(command -v mamba || command -v conda || true)"
fi
if [ -z "$conda_bin" ]; then
echo "seqtk is not on PATH and conda/mamba was not found."
echo "Install with: conda install -c bioconda seqtk"
return 1
fi
echo "Installing optional seqtk (https://github.com/lh3/seqtk) via bioconda ..."
if ! "$conda_bin" install -y -c bioconda -c conda-forge seqtk; then
echo "Warning: seqtk install failed. Rarefaction with seqtk sample will be unavailable."
return 1
fi
hash -r 2>/dev/null || true
if command -v seqtk >/dev/null 2>&1; then
echo "seqtk: $(command -v seqtk)"
return 0
fi
echo "seqtk installed but not on PATH in this shell."
return 1
}
install_nextflow() {
if command -v nextflow >/dev/null 2>&1; then
echo "nextflow: $(command -v nextflow)"
return 0
fi
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Skipping nextflow install in offline mode. conda install -c bioconda nextflow"
return 1
fi
local conda_bin="${SAMOVAR_CONDA:-}"
if [ -z "$conda_bin" ]; then
conda_bin="$(command -v mamba || command -v conda || true)"
fi
if [ -z "$conda_bin" ]; then
echo "nextflow is not on PATH and conda/mamba was not found."
echo "Install with: conda install -c bioconda nextflow"
echo "or https://www.nextflow.io/docs/latest/install.html"
return 1
fi
echo "Installing optional Nextflow via bioconda (needed for CAMISIM 2 read simulation) ..."
if ! "$conda_bin" install -y -c bioconda -c conda-forge nextflow; then
echo "Warning: nextflow install failed. CAMISIM table+ISS mode still works without it."
return 1
fi
hash -r 2>/dev/null || true
if command -v nextflow >/dev/null 2>&1; then
echo "nextflow: $(command -v nextflow)"
return 0
fi
echo "nextflow installed but not on PATH in this shell."
return 1
}
print_install_status() {
"$PYTHON_PATH" - <<'PY' || true
try:
from samovar.paths import format_install_status
print("")
print(format_install_status())
except Exception as exc:
print("Could not print tool status:", exc)
PY
}
normalize_optional_arg() {
local raw="${1:-}"
local lower
lower="$(printf '%s' "$raw" | tr '[:upper:]' '[:lower:]')"
case "$lower" in
r-package|rpackage|r) echo "r-package" ;;
opal) echo "opal" ;;
multiqc) echo "multiqc" ;;
camisim) echo "camisim" ;;
nanosim|nanosim3) echo "nanosim" ;;
art|art_illumina) echo "art" ;;
nextflow) echo "nextflow" ;;
seqtk) echo "seqtk" ;;
megahit|mega-hit) echo "megahit" ;;
prodigal) echo "prodigal" ;;
minimap2) echo "minimap2" ;;
coverm|cover-m) echo "coverm" ;;
dastool|das_tool|das-tool) echo "dastool" ;;
anvio|anvi) echo "anvio" ;;
checkm2|checkm) echo "checkm2" ;;
gtdbtk|gtdb-tk|gtdb_tk) echo "gtdbtk" ;;
sparsedossa2|sparsedossa|sd2) echo "sparsedossa2" ;;
full|all|everything) echo "full" ;;
*) echo "" ;;
esac
}
run_optional_named() {
local name="$1"
case "$name" in
r-package) install_samovar_r_package ;;
opal)
PIP_OPTS=()
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
PIP_OPTS+=(--offline --no-build-isolation)
if [ -n "${SAMOVAR_WHEELHOUSE:-}" ]; then
PIP_OPTS+=(--no-index --find-links "$SAMOVAR_WHEELHOUSE")
fi
fi
install_opal
;;
multiqc)
PIP_OPTS=()
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
PIP_OPTS+=(--offline --no-build-isolation)
if [ -n "${SAMOVAR_WHEELHOUSE:-}" ]; then
PIP_OPTS+=(--no-index --find-links "$SAMOVAR_WHEELHOUSE")
fi
fi
install_multiqc
;;
camisim) install_camisim ;;
nanosim) install_nanosim ;;
art) install_art ;;
seqtk) install_seqtk ;;
nextflow) install_nextflow ;;
megahit) "$PYTHON_PATH" -m samovar.sidecar megahit ;;
prodigal) "$PYTHON_PATH" -m samovar.sidecar prodigal ;;
minimap2) "$PYTHON_PATH" -m samovar.sidecar minimap2 ;;
coverm) "$PYTHON_PATH" -m samovar.sidecar coverm ;;
dastool) "$PYTHON_PATH" -m samovar.sidecar dastool ;;
anvio) "$PYTHON_PATH" -m samovar.sidecar anvio ;;
checkm2) "$PYTHON_PATH" -m samovar.sidecar checkm2 ;;
gtdbtk) "$PYTHON_PATH" -m samovar.sidecar gtdbtk ;;
sparsedossa2) install_sparsedossa2 ;;
*) return 1 ;;
esac
}
rebuild_citations() {
if [ "$REBUILD_CITATIONS" = "0" ]; then
echo "Skipping cite/*.bib refresh (--rebuild-citations 0)."
return 0
fi
echo "Refreshing cite/*.bib (doi.org, R citation(), CLI --citation)..."
local extra=()
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
extra+=(--offline)
fi
if ! "$PYTHON_PATH" -m samovar.citations rebuild --root "$ROOT" "${extra[@]+"${extra[@]}"}"; then
echo "Warning: citation rebuild failed; bundled cite/ files were left as-is."
return 0
fi
}
enable_full_install_flags() {
export SAMOVAR_INSTALL_R=1
export SAMOVAR_INSTALL_OPAL=1
export SAMOVAR_INSTALL_MULTIQC=1
export SAMOVAR_INSTALL_CAMISIM=1
export SAMOVAR_INSTALL_NANOSIM=1
export SAMOVAR_INSTALL_ART=1
export SAMOVAR_INSTALL_SEQTK=1
export SAMOVAR_INSTALL_NEXTFLOW=1
export SAMOVAR_INSTALL_SPARSEDOSSA2=1
}
INSTALL_FULL=0
if [ "${SAMOVAR_INSTALL_FULL:-0}" != "0" ]; then
INSTALL_FULL=1
fi
REBUILD_CITATIONS="${SAMOVAR_REBUILD_CITATIONS:-1}"
FILTERED_ARGS=()
SKIP_NEXT=0
for arg in "$@"; do
if [ "$SKIP_NEXT" = "1" ]; then
SKIP_NEXT=0
case "$arg" in
0|false|FALSE|no|NO|off|OFF) REBUILD_CITATIONS=0 ;;
*) REBUILD_CITATIONS=1 ;;
esac
continue
fi
case "$arg" in
--rebuild-citations)
SKIP_NEXT=1
continue
;;
--rebuild-citations=*)
case "${arg#--rebuild-citations=}" in
0|false|FALSE|no|NO|off|OFF) REBUILD_CITATIONS=0 ;;
*) REBUILD_CITATIONS=1 ;;
esac
continue
;;
--no-rebuild-citations)
REBUILD_CITATIONS=0
continue
;;
esac
mapped="$(normalize_optional_arg "$arg")"
if [ "$mapped" = "full" ]; then
INSTALL_FULL=1
continue
fi
FILTERED_ARGS+=("$arg")
done
if [ "$SKIP_NEXT" = "1" ]; then
REBUILD_CITATIONS=1
fi
if [ "${#FILTERED_ARGS[@]}" -gt 0 ]; then
set -- "${FILTERED_ARGS[@]}"
else
set --
fi
if [ "$INSTALL_FULL" = "1" ]; then
echo "Full install: Python pipeline plus every optional extra (reuse if already present, then record in config)."
enable_full_install_flags
fi
OPTIONAL_ONLY_ARGS=()
if [ "$INSTALL_FULL" != "1" ] && [ "$#" -gt 0 ]; then
ALL_OPTIONAL=1
for arg in "$@"; do
mapped="$(normalize_optional_arg "$arg")"
if [ -z "$mapped" ]; then
ALL_OPTIONAL=0
break
fi
OPTIONAL_ONLY_ARGS+=("$mapped")
done
if [ "$ALL_OPTIONAL" = "1" ] && [ "${#OPTIONAL_ONLY_ARGS[@]}" -gt 0 ]; then
FAIL=0
for name in "${OPTIONAL_ONLY_ARGS[@]}"; do
echo "Optional install: $name"
run_optional_named "$name" || FAIL=1
done
rebuild_citations
print_install_status
exit "$FAIL"
fi
fi
PYTHON_VERSION=$("$PYTHON_PATH" --version)
echo "Using $PYTHON_VERSION ($PYTHON_PATH)"
if [ -n "${CONDA_PREFIX:-}" ]; then
echo "Conda prefix: $CONDA_PREFIX"
fi
# NCBI Entrez email (genome fetch)
if [ -n "${CI:-}" ]; then
NCBI_EMAIL="${NCBI_EMAIL:-test@samovar.com}"
fi
NCBI_EMAIL="${NCBI_EMAIL:-${ENTREZ_EMAIL:-${SAMOVAR_EMAIL:-}}}"
if [ -z "$NCBI_EMAIL" ]; then
if [ -t 0 ] && [ -z "${CI:-}" ]; then
printf "NCBI Entrez email (required for genome downloads): "
read -r NCBI_EMAIL
fi
fi
if [ -z "$NCBI_EMAIL" ]; then
NCBI_EMAIL="anonymous@example.com"
echo "Warning: no NCBI email set; using $NCBI_EMAIL. Re-run with NCBI_EMAIL=you@institution.edu"
fi
export NCBI_EMAIL
echo "NCBI email: $NCBI_EMAIL"
PIP_OPTS=()
if [ "${SAMOVAR_OFFLINE:-0}" != "0" ]; then
echo "Offline mode (SAMOVAR_OFFLINE=1): skipping pip upgrade / PyPI"
PIP_OPTS+=(--offline --no-build-isolation)
if [ -n "${SAMOVAR_WHEELHOUSE:-}" ]; then
PIP_OPTS+=(--no-index --find-links "$SAMOVAR_WHEELHOUSE")
else
echo "Warning: SAMOVAR_WHEELHOUSE is unset; offline pip needs local wheels."
fi
else
echo "Installing Python package (editable)..."
"$PYTHON_PATH" -m pip install --upgrade pip
fi
if [ "${SAMOVAR_INSTALL_DEV:-0}" != "0" ] || [ -n "${CI:-}" ]; then
echo "Installing package + dev extras..."
"$PYTHON_PATH" -m pip install -e ".[dev]" "${PIP_OPTS[@]+"${PIP_OPTS[@]}"}"
else
echo "Installing package (no dev extras; set SAMOVAR_INSTALL_DEV=1 for pytest/flake8)..."
"$PYTHON_PATH" -m pip install -e . "${PIP_OPTS[@]+"${PIP_OPTS[@]}"}"
fi
# ISS / snakemake: try pip, then hard-exit if still missing
ensure_cli() {
local name="$1"
local pip_spec="$2"
local hint="$3"
if command -v "$name" >/dev/null 2>&1; then
echo "$name: $(command -v "$name")"
return 0
fi
if [ -x "$PY_BIN/$name" ]; then
echo "$name: $PY_BIN/$name"
return 0
fi
echo "$name not on PATH; installing ${pip_spec}..."
"$PYTHON_PATH" -m pip install "$pip_spec" "${PIP_OPTS[@]+"${PIP_OPTS[@]}"}" || true
hash -r 2>/dev/null || true
if command -v "$name" >/dev/null 2>&1; then
echo "$name: $(command -v "$name")"
return 0
fi
if [ -x "$PY_BIN/$name" ]; then
echo "$name: $PY_BIN/$name"
return 0
fi
echo "ERROR: $name is required but was not found after install attempt."
echo "$hint"
return 1
}
ensure_cli iss "insilicoseq>2.0.0" \
"Install with: $PYTHON_PATH -m pip install 'insilicoseq>2.0.0' (conda: insilicoseq)" || exit 1
ensure_cli snakemake "snakemake>=7.0" \
"Install with: $PYTHON_PATH -m pip install 'snakemake>=7.0' or conda install -c bioconda snakemake-minimal" || exit 1
chmod +x bin/* workflow/database_prep/samovar_build_database.sh workflow/database_prep/samovar_build_database.py workflow/compare_annotations.py workflow/annotation_regenerate.py workflow/combine_annotation_tables.py workflow/remap_taxids.py workflow/ML.py 2>/dev/null || true
echo "Building C++ annotation combiner..."
CXX_BIN="${CXX:-}"
if [ -z "$CXX_BIN" ] || ! command -v "$CXX_BIN" >/dev/null 2>&1; then
for cand in g++ c++ clang++; do
if command -v "$cand" >/dev/null 2>&1; then
CXX_BIN="$(command -v "$cand")"
break
fi
done
fi
if [ -n "${CXX_BIN:-}" ]; then
echo "C++ compiler: $CXX_BIN"
make -C src/cpp CXX="$CXX_BIN"
chmod +x bin/samovar_combine_annotations 2>/dev/null || true
else
echo "Warning: no C++ compiler (g++/c++/clang++); annotation merge will try to compile on first use."
fi
if [ "${SAMOVAR_INSTALL_R:-0}" != "0" ]; then
install_samovar_r_package || echo "Warning: optional R package install did not complete."
else
echo "Skipping R package (not required). Use ./install.sh R-package to install samovaR from GitHub branch r-package."
fi
if [ "${SAMOVAR_INSTALL_OPAL:-0}" != "0" ]; then
install_opal || echo "Warning: optional OPAL install did not complete."
else
echo "Skipping OPAL (not required). Use ./install.sh OPAL to install CAMI OPAL (cami-opal)."
fi
if [ "${SAMOVAR_INSTALL_MULTIQC:-0}" != "0" ]; then
install_multiqc || echo "Warning: optional MultiQC install did not complete."
else
echo "Skipping MultiQC (not required). Use ./install.sh MultiQC to install MultiQC."
fi
if [ "${SAMOVAR_INSTALL_CAMISIM:-0}" != "0" ]; then
install_camisim || echo "Warning: optional CAMISIM install did not complete."
else
echo "Skipping CAMISIM (not required). Use ./install.sh CAMISIM to clone https://github.com/CAMI-challenge/CAMISIM"
fi
if [ "${SAMOVAR_INSTALL_NANOSIM:-0}" != "0" ]; then
install_nanosim || echo "Warning: optional NanoSim sidecar install did not complete."
else
echo "Skipping NanoSim (not required). Use ./install.sh NanoSim for a separate conda env (CAMISIM ONT/hybrid)."
fi
if [ "${SAMOVAR_INSTALL_ART:-0}" != "0" ]; then
install_art || echo "Warning: optional ART sidecar install did not complete."
else
echo "Skipping ART (not required). Use ./install.sh ART for a separate conda env (CAMISIM Illumina)."
fi
if [ "${SAMOVAR_INSTALL_SEQTK:-0}" != "0" ]; then
install_seqtk || echo "Warning: optional seqtk install did not complete."
else
echo "Skipping seqtk (not required). Use ./install.sh seqtk for FASTQ subsample / rarefaction."
fi
if [ "${SAMOVAR_INSTALL_NEXTFLOW:-0}" != "0" ]; then
install_nextflow || echo "Warning: optional nextflow install did not complete."
else
echo "Skipping nextflow (not required). Use ./install.sh nextflow or ./install.sh full."
fi
if [ "${SAMOVAR_INSTALL_SPARSEDOSSA2:-0}" != "0" ]; then
if ! install_sparsedossa2; then
echo "ERROR: SparseDOSSA2 install failed (required by ./install.sh full / SAMOVAR_INSTALL_SPARSEDOSSA2=1)."
echo "Wiki: https://github.com/biobakery/biobakery/wiki/SparseDOSSA2"
exit 1
fi
if ! "$PYTHON_PATH" -c "from samovar.sparsedossa2 import sparsedossa2_available; raise SystemExit(0 if sparsedossa2_available() else 1)"; then
echo "ERROR: SparseDOSSA2 R package is not importable after install."
exit 1
fi
else
echo "Skipping SparseDOSSA2 (not required). Use ./install.sh SparseDOSSA2 for table generators + CV scoring."
fi
# Write main config.json (location: $SAMOVAR_CONFIG) and build/config_path
export USER_CFG_DIR
export SAMOVAR_CONFIG
export SAMOVAR_ROOT="$ROOT"
export PYTHON_PATH
"$PYTHON_PATH" - <<'PY'
import json, os, shutil
from pathlib import Path
from samovar.main_config import build_install_config, format_install_report
from samovar.paths import (
PACKAGE_VERSION,
collect_runtime_path_dirs,
discover_multiqc,
discover_opal,
discover_tools,
load_config,
write_config,
)
try:
from samovar.camisim import discover_camisim
except Exception:
def discover_camisim():
return None
try:
from samovar.paths import discover_art, discover_nanosim, cxx_compiler
except Exception:
def discover_art():
return None
def discover_nanosim():
return None
def cxx_compiler():
return None
root = os.environ["SAMOVAR_ROOT"]
python_path = os.environ["PYTHON_PATH"]
cfg_file = Path(os.environ.get("SAMOVAR_CONFIG") or "").expanduser()
previous_raw = None
if cfg_file.is_file():
try:
loaded = json.loads(cfg_file.read_text(encoding="utf-8"))
if isinstance(loaded, dict) and loaded:
previous_raw = loaded
except (OSError, json.JSONDecodeError, TypeError, UnicodeError):
previous_raw = None
existing = load_config()
tools = dict(discover_tools())
# Preserve previously configured tool paths (any schema).
from samovar.main_config import iter_tools, tool_path as _tool_path
for name, spec in iter_tools(existing).items():
path = _tool_path(spec, name)
if path:
tools.setdefault(name, path)
for name, path in (existing.get("tools") or {}).items():
if isinstance(path, str) and path.strip():
tools.setdefault(name, path)
_home = Path.home().resolve()
def _not_under_home(path: Path) -> bool:
try:
return not path.expanduser().resolve().is_relative_to(_home)
except (OSError, ValueError):
return True
default_genomes = ""
if os.environ.get("SAMOVAR_GENOMES", "").strip():
default_genomes = os.environ["SAMOVAR_GENOMES"].strip()
elif os.environ.get("XDG_CACHE_HOME", "").strip():
default_genomes = str(Path(os.environ["XDG_CACHE_HOME"]) / "samovar" / "genomes")
def _usable_dir(raw, *, allow_home: bool = False):
text = str(raw or "").strip()
if not text:
return ""
path = Path(text).expanduser()
if not allow_home and not _not_under_home(path):
return ""
try:
path.mkdir(parents=True, exist_ok=True)
except OSError:
return ""
return str(path)
samovar_database = _usable_dir(
os.environ.get("SAMOVAR_DATABASE", "").strip() or str(Path(root) / "genomes")
) or str(Path(root) / "genomes")
_store_processed = _usable_dir(str(Path(samovar_database) / "processed")) or str(Path(samovar_database) / "processed")