| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified January 26, 2021 |
| 7 | |
| 8 | Description: Given a reference, generates a kmer spectrum including a |
| 9 | specified number of substitutions, insertions, and deletions. The output is |
| 10 | useful for analyzing barcodes or other short oligos, and filtering using |
| 11 | BBDuk or Seal. Input may be fasta or fastq, compressed or raw. |
| 12 | See also kcompress, kmercountexact, and bbkmerset. |
| 13 | |
| 14 | Usage: kmutate.sh in=<file> out=<file> k=<kmer length> edist=<edit distance> |
| 15 | |
| 16 | Examples: |
| 17 | |
| 18 | kmutate.sh in=x.fa out=y.fa k=31 edist=2 |
| 19 | This will generate all 31-mers in x.fa, along with all 31-mer mutants with |
| 20 | an edit distance of up to 2. For example, 1 substitution, or 1 substitution |
| 21 | plus 1 deletion, or any other combination of subsitutions, insertions, |
| 22 | and deletions that sum to 0, 1, or 2. |
| 23 | |
| 24 | kmutate.sh in=x.fa out=y.fa k=31 idist=1 ddist=3 |
| 25 | This will generate all 31-mers in x.fa, along with all 31-mer mutants allowing |
| 26 | up to 1 insertion and 3 deletions, but no substitutions. For example, |
| 27 | 1 insertion and 3 deletions is possible (edit distance 4), but 1 deletion and |
| 28 | 1 substitution is not directly possible (though some equivalent mutants would |
| 29 | still be generated because a deletion and subsequent insertion is equivalent |
| 30 | to a substitution). |
| 31 | |
| 32 | Note that deletion events have limitations; e.g., they cannot occur on input |
| 33 | sequences of length k because the resulting sequence is shorter than k. As |
| 34 | a result, running the program twice consecutively with edist=1 will not give |
| 35 | the same results as running once with edist=2 since the intermediate file will |
| 36 | be only k-length sequences. However, running consecutively with sdist or |
| 37 | idist would be equivalent since they do not involve deletions. |
| 38 | |
| 39 | Standard parameters: |
| 40 | in=<file> Primary input, or read 1 input. |
| 41 | in2=<file> Read 2 input if reads are in two files. |
| 42 | out=<file> Primary output, or read 1 output. |
| 43 | overwrite=t (ow) Set to false to force the program to abort rather than |
| 44 | overwrite an existing file. |
| 45 | |
| 46 | Processing parameters: |
| 47 | k=31 Kmer length; 1-31. |
| 48 | rcomp=t Consider kmers equivalent to their reverse-complements. |
| 49 | |
| 50 | Edit mode flags (used if edist>0): |
| 51 | edist=0 Set the maximal edit distance (0-3). |
| 52 | smax=99 (optional) Don't allow more than this many total substitutions. |
| 53 | dmax=99 (optional) Don't allow more than this many total deletions. |
| 54 | imax=99 (optional) Don't allow more than this many total insertions. |
| 55 | |
| 56 | SDI mode flags: |
| 57 | sdist=0 Maximum substitutions allowed. |
| 58 | idist=0 Maximum insertions allowed. |
| 59 | ddist=0 Maximum deletions allowed (0-3). |
| 60 | emax=99 (optional) Don't allow more than this many total edits. |
| 61 | |
| 62 | *** Note - please use SDI mode flags OR Edit mode flag, not both. *** |
| 63 | *** Both modes are equivalent, they just have different defaults. *** |
| 64 | |
| 65 | Java Parameters: |
| 66 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 67 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will |
| 68 | specify 200 megs. The max is typically 85% of physical memory. |
| 69 | -eoom This flag will cause the process to exit if an out-of-memory |
| 70 | exception occurs. Requires Java 8u92+. |
| 71 | -da Disable assertions. |
| 72 | |
| 73 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 74 | " |
| 75 | } |
| 76 | |
| 77 | #This block allows symlinked shellscripts to correctly set classpath. |
| 78 | pushd . > /dev/null |
| 79 | DIR="${BASH_SOURCE[0]}" |
| 80 | while [ -h "$DIR" ]; do |
| 81 | cd "$(dirname "$DIR")" |
| 82 | DIR="$(readlink "$(basename "$DIR")")" |
| 83 | done |
| 84 | cd "$(dirname "$DIR")" |
| 85 | DIR="$(pwd)/" |
| 86 | popd > /dev/null |
| 87 | |
| 88 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 89 | CP="$DIR""current/" |
| 90 | |
| 91 | z="-Xmx4g" |
| 92 | z2="-Xms4g" |
| 93 | set=0 |
| 94 | |
| 95 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 96 | usage |
| 97 | exit |
| 98 | fi |
| 99 | |
| 100 | calcXmx () { |
| 101 | source "$DIR""/calcmem.sh" |
| 102 | setEnvironment |
| 103 | parseXmx "$@" |
| 104 | if [[ $set == 1 ]]; then |
| 105 | return |
| 106 | fi |
| 107 | freeRam 4000m 84 |
| 108 | z="-Xmx${RAM}m" |
| 109 | z2="-Xms${RAM}m" |
| 110 | } |
| 111 | calcXmx "$@" |
| 112 | |
| 113 | kmutate() { |
| 114 | local CMD="java $EA $EOOM $z $z2 -cp $CP jgi.KExpand $@" |
| 115 | echo $CMD >&2 |
| 116 | eval $CMD |
| 117 | } |
| 118 | |
| 119 | kmutate "$@" |