Map reads to individual MEGAHIT assemblies - #43
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Pawsey SLURM array job to map each sample’s paired-end reads back to its own MEGAHIT assembly contigs, producing a coordinate-sorted BAM and BAI per sample for downstream analysis.
Changes:
- Introduces
pawsey_shortread/megahit_map_reads.slurmto mapHOSTREMOVEDreads tomegahit/<sample>/final.contigs.fawithminimap2. - Filters to mapped alignments only, coordinate-sorts, indexes, and validates outputs.
- Adds input/output validation and uses temporary BAM outputs to avoid publishing partial results.
Suppressed comments (1)
pawsey_shortread/megahit_map_reads.slurm:85
- After creating the BAM index, the script validates the BAM with quickcheck but still doesn’t validate that the newly created .bai is readable (e.g., not truncated). Adding an idxstats check here will catch index-write failures early before publishing outputs.
samtools index -@ "$SLURM_CPUS_PER_TASK" "$TMP_BAM"
samtools quickcheck "$TMP_BAM"
mv -- "$TMP_BAM" "$BAM"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce3336309c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
pawsey_shortread/megahit_map_reads.slurm:38
- The script assumes SLURM arrays are 1-indexed (matching the repo README). If someone submits an array starting at 0,
sed -n "${SLURM_ARRAY_TASK_ID}p"will error before the-z "$R1"guard. Add an explicitSLURM_ARRAY_TASK_ID >= 1validation with a clear message.
: "${SLURM_ARRAY_TASK_ID:?Submit this script as a SLURM array job}"
: "${SLURM_CPUS_PER_TASK:?SLURM_CPUS_PER_TASK is not set}"
if (( SLURM_CPUS_PER_TASK < 5 )); then
echo "This job requires at least 5 CPUs, but SLURM_CPUS_PER_TASK=$SLURM_CPUS_PER_TASK" >&2
exit 2
pawsey_shortread/megahit_map_reads.slurm:87
minimap2 --split-prefix(andsamtools sort -T) can leave large temporary files in $TMPDIR if the job fails. The EXIT cleanup currently only removes the temporary BAM and index, so a failure can fill shared scratch/tmp over time. Consider removing the${TMP_PREFIX}*temp files incleanup()as well.
cleanup() {
status=$?
rm -f -- "$TMP_BAM" "$TMP_BAM.bai"
exit "$status"
}
pawsey_shortread/megahit_map_reads.slurm:96
- The script later assumes the index file is
$TMP_BAM.baiand renames it to$BAM.bai. To make that reliable across samtools defaults, explicitly request a BAI index when runningsamtools index.
samtools index -@ "$INDEX_THREADS" "$TMP_BAM"
Summary
megahit/<sample>/final.contigs.famapped_reads.bamandmapped_reads.bam.baiin each assembly directoryWhy
Each individual MEGAHIT assembly needs a sample-specific, indexed BAM containing only reads that align to that assembly for downstream analysis.
Validation
bash -n pawsey_shortread/megahit_map_reads.slurmgit diff --cached --checkShellCheckwas unavailable in the current environment, and the job was not submitted because that requires the user's sequencing data and a SLURM allocation.