#!/bin/bash -euo pipefail
# Load sample_type_map into associative array (skip header)
declare -A type_map
while IFS=, read -r sid stype; do
type_map["$sid"]="$stype"
done < <(tail -n +2 sample_type_map.csv)
echo "sample,sample_type,fastq_1,fastq_2,strandedness" > samplesheet.csv
while IFS= read -r sample_id; do
[ -z "$sample_id" ] && continue
st="${type_map[$sample_id]:-}"
if [ -z "$st" ]; then
echo "ERROR: no sample_type found for '$sample_id' in sample_type_map.csv" >&2
exit 1
fi
echo "${sample_id},${st},s3://natera-rnd-pltf-dev-s3-gitlab-results/rnafusion/build2803284/baseline-run/63723377/bclconvert/fastqs/${sample_id}/${sample_id}_R1.fastq.gz,s3://natera-rnd-pltf-dev-s3-gitlab-results/rnafusion/build2803284/baseline-run/63723377/bclconvert/fastqs/${sample_id}/${sample_id}_R2.fastq.gz,reverse" >> samplesheet.csv
done < sample_ids.txt
cat <<-END_VERSIONS > versions.yml
"NFCORE_RNAFUSION:DEMUX_FROM_RUNDIR:DEMULTIPLEX:SAMPLESHEET_FROM_MERGED":
bash: $(bash --version | head -1 | awk '{print $4}')
END_VERSIONS