Created
December 8, 2015 13:20
-
-
Save marcelm/7a2eca90698c6d7d8e10 to your computer and use it in GitHub Desktop.
Index a BAM file while sorting it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
if [ $# -ne 1 -o x$1 == x-h -o x$1 == x--help ]; then | |
echo \ | |
"Usage: | |
samtools sort -O bam -T prefix ... | bambai BAMPATH | |
Read a sorted BAM file from standard input, write it to BAMPATH and | |
index it at the same time (creating BAMPATH.bai)." | |
exit 2 | |
fi | |
if [ -t 0 ]; then | |
echo "Reading input from terminal - this is probably not what you want. Use Ctrl+C to cancel." | |
fi | |
BAM="$1" | |
WORKDIR=$(mktemp -d) || exit 1 | |
trap "rm -rf ${WORKDIR}" exit | |
FIFO=${WORKDIR}/fifo.bam | |
mkfifo ${FIFO} | |
samtools index ${FIFO} && mv ${FIFO}.bai "${BAM}.bai" & | |
tee ${FIFO} > "${BAM}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment