| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified Jan 7, 2020 |
| 7 | |
| 8 | Description: Splits sequences according to their taxonomy, |
| 9 | as determined by the sequence name. Sequences should |
| 10 | be labeled with a gi number, NCBI taxID, or species name. |
| 11 | |
| 12 | Usage: splitbytaxa.sh in=<input file> out=<output pattern> tree=<tree file> table=<table file> level=<name or number> |
| 13 | |
| 14 | Input may be fasta or fastq, compressed or uncompressed. |
| 15 | |
| 16 | |
| 17 | Standard parameters: |
| 18 | in=<file> Primary input. |
| 19 | out=<file> Output pattern; must contain % symbol. |
| 20 | overwrite=f (ow) Set to false to force the program to abort rather than |
| 21 | overwrite an existing file. |
| 22 | showspeed=t (ss) Set to 'f' to suppress display of processing speed. |
| 23 | ziplevel=2 (zl) Set to 1 (lowest) through 9 (max) to change compression |
| 24 | level; lower compression is faster. |
| 25 | |
| 26 | Processing parameters: |
| 27 | level=phylum Taxonomic level, such as phylum. Filtering will operate on |
| 28 | sequences within the same taxonomic level as specified ids. |
| 29 | tree= A taxonomic tree made by TaxTree, such as tree.taxtree.gz. |
| 30 | table= A table translating gi numbers to NCBI taxIDs. |
| 31 | Only needed if gi numbers will be used. |
| 32 | On Genepool, use 'tree=auto table=auto'. |
| 33 | * Note * |
| 34 | Tree and table files are in /global/projectb/sandbox/gaag/bbtools/tax |
| 35 | For non-Genepool users, or to make new ones, use taxtree.sh and gitable.sh |
| 36 | |
| 37 | Java Parameters: |
| 38 | -Xmx This will set Java's memory usage, overriding automatic |
| 39 | memory detection. |
| 40 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify |
| 41 | 200 megs. The max is typically 85% of physical memory. |
| 42 | -eoom This flag will cause the process to exit if an out-of-memory |
| 43 | exception occurs. Requires Java 8u92+. |
| 44 | -da Disable assertions. |
| 45 | |
| 46 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 47 | " |
| 48 | } |
| 49 | |
| 50 | #This block allows symlinked shellscripts to correctly set classpath. |
| 51 | pushd . > /dev/null |
| 52 | DIR="${BASH_SOURCE[0]}" |
| 53 | while [ -h "$DIR" ]; do |
| 54 | cd "$(dirname "$DIR")" |
| 55 | DIR="$(readlink "$(basename "$DIR")")" |
| 56 | done |
| 57 | cd "$(dirname "$DIR")" |
| 58 | DIR="$(pwd)/" |
| 59 | popd > /dev/null |
| 60 | |
| 61 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 62 | CP="$DIR""current/" |
| 63 | |
| 64 | z="-Xmx4g" |
| 65 | z2="-Xms4g" |
| 66 | set=0 |
| 67 | |
| 68 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 69 | usage |
| 70 | exit |
| 71 | fi |
| 72 | |
| 73 | calcXmx () { |
| 74 | source "$DIR""/calcmem.sh" |
| 75 | setEnvironment |
| 76 | parseXmx "$@" |
| 77 | if [[ $set == 1 ]]; then |
| 78 | return |
| 79 | fi |
| 80 | freeRam 1000m 84 |
| 81 | z="-Xmx${RAM}m" |
| 82 | z2="-Xms${RAM}m" |
| 83 | } |
| 84 | calcXmx "$@" |
| 85 | |
| 86 | splitbytaxa() { |
| 87 | local CMD="java $EA $EOOM $z -cp $CP tax.SplitByTaxa $@" |
| 88 | echo $CMD >&2 |
| 89 | eval $CMD |
| 90 | } |
| 91 | |
| 92 | splitbytaxa "$@" |