junidude14 commited on
Commit
78180f7
·
verified ·
1 Parent(s): 2d0f7dc

Archive 4 checkpoints (1-4)

Browse files
paper-releases/pbisc-diffusion/updates/20261008T022410Z-deconv-scsemi-deck/diffusion/dataset/server_1/model8/plans/bayesprism_paired_20261006/tools/finalize_full.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Score every full-gene BayesPrism comparison (score_bp.py ... full) and write the tables of both gene modes.
3
+ # CPU only; each scoring call in a bounded scope (MemoryMax 16G, 2 threads). usage: finalize_full.sh
4
+ set -uo pipefail
5
+ P=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/bayesprism_paired_20261006
6
+ PY=/home/sj_server_1/miniforge3/envs/cxg_corpus/bin/python
7
+ LOG=$P/logs/finalize_full_$(date +%Y%m%dT%H%M%S).log
8
+ log() { echo "$(date +%FT%T) $*" | tee -a "$LOG"; }
9
+ score() { systemd-run --user --scope --quiet -p MemoryMax=16G -p MemorySwapMax=0 -p CPUQuota=200% nice -n 10 \
10
+ env CUDA_VISIBLE_DEVICES= PYTHONDONTWRITEBYTECODE=1 OMP_NUM_THREADS=2 OPENBLAS_NUM_THREADS=2 "$PY" "$P/tools/score_bp.py" "$@" >> "$LOG" 2>&1; }
11
+ n_fail=0
12
+ for mode in full score; do
13
+ for ds in immicro ye2026_sepsis ji2025_chili imperial_eskd giroux2022; do
14
+ for j in 0 1 2 3 4; do score "$ds" fewshot "$j" "$mode" || { n_fail=$((n_fail+1)); log "WARN: $mode $ds fewshot $j"; }; done
15
+ score "$ds" cv "$mode" || { n_fail=$((n_fail+1)); log "WARN: $mode $ds cv"; }
16
+ done
17
+ "$PY" "$P/tools/aggregate_bp.py" "$mode" >> "$LOG" 2>&1 || { n_fail=$((n_fail+1)); log "WARN: aggregate $mode"; }
18
+ done
19
+ log "finalize done; failed=$n_fail"
paper-releases/pbisc-diffusion/updates/20261008T022410Z-deconv-scsemi-deck/diffusion/dataset/server_1/model8/plans/bayesprism_paired_20261006/tools/run_all.sh ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # BayesPrism over every split of the given cohorts (CPU only; 2026-10-06): for each cohort, the five few-pair draws
3
+ # then the five CV folds; per split build_split.py (skipped when SPLIT.json exists) and run_bp.R (skipped when bp/DONE
4
+ # exists), each as a bounded transient unit (MemoryMax 16G, MemorySwapMax 0, CPUQuota = cores x 100 %, Nice 10).
5
+ # A split starts only when MemAvailable >= 32 GiB floor + 16 GiB cap. A failure is logged and the next split runs.
6
+ # usage: run_all.sh LANE_NAME CORES DATASET [DATASET ...] (two lanes run side by side, 4 cores each)
7
+ # env GENES=full: BayesPrism's recommended gene set (common.full_genes; split dirs <split>_full); default score
8
+ set -uo pipefail
9
+ export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
10
+ export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=$XDG_RUNTIME_DIR/bus}"
11
+ P=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/bayesprism_paired_20261006
12
+ PY=/home/sj_server_1/miniforge3/envs/cxg_corpus/bin/python
13
+ RS=/home/sj_server_1/miniforge3/envs/r_env/bin/Rscript
14
+ lane=$1; cores=$2; shift 2
15
+ GENES=${GENES:-score}; SFX=$([[ $GENES == score ]] || echo "_$GENES")
16
+ LOG=$P/logs/run_all_${lane}_$(date +%Y%m%dT%H%M%S).log
17
+ log() { echo "$(date +%FT%T) $*" | tee -a "$LOG"; }
18
+ unit() { # unit NAME LOGFILE CMD...
19
+ local name=$1 lf=$2; shift 2
20
+ until (( $(awk '/MemAvailable/ {print int($2/1048576)}' /proc/meminfo) >= 48 )); do sleep 60; done
21
+ systemd-run --user --unit="bp-$name-$(date +%H%M%S)" --wait --collect --quiet -p MemoryMax=16G -p MemorySwapMax=0 \
22
+ -p CPUQuota=$((cores * 100))% -p Nice=10 --working-directory="$P" \
23
+ -p StandardOutput=append:"$lf" -p StandardError=append:"$lf" \
24
+ --setenv=CUDA_VISIBLE_DEVICES= --setenv=PYTHONDONTWRITEBYTECODE=1 --setenv=OMP_NUM_THREADS=$cores \
25
+ --setenv=OPENBLAS_NUM_THREADS=$cores "$@"
26
+ }
27
+ n_fail=0
28
+ log "lane $lane: $cores cores, cohorts $*"
29
+ for ds in "$@"; do
30
+ for split in fewshot0 fewshot1 fewshot2 fewshot3 fewshot4 cv0 cv1 cv2 cv3 cv4; do
31
+ kind=${split%[0-9]}; idx=${split: -1}; d=$P/inputs/$ds/$split$SFX; split=$split$SFX
32
+ if [[ ! -s $d/SPLIT.json ]]; then
33
+ unit "split-$ds-$split" "$P/logs/split_${ds}_${split}.log" "$PY" "$P/tools/build_split.py" "$ds" "$kind" "$idx" "$GENES" \
34
+ || { n_fail=$((n_fail+1)); log "WARN: build_split $ds $split failed"; continue; }
35
+ fi
36
+ if [[ -f $d/bp/DONE ]]; then log "$ds $split: done already"; continue; fi
37
+ log "--- $ds $split ($(python3 -c "import json;d=json.load(open('$d/SPLIT.json'));print(d['n_mixture_samples'],'mixture,',d['n_reference_samples'],'reference samples,',d['states'],'states,',d['genes_kept'],'genes')"))"
38
+ if unit "run-$ds-$split" "$P/logs/bp_${ds}_${split}.log" "$RS" "$P/tools/run_bp.R" "$d" "$cores"; then
39
+ log "$ds $split: $(grep -h 'elapsed min' "$P/logs/bp_${ds}_${split}.log" | tail -1)"
40
+ else
41
+ n_fail=$((n_fail+1)); log "WARN: BayesPrism $ds $split failed (logs/bp_${ds}_${split}.log)"
42
+ fi
43
+ done
44
+ done
45
+ log "lane $lane finished; failed=$n_fail"
46
+ (( n_fail == 0 ))
paper-releases/pbisc-diffusion/updates/20261008T022410Z-deconv-scsemi-deck/diffusion/dataset/server_1/model8/plans/bayesprism_paired_20261006/tools/run_bp.R ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # BayesPrism on one split of plans/bayesprism_paired_20261006 (CPU only; 2026-10-06).
2
+ # Settings as utility_studies_final6k_20260925/deconv/scripts/run_bayesprism_sle_z.R (the SLE comparison where
3
+ # BayesPrism's Z beat the generator): input.type "GEP" with per-state summed UMI, cell.type.labels = six-type gate,
4
+ # cell.state.labels = "<gate>|<AIFI L2>", outlier.cut 0.01, outlier.fraction 0.1, key NULL, run.prism defaults.
5
+ # Writes into <split dir>/bp/: theta_final.csv, theta_first.csv (type level), Z_type_<type>.tsv.gz (samples x genes,
6
+ # posterior type-level expression, get.exp), genes_used.txt, DONE (elapsed minutes). Skips when DONE exists.
7
+ # Rscript run_bp.R <split dir> <n_cores>
8
+ .libPaths(c("/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/utility_studies_final6k_20260925/deconv/Rlib", .libPaths()))
9
+ suppressPackageStartupMessages(library(BayesPrism))
10
+ args <- commandArgs(trailingOnly = TRUE)
11
+ d <- args[1]; ncores <- as.integer(args[2])
12
+ out <- file.path(d, "bp")
13
+ dir.create(out, showWarnings = FALSE, recursive = TRUE)
14
+ if (file.exists(file.path(out, "DONE"))) { cat("SKIP: done\n"); quit(save = "no") }
15
+ t0 <- Sys.time()
16
+ read_mat <- function(path) as.matrix(read.delim(gzfile(path), row.names = 1, check.names = FALSE))
17
+ ref <- read_mat(file.path(d, "reference.tsv.gz"))
18
+ st <- read.delim(file.path(d, "state_types.tsv"), stringsAsFactors = FALSE)
19
+ stopifnot(identical(rownames(ref), st$state))
20
+ mix <- read_mat(file.path(d, "mixture.tsv.gz"))
21
+ stopifnot(identical(colnames(ref), colnames(mix)))
22
+ cat("reference", nrow(ref), "states x", ncol(ref), "genes; mixture", nrow(mix), "samples; cores", ncores, "\n")
23
+ prism <- new.prism(reference = ref, input.type = "GEP", cell.type.labels = st$type,
24
+ cell.state.labels = st$state, key = NULL, mixture = mix,
25
+ outlier.cut = 0.01, outlier.fraction = 0.1)
26
+ res <- run.prism(prism = prism, n.cores = ncores)
27
+ write.csv(get.fraction(bp = res, which.theta = "final", state.or.type = "type"), file.path(out, "theta_final.csv"))
28
+ write.csv(get.fraction(bp = res, which.theta = "first", state.or.type = "type"), file.path(out, "theta_first.csv"))
29
+ Z <- get.exp(bp = res, state.or.type = "type")
30
+ cat("Z dims:", paste(dim(Z), collapse = " x "), "\n")
31
+ for (k in dimnames(Z)[[3]]) {
32
+ con <- gzfile(file.path(out, paste0("Z_type_", gsub(" ", "_", k), ".tsv.gz")), "w")
33
+ write.table(Z[, , k], con, sep = "\t", quote = FALSE, col.names = NA)
34
+ close(con)
35
+ }
36
+ writeLines(colnames(prism@mixture), file.path(out, "genes_used.txt"))
37
+ el <- round(as.numeric(difftime(Sys.time(), t0, units = "mins")), 2)
38
+ cat("genes used after the outlier filter:", ncol(prism@mixture), "\n")
39
+ cat("elapsed min:", el, "\n")
40
+ writeLines(as.character(el), file.path(out, "DONE"))
41
+ cat("BAYESPRISM_OK", d, "\n")
paper-releases/pbisc-diffusion/updates/20261008T022410Z-deconv-scsemi-deck/diffusion/dataset/server_1/model8/plans/bayesprism_paired_20261006/tools/run_cibersortx.sh ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Official CIBERSORTx (Docker images cibersortx/fractions and cibersortx/hires, x86 under the qemu binfmt emulation
3
+ # registered on server_1 with tonistiigi/binfmt, user-approved 2026-10-06) on every split of the given cohorts.
4
+ # CPU only; each container: --memory 16g (no swap), --cpus CORES. Inputs: cibersortx/<ds>/<split>/
5
+ # (tools/build_cibersortx_inputs.py). Per split, skipped when its DONE marker exists:
6
+ # 1. Fractions, single-cell reference mode with S-mode batch correction (the setting CIBERSORTx recommends for an
7
+ # scRNA-seq-derived signature applied to bulk RNA-seq): --single_cell TRUE --refsample refsample.txt
8
+ # --mixture mixture.txt --rmbatchSmode TRUE --fraction 0 (UMI data) --replicates 5 --sampling 0.5 --G.min 300
9
+ # --G.max 500 --q.value 0.01 --perm 0 --QN FALSE -> out_fractions/
10
+ # 2. HiRes (per-sample cell-type expression, the analogue of BayesPrism's Z) on the scoring genes; skipped for splits
11
+ # with <= 8 test samples (HiRes' per-gene regression needs more samples than cell types; Giroux CV folds):
12
+ # --mixture mixture.txt --sigmatrix <Fractions signature> --cibresults <Fractions results> --rmbatchSmode TRUE
13
+ # --sourceGEPs <Fractions signature> --subsetgenes hires_genes.txt --threads CORES -> out_hires/
14
+ # Credentials: /home/sj_server_1/cibersortx.key ("email: ..." / "token: ..." lines, or a bare token plus an email
15
+ # line). They are read at run time into a 600 env file that only the container reads, passed with --env-file and
16
+ # expanded inside the container; never echoed or logged.
17
+ # usage: run_cibersortx.sh LANE CORES DATASET [DATASET ...] env: STEPS (fractions,hires), SPLITS (all ten)
18
+ set -uo pipefail
19
+ P=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/bayesprism_paired_20261006
20
+ KEY=/home/sj_server_1/cibersortx.key
21
+ lane=$1; cores=$2; shift 2
22
+ STEPS=${STEPS:-fractions,hires}
23
+ LOG=$P/logs/cibersortx_${lane}_$(date +%Y%m%dT%H%M%S).log
24
+ log() { echo "$(date +%FT%T) $*" | tee -a "$LOG"; }
25
+ ENVF=$(mktemp "$P/logs/.cx_env_XXXXXX"); chmod 600 "$ENVF"; trap 'rm -f "$ENVF"' EXIT
26
+ python3 - "$KEY" "$ENVF" <<'EOF'
27
+ import re, sys
28
+ txt = open(sys.argv[1]).read()
29
+ user = re.search(r"(?im)^\s*(?:email|username|user)\s*[:=]\s*(\S+)", txt)
30
+ tok = re.search(r"(?im)^\s*token\s*[:=]\s*(\S+)", txt)
31
+ if not tok: # a bare token line (no label)
32
+ bare = [l.strip() for l in txt.splitlines() if l.strip() and not re.match(r"(?i)^\s*(email|username|user)\s*[:=]", l)]
33
+ tok = bare[0] if len(bare) == 1 and re.fullmatch(r"[0-9a-fA-F]{20,}", bare[0]) else None
34
+ else:
35
+ tok = tok.group(1)
36
+ if not user or not tok:
37
+ sys.exit("cibersortx.key needs an 'email: ...' line and a token")
38
+ open(sys.argv[2], "w").write(f"CX_USER={user.group(1)}\nCX_TOKEN={tok}\n")
39
+ EOF
40
+ [[ $? -eq 0 ]] || { log "ABORT: credentials incomplete in $KEY (values not shown)"; exit 1; }
41
+ run_cx() { # run_cx IMAGE BINARY WORKDIR OUTDIR ARGS...
42
+ local image=$1 bin=$2 wd=$3 od=$4; shift 4
43
+ mkdir -p "$od"
44
+ # the binary echoes every option, username and token included: redact them before anything reaches a log
45
+ set -o pipefail
46
+ local cname="cx_${lane}_$(basename "$od")_$$" # named, so a container hung after a qemu abort is always removed
47
+ timeout -s KILL "${CX_TIMEOUT:-14400}" docker run --rm --name "$cname" --ulimit core=0 --platform linux/amd64 --memory=16g --memory-swap=16g --cpus="$cores" \
48
+ --env-file "$ENVF" -v "$wd":/src/data -v "$od":/src/outdir --entrypoint /bin/bash "$image" \
49
+ -c 'exec ./'"$bin"' --username "$CX_USER" --token "$CX_TOKEN" "$@"' _ "$@" 2>&1 \
50
+ | sed -u -E 's/^(>\[Options\] *(token|username)[^:]*:).*/\1 [REDACTED]/I'
51
+ local rc=$?
52
+ docker rm -f "$cname" >/dev/null 2>&1
53
+ return $rc
54
+ }
55
+ n_fail=0
56
+ log "lane $lane: $cores cores, steps $STEPS, cohorts $*"
57
+ for ds in "$@"; do
58
+ for split in ${SPLITS:-fewshot0 fewshot1 fewshot2 fewshot3 fewshot4 cv0 cv1 cv2 cv3 cv4}; do
59
+ d=$P/cibersortx/$ds/$split
60
+ [[ -s $d/INPUT.json ]] || { log "WARN: $ds $split has no inputs"; n_fail=$((n_fail+1)); continue; }
61
+ if [[ $STEPS == *fractions* && ! -f $d/out_fractions/DONE ]]; then
62
+ until (( $(awk '/MemAvailable/ {print int($2/1048576)}' /proc/meminfo) >= 48 )); do sleep 60; done
63
+ log "--- fractions $ds $split"; t0=$(date +%s)
64
+ mkdir -p "$d/out_fractions"
65
+ if run_cx cibersortx/fractions:latest CIBERSORTxFractions "$d" "$d/out_fractions" --single_cell TRUE \
66
+ --refsample refsample.txt --mixture mixture.txt --rmbatchSmode TRUE --fraction 0 --replicates 5 \
67
+ --sampling 0.5 --G.min 300 --G.max 500 --q.value 0.01 --perm 0 --QN FALSE --verbose TRUE \
68
+ 2>&1 | tee -a "$P/logs/cx_fractions_${ds}_${split}.log" > "$d/out_fractions/.run.log" && \
69
+ ! grep -q 'Abort!' "$d/out_fractions/.run.log" && \
70
+ ls "$d"/out_fractions/CIBERSORTx_Adjusted.txt "$d"/out_fractions/CIBERSORTx_Results.txt >/dev/null 2>&1 \
71
+ || ls "$d"/out_fractions/CIBERSORTx_Adjusted.txt >/dev/null 2>&1; then
72
+ echo "$(( $(date +%s) - t0 ))" > "$d/out_fractions/DONE"; log "fractions $ds $split: $(cat "$d/out_fractions/DONE") s"
73
+ else
74
+ n_fail=$((n_fail+1)); log "WARN: fractions $ds $split failed (logs/cx_fractions_${ds}_${split}.log)"; continue
75
+ fi
76
+ fi
77
+ if [[ $STEPS == *hires* && ! -f $d/out_hires/DONE ]]; then
78
+ sig=$(ls "$d"/out_fractions/*inferred_refsample.bm.K999.txt 2>/dev/null | head -1)
79
+ res=$(ls "$d"/out_fractions/CIBERSORTx_Adjusted.txt "$d"/out_fractions/CIBERSORTx_Results.txt 2>/dev/null | head -1)
80
+ [[ -n $sig && -n $res ]] || { log "WARN: hires $ds $split: no signature/results from fractions"; n_fail=$((n_fail+1)); continue; }
81
+ src=$d/out_fractions/CIBERSORTx_cell_type_sourceGEP.txt # S-mode source GEPs written by Fractions
82
+ [[ -s $src ]] || { log "WARN: hires $ds $split: no S-mode source GEPs"; n_fail=$((n_fail+1)); continue; }
83
+ nmix=$(python3 -c "import json,sys;print(len(json.load(open(sys.argv[1]))['mixture_samples']))" "$d/INPUT.json")
84
+ if (( nmix <= 8 )); then # HiRes regresses each gene on the 6 type fractions: df = samples - types must be > 0
85
+ log "skip hires $ds $split: $nmix samples (HiRes needs more samples than cell types)"; continue
86
+ fi
87
+ mkdir -p "$d/out_hires" # HiRes reads --cibresults from its output mount (/src/outdir)
88
+ cp "$sig" "$d/sigmatrix.txt"; cp "$src" "$d/source_geps.txt"
89
+ # only the cell-type columns: the extra P-value / Correlation / RMSE columns make HiRes' matrix product fail
90
+ /home/sj_server_1/miniforge3/envs/cxg_corpus/bin/python -c "import pandas as pd,sys;f=pd.read_csv(sys.argv[1],sep='\t',index_col=0);f[[c for c in f.columns if c not in ('P-value','Correlation','RMSE')]].to_csv(sys.argv[2],sep='\t')" "$res" "$d/out_hires/fractions_results.txt" \
91
+ || { log "WARN: hires $ds $split: could not write the fractions table"; n_fail=$((n_fail+1)); continue; }
92
+ until (( $(awk '/MemAvailable/ {print int($2/1048576)}' /proc/meminfo) >= 48 )); do sleep 60; done
93
+ log "--- hires $ds $split"; t0=$(date +%s)
94
+ if run_cx cibersortx/hires:latest CIBERSORTxHiRes "$d" "$d/out_hires" --mixture mixture.txt \
95
+ --sigmatrix sigmatrix.txt --cibresults fractions_results.txt --rmbatchSmode TRUE --sourceGEPs source_geps.txt \
96
+ --subsetgenes hires_genes.txt --threads "$cores" 2>&1 | tee -a "$P/logs/cx_hires_${ds}_${split}.log" \
97
+ > "$d/hires_run.log" && ! grep -q 'Abort!' "$d/hires_run.log" && ls "$d"/out_hires/*.txt >/dev/null 2>&1; then
98
+ echo "$(( $(date +%s) - t0 ))" > "$d/out_hires/DONE"; log "hires $ds $split: $(cat "$d/out_hires/DONE") s"
99
+ else
100
+ n_fail=$((n_fail+1)); log "WARN: hires $ds $split failed (logs/cx_hires_${ds}_${split}.log)"
101
+ fi
102
+ fi
103
+ done
104
+ done
105
+ log "lane $lane finished; failed=$n_fail"
106
+ (( n_fail == 0 ))