Skip to content

Gam and bam processing

CormacKinsella edited this page Oct 7, 2025 · 1 revision

Gam and bam processing

vg surject

Projects graph alignments to a linear reference assembly (GAM to BAM, against one or several linear reference assemblies depending on the mode). When graphs contain multiple reference assemblies, grave uses .paths files (path list files), and provides the --into-paths option to vg surject, surjecting into each reference separately.

Usage: vg surject [options] <aln.gam> >[proj.cram]

Example grave command:

vg surject -t ${task.cpus} -x ${graph} --bam-output ${mapped_gam}

samtools addreplacerg

Adds readgroup information to library level BAM files to inform the deduplication step. Adds the readgroup (made up of sample id, library id, and repeat number), plus separate library and sample tags for MarkDuplicates.

Usage: samtools addreplacerg [options] [-r <@RG line> | -R <existing id>] [-m orphan_only|overwrite_all] [-o <output.bam>] <input.bam>

Example grave command:

samtools addreplacerg --threads ${task.cpus} --output-fmt BAM -r '@RG\\tID:${meta.read_group}\\tLB:${meta.library}\\tSM:${meta.id}'

samtools sort

Coordinate sorts library level BAM files.

Usage: samtools sort [options...] [in.bam]

Example grave command:

samtools sort --threads ${task.cpus} --output-fmt BAM

samtools merge

Sorted library BAMs are gathered at the sample level and merged, reatining the coordinate sort order. Merge is skipped if only one BAM.

Usage: samtools merge [options] -o <out.bam> [options] <in1.bam> ... <inN.bam>

Example grave command:

samtools merge --threads ${task.cpus} -p -o ${meta.id}.merge.bam ${bams}

  • -p Combine @PG headers with colliding IDs [alter IDs to be distinct] (simplifies merged SAM header)

picard MarkDuplicates

Marks duplicate reads in sample level BAM files. Uses readgroup information deduplicate within repeats of the same library. For ancient samples, MarkDuplicates is configured to replicate the behaviour of the dedup tool, considering both the 5' and 3' mapping positions when duplicate marking. For modern samples, typical duplicate marking is performed, considering only the 5' mapping position.

Usage: picard MarkDuplicates --INPUT --METRICS_FILE --OUTPUT

Example grave command:

picard -Xms2g -Xmx\${MAX_HEAP_GB}g MarkDuplicates --INPUT ${meta.id}.merge.bam --OUTPUT ${meta.id}.dedup.bam --METRICS_FILE ${meta.id}.dedup_metrics.txt --TAGGING_POLICY ${params.duplicateTaggingPolicy} --REMOVE_DUPLICATES ${params.removeDuplicates} --VALIDATION_STRINGENCY STRICT --ASSUME_SORT_ORDER coordinate ${args}

  • --INPUT input BAM file
  • --OUTPUT output BAM file
  • --METRICS_FILE file to write duplication metrics to
  • --TAGGING_POLICY determines how duplicate types are recorded in the DT optional attribute
  • --REMOVE_DUPLICATES if true, duplicate reads are removed from the output file. If false, they are marked in the BAM file with a flag but not removed.
  • --VALIDATION_STRINGENCY stringency of BAM file integrity checks
  • --ASSUME_SORT_ORDER assume the input file is sorted in the specified order
  • ${args} set by --dedupConsiderBothEnds: if true, for aDNA provides --FLOW_MODE --FLOW_USE_END_IN_UNPAIRED_READS to picard MarkDuplicates, which causes the tool to consider both the 5' and 3' mapping positions when marking duplicates

samtools index

Indexes the BAM file for downstream tools.

Usage: samtools index -M [-bc] [-m INT] <in1.bam> <in2.bam>...

Example grave command: samtools index --threads ${task.cpus} ${meta.id}.dedup.bam

Clone this wiki locally