Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 46 lines (36 sloc) 964 Bytes
#!/bin/bash
# module init required when running on non-OSG resources, and has to sourced
# before set -e as sometimes it exits non-0 when a module environment is
# already set up
. /cvmfs/oasis.opensciencegrid.org/osg/sw/module-init.sh
set -e
module load samtools/1.3.1
module load java/8u25
# 1 input file is possible, but samtools can't handle that
COUNT=`ls *.bam | wc -l`
if [ $COUNT = 1 ]; then
echo "Only 1 input give. Ouput will be a copy of that one input"
mv *.bam $1-merged.bam
exit 0
fi
# remove "empty" inputs
for F in `ls *bam`; do
SIZE=`du -sb $F | cut -f 1`
if [ $SIZE -lt 50 ]; then
echo "Removing $F due to it being empty"
rm $F
fi
done
echo
echo
ls -l
echo
echo
# no input files left
COUNT=`ls *.bam 2>/dev/null | wc -l`
if [ $COUNT = 0 ]; then
echo "No bam files left - creating a new one"
touch $1-merged.bam
exit 0
fi
samtools merge $1-merged.bam *.bam