| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified November 9, 2016 |
| 7 | |
| 8 | Description: Reorders reads randomly, keeping pairs together. |
| 9 | |
| 10 | Usage: shuffle.sh in=<file> out=<file> |
| 11 | |
| 12 | Standard parameters: |
| 13 | in=<file> The 'in=' flag is needed if the input file is not the first parameter. 'in=stdin' will pipe from standard in. |
| 14 | in2=<file> Use this if 2nd read of pairs are in a different file. |
| 15 | out=<file> The 'out=' flag is needed if the output file is not the second parameter. 'out=stdout' will pipe to standard out. |
| 16 | out2=<file> Use this to write 2nd read of pairs to a different file. |
| 17 | overwrite=t (ow) Set to false to force the program to abort rather than overwrite an existing file. |
| 18 | ziplevel=2 (zl) Set to 1 (lowest) through 9 (max) to change compression level; lower compression is faster. |
| 19 | int=auto (interleaved) Set to t or f to override interleaving autodetection. |
| 20 | |
| 21 | Processing parameters: |
| 22 | shuffle Randomly reorders reads (default). |
| 23 | name Sort reads by name. |
| 24 | coordinate Sort reads by mapping location. |
| 25 | sequence Sort reads by sequence. |
| 26 | |
| 27 | |
| 28 | Java Parameters: |
| 29 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 30 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. |
| 31 | The max is typically 85% of physical memory. |
| 32 | -eoom This flag will cause the process to exit if an out-of-memory |
| 33 | exception occurs. Requires Java 8u92+. |
| 34 | -da Disable assertions. |
| 35 | |
| 36 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 37 | " |
| 38 | } |
| 39 | |
| 40 | #This block allows symlinked shellscripts to correctly set classpath. |
| 41 | pushd . > /dev/null |
| 42 | DIR="${BASH_SOURCE[0]}" |
| 43 | while [ -h "$DIR" ]; do |
| 44 | cd "$(dirname "$DIR")" |
| 45 | DIR="$(readlink "$(basename "$DIR")")" |
| 46 | done |
| 47 | cd "$(dirname "$DIR")" |
| 48 | DIR="$(pwd)/" |
| 49 | popd > /dev/null |
| 50 | |
| 51 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 52 | CP="$DIR""current/" |
| 53 | |
| 54 | z="-Xmx2g" |
| 55 | z2="-Xms2g" |
| 56 | set=0 |
| 57 | |
| 58 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 59 | usage |
| 60 | exit |
| 61 | fi |
| 62 | |
| 63 | calcXmx () { |
| 64 | source "$DIR""/calcmem.sh" |
| 65 | setEnvironment |
| 66 | parseXmx "$@" |
| 67 | if [[ $set == 1 ]]; then |
| 68 | return |
| 69 | fi |
| 70 | freeRam 2000m 84 |
| 71 | z="-Xmx${RAM}m" |
| 72 | z2="-Xms${RAM}m" |
| 73 | } |
| 74 | calcXmx "$@" |
| 75 | |
| 76 | shuffle() { |
| 77 | local CMD="java $EA $EOOM $z $z2 -cp $CP sort.Shuffle $@" |
| 78 | echo $CMD >&2 |
| 79 | eval $CMD |
| 80 | } |
| 81 | |
| 82 | shuffle "$@" |