Debian Codegraph @

pipelines/assemblyPipeline.sh

raw symbols SCIP
1 #!/bin/bash
2 set -e
3
4 #Written by Brian Bushnell
5 #Last updated March 4, 2019
6
7 #This script is designed to preprocess data for assembly of overlapping 2x150bp reads from Illumina HiSeq 2500.
8 #Some numbers and steps may need adjustment for different data types or file paths.
9 #For large genomes, tadpole and bbmerge (during the "Merge" phase) may need the flag "prefilter=2" to avoid running out of memory.
10 #"prefilter" makes these take twice as long though so don't use it if you have enough memory.
11 #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,
12 #without affecting the input file name of the next stage.
13
14
15 # --- Setup ---
16
17 #Load dependencies.
18 #These module load commands are for Genepool; getting the correct executables in your path will vary by system.
19 if [[ $NERSC_HOST == genepool ]]; then
20 #module load bbtools
21 module load spades/3.9.0
22 module load megahit
23 module load pigz
24 module load quast
25 elif [[ $NERSC_HOST == denovo ]]; then
26 #TODO
27 elif [[ $NERSC_HOST == cori ]]; then
28 #TODO
29 fi
30
31
32 #Link the interleaved input file as "temp.fq.gz"
33 rm temp.fq.gz; ln -s reads.fq.gz temp.fq.gz
34
35 # --- Preprocessing ---
36
37 #Remove optical duplicates
38 clumpify.sh in=temp.fq.gz out=clumped.fq.gz dedupe optical
39 rm temp.fq.gz; ln -s clumped.fq.gz temp.fq.gz
40
41 #Remove low-quality regions
42 filterbytile.sh in=temp.fq.gz out=filtered_by_tile.fq.gz
43 rm temp.fq.gz; ln -s filtered_by_tile.fq.gz temp.fq.gz
44
45 #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".
46 bbduk.sh in=temp.fq.gz out=trimmed.fq.gz ktrim=r k=23 mink=11 hdist=1 tbo tpe minlen=70 ref=adapters ftm=5 ordered
47 rm temp.fq.gz; ln -s trimmed.fq.gz temp.fq.gz
48
49 #Remove synthetic artifacts and spike-ins by kmer-matching.
50 bbduk.sh in=temp.fq.gz out=filtered.fq.gz k=31 ref=artifacts,phix ordered cardinality
51 rm temp.fq.gz; ln -s filtered.fq.gz temp.fq.gz
52
53 #Decontamination by mapping can be done here.
54 #JGI removes these in two phases:
55 #1) common microbial contaminants (E.coli, Pseudomonas, Delftia, others)
56 #2) common animal contaminants (Human, cat, dog, mouse)
57
58 #Error-correct phase 1
59 bbmerge.sh in=temp.fq.gz out=ecco.fq.gz ecco mix vstrict ordered ihist=ihist_merge1.txt
60 rm temp.fq.gz; ln -s ecco.fq.gz temp.fq.gz
61
62 #Error-correct phase 2
63 clumpify.sh in=temp.fq.gz out=eccc.fq.gz ecc passes=4 reorder
64 rm temp.fq.gz; ln -s eccc.fq.gz temp.fq.gz
65
66 #Error-correct phase 3
67 #Low-depth reads can be discarded here with the "tossjunk", "tossdepth", or "tossuncorrectable" flags.
68 #For very large datasets, "prefilter=1" or "prefilter=2" can be added to conserve memory.
69 #Alternatively, bbcms.sh can be used if Tadpole still runs out of memory.
70 tadpole.sh in=temp.fq.gz out=ecct.fq.gz ecc k=62 ordered
71 rm temp.fq.gz; ln -s ecct.fq.gz temp.fq.gz
72
73 #Normalize
74 #This phase can be very beneficial for data with uneven coverage like metagenomes, MDA-amplified single cells, and RNA-seq, but is not usually recommended for isolate DNA.
75 #So normally, this stage should be commented out, as it is here.
76 #bbnorm.sh in=temp.fq.gz out=normalized.fq.gz target=100 hist=khist.txt peaks=peaks.txt
77 #rm temp.fq.gz; ln -s normalized.fq.gz temp.fq.gz
78
79 #Merge
80 #This phase handles overlapping reads,
81 #and also nonoverlapping reads, if there is sufficient coverage and sufficiently short inter-read gaps
82 #For very large datasets, "prefilter=1" or "prefilter=2" can be added to conserve memory.
83 bbmerge-auto.sh in=temp.fq.gz out=merged.fq.gz outu=unmerged.fq.gz strict k=93 extend2=80 rem ordered ihist=ihist_merge.txt
84
85 #Quality-trim the unmerged reads.
86 bbduk.sh in=unmerged.fq.gz out=qtrimmed.fq.gz qtrim=r trimq=10 minlen=70 ordered
87
88 # --- Assembly ---
89
90 #You do not need to assemble with all assemblers, but I have listed the commands for the 3 I use most often
91
92 #Assemble with Tadpole
93 #For very large datasets, "prefilter=1" or "prefilter=2" can be added to conserve memory.
94 tadpole.sh in=merged.fq.gz,qtrimmed.fq.gz out=tadpole_contigs.fa k=124
95
96 #Or assemble with TadWrapper (which automatically finds the best value of K but takes longer)
97 tadwrapper.sh in=merged.fq.gz,qtrimmed.fq.gz out=tadwrapper_contigs_%.fa outfinal=tadwrapper_contigs k=40,124,217 bisect
98
99 #Assemble with Spades
100 spades.py -k 25,55,95,125 --phred-offset 33 -s merged.fq.gz --12 qtrimmed.fq.gz -o spades_out
101
102 #Assemble with Megahit
103 #Note that the above error correction phases tend to not be beneficial for Megahit
104 megahit --k-min 45 --k-max 225 --k-step 26 --min-count 2 -r merged.fq.gz --12 qtrimmed.fq.gz -o megahit_out
105
106 # --- Evaluation ---
107
108 #Evaluate assemblies with AssemblyStats
109 statswrapper.sh contigs.fa spades_out/scaffolds.fasta megahit_out/contigs.fa format=3 out=
110
111 #Evaluate assemblies with Quast (leave out "-R ref.fa if you don't have a reference)
112 quast.py -f -o quast -R ref.fa tadpole_contigs.fa spades_out/scaffolds.fasta megahit_out/contigs.fa
113
114 #Pick which assembly you like best
115
116 #Determine the overall taxonomic makeup of the assembly
117 sendsketch.sh in=tadpole_contigs.fa
118
119 #Or, try to determine taxonomy on a per-contig basis. If this is not sensitive enough, try BLAST instead.
120 sendsketch.sh in=tadpole_contigs.fa persequence minhits=1 records=4
121
122 #Calculate the coverage distribution, and capture reads that did not make it into the assembly
123 bbmap.sh in=filtered.fq.gz ref=tadpole_contigs.fa nodisk covhist=covhist.txt covstats=covstats.txt outm=assembled.fq.gz outu=unassembled.fq.gz maxindel=200 minid=90 qtrim=10 untrim ambig=all
124