| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell with help from Simon Roux |
| 6 | Last modified Nov 22, 2023 |
| 7 | |
| 8 | Description: Finds interspersed repeats contained within sequences; |
| 9 | specifically, only information within a sequence is used. This is based |
| 10 | on the repeat-spacer model of crisprs. Designed for short reads, |
| 11 | but should work with full genomes. |
| 12 | |
| 13 | Usage: bbcrisprfinder.sh in=<input file> |
| 14 | See bbmap/pipelines/crisprPipeline.sh for more examples. |
| 15 | |
| 16 | Standard parameters: |
| 17 | in=<file> Primary input (a fasta or fastq file). |
| 18 | out=<file> Output for annotated reads containing |
| 19 | interspersed repeats. Reads not matching the criteria |
| 20 | are discarded (though pairs are retained). |
| 21 | outc=<file> Output for crispr sequences and their flanking repeats. |
| 22 | Repeats are in lower-case; spacer is upper-case. |
| 23 | outr=<file> Output of just repeats (one copy of each unique repeat). |
| 24 | Only includes full-length repeats. |
| 25 | outs=<file> Output of just spacers (one copy of each unique spacer). |
| 26 | Only includes spacers adjacent to at least one full-length |
| 27 | repeat (so the bounds are known). |
| 28 | chist=<file> Histogram of crispr stats. |
| 29 | phist=<file> Histogram of palindrome stats. |
| 30 | *All output files are optional. |
| 31 | |
| 32 | Processing parameters: |
| 33 | merge=f Try to merge paired reads before processing them. |
| 34 | masked=f Indicates that the sequences are masked to lowercase; |
| 35 | repeats will not be extended outside of lowercase regions. |
| 36 | BBDuk or BBMask can produce masked sequences. |
| 37 | pad=0 Extend the boundaries of the repeats by this much when |
| 38 | printing to outcrisper. The padding will be in uppercase. |
| 39 | This helps to show why a repeat was not extended. |
| 40 | annotate=f Rename reads to indicate the repeat boundaries. Annotations |
| 41 | look like this: [56-77,117-138;150],P=7,M=5,L=6,S=62,T=6+0 |
| 42 | ...meaning the repeat occurs at positions 56-77 and 117-138; |
| 43 | the read length is 150; and there is a palindrome of length |
| 44 | 7 with 5 matches, a loop length of 6, starting at position |
| 45 | 62, with tails outside the palindromic region length 6 and 0. |
| 46 | reads=-1 If positive, quit after processing this many reads. |
| 47 | |
| 48 | Repeat Parameters: |
| 49 | krepeat=13 (kr) Use this seed kmer length to find repeats. |
| 50 | Repeats shorter than k may not be found. Max is 31. |
| 51 | mm=1 (mmr) Mask this many bases in the middle of kmers to allow |
| 52 | imperfect repeats. Also requires rmismatches to be set. |
| 53 | minrepeats=2 Ignore repeats with fewer than this many nearby copies. |
| 54 | The more copies, the better consensus will refine the borders. |
| 55 | For this purpose 2 partials count as 1 full-length repeat. |
| 56 | rmismatches=3 (rmm) Maximum allowed mismatches in a repeat pair. |
| 57 | minspacer=14 Ignore spacers shorter than this. |
| 58 | maxspacer=60 Ignore spacers longer than this. |
| 59 | minrepeat=20 Ignore repeats shorter than this. |
| 60 | maxrepeat=54 Ignore repeats longer than this. |
| 61 | minrgc=0.09 Ignore repeats with GC below this. |
| 62 | maxrgc=0.89 Ignore repeats with GC above this. |
| 63 | grow=t Extend repeats through mismatches, if rmm>0. Increases the |
| 64 | number of unique repeats, and decreases unique spacers. |
| 65 | lookahead=5 Minimum subsequent matches to extend through a mismatch. |
| 66 | |
| 67 | Reference Parameters: |
| 68 | ref=<file> If a reference of known CRISPR repeats is supplied, all |
| 69 | detected repeates will be aligned to it, using the best match |
| 70 | to override the predicted repeat boundaries. Subsequent |
| 71 | parameters in this section have no effect without a ref. |
| 72 | outref=<file> Output the reference sequences used, annotated to indicate |
| 73 | the number of uses and palindrome position. |
| 74 | kref=13 Kmer length for selecting ref sequences to attempt align. |
| 75 | Lower is more sensitive but can take exponentially longer. |
| 76 | 'k' will set both krepeat and kref to the same value. |
| 77 | mmref=1 (maskMiddleRef) Number of bases masked in the middle of the |
| 78 | kmer. 0 is umasked, and more increases mismatch tolerance. |
| 79 | minrefm=18 (minRefMatches) Reject alignments with fewer matching bases. |
| 80 | refmm=5 (refMismatches) Reject alignments with more mismatches. |
| 81 | refmmf=0.2 (refmismatchfraction) Allowed mismatches will be the maximum |
| 82 | of refmm and refmmf*length. |
| 83 | minrefc=0 (minRefCount) Only load reference sequences with a count |
| 84 | of at least this. Intended for repeats generated via the |
| 85 | 'outr' flag, whose headers have a 'count=x' term indicating |
| 86 | how many times that exact repeat was encountered. Small |
| 87 | numbers can be slow with large references. |
| 88 | discardaf=t (discardAlignmentFailures) When the best alignment for a |
| 89 | repeat fails repeat thresholds like minspacer, minrepeat, or |
| 90 | rmismatches, discard that repeat. |
| 91 | shrinkaf=f Trim mismatches from the ends of alignment failures. |
| 92 | revertaf=f Revert alignment failures to their pre-alignment borders. |
| 93 | discardua=f (discardUnaligned) Discard repeats that do not align to any |
| 94 | ref repeats. This means they did not meet minrefm/maxrefmm. |
| 95 | minrepeat0=11 Allow repeats this short prior to alignment (discarded unless |
| 96 | they lengthen). Has no impact if below kref or krepeat. |
| 97 | sortref=auto Sort alignment candidates by count, then length. May be set |
| 98 | to t/f/auto. When set to auto, sequences will be sorted only |
| 99 | if counts are present. |
| 100 | doublefetch=t (ff) Fetch ref sequences using kmers from both repeat copies. |
| 101 | Increases sensitivity in the presence of mismatches. |
| 102 | doublealign=t (aa) Align ref sequences to both ref repeat copies. |
| 103 | |
| 104 | Consensus Parameters: |
| 105 | consensus=t When 3+ nearby repeat copies are found, adjust the boundaries |
| 106 | so that all are identical. |
| 107 | minoverlapconsensus=18 Only try consensus on repeats that overlap at least |
| 108 | this much. |
| 109 | maxtrimconsensus=5 Do not trim more than this many bases on each end. |
| 110 | |
| 111 | Partial Repeat Parameters: |
| 112 | bruteforce=t Look for partial or inexact repeats adjacent to detected |
| 113 | repeats. These can improve consensus. |
| 114 | mintailrepeat=9 (mtr) Minimum length of partial repeats on read tips. |
| 115 | rmmt=1 Maximum allowed mismatches in short repeats at read tips. |
| 116 | rmmtpad=3 Ignore this many extra leading mismatches when looking |
| 117 | for tip repeats (they will be trimmed later). |
| 118 | |
| 119 | Palindrome Parameters: |
| 120 | minpal=5 If greater than 0, each repeat will be scanned for its |
| 121 | longest palindrome of at least this length (just the |
| 122 | palindrome sequence, excluding the loop or tail). |
| 123 | Palindromes will be annotated alongside repeats. |
| 124 | pmatches=4 Minimum number of matches in a palindrome. |
| 125 | pmismatches=2 Maximum allowed mismatches in a palindrome. |
| 126 | minloop=3 Ignore palindromes with a loop shorter than this. |
| 127 | maxloop=26 Ignore palindromes with a loop longer than this. |
| 128 | mintail=0 Ignore palindromes with a tail shorter than this. |
| 129 | maxtail=24 Ignore palindromes with a tail longer than this. |
| 130 | maxtaildif=21 Ignore palindromes with a tail length difference greater |
| 131 | than this. |
| 132 | reqpal=f Discard repeats that lack a suitable palindrome. |
| 133 | symmetric=f Trim repeats to make them symmetric around the palindrome. |
| 134 | Not recommended. |
| 135 | |
| 136 | Java Parameters: |
| 137 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 138 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will |
| 139 | specify 200 megs. The max is typically 85% of physical memory. |
| 140 | -eoom This flag will cause the process to exit if an out-of-memory |
| 141 | exception occurs. Requires Java 8u92+. |
| 142 | -da Disable assertions. |
| 143 | |
| 144 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 145 | " |
| 146 | } |
| 147 | |
| 148 | #This block allows symlinked shellscripts to correctly set classpath. |
| 149 | pushd . > /dev/null |
| 150 | DIR="${BASH_SOURCE[0]}" |
| 151 | while [ -h "$DIR" ]; do |
| 152 | cd "$(dirname "$DIR")" |
| 153 | DIR="$(readlink "$(basename "$DIR")")" |
| 154 | done |
| 155 | cd "$(dirname "$DIR")" |
| 156 | DIR="$(pwd)/" |
| 157 | popd > /dev/null |
| 158 | |
| 159 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 160 | CP="$DIR""current/" |
| 161 | |
| 162 | z="-Xmx2g" |
| 163 | #z2="-Xms2g" |
| 164 | set=0 |
| 165 | |
| 166 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 167 | usage |
| 168 | exit |
| 169 | fi |
| 170 | |
| 171 | calcXmx () { |
| 172 | source "$DIR""/calcmem.sh" |
| 173 | setEnvironment |
| 174 | parseXmx "$@" |
| 175 | } |
| 176 | calcXmx "$@" |
| 177 | |
| 178 | crisprfinder() { |
| 179 | local CMD="java $SIMD $EA $EOOM $z -cp $CP jgi.CrisprFinder $@" |
| 180 | echo $CMD >&2 |
| 181 | eval $CMD |
| 182 | } |
| 183 | |
| 184 | crisprfinder "$@" |