Debian Codegraph @

calctruequality.sh

raw symbols SCIP
1 #!/bin/bash
2
3 usage(){
4 echo "
5 Written by Brian Bushnell
6 Last modified October 8, 2024
7
8 Description: Calculates observed quality scores from mapped sam/bam files.
9 Generates matrices for use in recalibrating quality scores. By default,
10 the matrices are written to /ref/qual/ in the current directory.
11
12 If you have multiple sam/bam files demultiplexed from a single sequencing run,
13 it is recommended to use all of them as input for increased statistical power.
14 Once the matrices are generated, recalibration can be done on mapped or
15 unmapped reads; you may get better results by recalibrating the fastq and
16 remapping the calibrated reads.
17
18 Note! Diploid organisms with a high heterozygousity rate will induce
19 inaccurate recalibration at the high end of the quality scale unless SNP
20 locations are masked or variations are called. For example, recalibrating
21 human reads mapped to an unmasked human reference would generate an
22 expected maximal Q-score of roughly 30 due to the human 1/1000 SNP rate.
23 Variations can be ignored by using the callvars flag or providing
24 a file of variations.
25
26 Usage:
27
28 Step 1. Generate matrices (from mapped sam or bam files):
29 calctruequality.sh in=<file,file,...file> path=<directory>
30
31 Step 2. Recalibrate reads (any kind of files):
32 bbduk.sh in=<file> out=<file> recalibrate
33
34
35 Parameters (and their defaults)
36
37 Input parameters:
38 in=<file,file> Sam file or comma-delimited list of files. Alignments
39 must use = and X cigar symbols, or have MD tags, or
40 ref must be specified.
41 reads=-1 Stop after processing this many reads (if positive).
42 samstreamer=t (ss) Load reads multithreaded to increase speed.
43 unpigz=t Use pigz to decompress.
44
45 Output parameters:
46 overwrite=t (ow) Set to true to allow overwriting of existing files.
47 path=. Directory to write quality matrices (within /ref subdir).
48 write=t Write matrices.
49 showstats=t Print a summary.
50 pigz=f Use pigz to compress.
51
52 Other parameters:
53 t=auto Number of worker threads.
54 passes=2 Recalibration passes, 1 or 2. 2 is slower but gives more
55 accurate quality scores.
56 recalqmax=42 Adjust max quality scores tracked. The actual highest
57 quality score allowed is recalqmax-1.
58 trackall=f Track all available quality metrics and produce all
59 matrices, including the ones that are not selected for
60 quality adjustment. Reduces speed, but allows testing the
61 effects of different recalibration matrices.
62 indels=t Include indels in quality calculations.
63 usetiles=f Use per-tile quality statistics to generate matrices.
64 If this is true, the flag must also be used during
65 recalibration (e.g. in BBDuk).
66
67 Variation calling:
68 varfile=<file> Use the variants in this var file, instead of calling
69 variants. The format can be produced by CallVariants.
70 vcf=<file> Use the variants in this VCF file, instead of
71 calling variants.
72 callvars=f Call SNPs, and do not count them as errors.
73 ploidy=1 Set the organism's ploidy.
74 ref= Required for variation-calling.
75
76 *** 'Variant-Calling Cutoffs' flags in callvariants.sh are also supported ***
77
78 Selecting matrices:
79 loadq102= For each recalibration matrix, enable or disable that matrix with t/f.
80 You can specify pass1 or pass2 like this: loadq102_p1=f loadq102_p2=t.
81 The default is loadqbp_p1=t loadqbp_p2=t loadqb123_p=t.
82 clearmatrices=f If true, clear all the existing matrix selections. For example:
83 'clearmatrices loadqbp_p1'
84 This would ignore defaults and select only qbp for the first pass.
85
86 Available matrices:
87 q102 Quality, leading quality, trailing quality.
88 qap Quality, average quality, position.
89 qbp Quality, current base, position.
90 q10 Quality, leading quality.
91 q12 Quality, trailing quality.
92 qb12 Quality, leading base, current base.
93 qb012 Quality, two leading bases, current base.
94 qb123 Quality, leading base, current base, trailing base.
95 qb234 Quality, current base, two trailing bases.
96 q12b12 Quality, trailing quality, leading base, current base.
97 qp Quality, position.
98 q Current quality score only.
99
100
101 Java Parameters:
102 -Xmx This will set Java's memory usage, overriding autodetection.
103 -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs.
104 The max is typically 85% of physical memory.
105 -eoom This flag will cause the process to exit if an
106 out-of-memory exception occurs. Requires Java 8u92+.
107 -da Disable assertions.
108
109 Please contact Brian Bushnell at [email protected] if you encounter any problems.
110 "
111 }
112
113 #This block allows symlinked shellscripts to correctly set classpath.
114 pushd . > /dev/null
115 DIR="${BASH_SOURCE[0]}"
116 while [ -h "$DIR" ]; do
117 cd "$(dirname "$DIR")"
118 DIR="$(readlink "$(basename "$DIR")")"
119 done
120 cd "$(dirname "$DIR")"
121 DIR="$(pwd)/"
122 popd > /dev/null
123
124 #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
125 CP="$DIR""current/"
126
127 z="-Xmx2g"
128 z2="-Xms2g"
129 set=0
130
131 if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
132 usage
133 exit
134 fi
135
136 calcXmx () {
137 source "$DIR""/calcmem.sh"
138 setEnvironment
139 parseXmx "$@"
140 if [[ $set == 1 ]]; then
141 return
142 fi
143 freeRam 3200m 84
144 z="-Xmx${RAM}m"
145 z2="-Xms${RAM}m"
146 }
147 calcXmx "$@"
148
149 calctruequality() {
150 local CMD="java $EA $EOOM $z $z2 -cp $CP jgi.CalcTrueQuality $@"
151 echo $CMD >&2
152 eval $CMD
153 }
154
155 calctruequality "$@"