| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified May 9, 2024 |
| 7 | |
| 8 | Description: Compares delimited labels in read headers to count |
| 9 | how many match. The 'unknown' label is a special case. The original |
| 10 | goal was to measure the differences between demultiplexing methods. |
| 11 | Labels can be added with the rename.sh suffix flag, or the |
| 12 | novademux.sh rename+nosplit flags, or seal.sh with rename, addcount=f, |
| 13 | and tophitonly. The assumption is that a header will look like: |
| 14 | @VP2:12:H7:2:1101:8:2 1:N:0:CAAC (tab) CAAC (tab) CAAC |
| 15 | ...in which case the labels CAAC would be compared and found equal. |
| 16 | |
| 17 | |
| 18 | Usage: comparelables.sh in=<input file> out=<output file> |
| 19 | |
| 20 | Input may be fasta or fastq, compressed or uncompressed. |
| 21 | |
| 22 | Standard parameters: |
| 23 | in=<file> Primary input, or read 1 input. |
| 24 | out=stdout Print the results to this destination. Default is stdout |
| 25 | but a file may be specified. |
| 26 | labelstats= Optional destination for per-label stats. |
| 27 | quantset=<file> If set, ignore reads with labels not contained in this file; |
| 28 | one label per line. 'unknown' is automatically included. |
| 29 | swap=f Swap the order of label 1 and label 2. |
| 30 | delimiter=tab Compare the last two terms in the header, using this |
| 31 | single-character delimiter. Most symbols can be expressed |
| 32 | as literals (e.g. 'delimiter=_' for underscore) but you can |
| 33 | also spell out some of the problematic ones: |
| 34 | space, tab, pound, greaterthan, lessthan, equals, |
| 35 | colon, semicolon, bang, and, quote, singlequote, |
| 36 | backslash, hat, dollar, dot, pipe, questionmark, star, |
| 37 | plus, openparen, closeparen, opensquare, opencurly |
| 38 | |
| 39 | Output Terminology: |
| 40 | aa Both labels were equal. |
| 41 | uu Both labels were unknown. |
| 42 | au Label 1 was assigned, label 2 was unknown. |
| 43 | ua Label 1 was unknown, label 2 was assigned. |
| 44 | ab Both labels were assigned, but not equal. For per-label |
| 45 | stats, indicates label 1 was assigned to this, and label 2 |
| 46 | was assigned to something else. |
| 47 | ba In per-label stats, indicates label 2 was assigned to this and |
| 48 | label 1 was assigned to something else. |
| 49 | yield Fraction of reads assigned to the same label. E.g. if aa=10, |
| 50 | au=1, ab=2, then yield2 = aa/(aa+au+ab) = 10/13 = 0.77. |
| 51 | contam Fraction of reads assigned to a different label, using the |
| 52 | other as ground truth. For example, if aa=10, au=1, ab=2, |
| 53 | then contam1=ab/(aa+au+ab) = 2/13 = 153846 PPM. |
| 54 | |
| 55 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 56 | " |
| 57 | } |
| 58 | |
| 59 | #This block allows symlinked shellscripts to correctly set classpath. |
| 60 | pushd . > /dev/null |
| 61 | DIR="${BASH_SOURCE[0]}" |
| 62 | while [ -h "$DIR" ]; do |
| 63 | cd "$(dirname "$DIR")" |
| 64 | DIR="$(readlink "$(basename "$DIR")")" |
| 65 | done |
| 66 | cd "$(dirname "$DIR")" |
| 67 | DIR="$(pwd)/" |
| 68 | popd > /dev/null |
| 69 | |
| 70 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 71 | CP="$DIR""current/" |
| 72 | |
| 73 | z="-Xmx300m" |
| 74 | z2="-Xms300m" |
| 75 | set=0 |
| 76 | |
| 77 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 78 | usage |
| 79 | exit |
| 80 | fi |
| 81 | |
| 82 | calcXmx () { |
| 83 | source "$DIR""/calcmem.sh" |
| 84 | setEnvironment |
| 85 | parseXmx "$@" |
| 86 | } |
| 87 | calcXmx "$@" |
| 88 | |
| 89 | function comparelabels() { |
| 90 | local CMD="java $EA $EOOM $z $z2 -cp $CP barcode.CompareLabels $@" |
| 91 | echo $CMD >&2 |
| 92 | eval $CMD |
| 93 | } |
| 94 | |
| 95 | comparelabels "$@" |