#!/bin/bash -euo pipefail
# Find the kallisto abundance.h5 file
# KALLISTO_QUANT outputs a directory (rna_s1221_S42) containing abundance.h5
H5_FILE=""
# Try the staged path directly (should be a directory)
if [ -d "rna_s1221_S42" ]; then
# Look for abundance.h5 inside the directory
if [ -f "rna_s1221_S42/abundance.h5" ]; then
H5_FILE="rna_s1221_S42/abundance.h5"
fi
# Try common patterns
elif [ -f "rna_s1221_S42/abundance.h5" ]; then
H5_FILE="rna_s1221_S42/abundance.h5"
# Search for the file
else
H5_FILE=$(find . -name "abundance.h5" -type f | head -n 1)
fi
# Validate file exists
if [ -z "$H5_FILE" ] || [ ! -f "$H5_FILE" ]; then
echo "Error: Could not find Kallisto abundance.h5 file" >&2
echo "Searched for: rna_s1221_S42/abundance.h5, rna_s1221_S42/abundance.h5, or abundance.h5" >&2
echo "In directory: $(pwd)" >&2
echo "Contents:" >&2
ls -laR . >&2
exit 1
fi
echo "Processing Kallisto file: $H5_FILE" >&2
# Convert Kallisto abundance.h5 to MultiQC embedded TSV format (with expression QC columns from sample_qc)
kallisto_to_multiqc.py \
"$H5_FILE" \
"rna_s1221_S42_kallisto_mqc.tsv" \
--sample-id "rna_s1221_S42" \
--sample-qc rna_s1221_S42.sample_qc.tsv
# Create versions file
cat <<-END_VERSIONS > versions.yml
"NFCORE_RNAFUSION:RNAFUSION:KALLISTO_TO_MULTIQC":
python: $(python3 --version | sed 's/Python //g')
kallisto_to_multiqc: 1.0.0
END_VERSIONS