Debian Codegraph @

bbnorm.sh

raw symbols SCIP
1 #!/bin/bash
2
3 usage(){
4 echo "
5 Written by Brian Bushnell
6 Last modified October 19, 2017
7
8 Description: Normalizes read depth based on kmer counts.
9 Can also error-correct, bin reads by kmer depth, and generate a kmer depth histogram.
10 However, Tadpole has superior error-correction to BBNorm.
11 Please read bbmap/docs/guides/BBNormGuide.txt for more information.
12
13 Usage: bbnorm.sh in=<input> out=<reads to keep> outt=<reads to toss> hist=<histogram output>
14
15 Input parameters:
16 in=null Primary input. Use in2 for paired reads in a second file
17 in2=null Second input file for paired reads in two files
18 extra=null Additional files to use for input (generating hash table) but not for output
19 fastareadlen=2^31 Break up FASTA reads longer than this. Can be useful when processing scaffolded genomes
20 tablereads=-1 Use at most this many reads when building the hashtable (-1 means all)
21 kmersample=1 Process every nth kmer, and skip the rest
22 readsample=1 Process every nth read, and skip the rest
23 interleaved=auto May be set to true or false to force the input read file to ovverride autodetection of the input file as paired interleaved.
24 qin=auto ASCII offset for input quality. May be 33 (Sanger), 64 (Illumina), or auto.
25
26 Output parameters:
27 out=<file> File for normalized or corrected reads. Use out2 for paired reads in a second file
28 outt=<file> (outtoss) File for reads that were excluded from primary output
29 reads=-1 Only process this number of reads, then quit (-1 means all)
30 sampleoutput=t Use sampling on output as well as input (not used if sample rates are 1)
31 keepall=f Set to true to keep all reads (e.g. if you just want error correction).
32 zerobin=f Set to true if you want kmers with a count of 0 to go in the 0 bin instead of the 1 bin in histograms.
33 Default is false, to prevent confusion about how there can be 0-count kmers.
34 The reason is that based on the 'minq' and 'minprob' settings, some kmers may be excluded from the bloom filter.
35 tmpdir=$TMPDIR This will specify a directory for temp files (only needed for multipass runs). If null, they will be written to the output directory.
36 usetempdir=t Allows enabling/disabling of temporary directory; if disabled, temp files will be written to the output directory.
37 qout=auto ASCII offset for output quality. May be 33 (Sanger), 64 (Illumina), or auto (same as input).
38 rename=f Rename reads based on their kmer depth.
39
40 Hashing parameters:
41 k=31 Kmer length (values under 32 are most efficient, but arbitrarily high values are supported)
42 bits=32 Bits per cell in bloom filter; must be 2, 4, 8, 16, or 32. Maximum kmer depth recorded is 2^cbits. Automatically reduced to 16 in 2-pass.
43 Large values decrease accuracy for a fixed amount of memory, so use the lowest number you can that will still capture highest-depth kmers.
44 hashes=3 Number of times each kmer is hashed and stored. Higher is slower.
45 Higher is MORE accurate if there is enough memory, and LESS accurate if there is not enough memory.
46 prefilter=f True is slower, but generally more accurate; filters out low-depth kmers from the main hashtable. The prefilter is more memory-efficient because it uses 2-bit cells.
47 prehashes=2 Number of hashes for prefilter.
48 prefilterbits=2 (pbits) Bits per cell in prefilter.
49 prefiltersize=0.35 Fraction of memory to allocate to prefilter.
50 buildpasses=1 More passes can sometimes increase accuracy by iteratively removing low-depth kmers
51 minq=6 Ignore kmers containing bases with quality below this
52 minprob=0.5 Ignore kmers with overall probability of correctness below this
53 threads=auto (t) Spawn exactly X hashing threads (default is number of logical processors). Total active threads may exceed X due to I/O threads.
54 rdk=t (removeduplicatekmers) When true, a kmer's count will only be incremented once per read pair, even if that kmer occurs more than once.
55
56 Normalization parameters:
57 fixspikes=f (fs) Do a slower, high-precision bloom filter lookup of kmers that appear to have an abnormally high depth due to collisions.
58 target=100 (tgt) Target normalization depth. NOTE: All depth parameters control kmer depth, not read depth.
59 For kmer depth Dk, read depth Dr, read length R, and kmer size K: Dr=Dk*(R/(R-K+1))
60 maxdepth=-1 (max) Reads will not be downsampled when below this depth, even if they are above the target depth.
61 mindepth=5 (min) Kmers with depth below this number will not be included when calculating the depth of a read.
62 minkmers=15 (mgkpr) Reads must have at least this many kmers over min depth to be retained. Aka 'mingoodkmersperread'.
63 percentile=54.0 (dp) Read depth is by default inferred from the 54th percentile of kmer depth, but this may be changed to any number 1-100.
64 uselowerdepth=t (uld) For pairs, use the depth of the lower read as the depth proxy.
65 deterministic=t (dr) Generate random numbers deterministically to ensure identical output between multiple runs. May decrease speed with a huge number of threads.
66 passes=2 (p) 1 pass is the basic mode. 2 passes (default) allows greater accuracy, error detection, better contol of output depth.
67
68 Error detection parameters:
69 hdp=90.0 (highdepthpercentile) Position in sorted kmer depth array used as proxy of a read's high kmer depth.
70 ldp=25.0 (lowdepthpercentile) Position in sorted kmer depth array used as proxy of a read's low kmer depth.
71 tossbadreads=f (tbr) Throw away reads detected as containing errors.
72 requirebothbad=f (rbb) Only toss bad pairs if both reads are bad.
73 errordetectratio=125 (edr) Reads with a ratio of at least this much between their high and low depth kmers will be classified as error reads.
74 highthresh=12 (ht) Threshold for high kmer. A high kmer at this or above are considered non-error.
75 lowthresh=3 (lt) Threshold for low kmer. Kmers at this and below are always considered errors.
76
77 Error correction parameters:
78 ecc=f Set to true to correct errors. NOTE: Tadpole is now preferred for ecc as it does a better job.
79 ecclimit=3 Correct up to this many errors per read. If more are detected, the read will remain unchanged.
80 errorcorrectratio=140 (ecr) Adjacent kmers with a depth ratio of at least this much between will be classified as an error.
81 echighthresh=22 (echt) Threshold for high kmer. A kmer at this or above may be considered non-error.
82 eclowthresh=2 (eclt) Threshold for low kmer. Kmers at this and below are considered errors.
83 eccmaxqual=127 Do not correct bases with quality above this value.
84 aec=f (aggressiveErrorCorrection) Sets more aggressive values of ecr=100, ecclimit=7, echt=16, eclt=3.
85 cec=f (conservativeErrorCorrection) Sets more conservative values of ecr=180, ecclimit=2, echt=30, eclt=1, sl=4, pl=4.
86 meo=f (markErrorsOnly) Marks errors by reducing quality value of suspected errors; does not correct anything.
87 mue=t (markUncorrectableErrors) Marks errors only on uncorrectable reads; requires 'ecc=t'.
88 overlap=f (ecco) Error correct by read overlap.
89
90 Depth binning parameters:
91 lowbindepth=10 (lbd) Cutoff for low depth bin.
92 highbindepth=80 (hbd) Cutoff for high depth bin.
93 outlow=<file> Pairs in which both reads have a median below lbd go into this file.
94 outhigh=<file> Pairs in which both reads have a median above hbd go into this file.
95 outmid=<file> All other pairs go into this file.
96
97 Histogram parameters:
98 hist=<file> Specify a file to write the input kmer depth histogram.
99 histout=<file> Specify a file to write the output kmer depth histogram.
100 histcol=3 (histogramcolumns) Number of histogram columns, 2 or 3.
101 pzc=f (printzerocoverage) Print lines in the histogram with zero coverage.
102 histlen=1048576 Max kmer depth displayed in histogram. Also affects statistics displayed, but does not affect normalization.
103
104 Peak calling parameters:
105 peaks=<file> Write the peaks to this file. Default is stdout.
106 minHeight=2 (h) Ignore peaks shorter than this.
107 minVolume=5 (v) Ignore peaks with less area than this.
108 minWidth=3 (w) Ignore peaks narrower than this.
109 minPeak=2 (minp) Ignore peaks with an X-value below this.
110 maxPeak=BIG (maxp) Ignore peaks with an X-value above this.
111 maxPeakCount=8 (maxpc) Print up to this many peaks (prioritizing height).
112
113 Java Parameters:
114 -Xmx This will set Java's memory usage, overriding autodetection.
115 -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs.
116 The max is typically 85% of physical memory.
117 -eoom This flag will cause the process to exit if an
118 out-of-memory exception occurs. Requires Java 8u92+.
119 -da Disable assertions.
120
121 Please contact Brian Bushnell at [email protected] if you encounter any problems.
122 "
123 }
124
125 #This block allows symlinked shellscripts to correctly set classpath.
126 pushd . > /dev/null
127 DIR="${BASH_SOURCE[0]}"
128 while [ -h "$DIR" ]; do
129 cd "$(dirname "$DIR")"
130 DIR="$(readlink "$(basename "$DIR")")"
131 done
132 cd "$(dirname "$DIR")"
133 DIR="$(pwd)/"
134 popd > /dev/null
135
136 #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
137 CP="$DIR""current/"
138
139 z="-Xmx31g"
140 z2="-Xms31g"
141 set=0
142
143 if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
144 usage
145 exit
146 fi
147
148 calcXmx () {
149 source "$DIR""/calcmem.sh"
150 setEnvironment
151 parseXmx "$@"
152 if [[ $set == 1 ]]; then
153 return
154 fi
155 freeRam 31000m 84
156 z="-Xmx${RAM}m"
157 z2="-Xms${RAM}m"
158 }
159 calcXmx "$@"
160
161 normalize() {
162 local CMD="java $EA $EOOM $z $z2 -cp $CP jgi.KmerNormalize bits=32 $@"
163 echo $CMD >&2
164 eval $CMD
165 }
166
167 normalize "$@"