#!/bin/bash -Ceuo pipefail
SHARD1="chr1,chr4,chr15,chr19,chr22,chrY"
SHARD2="chr2,chr8,chr9,chr17,chr18,chr20"
SHARD3="chr3,chr5,chr10,chr11,chr13,chr14"
SHARD4="chr6,chr7,chr12,chr16,chr21,chrX"
probe_counts -m frac -t 1 -r "$SHARD1" 869_G71-N1-BDNA-1_B2377KTLT3_3.recalibrated.bam xgen-exome-hyb-panel-v2_AND_altera_v3_probes_short_hg38_AND_cdx_spike_custom30off4x_hg38_AND_foresight_clarity.bed \
"sample_id=869_G71-N1-BDNA-1_B2377KTLT3_3" "specimen_id=869_G71" \
"flowcell=B2377KTLT3" "sample_type=normal" > counts_s1.tsv &
probe_counts -m frac -t 1 -r "$SHARD2" 869_G71-N1-BDNA-1_B2377KTLT3_3.recalibrated.bam xgen-exome-hyb-panel-v2_AND_altera_v3_probes_short_hg38_AND_cdx_spike_custom30off4x_hg38_AND_foresight_clarity.bed \
"sample_id=869_G71-N1-BDNA-1_B2377KTLT3_3" "specimen_id=869_G71" \
"flowcell=B2377KTLT3" "sample_type=normal" > counts_s2.tsv &
probe_counts -m frac -t 1 -r "$SHARD3" 869_G71-N1-BDNA-1_B2377KTLT3_3.recalibrated.bam xgen-exome-hyb-panel-v2_AND_altera_v3_probes_short_hg38_AND_cdx_spike_custom30off4x_hg38_AND_foresight_clarity.bed \
"sample_id=869_G71-N1-BDNA-1_B2377KTLT3_3" "specimen_id=869_G71" \
"flowcell=B2377KTLT3" "sample_type=normal" > counts_s3.tsv &
probe_counts -m frac -t 1 -r "$SHARD4" 869_G71-N1-BDNA-1_B2377KTLT3_3.recalibrated.bam xgen-exome-hyb-panel-v2_AND_altera_v3_probes_short_hg38_AND_cdx_spike_custom30off4x_hg38_AND_foresight_clarity.bed \
"sample_id=869_G71-N1-BDNA-1_B2377KTLT3_3" "specimen_id=869_G71" \
"flowcell=B2377KTLT3" "sample_type=normal" > counts_s4.tsv &
wait
{ head -1 counts_s1.tsv | cut -f2-;
for f in counts_s*.tsv; do tail -n +2 "$f"; done | sort -t' ' -k1,1n | cut -f2-;
} | gzip > 869_G71-N1-BDNA-1_B2377KTLT3_3_probes.tsv.gz
cat <<-END_VERSIONS > versions.yml
"SOMATIC_CNV_REF_BUILDER:SOMA_CNV_PROBE_COUNTS":
soma-cnv: 20260604-3cb5ec5
END_VERSIONS