Debian Codegraph @

rqcfilter2.sh

raw symbols SCIP
1 #!/bin/bash
2
3 usage(){
4 echo "
5 Written by Brian Bushnell
6 Last modified September 20, 2024
7
8 Description: RQCFilter2 is a revised version of RQCFilter that uses a common path for all dependencies.
9 The dependencies are available at http://portal.nersc.gov/dna/microbial/assembly/bushnell/RQCFilterData.tar
10
11 Performs quality-trimming, artifact removal, linker-trimming, adapter trimming, and spike-in removal using BBDuk.
12 Performs human/cat/dog/mouse/microbe removal using BBMap.
13 It requires 40 GB RAM for mousecatdoghuman, but only 1GB or so without them.
14
15 Usage: rqcfilter2.sh in=<input file> path=<output directory> rqcfilterdata=<path to RQCFilterData directory>
16
17 Primary I/O parameters:
18 in=<file> Input reads.
19 in2=<file> Use this if 2nd read of pairs are in a different file.
20 path=null Set to the directory to use for all output files.
21
22 Reference file paths:
23 rqcfilterdata= Path to unzipped RQCFilterData directory. Default is /global/projectb/sandbox/gaag/bbtools/RQCFilterData
24 ref=<file,file> Comma-delimited list of additional reference files for filtering via BBDuk.
25
26 Output parameters:
27 scafstats=scaffoldStats.txt Scaffold stats file name (how many reads matched which reference scaffold) .
28 kmerstats=kmerStats.txt Kmer stats file name (duk-like output).
29 log=status.log Progress log file name.
30 filelist=file-list.txt List of output files.
31 stats=filterStats.txt Overall stats file name.
32 stats2=filterStats2.txt Better overall stats file name.
33 ihist=ihist_merge.txt Insert size histogram name. Set to null to skip merging.
34 outribo=ribo.fq.gz Output for ribosomal reads, if removeribo=t.
35 reproduceName=reproduce.sh Name of shellscript to reproduce these results.
36 usetmpdir=t Write temp files to TMPDIR.
37 tmpdir= Override TMPDIR.
38
39 Adapter trimming parameters:
40 trimhdist=1 Hamming distance used for trimming.
41 trimhdist2= Hamming distance used for trimming with short kmers. If unset, trimhdist will be used.
42 trimk=23 Kmer length for trimming stage.
43 mink=11 Minimum kmer length for short kmers when trimming.
44 trimfragadapter=t Trim all known Illumina adapter sequences, including TruSeq and Nextera.
45 trimrnaadapter=f Trim Illumina TruSeq-RNA adapters.
46 bisulfite=f Currently, this trims the last 1bp from all reads after the adapter-trimming phase.
47 findadapters=t For paired-end files, attempt to discover the adapter sequence with BBMerge and use that rather than a set of known adapters.
48 swift=f Trim Swift sequences: Trailing C/T/N R1, leading G/A/N R2.
49
50 Quality trimming parameters:
51 qtrim=f Trim read ends to remove bases with quality below minq. Performed AFTER looking for kmers.
52 Values: rl (trim both ends), f (neither end), r (right end only), l (left end only).
53 trimq=10 Trim quality threshold. Must also set qtrim for direction.
54 minlength=45 (ml) Reads shorter than this after trimming will be discarded. Pairs will be discarded only if both are shorter.
55 mlf=0.333 (minlengthfraction) Reads shorter than this fraction of original length after trimming will be discarded.
56 minavgquality=5 (maq) Reads with average quality (before trimming) below this will be discarded.
57 maxns=0 Reads with more Ns than this will be discarded.
58 forcetrimmod=5 (ftm) If positive, right-trim length to be equal to zero, modulo this number.
59 forcetrimleft=-1 (ftl) If positive, trim bases to the left of this position
60 (exclusive, 0-based).
61 forcetrimright=-1 (ftr) If positive, trim bases to the right of this position
62 (exclusive, 0-based).
63 forcetrimright2=-1 (ftr2) If positive, trim this many bases on the right end.
64
65 Mapping parameters (for vertebrate contaminants):
66 mapk=14 Kmer length for mapping stage (9-15; longer is faster).
67 removehuman=f (human) Remove human reads via mapping.
68 keephuman=f Keep reads that map to human (or cat, dog, mouse) rather than removing them.
69 removedog=f (dog) Remove dog reads via mapping.
70 removecat=f (cat) Remove cat reads via mapping.
71 removemouse=f (mouse) Remove mouse reads via mapping.
72 aggressivehuman=f Aggressively remove human reads (and cat/dog/mouse) using unmasked references.
73 aggressivemicrobe=f Aggressively microbial contaminant reads using unmasked references.
74 aggressive=f Set both aggressivehuman and aggressivemicrobe at once.
75 mapref= Remove contaminants by mapping to this fasta file (or comma-delimited list).
76
77 Bloom filter parameters (for vertebrate mapping):
78 bloom=t Use a Bloom filter to accelerate mapping.
79 bloomminreads=4m Disable Bloom filter if there are fewer than this many reads.
80 bloomk=29 Kmer length for Bloom filter
81 bloomhashes=1 Number of hashes for the Bloom filter.
82 bloomminhits=6 Minimum consecutive hits to consider a read as matching.
83 bloomserial=t Use the serialized Bloom filter for greater loading speed.
84 This will use the default Bloom filter parameters.
85
86 Microbial contaminant removal parameters:
87 detectmicrobes=f Detect common microbes, but don't remove them. Use this OR removemicrobes, not both.
88 removemicrobes=f (microbes) Remove common contaminant microbial reads via mapping, and place them in a separate file.
89 taxlist= (tax) Remove these taxa from the database before filtering. Typically, this would be the organism name or NCBI ID, or a comma-delimited list. Organism names should have underscores instead of spaces, such as Escherichia_coli.
90 taxlevel=order (level) Level to remove. For example, 'phylum' would remove everything in the same phylum as entries in the taxlist.
91 taxtree=auto (tree) Override location of the TaxTree file.
92 gitable=auto Override location of the gitable file.
93 loadgitable=f Controls whether gi numbers may be used for taxonomy.
94 microberef= Path to fasta file of microbes.
95 microbebuild=1 Chooses which masking was used. 1 is most stringent and should be used for bacteria. Eukaryotes should use 3.
96
97 Extended microbial contaminant parameters:
98 detectmicrobes2=f (detectothermicrobes) Detect an extended set of microbes that are currently being screened. This can be used in conjunction with removemicrobes.
99
100 Filtering parameters (for artificial and genomic contaminants):
101 skipfilter=f Skip this phase. Not recommended.
102 filterpolya=f Remove reads containing poly-A sequence (for RNA-seq).
103 filterpolyg=0 Remove reads that start with a G polymer at least this long (0 disables).
104 trimpolyg=6 Trim reads that start or end with a G polymer at least this long (0 disables).
105 phix=t Remove reads containing phiX kmers.
106 lambda=f Remove reads containing Lambda phage kmers.
107 pjet=t Remove reads containing PJET kmers.
108 sip=f Remove SIP spikeins.
109 maskmiddle=t (mm) Treat the middle base of a kmer as a wildcard, to increase sensitivity in the presence of errors.
110 maxbadkmers=0 (mbk) Reads with more than this many contaminant kmers will be discarded.
111 filterhdist=1 Hamming distance used for filtering.
112 filterqhdist=1 Query hamming distance used for filtering.
113 copyundefined=f (cu) Match all possible bases for sequences containing degerate IUPAC symbols.
114 entropy=f Remove low-complexity reads. The threshold can be specified by e.g entropy=0.4; default is 0.42 if enabled.
115 entropyk=2 Kmer length to use for entropy calculation.
116 entropywindow=40 Window size to use for entropy calculation.
117
118 Spikein removal/quantification parameters:
119 mtst=f Remove mtst.
120 kapa=t Remove and quantify kapa.
121 spikeink=31 Kmer length for spikein removal.
122 spikeinhdist=0 Hamming distance for spikein removal.
123 spikeinref= Additional references for spikein removal (comma-delimited list).
124
125 Ribosomal filtering parameters:
126 ribohdist=1 Hamming distance used for rRNA removal.
127 riboedist=0 Edit distance used for rRNA removal.
128 removeribo=f (ribo) Remove ribosomal reads via kmer-matching, and place them in a separate file.
129
130 Organelle filtering parameters:
131 chloromap=f Remove chloroplast reads by mapping to this organism's chloroplast.
132 mitomap=f Remove mitochondrial reads by mapping to this organism's mitochondria.
133 ribomap=f Remove ribosomal reads by mapping to this organism's ribosomes.
134 NOTE: organism TaxID should be specified in taxlist, and taxlevel should be set to genus or species.
135
136 FilterByTile parameters:
137 filterbytile=t Run FilterByTile to remove reads from low-quality parts of the flowcell.
138 tiledump= Set this to the tiledump of the full lane (recommended).
139
140 Recalibration parameters:
141 recalibrate=t Recalibrate quality scores based on PhiX alignment.
142 phixsam= Set this to the aligned PhiX data for the lane (required).
143 quantize=2 Quantize the quality scores to reduce file size, using this divisor.
144 2 reduces size by roughly 25%. Disabled if recalibrate=f.
145 Quantization happens AFTER all the quality-related steps.
146
147 Polyfilter parameters:
148 polyfilter=GC Remove reads with homopolymers of these subunits.
149 Set polyfilter=null to disable.
150
151 Clumpify parameters:
152 clumpify=f Run clumpify; all deduplication flags require this.
153 dedupe=f Remove duplicate reads; all deduplication flags require this.
154 opticaldupes=f Remove optical duplicates (Clumpify optical flag).
155 edgedupes=f Remove tile-edge duplicates (Clumpify spany and adjacent flags).
156 dpasses=1 Use this many deduplication passes.
157 dsubs=2 Allow this many substitutions between duplicates.
158 ddist=40 Remove optical/edge duplicates within this distance.
159 lowcomplexity=f Set to true for low-complexity libraries such as RNA-seq to improve estimation of memory requirements.
160 clumpifytmpdir=f Use TMPDIR for clumpify temp files.
161 clumpifygroups=-1 If positive, force Clumpify to use this many groups.
162 *** For NextSeq, the recommended deduplication flags are: clumpify dedupe edgedupes
163 *** For NovaSeq, the recommended deduplication flags are: clumpify dedupe opticaldupes ddist=12000
164 *** For HiSeq, the recommended deduplication flags are: clumpify dedupe opticaldupes
165
166 Sketch parameters:
167 sketch=t Run SendSketch on 2M read pairs.
168 silvalocal=t Use the local flag for Silva (requires running RQCFilter on NERSC).
169 sketchreads=1m Number of read pairs to sketch.
170 sketchsamplerate=1 Samplerate for SendSketch.
171 sketchminprob=0.2 Minprob for SendSketch.
172 sketchdb=nt,refseq,silva Servers to use for SendSketch.
173
174 Other processing parameters:
175 threads=auto (t) Set number of threads to use; default is number of logical processors.
176 library=frag Set to 'frag', 'clip', 'lfpe', or 'clrs'.
177 filterk=31 Kmer length for filtering stage.
178 rcomp=t Look for reverse-complements of kmers in addition to forward kmers.
179 nexteralmp=f Split into different files based on Nextera LMP junction sequence. Only for Nextera LMP, not normal Nextera.
180 extend=f Extend reads during merging to allow insert size estimation of non-overlapping reads.
181 pigz=t Use pigz for compression.
182 unpigz=t Use pigz for decompression.
183 khist=f Set to true to generate a kmer-frequency histogram of the output data.
184 merge=t Set to false to skip generation of insert size histogram.
185
186 Header-specific parameters: (NOTE - Be sure to disable these if the reads have improper headers, like SRA data.)
187 chastityfilter=t Remove reads failing chastity filter.
188 barcodefilter=f Crash when improper barcodes are discovered. Set to 'f' to disable,
189 't' to remove improper barcodes, or 'crash' to crash if they are discovered.
190 barcodes= A comma-delimited list of barcodes or files of barcodes.
191
192 Java Parameters:
193 -Xmx This will set Java's memory usage, overriding autodetection.
194 -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs.
195 The max is typically 85% of physical memory.
196 -eoom This flag will cause the process to exit if an
197 out-of-memory exception occurs. Requires Java 8u92+.
198 -da Disable assertions.
199
200 ***** All additional parameters supported by BBDuk may also be used, and will be passed directly to BBDuk *****
201
202 Please contact Brian Bushnell at [email protected] if you encounter any problems.
203 "
204 }
205
206 #This block allows symlinked shellscripts to correctly set classpath.
207 pushd . > /dev/null
208 DIR="${BASH_SOURCE[0]}"
209 while [ -h "$DIR" ]; do
210 cd "$(dirname "$DIR")"
211 DIR="$(readlink "$(basename "$DIR")")"
212 done
213 cd "$(dirname "$DIR")"
214 DIR="$(pwd)/"
215 popd > /dev/null
216
217 #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
218 CP="$DIR""current/"
219 JNI="-Djava.library.path=""$DIR""jni/"
220 JNI=""
221
222 z="-Xmx40g"
223 z2="-Xms40g"
224 set=0
225 export TZ="America/Los_Angeles"
226
227 if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
228 usage
229 exit
230 fi
231
232 calcXmx () {
233 source "$DIR""/calcmem.sh"
234 setEnvironment
235 parseXmx "$@"
236
237 if [[ $set == 1 ]]; then
238 return
239 fi
240 freeRam 39200m 84
241
242 if [[ $NSLOTS == 8 ]]; then
243 RAM=39200
244 fi
245
246 z="-Xmx${RAM}m"
247 z2="-Xms${RAM}m"
248 }
249
250 calcXmx "$@"
251
252
253 rqcfilter() {
254 if [[ $SHIFTER_RUNTIME == 1 ]]; then
255 #Ignore NERSC_HOST
256 shifter=1
257 elif [[ $NERSC_HOST == genepool ]]; then
258 module unload oracle-jdk
259 module load oracle-jdk/1.8_144_64bit
260 module load pigz
261 export TZ="America/Los_Angeles"
262 elif [[ $NERSC_HOST == denovo ]]; then
263 module unload java
264 module load java/1.8.0_144
265 module load pigz
266 export TZ="America/Los_Angeles"
267 elif [[ $NERSC_HOST == cori ]]; then
268 module use /global/common/software/m342/nersc-builds/denovo/Modules/jgi
269 module use /global/common/software/m342/nersc-builds/denovo/Modules/usg
270 module unload java
271 module load java/1.8.0_144
272 module load pigz
273 fi
274 local CMD="java $EA $EOOM $z $z2 $JNI -cp $CP jgi.RQCFilter2 jni=t $@"
275 echo $CMD >&2
276 eval $CMD
277 }
278
279 rqcfilter "$@"