| 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | #Written by Brian Bushnell |
| 5 | #Last updated September 20, 2023 |
| 6 | |
| 7 | #This script is designed to preprocess data for CRISPR detection in Illumina 2x150bp libraries. |
| 8 | #The "rm temp.fq.gz; ln -s reads.fq.gz temp.fq.gz" is not necessary but added so that any pipeline stage can be easily disabled, |
| 9 | #without affecting the input file name of the next stage. |
| 10 | |
| 11 | |
| 12 | # --- Setup --- |
| 13 | |
| 14 | #Link the interleaved input file as "temp.fq.gz" |
| 15 | #rm temp.fq.gz #Only if already present |
| 16 | ln -s reads.fq.gz temp.fq.gz |
| 17 | |
| 18 | # --- Preprocessing (for raw data only) --- |
| 19 | |
| 20 | #Remove reads from low-quality regions of the flowcell |
| 21 | filterbytile.sh in=temp.fq.gz out=filtered_by_tile.fq.gz |
| 22 | rm temp.fq.gz; ln -s filtered_by_tile.fq.gz temp.fq.gz |
| 23 | |
| 24 | #Trim adapters. Optionally, reads with Ns can be discarded by adding "maxns=0" and reads with really low average quality can be discarded with "maq=8". |
| 25 | bbduk.sh in=temp.fq.gz out=trimmed.fq.gz ktrim=r k=23 mink=11 hdist=1 tbo tpe minlen=90 ref=adapters ftm=5 |
| 26 | rm temp.fq.gz; ln -s trimmed.fq.gz temp.fq.gz |
| 27 | |
| 28 | #Remove synthetic artifacts and spike-ins by kmer-matching. |
| 29 | bbduk.sh in=temp.fq.gz out=filtered.fq.gz k=31 ref=artifacts,phix cardinality |
| 30 | rm temp.fq.gz; ln -s filtered.fq.gz temp.fq.gz |
| 31 | |
| 32 | #It would be nice to do quality-score correction here but that requires a reference so we will skip it. |
| 33 | |
| 34 | # --- Merging and Error Correction --- |
| 35 | |
| 36 | #Merge the reads first since they will be merged at some point anyway. 'mix' puts the merged and unmerged reads in the same file. |
| 37 | bbmerge.sh in=temp.fq.gz out=merged.fq.gz mix strict |
| 38 | rm temp.fq.gz; ln -s merged.fq.gz temp.fq.gz |
| 39 | |
| 40 | #Error-correct phase 1. Note the int=f flag because the file is no longer interleaved. |
| 41 | #This is optional but seems safe and effective. |
| 42 | clumpify.sh in=temp.fq.gz int=f out=eccc.fq.gz ecc conservative passes=9 |
| 43 | rm temp.fq.gz; ln -s eccc.fq.gz temp.fq.gz |
| 44 | |
| 45 | #Error-correct phase 2 |
| 46 | #If this runs out of memory just skip it. |
| 47 | #This is optional but seems safe and effective. |
| 48 | tadpole.sh in=temp.fq.gz int=f out=ecct.fq.gz ecc k=72 conservative |
| 49 | rm temp.fq.gz; ln -s ecct.fq.gz temp.fq.gz |
| 50 | |
| 51 | # --- CRISPR-Finding --- |
| 52 | |
| 53 | #With a reference of known repeats: |
| 54 | bbcrisprfinder.sh in=temp.fq.gz int=f outc=crisprs.fq outr=repeats.fa outs=spacers.fa chist=chist.txt phist=phist.txt ref=knownRepeats.fa outref=uses.fa |
| 55 | |
| 56 | #- or - |
| 57 | |
| 58 | #With no reference: |
| 59 | bbcrisprfinder.sh in=temp.fq.gz int=f outc=crisprs.fq outr=repeats.fa outs=spacers.fa chist=chist.txt phist=phist.txt ow |
| 60 | |
| 61 | |
| 62 | #In either case, you can subsequently run additional passes using output from the first pass to refine the results. |
| 63 | #Without a reference, 3 total passes are advised (including the initial pass); with a reference, 1 or 2 total passes are advised. |
| 64 | #Here, mincount=3 will restrict the tool to use repeats encountered at least 3 times in the first pass as references, |
| 65 | #to prevent polluting the reference pool with spurious repeats. In practice, lower seems better (even 1 is fine), |
| 66 | #but it can become much slower for pass 2 if mincount is set low. |
| 67 | |
| 68 | bbcrisprfinder.sh in=temp.fq.gz int=f outc=crisprs2.fq outr=repeats2.fa outs=spacers2.fa chist=chist2.txt phist=phist2.txt ref=repeats.fa mincount=3 |
| 69 | bbcrisprfinder.sh in=temp.fq.gz int=f outc=crisprs3.fq outr=repeats3.fa outs=spacers3.fa chist=chist3.txt phist=phist3.txt ref=repeats2.fa mincount=3 |