Skip to content

Instantly share code, notes, and snippets.

@ipstone
Forked from mtw/extract_pp.sh
Created August 21, 2018 15:02
Show Gist options
  • Select an option

  • Save ipstone/4e35ddf39c231681b2a188d73107e71d to your computer and use it in GitHub Desktop.

Select an option

Save ipstone/4e35ddf39c231681b2a188d73107e71d to your computer and use it in GitHub Desktop.

Revisions

  1. @mtw mtw created this gist Oct 26, 2013.
    22 changes: 22 additions & 0 deletions extract_pp.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/bin/bash
    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