| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified September 12, 2018 |
| 7 | |
| 8 | Description: Sorts reads by name or other keys such as length, |
| 9 | quality, mapping position, flowcell coordinates, or taxonomy. |
| 10 | Intended to merge temp files produced by SortByName if the program |
| 11 | ran out of time during merging. |
| 12 | |
| 13 | Usage: mergesorted.sh sort_temp* out=<file> |
| 14 | |
| 15 | Input may be fasta, fastq, or sam, compressed or uncompressed. |
| 16 | |
| 17 | Parameters: |
| 18 | |
| 19 | in=<file,file,...> Input files. Files may be specified without in=. |
| 20 | out=<file> Output file. |
| 21 | delete=t Delete input files after merging. |
| 22 | name=t Sort reads by name. |
| 23 | length=f Sort reads by length. |
| 24 | quality=f Sort reads by quality. |
| 25 | position=f Sort reads by position (for mapped reads). |
| 26 | taxa=f Sort reads by taxonomy (for NCBI naming convention). |
| 27 | sequence=f Sort reads by sequence, alphabetically. |
| 28 | flowcell=f Sort reads by flowcell coordinates. |
| 29 | shuffle=f Shuffle reads randomly (untested). |
| 30 | list=<file> Sort reads according to this list of names. |
| 31 | ascending=t Sort ascending. |
| 32 | memmult=.35 Write a temp file when used memory drops below this |
| 33 | fraction of total memory. |
| 34 | |
| 35 | Taxonomy-sorting parameters: |
| 36 | tree= Specify a taxtree file. On Genepool, use 'auto'. |
| 37 | gi= Specify a gitable file. On Genepool, use 'auto'. |
| 38 | accession= Specify one or more comma-delimited NCBI accession to |
| 39 | taxid files. On Genepool, use 'auto'. |
| 40 | |
| 41 | Java Parameters: |
| 42 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 43 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. |
| 44 | The max is typically 85% of physical memory. |
| 45 | -eoom This flag will cause the process to exit if an |
| 46 | out-of-memory exception occurs. Requires Java 8u92+. |
| 47 | -da Disable assertions. |
| 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="-Xmx2g" |
| 68 | z2="-Xms2g" |
| 69 | set=0 |
| 70 | |
| 71 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 72 | usage |
| 73 | exit |
| 74 | fi |
| 75 | |
| 76 | calcXmx () { |
| 77 | source "$DIR""/calcmem.sh" |
| 78 | setEnvironment |
| 79 | parseXmx "$@" |
| 80 | if [[ $set == 1 ]]; then |
| 81 | return |
| 82 | fi |
| 83 | freeRam 2000m 84 |
| 84 | z="-Xmx${RAM}m" |
| 85 | z2="-Xms${RAM}m" |
| 86 | } |
| 87 | calcXmx "$@" |
| 88 | |
| 89 | mergesorted() { |
| 90 | local CMD="java $EA $EOOM $z $z2 -cp $CP sort.MergeSorted $@" |
| 91 | echo $CMD >&2 |
| 92 | eval $CMD |
| 93 | } |
| 94 | |
| 95 | mergesorted "$@" |