1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#!/bin/bash
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
PATH=$SCRIPTPATH:$PATH
MB=metabat2
SUM=jgi_summarize_bam_contig_depths
BADMAP=${BADMAP:=0}
PCTID=${PCTID:=97}
MINDEPTH=${MINDEPTH:=1.0}
MB_LABEL=${MB_LABEL:="bins"}
if ! $MB --help 2>/dev/null
then
echo "Please ensure that the MetaBAT binaries are in your PATH: Could not find $MB" 2>&1
exit 1
fi
if ! $SUM 2>/dev/null
then
echo "Please ensure that the MetaBAT binaries are in your PATH: Could not find $SUM" 2>&1
exit 1
fi
USAGE="$0 <select metabat options> assembly.fa sample1.bam [ sample2.bam ...]
You can specify any metabat options EXCEPT:
-i --inFile
-o --outFile
-a --abdFile
Also for depth calculations stage only, you can set the following environmental variables:
PCTID=${PCTID} -- reads below this threshold will be discarded
BADMAP=${BADMAP} -- output the discarded reads to a sub directory
MINDEPTH=${MINDEPTH} -- require contigs to have this minimum depth to be output
MB_LABEL=${MB_LABEL} -- optional label to include within output path
For full metabat options: $MB -h
"
#metabatopts="--verbose --debug"
metabatopts=""
for arg in $@
do
if [ -f "$arg" ]
then
break
fi
metabatopts="$metabatopts $arg"
shift
done
if [ $# -lt 2 ]
then
echo "$USAGE" 1>&2
exit 1
fi
assembly=$1
shift
if [ ! -f "$assembly" ]
then
echo "Please specify the assembly fasta file: $assembly does not exist" 1>&2
exit 1
fi
for bam in $@
do
if [ ! -f "$bam" ]
then
echo "Could not find the expected bam file: $bam" 1>&2
exit 1
fi
done
set -e
depth=${assembly##*/}.depth.txt
lock=$depth.BUILDING
waitforlock()
{
while [ -L "$lock" ]
do
echo "Waiting for $lock to be complete before continuing $(date)"
sleep 60
done
}
cleanup()
{
rm -f $lock
}
trap cleanup 0 1 2 3 15
waitforlock
badmap=${assembly##*/}.d
badmapopts=
if [ "$BADMAP" != '0' ]
then
mkdir -p ${badmap}
badmapopts="--unmappedFastq ${badmap}/badmap"
fi
if [ ! -f "${depth}" ] && ln -s "$(uname -n) $$" $lock
then
if [ ! -f "${depth}" ]
then
sumopts="--outputDepth ${depth}.tmp --percentIdentity ${PCTID} --minContigLength 1000 --minContigDepth ${MINDEPTH} ${badmapopts} --referenceFasta ${assembly}"
echo "Executing: '$SUM $sumopts $@' at `date`"
$SUM $sumopts $@ && mv ${depth}.tmp ${depth} || false
echo "Finished $SUM at `date`"
fi
echo "Creating depth file for metabat at `date`"
rm $lock
else
waitforlock
echo "Skipping $SUM as $depth already exists"
fi
outname=${assembly##*/}.metabat-${MB_LABEL}-$(date '+%Y%m%d_%H%M%S')/bin
echo "Executing: '$MB $metabatopts --inFile $assembly --outFile $outname --abdFile ${depth}' at `date`"
$MB $metabatopts --inFile $assembly --outFile $outname --abdFile ${depth}
echo "Finished $MB at `date`"
|