Files
obikmer/benchmark/simulate_skim.sh
T
Eric Coissac f29dcbcfb8
Release / create-release (push) Successful in 2m35s
Release / build-linux-x86_64 (push) Successful in 8m19s
Release / build-macos-arm64 (push) Successful in 2m3s
ci.yml / build (pull_request) Successful in 4m8s
Implement advanced sampling and family annex logic
Introduces complex sampling mechanisms including quartet filtering, pair balance weighting, and entropy bias. Enforces the `--no-ambiguity` convention for family counting and updates annex storage for scalar data.

This includes new logic for calculating family weights based on overlap, quota-based layer determination, and filtering families based on quartet informativeness. Updates also include argument parsing for `--n-sites` and improved handling of family overlap files.
2026-10-13 08:57:18 +02:00

58 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Genome-skimming test bed: re-simulate the benchmark genomes at a low
# coverage, index each specimen, and merge them into one presence index.
#
# Usage: simulate_skim.sh (env: COVERAGE=1 SEED=1 CPUS=...)
#
# The genome → specimen mapping is read from deps.mk (same source of truth
# as the Makefile pipeline); the pipeline's own run/ tree is left untouched.
# Output: run/skim_${COVERAGE}x_s${SEED}/
# simulated_data/<species>/<strain>/reads_R{1,2}.fastq.gz
# specimen_index_presence/<species>--<strain>/
# global_index_presence/
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ISS="${SCRIPT_DIR}/../.venv/bin/iss"
BINARY="${SCRIPT_DIR}/../src/target/release/obikmer"
COVERAGE="${COVERAGE:-1}"
SEED="${SEED:-1}"
READ_LENGTH=150
CPUS="${CPUS:-$(sysctl -n hw.logicalcpu 2>/dev/null || nproc 2>/dev/null || echo 2)}"
OUT="${SCRIPT_DIR}/run/skim_${COVERAGE}x_s${SEED}"
mkdir -p "${OUT}/simulated_data" "${OUT}/specimen_index_presence"
tmp_fasta=$(mktemp "${TMPDIR:-/tmp}/obikmer_skim_XXXXXX.fna")
trap 'rm -f "${tmp_fasta}"' EXIT
# lines of the form run/simulated_data/<species>/<strain>/reads_R1.fastq.gz: run/genomes/<file>
sed -nE 's#^run/simulated_data/([^/]+)/([^/]+)/reads_R1\.fastq\.gz: (run/genomes/[^ ]+)$#\1 \2 \3#p' \
"${SCRIPT_DIR}/deps.mk" | sort -u | while read -r species strain genome; do
specimen="${species}--${strain}"
reads_dir="${OUT}/simulated_data/${species}/${strain}"
index_dir="${OUT}/specimen_index_presence/${specimen}"
mkdir -p "${reads_dir}"
gzip -dc "${SCRIPT_DIR}/${genome}" > "${tmp_fasta}"
genome_size=$(grep -v "^>" "${tmp_fasta}" | tr -d '[:space:]' | wc -c | tr -d ' ')
n_reads=$(python3 -c "import math; print(math.ceil(${COVERAGE} * ${genome_size} / (2 * ${READ_LENGTH})))")
echo "[${specimen}] genome=${genome_size} bp → ${n_reads} read pairs (${COVERAGE}x, seed ${SEED})"
"${ISS}" generate \
--genomes "${tmp_fasta}" --model HiSeq --n_reads "${n_reads}" \
--cpus "${CPUS}" --seed "${SEED}" --compress \
--output "${reads_dir}/reads" 2>/dev/null
rm -f "${reads_dir}"/reads.iss.tmp.*.vcf
"${BINARY}" index --output "${index_dir}" --force --theta 0 \
--label "${specimen}" --meta "species=${species}" \
"${reads_dir}/reads_R1.fastq.gz" "${reads_dir}/reads_R2.fastq.gz" 2>/dev/null
done
mapfile -t sources < <(find "${OUT}/specimen_index_presence" -mindepth 1 -maxdepth 1 -type d | sort)
echo "Merging ${#sources[@]} presence indexes → ${OUT}/global_index_presence"
"${BINARY}" merge --output "${OUT}/global_index_presence" --force --force-presence \
"${sources[@]}" 2>/dev/null
echo "Done: ${OUT}/global_index_presence"