Skip to content

Instantly share code, notes, and snippets.



Forked from mtw/
Created Aug 21, 2018
What would you like to do?
Extract properly-paired reads and their mates (ie flags 99/147/163/83) from paired-end BAM files
samtools=`which samtools`
bn=$(basename $1 .bam)
echo processing $bn
$samtools view -h -b -f99 $1 > $bn.flag99.bam
$samtools view -h -b -f147 $1 > $bn.flag147.bam
$samtools view -h -b -f163 $1 > $bn.flag163.bam
$samtools view -h -b -f83 $1 > $bn.flag83.bam
echo merging tmp BAM files
$samtools merge $bn.uns.pp.bam $bn.flag99.bam $bn.flag147.bam $bn.flag163.bam $bn.flag83.bam
echo sorting final BAM file
$samtools sort $bn.uns.pp.bam $bn.pp
echo cleaning up
rm $bn.flag99.bam
rm $bn.flag147.bam
rm $bn.flag163.bam
rm $bn.flag83.bam
rm $bn.uns.pp.bam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment