| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified February 17, 2015 |
| 7 | |
| 8 | Description: Separates paired reads into files of 'good' pairs and 'good' singletons by removing 'bad' reads that are shorter than a min length. |
| 9 | Designed to handle situations where reads become too short to be useful after trimming. This program also optionally performs quality trimming. |
| 10 | |
| 11 | Usage: bbsplitpairs.sh in=<input file> out=<pair output file> outs=<singleton output file> minlen=<minimum read length, an integer> |
| 12 | |
| 13 | Input may be fasta or fastq, compressed or uncompressed. |
| 14 | |
| 15 | Optional parameters (and their defaults) |
| 16 | |
| 17 | in=<file> The 'in=' flag is needed if the input file is not the first parameter. 'in=stdin' will pipe from standard in. |
| 18 | in2=<file> Use this if 2nd read of pairs are in a different file. |
| 19 | out=<file> The 'out=' flag is needed if the output file is not the second parameter. 'out=stdout' will pipe to standard out. |
| 20 | out2=<file> Use this to write 2nd read of pairs to a different file. |
| 21 | outsingle=<file> (outs) Write singleton reads here. |
| 22 | |
| 23 | overwrite=t (ow) Set to false to force the program to abort rather than overwrite an existing file. |
| 24 | showspeed=t (ss) Set to 'f' to suppress display of processing speed. |
| 25 | interleaved=auto (int) If true, forces fastq input to be paired and interleaved. |
| 26 | qtrim=f Trim read ends to remove bases with quality below trimq. |
| 27 | Values: rl (trim both ends), f (neither end), r (right end only), l (left end only). |
| 28 | trimq=6 Trim quality threshold. |
| 29 | minlen=20 (ml) Reads shorter than this after trimming will be discarded. |
| 30 | ziplevel=2 (zl) Set to 1 (lowest) through 9 (max) to change compression level; lower compression is faster. |
| 31 | fixinterleaving=f (fint) Fixes corrupted interleaved files by examining pair names. Only use on files with broken interleaving. |
| 32 | repair=f (rp) Fixes arbitrarily corrupted paired reads by examining read names. High memory. |
| 33 | ain=f (allowidenticalnames) When detecting pair names, allows identical names, instead of requiring /1 and /2 or 1: and 2: |
| 34 | |
| 35 | Java Parameters: |
| 36 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 37 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. |
| 38 | The max is typically 85% of physical memory. |
| 39 | -eoom This flag will cause the process to exit if an |
| 40 | out-of-memory exception occurs. Requires Java 8u92+. |
| 41 | -da Disable assertions. |
| 42 | |
| 43 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 44 | " |
| 45 | } |
| 46 | |
| 47 | #This block allows symlinked shellscripts to correctly set classpath. |
| 48 | pushd . > /dev/null |
| 49 | DIR="${BASH_SOURCE[0]}" |
| 50 | while [ -h "$DIR" ]; do |
| 51 | cd "$(dirname "$DIR")" |
| 52 | DIR="$(readlink "$(basename "$DIR")")" |
| 53 | done |
| 54 | cd "$(dirname "$DIR")" |
| 55 | DIR="$(pwd)/" |
| 56 | popd > /dev/null |
| 57 | |
| 58 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 59 | CP="$DIR""current/" |
| 60 | |
| 61 | z="-Xmx200m" |
| 62 | set=0 |
| 63 | |
| 64 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 65 | usage |
| 66 | exit |
| 67 | fi |
| 68 | |
| 69 | calcXmx () { |
| 70 | source "$DIR""/calcmem.sh" |
| 71 | setEnvironment |
| 72 | parseXmx "$@" |
| 73 | } |
| 74 | calcXmx "$@" |
| 75 | |
| 76 | splitpairs() { |
| 77 | local CMD="java $EA $EOOM $z -cp $CP jgi.SplitPairsAndSingles $@" |
| 78 | echo $CMD >&2 |
| 79 | eval $CMD |
| 80 | } |
| 81 | |
| 82 | splitpairs "$@" |