| 1 | #!/bin/bash |
| 2 | |
| 3 | ## Written by Brian Bushnell |
| 4 | ## Last modified May 21, 2020 |
| 5 | ## Description: Creates a recalibration matrix for Illumina data. |
| 6 | |
| 7 | ## Usage: recal.sh <prefix> |
| 8 | ## For example, "recal.sh Sample1" if the data is in Sample1.fq.gz |
| 9 | |
| 10 | ## This script creates quality-score recalibration matrices for processing Illumina PE reads. |
| 11 | ## It needs to be run ONCE on a single library (preferably a large one) from a sequencing run. |
| 12 | ## Then the primary script will use the recalibration matrices for all of the libraries, |
| 13 | ## assuming all the processing is done in the same directory. |
| 14 | ## This script assumes input data is single-ended or paired and interleaved. |
| 15 | ## If data is paired in twin files, you can run "reformat.sh in1=r1.fq.gz in2=r2.fq.gz out=both.fq.gz" to interleave it. |
| 16 | |
| 17 | |
| 18 | ## Grab the sample name from the command line |
| 19 | NAME="$1" |
| 20 | |
| 21 | ## Set this to read length |
| 22 | READLEN=150 |
| 23 | |
| 24 | ## Specify the viral reference file. |
| 25 | ## NC_045512.fasta contains the SARS-CoV-2 genome, equivalent to bbmap/resources/Covid19_ref.fa |
| 26 | REF="NC_045512.fasta" |
| 27 | |
| 28 | ## Discover adapter sequence for this library based on read overlap. |
| 29 | ## This step should be skipped for single-ended reads. |
| 30 | bbmerge.sh in="$NAME".fq.gz outa="$NAME"_adapters.fa ow reads=1m |
| 31 | |
| 32 | ## Adapter-trim and discard everything with adapter sequence so the reads are uniform length. |
| 33 | bbduk.sh -Xmx1g in="$NAME".fq.gz out=recal.fq.gz minlen="$READLEN" ktrim=r k=21 mink=9 hdist=2 hdist2=1 ref="$NAME"_adapters.fa altref=adapters ow tbo tpe |
| 34 | |
| 35 | ## Note - if the reads are single-ended, use this command instead: |
| 36 | #bbduk.sh -Xmx1g in="$NAME".fq.gz out=trimmed.fq.gz minlen="$READLEN" ktrim=r k=21 mink=9 hdist=2 hdist2=1 ref=adapters ow |
| 37 | |
| 38 | ## Map the reads with very high sensitivity. |
| 39 | bbmap.sh ref="$REF" in=recal.fq.gz outm=mapped.sam.gz vslow -Xmx6g ow |
| 40 | |
| 41 | ## Discover true variants. |
| 42 | callvariants.sh in=mapped.sam.gz ref="$REF" out=recal.vcf -Xmx6g ow |
| 43 | |
| 44 | ## Generate recalibration matrices. |
| 45 | callvariants.sh in=mapped.sam.gz ref="$REF" out=recal.vcf -Xmx6g ow usebias=f strandedcov minstrandratio=0 |
| 46 | |
| 47 | ## Now the recalibration matrices are stored in ./ref |
| 48 | ## BBDuk can be run with the 'recal' flag to recalibrate data (mapped or unmapped). |
| 49 | ## It should be run from the directory containing /ref |