| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified October 16, 2015 |
| 7 | |
| 8 | Description: Counts the number of reads with each barcode. |
| 9 | |
| 10 | Usage: countbarcodes.sh in=<file> counts=<file> |
| 11 | |
| 12 | Input may be stdin or a fasta or fastq file, raw or gzipped. |
| 13 | If you pipe via stdin/stdout, please include the file type; e.g. for gzipped fasta input, set in=stdin.fa.gz |
| 14 | |
| 15 | Input parameters: |
| 16 | in=<file> Input reads, whose names end in a colon then barcode. |
| 17 | counts=<file> Output of counts. |
| 18 | interleaved=auto (int) If true, forces fastq input to be paired and interleaved. |
| 19 | qin=auto ASCII offset for input quality. May be 33 (Sanger), 64 (Illumina), or auto. |
| 20 | unpigz=t Use pigz to decompress. |
| 21 | expected= Comma-delimited list of expected bar codes. |
| 22 | valid= Comma-delimited list of valid bar codes. |
| 23 | countundefined=t Count barcodes that contain non-ACGT symbols. |
| 24 | printheader=t Print a header. |
| 25 | maxrows=-1 Optionally limit the number of rows printed. |
| 26 | |
| 27 | Output parameters: |
| 28 | out=<file> Write bar codes and counts here. 'out=stdout' will pipe to standard out. |
| 29 | |
| 30 | Java Parameters: |
| 31 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 32 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. |
| 33 | The max is typically 85% of physical memory. |
| 34 | -eoom This flag will cause the process to exit if an |
| 35 | out-of-memory exception occurs. Requires Java 8u92+. |
| 36 | -da Disable assertions. |
| 37 | |
| 38 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 39 | " |
| 40 | } |
| 41 | |
| 42 | #This block allows symlinked shellscripts to correctly set classpath. |
| 43 | pushd . > /dev/null |
| 44 | DIR="${BASH_SOURCE[0]}" |
| 45 | while [ -h "$DIR" ]; do |
| 46 | cd "$(dirname "$DIR")" |
| 47 | DIR="$(readlink "$(basename "$DIR")")" |
| 48 | done |
| 49 | cd "$(dirname "$DIR")" |
| 50 | DIR="$(pwd)/" |
| 51 | popd > /dev/null |
| 52 | |
| 53 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 54 | CP="$DIR""current/" |
| 55 | |
| 56 | z="-Xmx200m" |
| 57 | set=0 |
| 58 | |
| 59 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 60 | usage |
| 61 | exit |
| 62 | fi |
| 63 | |
| 64 | calcXmx () { |
| 65 | source "$DIR""/calcmem.sh" |
| 66 | setEnvironment |
| 67 | parseXmx "$@" |
| 68 | } |
| 69 | calcXmx "$@" |
| 70 | |
| 71 | countbarcodes() { |
| 72 | local CMD="java $EA $EOOM $z -cp $CP barcode.CountBarcodes $@" |
| 73 | echo $CMD >&2 |
| 74 | eval $CMD |
| 75 | } |
| 76 | |
| 77 | countbarcodes "$@" |