| 1 | #Isolate assembly script for producing poly-G-artifact-free assemblies. |
| 2 | #For Perlmutter |
| 3 | #Version 1.1 |
| 4 | #Brian Bushnell |
| 5 | #October 30, 2024 |
| 6 | |
| 7 | #link dev version |
| 8 | export PATH=$PATH:/global/cfs/cdirs/bbtools/jgi-bbtools/ |
| 9 | |
| 10 | #Link mousecatdoghuman index (this is the Perlmutter location) |
| 11 | MCDH=/global/cfs/cdirs/bbtools/RQCFilterData_Local/mousecatdoghuman/ |
| 12 | |
| 13 | #Link your RAW (not filtered) reads |
| 14 | ln -s path/to/reads raw.fq.gz |
| 15 | |
| 16 | |
| 17 | #Set variables |
| 18 | CORES=64 |
| 19 | ZL=6 |
| 20 | HIGHRAM=31g |
| 21 | #MAXRAM here is for login nodes; scheduled jobs should set this to 85% of physical memory requested |
| 22 | MAXRAM=48g |
| 23 | |
| 24 | ARGS="t=$CORES zl=$ZL ow" |
| 25 | |
| 26 | #Max memory commands |
| 27 | MAX="-Xmx$MAXRAM" |
| 28 | |
| 29 | #High memory commands |
| 30 | HIGH="-Xmx$HIGHRAM" |
| 31 | |
| 32 | #Low memory commands |
| 33 | LOW="-Xmx4g" |
| 34 | |
| 35 | |
| 36 | #Find adapter sequence |
| 37 | bbmerge.sh "$LOW" "$ARGS" in=raw.fq.gz outa=adapters.fa |
| 38 | |
| 39 | #Trim adapters |
| 40 | bbduk.sh "$LOW" "$ARGS" in=raw.fq.gz out=raw_trimmed.fq.gz tbo tpe hdist=2 k=23 mink=9 hdist2=1 ref=adapters.fa minlen=135 ktrim=r |
| 41 | |
| 42 | #Deduplicate |
| 43 | clumpify.sh "$MAX" "$ARGS" in=raw_trimmed.fq.gz out=deduped.fq.gz passes=4 groups=1 dedupe optical dist=50 |
| 44 | |
| 45 | #Filter artifacts |
| 46 | bbduk.sh "$LOW" "$ARGS" ref=artifacts,phix literal=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA in=deduped.fq.gz k=31 hdist=1 out=filtered.fq.gz |
| 47 | |
| 48 | #Filter human |
| 49 | bbsplit.sh "$MAX" "$ARGS" deterministic ordered=false k=14 usemodulo printunmappedcount kfilter=25 maxsites=1 tipsearch=0 minratio=.9 maxindel=3 minhits=2 bw=12 bwr=0.16 fast maxsites2=10 build=1 ef=0.03 bloomfilter bloomk=29 bloomhashes=1 bloomminhits=6 bloomserial path="$MCDH" refstats=refStats.txt forcereadonly in=filtered.fq.gz out=clean.fq.gz outm=human.fq.gz |
| 50 | |
| 51 | #Filter microbes: Disabled due to potential false positives |
| 52 | ###bbmap.sh "$HIGH" "$ARGS" deterministic quickmatch k=13 idtag=t printunmappedcount qtrim=rl trimq=10 untrim ef=0.001 path=/global/cfs/cdirs/bbtools/RQCFilterData_Local/commonMicrobes/ pigz=t unpigz=t "$ZL" minid=.95 idfilter=.95 maxindel=3 minhits=2 bw=12 bwr=0.16 fast=true maxsites2=10 build=1 tipsearch=0 in=filtered.fq.gz out=nonmicrobe.fq.gz outm=microbes.fq.gz scafstats=commonMicrobes.txt |
| 53 | |
| 54 | #make quick assembly |
| 55 | tadpole.sh "$HIGH" "$ARGS" in=clean.fq.gz out=qecc.fq.gz k=62 merge wash ecc tossjunk tu ldf=0.4 tossdepth=1 aecc |
| 56 | tadpole.sh "$HIGH" "$ARGS" in=qecc.fq.gz out=quick.fa k=124 mcs=5 mce=4 merge |
| 57 | |
| 58 | #map trimmed reads to quick assembly |
| 59 | bbmap.sh "$HIGH" "$ARGS" in=clean.fq.gz out=clean.sam.gz vslow maxindel=40 ref=quick.fa |
| 60 | |
| 61 | #Make recal matrices |
| 62 | calctruequality.sh "$HIGH" "$ARGS" in=clean.sam.gz usetiles ref=quick.fa callvars |
| 63 | |
| 64 | #Recalibrate quality |
| 65 | bbduk.sh "$LOW" "$ARGS" in=clean.fq.gz out=clean_recal_tile.fq.gz recalibrate usetiles |
| 66 | |
| 67 | #Filter low-quality flowcell areas |
| 68 | filterbytile.sh "$HIGH" "$ARGS" in=clean_recal_tile.fq.gz out=fbt_recal_tile.fq.gz lowqualityonly=t |
| 69 | |
| 70 | #Primary poly-G filter |
| 71 | polyfilter.sh "$HIGH" "$ARGS" in=fbt_recal_tile.fq.gz out=polyfilter_fbt_recal_tile.fq.gz |
| 72 | |
| 73 | #Trim residual poly-G reads; no longer needed since polyfilter does trimming and kmer matching now. |
| 74 | #bbduk.sh "$LOW" "$ARGS" in=polyfilter_fbt_recal_tile.fq.gz trimpolyg=6 trimpolyc=6 maxnonpoly=2 minlen=135 literal=GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG k=29 hdist=2 out=hdist2.fq.gz |
| 75 | |
| 76 | |
| 77 | #Poly-G removal and other generic steps are above this line |
| 78 | #---------------------------------------------------------- |
| 79 | #Isolate-assembly-specific preprocessing is below this line |
| 80 | |
| 81 | |
| 82 | #Error-correct phase 1 |
| 83 | bbmerge.sh "$HIGH" "$ARGS" in=hdist2.fq.gz out=ecco.fq.gz ecco mix adapters=adapters.fa kfilter=1 k=31 |
| 84 | |
| 85 | #Error-correct phase 3; note k has to be less than half of read length here |
| 86 | tadpole.sh "$HIGH" "$ARGS" in=ecco.fq.gz out=ecct.fq.gz ecc k=62 wash tu tossdepth=1 ldf=0.15 |
| 87 | |
| 88 | #Read merging pass 1 |
| 89 | bbmerge.sh "$HIGH" "$ARGS" in=ecct.fq.gz outm=merged0.fq.gz outu=unmerged0.fq.gz kfilter=1 adapters=adapters.fa |
| 90 | |
| 91 | #Read merging with kmer extension |
| 92 | bbmerge.sh "$HIGH" "$ARGS" in=unmerged0.fq.gz extra=merged0.fq.gz out=merged_rem.fq.gz outu=unmerged_rem.fq.gz rem k=124 extend2=120 |
| 93 | bbmerge.sh "$HIGH" "$ARGS" in=unmerged_rem.fq.gz extra=merged0.fq.gz,merged_rem.fq.gz out=merged_rem2.fq.gz outu=unmerged_rem2.fq.gz rem k=145 extend2=140 |
| 94 | bbmerge.sh "$HIGH" "$ARGS" in=unmerged_rem2.fq.gz extra=merged0.fq.gz,merged_rem.fq.gz,merged_rem2.fq.gz out=merged_rem3.fq.gz outu=unmerged_rem3.fq.gz rem k=93 extend2=100 strict |
| 95 | |
| 96 | #Combine merged read files |
| 97 | zcat merged0.fq.gz merged_rem.fq.gz merged_rem2.fq.gz merged_rem3.fq.gz | reformat.sh "$LOW" "$ARGS" in=stdin.fq int=f out=merged_both.fq.gz |
| 98 | |
| 99 | #Q-trim unmerged reads |
| 100 | bbduk.sh "$LOW" "$ARGS" in=unmerged_rem3.fq.gz out=qtrimmed.fq.gz qtrim=r trimq=15 cardinality cardinalityout maq=14 minlen=90 ftr=149 maxns=1 |
| 101 | |
| 102 | #Extend reads |
| 103 | tadpole.sh "$HIGH" "$ARGS" in=merged_both.fq.gz extra=qtrimmed.fq.gz out=merged_ext1.fq.gz mode=extend mce=4 er=10 el=10 k=145 |
| 104 | tadpole.sh "$HIGH" "$ARGS" in=qtrimmed.fq.gz extra=merged_both.fq.gz out=unmerged_ext1.fq.gz mode=extend mce=4 el=10 k=124 |
| 105 | |
| 106 | #Assemble with Spades |
| 107 | shifter --image=staphb/spades:4.0.0 spades.py -t "$CORES" -k 25,55,95,127 --phred-offset 33 --only-assembler --isolate --pe-m 1 merged_ext1.fq.gz --pe-12 1 unmerged_ext1.fq.gz -o spades_out 1>spades.o 2>&1 |
| 108 | |
| 109 | #Test for residual poly-G contam |
| 110 | bbduk.sh "$LOW" "$ARGS" in=spades_out/contigs.fasta literal=GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG hdist=2 k=25 |
| 111 | |
| 112 | #Test contiguity |
| 113 | stats.sh in=spades_out/contigs.fasta |
| 114 |