| 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | #Written by Brian Bushnell |
| 5 | #Last updated February 21, 2018 |
| 6 | |
| 7 | #This script is designed to evaluate the quality of a new Illumina platform such as NovaSeq. |
| 8 | #Input is assumed to be interleaved and paired. |
| 9 | #This is just an example of a P.heparinus library. |
| 10 | |
| 11 | |
| 12 | #If necessary, first demultiplex by barcodes. |
| 13 | #demuxbyname.sh in=all.fq.gz delimiter=space suffixmode out=%.fq.gz |
| 14 | |
| 15 | #Link input files |
| 16 | ln -s reads.fq.gz raw.fq.gz |
| 17 | ln -s P.heparinus.fa ref.fa |
| 18 | |
| 19 | #Remove PhiX, unless that is the intended organism. |
| 20 | #PhiX interferes with adapter sequence detection since it uses different adapters. |
| 21 | bbduk.sh -Xmx1g in=raw.fq.gz out=filtered.fq.gz ref=phix k=31 |
| 22 | |
| 23 | #Optionally determine actual adapter sequence |
| 24 | #This may fail if there are not enough overlapping reads. |
| 25 | bbmerge.sh in=filtered.fq.gz outa=adapters.fa reads=1m strict |
| 26 | |
| 27 | #Trim adapters |
| 28 | #"ref=adapters" will use BBMap's default set of adapters. |
| 29 | #You can alternately use the custom adapters discovered above, if the file contents look reasonable (you may want to trim a trailing poly-A or poly-C). |
| 30 | bbduk.sh -Xmx1g in=filtered.fq.gz out=trimmed.fq.gz ref=adapters k=23 mink=11 tbo tpe ktrim=r ow |
| 31 | |
| 32 | #Map to reference |
| 33 | #A reference can be constructed with Tadpole if none is available |
| 34 | bbmap.sh -Xmx8g in=trimmed.fq.gz ref=ref.fa maxindel=2000 slow out=mapped.sam.gz covstats=covstats.txt covhist=covhist.txt 32bit bhist=bhist.txt qhist=qhist.txt aqhist=aqhist.txt bqhist=bqhist.txt lhist=lhist.txt ihist=ihist.txt ehist=ehist.txt qahist=qahist.txt indelhist=indelhist.txt mhist=mhist.txt gchist=gchist.txt idhist=idhist.txt delcov=f ow unpigz=t pigz=t zl=6 |
| 35 | |
| 36 | #Calculate duplicate rates, both optical and full |
| 37 | #You may need remove groups=1 if you don't have enough memory. |
| 38 | #For fair comparisons, it may be useful to subsample to a fixed number of reads or use the first X reads in a file when calculating dupe rates. |
| 39 | #These approaches give different results. Using the "First X reads" is important for detecting optical and tile-edge duplicates. |
| 40 | clumpify.sh groups=1 in=trimmed.fq.gz dedupe 1>dedupe_normal.o 2>&1 |
| 41 | clumpify.sh groups=1 in=trimmed.fq.gz dedupe optical dist=12k 1>dedupe_optical.o 2>&1 |
| 42 | |
| 43 | #Call variants |
| 44 | callvariants.sh in=mapped.sam.gz ref=ref.fa out=vars.txt vcf=vars.vcf ploidy=1 -Xmx8g ow |
| 45 | |
| 46 | #Generate calibration matrices |
| 47 | calctruequality.sh in=mapped.sam.gz vcf=vars.vcf -Xmx8g |
| 48 | |
| 49 | #Recalibrate quality scores |
| 50 | bbduk.sh ow in=mapped.sam.gz out=recal.sam.gz recalibrate -Xmx8g ow |
| 51 | |
| 52 | #Generate quality statistics ignoring real variants |
| 53 | bbduk.sh ow in=mapped.sam.gz bhist=bhist.txt qhist=qhist.txt aqhist=aqhist.txt bqhist=bqhist.txt ehist=ehist.txt qahist=qahist.txt indelhist=indelhist.txt mhist=mhist.txt idhist=idhist.txt -Xmx8g vcf=vars.vcf ow |
| 54 | |
| 55 | #Generate recalibrated statistics to see if recalibration can generate correct quality scores |
| 56 | bbduk.sh ow in=recal.sam.gz qhist=qhist2.txt aqhist=aqhist2.txt bqhist=bqhist2.txt qahist=qahist2.txt mhist=mhist2.txt idhist=idhist2.txt -Xmx8g vcf=vars.vcf ow |
| 57 | |
| 58 | #See what is in the library |
| 59 | #You can iterate a few times by pulling out the primary organisms with BBDuk then rerunning SendSketch |
| 60 | sendsketch.sh in=trimmed.fq.gz reads=500k |
| 61 | |
| 62 | #Map the reads to various references you found to see how much contamination there is. |
| 63 | seal.sh -Xmx31g in=trimmed.fq.gz ref=all_fused.fa stats=sealstats.txt ambig=toss clearzone=10 ow |
| 64 |