#!/bin/bash -euo pipefail
# Find the preseq lc_extrap.txt file
EXTRAP_FILE=""
# Try the staged path directly
if [ -f "aih-tih-sc-0ce15f-R1_A23WJ53LT4_1.lc_extrap.txt" ]; then
EXTRAP_FILE="aih-tih-sc-0ce15f-R1_A23WJ53LT4_1.lc_extrap.txt"
# Search for the file
else
EXTRAP_FILE=$(find . -name "aih-tih-sc-0ce15f-R1_A23WJ53LT4_1*.lc_extrap.txt" -type f | head -n 1)
if [ -z "$EXTRAP_FILE" ] || [ ! -f "$EXTRAP_FILE" ]; then
EXTRAP_FILE=$(find . -name "*.lc_extrap.txt" -type f | head -n 1)
fi
fi
# Validate file exists
if [ -z "$EXTRAP_FILE" ] || [ ! -f "$EXTRAP_FILE" ]; then
echo "Error: Could not find Preseq lc_extrap.txt file" >&2
echo "Searched for: aih-tih-sc-0ce15f-R1_A23WJ53LT4_1.lc_extrap.txt, aih-tih-sc-0ce15f-R1_A23WJ53LT4_1*.lc_extrap.txt, or *.lc_extrap.txt" >&2
echo "In directory: $(pwd)" >&2
echo "Contents:" >&2
ls -laR . >&2
exit 1
fi
echo "Processing Preseq file: $EXTRAP_FILE" >&2
# Convert Preseq lc_extrap.txt to MultiQC embedded TSV format
preseq_to_multiqc.py \
"$EXTRAP_FILE" \
"aih-tih-sc-0ce15f-R1_A23WJ53LT4_1_preseq_mqc.tsv" \
--sample-id "aih-tih-sc-0ce15f-R1_A23WJ53LT4_1"
# Create versions file
cat <<-END_VERSIONS > versions.yml
"NFCORE_RNAFUSION:RNAFUSION:QC_WORKFLOW:PRESEQ_TO_MULTIQC":
python: $(python3 --version | sed 's/Python //g')
preseq_to_multiqc: 1.0.0
END_VERSIONS