jpayne@69: #!/bin/bash jpayne@69: jpayne@69: usage(){ jpayne@69: echo " jpayne@69: Written by Brian Bushnell jpayne@69: Last modified January 26, 2021 jpayne@69: jpayne@69: Description: Given a reference, generates a kmer spectrum including a jpayne@69: specified number of substitutions, insertions, and deletions. The output is jpayne@69: useful for analyzing barcodes or other short oligos, and filtering using jpayne@69: BBDuk or Seal. Input may be fasta or fastq, compressed or raw. jpayne@69: See also kcompress, kmercountexact, and bbkmerset. jpayne@69: jpayne@69: Usage: kmutate.sh in= out= k= edist= jpayne@69: jpayne@69: Examples: jpayne@69: jpayne@69: kmutate.sh in=x.fa out=y.fa k=31 edist=2 jpayne@69: This will generate all 31-mers in x.fa, along with all 31-mer mutants with jpayne@69: an edit distance of up to 2. For example, 1 substitution, or 1 substitution jpayne@69: plus 1 deletion, or any other combination of subsitutions, insertions, jpayne@69: and deletions that sum to 0, 1, or 2. jpayne@69: jpayne@69: kmutate.sh in=x.fa out=y.fa k=31 idist=1 ddist=3 jpayne@69: This will generate all 31-mers in x.fa, along with all 31-mer mutants allowing jpayne@69: up to 1 insertion and 3 deletions, but no substitutions. For example, jpayne@69: 1 insertion and 3 deletions is possible (edit distance 4), but 1 deletion and jpayne@69: 1 substitution is not directly possible (though some equivalent mutants would jpayne@69: still be generated because a deletion and subsequent insertion is equivalent jpayne@69: to a substitution). jpayne@69: jpayne@69: Note that deletion events have limitations; e.g., they cannot occur on input jpayne@69: sequences of length k because the resulting sequence is shorter than k. As jpayne@69: a result, running the program twice consecutively with edist=1 will not give jpayne@69: the same results as running once with edist=2 since the intermediate file will jpayne@69: be only k-length sequences. However, running consecutively with sdist or jpayne@69: idist would be equivalent since they do not involve deletions. jpayne@69: jpayne@69: Standard parameters: jpayne@69: in= Primary input, or read 1 input. jpayne@69: in2= Read 2 input if reads are in two files. jpayne@69: out= Primary output, or read 1 output. jpayne@69: overwrite=t (ow) Set to false to force the program to abort rather than jpayne@69: overwrite an existing file. jpayne@69: jpayne@69: Processing parameters: jpayne@69: k=31 Kmer length; 1-31. jpayne@69: rcomp=t Consider kmers equivalent to their reverse-complements. jpayne@69: jpayne@69: Edit mode flags (used if edist>0): jpayne@69: edist=0 Set the maximal edit distance (0-3). jpayne@69: smax=99 (optional) Don't allow more than this many total substitutions. jpayne@69: dmax=99 (optional) Don't allow more than this many total deletions. jpayne@69: imax=99 (optional) Don't allow more than this many total insertions. jpayne@69: jpayne@69: SDI mode flags: jpayne@69: sdist=0 Maximum substitutions allowed. jpayne@69: idist=0 Maximum insertions allowed. jpayne@69: ddist=0 Maximum deletions allowed (0-3). jpayne@69: emax=99 (optional) Don't allow more than this many total edits. jpayne@69: jpayne@69: *** Note - please use SDI mode flags OR Edit mode flag, not both. *** jpayne@69: *** Both modes are equivalent, they just have different defaults. *** jpayne@69: jpayne@69: Java Parameters: jpayne@69: -Xmx This will set Java's memory usage, overriding autodetection. jpayne@69: -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will jpayne@69: specify 200 megs. The max is typically 85% of physical memory. jpayne@69: -eoom This flag will cause the process to exit if an out-of-memory jpayne@69: exception occurs. Requires Java 8u92+. jpayne@69: -da Disable assertions. jpayne@69: jpayne@69: Please contact Brian Bushnell at bbushnell@lbl.gov if you encounter any problems. jpayne@69: " jpayne@69: } jpayne@69: jpayne@69: #This block allows symlinked shellscripts to correctly set classpath. jpayne@69: pushd . > /dev/null jpayne@69: DIR="${BASH_SOURCE[0]}" jpayne@69: while [ -h "$DIR" ]; do jpayne@69: cd "$(dirname "$DIR")" jpayne@69: DIR="$(readlink "$(basename "$DIR")")" jpayne@69: done jpayne@69: cd "$(dirname "$DIR")" jpayne@69: DIR="$(pwd)/" jpayne@69: popd > /dev/null jpayne@69: jpayne@69: #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" jpayne@69: CP="$DIR""current/" jpayne@69: jpayne@69: z="-Xmx4g" jpayne@69: z2="-Xms4g" jpayne@69: set=0 jpayne@69: jpayne@69: if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then jpayne@69: usage jpayne@69: exit jpayne@69: fi jpayne@69: jpayne@69: calcXmx () { jpayne@69: source "$DIR""/calcmem.sh" jpayne@69: setEnvironment jpayne@69: parseXmx "$@" jpayne@69: if [[ $set == 1 ]]; then jpayne@69: return jpayne@69: fi jpayne@69: freeRam 4000m 84 jpayne@69: z="-Xmx${RAM}m" jpayne@69: z2="-Xms${RAM}m" jpayne@69: } jpayne@69: calcXmx "$@" jpayne@69: jpayne@69: kmutate() { jpayne@69: local CMD="java $EA $EOOM $z $z2 -cp $CP jgi.KExpand $@" jpayne@69: echo $CMD >&2 jpayne@69: eval $CMD jpayne@69: } jpayne@69: jpayne@69: kmutate "$@"