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