Skip to content

Instantly share code, notes, and snippets.

@opplatek
Last active July 21, 2022 16:45
Show Gist options
  • Save opplatek/ff76ed1c64835c64e7a2dbd9b510b81a to your computer and use it in GitHub Desktop.
Save opplatek/ff76ed1c64835c64e7a2dbd9b510b81a to your computer and use it in GitHub Desktop.
Quickly remap BAM (from Heng Li post https://twitter.com/lh3lh3/status/1132756684789768202)
#!/bin/bash
#
# Quickly remap reads from BAM file to new reference
#
# Source: https://twitter.com/lh3lh3/status/1132756684789768202
# More details: https://janbio.home.blog/2019/05/30/useful-one-liners-collection/
#
samtools collate -uOn128 old-pos-srt.bam tmpxyz \
| samtools fastq - \
| bwa mem -pt16 ref.fa - \
| samtools sort --threads=4 -m4G -o new-pos-srt.bam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment