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