Skip to content

Instantly share code, notes, and snippets.

@mtw
Last active December 23, 2015 21:29
Show Gist options
  • Save mtw/6696800 to your computer and use it in GitHub Desktop.
Save mtw/6696800 to your computer and use it in GitHub Desktop.
Wrapper script for counting mapped reads in a bam file
#!/bin/bash
countdir="./count"
count_mapped_reads=`which count_mapped_reads_fast.pl`
bam_stat=`which bam_stat.py`
samtools=`which samtools`
samstats=`which sam-stats`
if [ -d "$countdir" ];
then
echo "$countdir available"
else
mkdir -p $countdir
fi
set -x
for BAM in $(ls *.bam)
do
#$bn=$(basename $BAM .bam)
name=${BAM%.bam}
$count_mapped_reads -bam $name.bam > $countdir/$name.count
$bam_stat -i $name.bam 2> $countdir/$name.bamstat
$samtools flagstat $name.bam > $countdir/$name.flagstat
$samstats -B $name.bam > $countdir/$name.samstats
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment