Debian Codegraph @

filterbytile.sh

raw symbols SCIP
1 #!/bin/bash
2
3 usage(){
4 echo "
5 Written by Brian Bushnell
6 Last modified November 18, 2024
7
8 Description: Filters reads based on positional quality over a flowcell.
9 Quality is estimated based on quality scores and kmer uniqueness; ideally,
10 the input to this program will already be adapter-trimmed and
11 quality-score recalibrated. PhiX, if present, will be used to estimate
12 absolute error rates from kmer uniqueness rates.
13 All reads within a small unit of area called a micro-tile are averaged,
14 then the micro-tile is either retained or discarded as a unit depending
15 on whether its metrics fall outside of a specified range (generally some
16 number of standard deviations away from average).
17 This program can process individual libraries, but achieves optimal
18 performance when processing one lane at a time. For this purpose it is best
19 to use as much memory as possible (e.g., 200GB RAM for 5 billion reads),
20 though it will still work with much less memory.
21
22 Please read bbmap/docs/guides/FilterByTileGuide.txt for more information.
23
24
25 Usage: filterbytile.sh in=<input> out=<output>
26
27 Input parameters:
28 in=<file> Primary input file.
29 in2=<file> Second input file for paired reads in twin files.
30 indump=<file> Specify an already-made dump file to use instead of
31 analyzing the input reads.
32 barcodes=<file> Optional list of expected barcodes, one per line.
33 reads=-1 Process this number of reads, then quit (-1 means all).
34 interleaved=auto Set true/false to override autodetection of the
35 input file as paired interleaved.
36
37 Output parameters:
38 out=<file> Output file for filtered reads.
39 dump=<file> Write a summary of quality information by coordinates.
40 This can be later used for filtering individual libraries.
41 counts=<file> Write barcode counts.
42
43
44 Tile parameters:
45 xsize=500 Initial width of micro-tiles. For NovaSeqX use 520.
46 ysize=500 Initial height of micro-tiles. For NovaSeqX use 590.
47 size= Allows setting xsize and ysize to the same value.
48 target=1600 Iteratively widen the micro-tiles until they contain
49 an average of at least this many reads.
50 alignedreads=250 Average aligned reads per tile for error rate calibration.
51
52 A micro-tile is discarded if any of several metrics indicate a problem.
53 The metrics are kmer uniqueness (u), average quality (q), probability
54 of being error-free (e), and poly-G rate (pg).
55 Each has 3 parameters: deviations (d), fraction (f), and absolute (a).
56 After calculating the difference (delta) between a micro-tile and average,
57 it is discarded only if all three of these conditions are true for at least
58 one metric (using quality as the example):
59 1) delta is greater than (qd) standard deviations.
60 2) delta is greater than average times the fraction (qf).
61 3) delta is greater than the absolute value (qa).
62 Tiles are also marked for discard if they have too few reads to calculate
63 statistics or an inferred error rate (ier) above an absolute value; ier
64 does not need deviations because it is calibrated.
65
66 Filtering parameters:
67 udeviations=1.5 (ud) Standard deviations for uniqueness discarding.
68 qdeviations=2.4 (qd) Standard deviations for quality discarding.
69 edeviations=3.0 (ed) Standard deviations for error-free probablity.
70 pgdeviations=1.4 (pgd) Standard deviations for poly-G discarding.
71 ufraction=0.01 (uf) Min fraction for uniqueness discarding.
72 qfraction=0.08 (qf) Min fraction for quality discarding.
73 efraction=0.2 (ef) Min fraction for error-free probablity discarding.
74 pgfraction=0.2 (pgf) Min fraction for poly-G discarding.
75 uabsolute=1 (ua) Min absolute value for uniqueness discarding.
76 qabsolute=2.0 (qa) Min absolute value for quality discarding.
77 eabsolute=6 (ea) Min absolute value for error-free probablity.
78 pgabsolute=0.2 (pga) Min absolute value for poly-G discarding.
79 ier=0.012 (inferrederrorrate) Maximum predicted base error rate.
80 A more recent addition and usually superior to using
81 uniqueness deviations, if ~1% PhiX is spiked in.
82 mdf=0.4 (maxdiscardfraction) Don't discard more than this
83 fraction of tiles no matter how bad the data is.
84
85 Alignment parameters:
86 Note: Alignment will only be performed if there is no input sam file,
87 and nothing will go to the output sam file unless internal alignment occurs.
88 samin=<file> Optional aligned sam input file for error rate analysis.
89 samout=<file> Output file for aligned reads. Can be sam or fastq.
90 align=true If no sam file is present, align reads to the reference.
91 alignref=phix Reference for aligning reads if there is no sam file.
92 alignk1=17 Kmer length for seeding alignment to reference.
93 alignk2=13 Kmer length for seeding alignment of unaligned reads
94 with an aligned mate.
95 minid1=0.62 Minimum identity to accept individual alignments.
96 minid2=0.54 Minimum identity for aligning reads with aligned mates.
97 alignmm1=1 Middle mask length for alignk1.
98 alignmm2=1 Middle mask length for alignk2.
99
100 Note: Alignment is optional, but allows translation of kmer depth to error
101 rate at high resolution. The default reference, phiX, is nonrepetitive down
102 to k=13. For internal alignment, the reference must be a short single
103 sequence that is almost completely nonrepetitive at the selected kmer length.
104 If a sam file is used, any reference is OK and the alignment parameters are
105 ignored, but it should have few mutations. A SNP rate of 1/1000 (like human)
106 is acceptable but sets an inferred error rate floor of 0.001 (Q30).
107
108 Other parameters:
109 usekmers=t Load kmers to calculate uniqueness and depth.
110 lowqualityonly=t (lqo) Only discard low quality reads within bad areas,
111 rather than the whole micro-tile. This usually discards
112 most of the reads in the bad micro-tiles anyway.
113 recalibrate=f Recalibrate reads while filling tile info.
114 Requires calibration matrices from CalcTrueQuality.
115 Changes sam output, but not positionally-filter output.
116 dmult=-.1 Lower increases amount removed when lqo=t. At 0, only
117 reads with below average quality (or polyG) are removed.
118 idmaskwrite=15 A bitmask, (2^N-1), controlling the fraction of kmers
119 loaded in the bloom filter. 15 means 1/16th are loaded.
120 0 uses all kmers.
121 idmaskread=7 Controls fraction of kmers read when counting uniqueness.
122 k=31 Kmer length for Bloom filter (uniqueness calculation).
123 hashes=3 Bloom filter hashes.
124 cbits=2 Bloom filter bits per cell.
125 merge=f Merge reads for insert and error rate statistics.
126 This can make the program take ~50% longer and only
127 affects the dump file.
128
129 Java Parameters:
130 -Xmx This will set Java's memory usage, overriding autodetection.
131 -Xmx20g will specify 20 GB of RAM; -Xmx200m will specify
132 200 MB. The max is typically 85% of physical memory.
133 -eoom This flag will cause the process to exit if an
134 out-of-memory exception occurs. Requires Java 8u92+.
135 -da Disable assertions.
136
137 Please contact Brian Bushnell at [email protected] if you encounter any problems.
138 "
139 }
140
141 #This block allows symlinked shellscripts to correctly set classpath.
142 pushd . > /dev/null
143 DIR="${BASH_SOURCE[0]}"
144 while [ -h "$DIR" ]; do
145 cd "$(dirname "$DIR")"
146 DIR="$(readlink "$(basename "$DIR")")"
147 done
148 cd "$(dirname "$DIR")"
149 DIR="$(pwd)/"
150 popd > /dev/null
151
152 #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
153 CP="$DIR""current/"
154
155 z="-Xmx8g"
156 z2="-Xms8g"
157 set=0
158
159 if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
160 usage
161 exit
162 fi
163
164 calcXmx () {
165 source "$DIR""/calcmem.sh"
166 setEnvironment
167 parseXmx "$@"
168 if [[ $set == 1 ]]; then
169 return
170 fi
171 freeRam 3200m 84
172 z="-Xmx${RAM}m"
173 z2="-Xms${RAM}m"
174 }
175 calcXmx "$@"
176
177 filterbytile() {
178 local CMD="java $EA $EOOM $z $z2 -cp $CP hiseq.AnalyzeFlowCell $@"
179 echo $CMD >&2
180 eval $CMD
181 }
182
183 filterbytile "$@"