Skip to content

Map reads to individual MEGAHIT assemblies - #43

Merged
linsalrob merged 2 commits into
mainfrom
agent/map-reads-to-megahit-assemblies
Aug 6, 2026
Merged

Map reads to individual MEGAHIT assemblies#43
linsalrob merged 2 commits into
mainfrom
agent/map-reads-to-megahit-assemblies

Conversation

@linsalrob

Copy link
Copy Markdown
Owner

Summary

  • add a SLURM array job that maps each sample's paired reads back to its own megahit/<sample>/final.contigs.fa
  • retain mapped alignment records only, disable secondary alignments, and coordinate-sort the result
  • create and validate mapped_reads.bam and mapped_reads.bam.bai in each assembly directory
  • validate inputs and existing outputs, and use temporary outputs to avoid publishing partial BAM files

Why

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.slurm
  • git diff --cached --check

ShellCheck was unavailable in the current environment, and the job was not submitted because that requires the user's sequencing data and a SLURM allocation.

Copilot AI lite review requested due to automatic review settings August 6, 2026 05:51
@linsalrob
linsalrob marked this pull request as ready for review August 6, 2026 05:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.slurm to map HOSTREMOVED reads to megahit/<sample>/final.contigs.fa with minimap2.
  • 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.

Comment thread pawsey_shortread/megahit_map_reads.slurm Outdated
Comment thread pawsey_shortread/megahit_map_reads.slurm Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread pawsey_shortread/megahit_map_reads.slurm Outdated
Copilot AI review requested due to automatic review settings August 6, 2026 06:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 explicit SLURM_ARRAY_TASK_ID >= 1 validation 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 (and samtools 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 in cleanup() 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.bai and renames it to $BAM.bai. To make that reliable across samtools defaults, explicitly request a BAI index when running samtools index.
samtools index -@ "$INDEX_THREADS" "$TMP_BAM"

@linsalrob
linsalrob merged commit 4a17ca8 into main Aug 6, 2026
1 check passed
@linsalrob
linsalrob deleted the agent/map-reads-to-megahit-assemblies branch August 6, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants