| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified July 27, 2015 |
| 7 | |
| 8 | Description: Maps reads, then filters an assembly by contig coverage. |
| 9 | Intended to reduce misassembly rate of SPAdes by removing suspicious contigs. |
| 10 | |
| 11 | Usage: postfilter.sh in=<reads> ref=<contigs> out=<filtered contigs> |
| 12 | |
| 13 | Standard Parameters: |
| 14 | in=<file> File containing input reads. |
| 15 | in2=<file> Optional file containing read mates. |
| 16 | ref=<file> File containing input assembly. |
| 17 | cov=covstats.txt File to write coverage stats generated by pileup. |
| 18 | out=filtered.fa Destination of clean output assembly. |
| 19 | outdirty=<file> (outd) Destination of removed contigs; optional. |
| 20 | ow=f (overwrite) Overwrites files that already exist. |
| 21 | app=f (append) Append to files that already exist. |
| 22 | zl=4 (ziplevel) Set compression level, 1 (low) to 9 (max). |
| 23 | int=f (interleaved) Determines whether input reads are considered interleaved. |
| 24 | |
| 25 | Filtering Parameters: |
| 26 | minc=2 (mincov) Discard contigs with lower average coverage. |
| 27 | minp=95 (minpercent) Discard contigs with a lower percent covered bases. |
| 28 | minr=6 (minreads) Discard contigs with fewer mapped reads. |
| 29 | minl=400 (minlength) Discard shorter contigs. |
| 30 | trim=0 (trimends) Trim the first and last X bases of each sequence. |
| 31 | |
| 32 | Mapping Parameters (unlisted params will use BBMap defaults) |
| 33 | minhits=2 |
| 34 | maxindel=0 |
| 35 | tipsearch=0 |
| 36 | bw=20 |
| 37 | rescue=f |
| 38 | |
| 39 | Java Parameters: |
| 40 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 41 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. |
| 42 | The max is typically 85% of physical memory. |
| 43 | -eoom This flag will cause the process to exit if an |
| 44 | out-of-memory exception occurs. Requires Java 8u92+. |
| 45 | -da Disable assertions. |
| 46 | |
| 47 | Other parameters will be passed directly to BBMap. |
| 48 | |
| 49 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 50 | " |
| 51 | } |
| 52 | |
| 53 | #This block allows symlinked shellscripts to correctly set classpath. |
| 54 | pushd . > /dev/null |
| 55 | DIR="${BASH_SOURCE[0]}" |
| 56 | while [ -h "$DIR" ]; do |
| 57 | cd "$(dirname "$DIR")" |
| 58 | DIR="$(readlink "$(basename "$DIR")")" |
| 59 | done |
| 60 | cd "$(dirname "$DIR")" |
| 61 | DIR="$(pwd)/" |
| 62 | popd > /dev/null |
| 63 | |
| 64 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 65 | CP="$DIR""current/" |
| 66 | |
| 67 | z="-Xmx800m" |
| 68 | set=0 |
| 69 | |
| 70 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 71 | usage |
| 72 | exit |
| 73 | fi |
| 74 | |
| 75 | calcXmx () { |
| 76 | source "$DIR""/calcmem.sh" |
| 77 | setEnvironment |
| 78 | parseXmx "$@" |
| 79 | if [[ $set == 1 ]]; then |
| 80 | return |
| 81 | fi |
| 82 | freeRam 800m 84 |
| 83 | z="-Xmx${RAM}m" |
| 84 | z2="-Xms${RAM}m" |
| 85 | } |
| 86 | calcXmx "$@" |
| 87 | |
| 88 | function postfilter() { |
| 89 | local CMD="java $EA $EOOM $z -cp $CP assemble.Postfilter $@" |
| 90 | echo $CMD >&2 |
| 91 | eval $CMD |
| 92 | } |
| 93 | |
| 94 | postfilter "$@" |