Debian Codegraph @

polyfilter.sh

raw symbols SCIP
1 #!/bin/bash
2
3 usage(){
4 echo "
5 Written by Brian Bushnell
6 Last modified October 1, 2024
7
8 Description: Filters reads to remove those with suspicious homopolymers.
9
10 Usage: polyfilter.sh in=<input reads> out=<filtered reads>
11
12 Example:
13 polyfilter.sh in=reads.fq out=clean.fq outb=bad.fq k=31 polymers=G
14
15
16 File parameters:
17 in=<file> Primary input, or read 1 input.
18 in2=<file> Read 2 input if reads are in two files.
19 out=<file> Output for clean reads.
20 outb=<file> Output for bad (homopolymer) reads.
21 extra=<file> Comma-delimited list of additional sequence files.
22 For depth-based filtering, set this to the same as the input.
23 overwrite=t (ow) Set to false to force the program to abort rather than
24 overwrite an existing file.
25
26 Hashing parameters:
27 k=31 Kmer length.
28 hashes=2 Number of hashes per kmer. Higher generally reduces
29 false positives at the expense of speed.
30 sw=t (symmetricwrite) Increases accuracy when bits>1 and hashes>1.
31 minprob=0.5 Ignore reference kmers with probability of being correct
32 below this (affects fastq references only).
33 memmult=1.0 Fraction of free memory to use for Bloom filter. 1.0 should
34 generally work; if the program crashes with an out of memory
35 error, set this lower. Higher increases specificity.
36 cells= Option to set the number of cells manually. By default this
37 will be autoset to use all available memory. The only reason
38 to set this is to ensure deterministic output.
39 seed=0 This will change the hash function used.
40 bits= Bits per cell; it is set automatically from mincount.
41
42 Filtering rules:
43 Reads will always be discarded if they fails ldf2, entropy2, or minpolymer2.
44 Reads will also be discarded if they fail (minpolymer AND (ldf OR entropy)).
45 A read pair will be discarded if either read is discarded.
46
47 Depth-filtering parameters:
48 mincount=2 Minimum number of times a read kmer must occur in the
49 read set to be considered 'high-depth'.
50 ldf=0.24 (lowdepthfraction) Consider a read low-depth if at least
51 this fraction of kmers are low depth. Setting this above 1
52 will disable depth analysis (making the program run faster).
53 ldf2=1.1 Discard reads with at least this fraction of low-depth kmers.
54 Values above 1 disables this filter (e.g., for metagenomes).
55
56 Entropy-filtering parameters:
57 entropy=0.67 Reads with average entropy below this are considered
58 low-entropy.
59 entropy2=0.2 Reads with average entropy below this are discarded.
60
61 Quality-filtering parameters (only useful if q-scores are correct):
62 quality=12.5 Reads with average quality below this are considered
63 low-quality.
64 quality2=7.5 Reads with average quality below this are discarded.
65
66 Homopolymer-filtering parameters:
67 polymers=GC Look for homopolymers of these symbols. e.g., polymers=GC
68 would look for poly-G or poly-C (but not poly-GC).
69 minpolymer=20 Minimum length of homopolymers.
70 minpolymer2=29 Discard any read with a homopolymer of at least this length.
71 purity=0.85 Min fraction of the homopolymer region that is the correct
72 symbol. For example, GGGGGGAGGG is length 10 with 9 Gs, for
73 a purity of 0.90 (insufficient in this case due to length).
74
75 Trimming parameters:
76 trimpolymers= Homopolymers to use for trimming. If unspecified, it will
77 be the same as 'polymers'.
78 trimleft=6 Trim left ends where there is a homopolymer at least this
79 long; 0 disables trimming.
80 trimright=6 Trim left ends where there is a homopolymer at least this
81 long; 0 disables trimming.
82 trim= Sets both trimleft and trimright.
83 maxnonpoly=2 Trim through up to this many consecutive mismatches.
84 minlen=50 Discard reads shorter than this after trimming.
85
86 Other parameters:
87 quantize=1 If greater than 1, bin the quality scores to reduce file size.
88 cardinality=t Report estimated number of unique output kmers.
89
90 Java Parameters:
91 -Xmx This will set Java's memory usage, overriding autodetection.
92 -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will
93 specify 200 megs. The max is typically 85% of physical memory.
94 -eoom This flag will cause the process to exit if an out-of-memory
95 exception occurs. Requires Java 8u92+.
96 -da Disable assertions.
97
98 Please contact Brian Bushnell at [email protected] if you encounter any problems.
99 "
100 }
101
102 #This block allows symlinked shellscripts to correctly set classpath.
103 pushd . > /dev/null
104 DIR="${BASH_SOURCE[0]}"
105 while [ -h "$DIR" ]; do
106 cd "$(dirname "$DIR")"
107 DIR="$(readlink "$(basename "$DIR")")"
108 done
109 cd "$(dirname "$DIR")"
110 DIR="$(pwd)/"
111 popd > /dev/null
112
113 #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
114 CP="$DIR""current/"
115
116 z="-Xmx4g"
117 z2="-Xms4g"
118 set=0
119
120 if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
121 usage
122 exit
123 fi
124
125 calcXmx () {
126 source "$DIR""/calcmem.sh"
127 setEnvironment
128 parseXmx "$@"
129 if [[ $set == 1 ]]; then
130 return
131 fi
132 freeRam 4000m 84
133 z="-Xmx${RAM}m"
134 z2="-Xms${RAM}m"
135 }
136 calcXmx "$@"
137
138 polyfilter() {
139 local CMD="java $EA $EOOM $z $z2 -cp $CP bloom.PolyFilter $@"
140 echo $CMD >&2
141 eval $CMD
142 }
143
144 polyfilter "$@"