jpayne@69: #!/bin/bash jpayne@69: jpayne@69: usage(){ jpayne@69: echo " jpayne@69: Written by Brian Bushnell jpayne@69: Last modified February 17, 2015 jpayne@69: jpayne@69: Description: Separates paired reads into files of 'good' pairs and 'good' singletons by removing 'bad' reads that are shorter than a min length. jpayne@69: Designed to handle situations where reads become too short to be useful after trimming. This program also optionally performs quality trimming. jpayne@69: jpayne@69: Usage: bbsplitpairs.sh in= out= outs= minlen= jpayne@69: jpayne@69: Input may be fasta or fastq, compressed or uncompressed. jpayne@69: jpayne@69: Optional parameters (and their defaults) jpayne@69: jpayne@69: in= The 'in=' flag is needed if the input file is not the first parameter. 'in=stdin' will pipe from standard in. jpayne@69: in2= Use this if 2nd read of pairs are in a different file. jpayne@69: out= The 'out=' flag is needed if the output file is not the second parameter. 'out=stdout' will pipe to standard out. jpayne@69: out2= Use this to write 2nd read of pairs to a different file. jpayne@69: outsingle= (outs) Write singleton reads here. jpayne@69: jpayne@69: overwrite=t (ow) Set to false to force the program to abort rather than overwrite an existing file. jpayne@69: showspeed=t (ss) Set to 'f' to suppress display of processing speed. jpayne@69: interleaved=auto (int) If true, forces fastq input to be paired and interleaved. jpayne@69: qtrim=f Trim read ends to remove bases with quality below trimq. jpayne@69: Values: rl (trim both ends), f (neither end), r (right end only), l (left end only). jpayne@69: trimq=6 Trim quality threshold. jpayne@69: minlen=20 (ml) Reads shorter than this after trimming will be discarded. jpayne@69: ziplevel=2 (zl) Set to 1 (lowest) through 9 (max) to change compression level; lower compression is faster. jpayne@69: fixinterleaving=f (fint) Fixes corrupted interleaved files by examining pair names. Only use on files with broken interleaving. jpayne@69: repair=f (rp) Fixes arbitrarily corrupted paired reads by examining read names. High memory. jpayne@69: ain=f (allowidenticalnames) When detecting pair names, allows identical names, instead of requiring /1 and /2 or 1: and 2: jpayne@69: jpayne@69: Java Parameters: jpayne@69: -Xmx This will set Java's memory usage, overriding autodetection. jpayne@69: -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. jpayne@69: The max is typically 85% of physical memory. jpayne@69: -eoom This flag will cause the process to exit if an jpayne@69: out-of-memory exception occurs. Requires Java 8u92+. jpayne@69: -da Disable assertions. jpayne@69: jpayne@69: Please contact Brian Bushnell at bbushnell@lbl.gov if you encounter any problems. jpayne@69: " jpayne@69: } jpayne@69: jpayne@69: #This block allows symlinked shellscripts to correctly set classpath. jpayne@69: pushd . > /dev/null jpayne@69: DIR="${BASH_SOURCE[0]}" jpayne@69: while [ -h "$DIR" ]; do jpayne@69: cd "$(dirname "$DIR")" jpayne@69: DIR="$(readlink "$(basename "$DIR")")" jpayne@69: done jpayne@69: cd "$(dirname "$DIR")" jpayne@69: DIR="$(pwd)/" jpayne@69: popd > /dev/null jpayne@69: jpayne@69: #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" jpayne@69: CP="$DIR""current/" jpayne@69: jpayne@69: z="-Xmx200m" jpayne@69: set=0 jpayne@69: jpayne@69: if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then jpayne@69: usage jpayne@69: exit jpayne@69: fi jpayne@69: jpayne@69: calcXmx () { jpayne@69: source "$DIR""/calcmem.sh" jpayne@69: setEnvironment jpayne@69: parseXmx "$@" jpayne@69: } jpayne@69: calcXmx "$@" jpayne@69: jpayne@69: splitpairs() { jpayne@69: local CMD="java $EA $EOOM $z -cp $CP jgi.SplitPairsAndSingles $@" jpayne@69: echo $CMD >&2 jpayne@69: eval $CMD jpayne@69: } jpayne@69: jpayne@69: splitpairs "$@"