Debian Codegraph @

countduplicates.sh

raw symbols SCIP
1 #!/bin/bash
2
3 usage(){
4 echo "
5 Written by Brian Bushnell
6 Last modified October 14, 2022
7
8 Description: Counts duplicate sequences probabilistically,
9 using around 20 bytes per unique read. Read pairs are treated
10 as a single read. Reads are converted to a hashcode and only
11 the hashcode is stored when tracking duplicates, so (rare) hash
12 collisions will result in false positive duplicate detection.
13 Optionally outputs the deduplicated and/or duplicate reads.
14
15 Usage: countduplicates.sh in=<input file>
16
17 Input may be fasta, fastq, or sam, compressed or uncompressed.
18 in2, out2, and outd2 are accepted for paired files.
19
20 Standard parameters:
21 in=<file> Primary input, or read 1 input.
22 out=<file> Optional output for deduplicated reads.
23 outd=<file> Optional output for duplicate reads. An extension like .fq
24 will output reads; .txt will output headers only.
25 stats=stdout May be replaced by a filename to write stats to a file.
26 showspeed=t (ss) Set to 'f' to suppress display of processing speed.
27
28 Processing parameters (these are NOT mutually exclusive):
29 bases=t Include bases when generating hashcodes.
30 names=f Include names (headers) when generating hashcodes.
31 qualities=f Include qualities when generating hashcodes.
32 maxfraction=-1.0 Set to a positive number 0-1 to FAIL input
33 that exceeds this fraction of reads with duplicates.
34 maxrate=-1.0 Set to a positive number >=1 to FAIL input that exceeds this
35 average duplication rate (the number of copies per read).
36 failcode=0 Set to some other number like 1 to produce a
37 non-zero exit code for failed input.
38 samplerate=1.0 Fraction of reads to subsample, to conserve memory. Sampling
39 is deterministic - if a read is sampled, copies will be too.
40 Unsampled reads are not sent to any output stream or counted
41 in statistics.
42
43 Java Parameters:
44 -Xmx This will set Java's memory usage, overriding autodetection.
45 -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will
46 specify 200 megs. The max is typically 85% of physical memory.
47 -eoom This flag will cause the process to exit if an out-of-memory
48 exception occurs. Requires Java 8u92+.
49 -da Disable assertions.
50
51 Please contact Brian Bushnell at [email protected] if you encounter any problems.
52 "
53 }
54
55 #This block allows symlinked shellscripts to correctly set classpath.
56 pushd . > /dev/null
57 DIR="${BASH_SOURCE[0]}"
58 while [ -h "$DIR" ]; do
59 cd "$(dirname "$DIR")"
60 DIR="$(readlink "$(basename "$DIR")")"
61 done
62 cd "$(dirname "$DIR")"
63 DIR="$(pwd)/"
64 popd > /dev/null
65
66 #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
67 CP="$DIR""current/"
68
69 z="-Xmx4g"
70 z2="-Xms4g"
71 set=0
72
73 if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
74 usage
75 exit
76 fi
77
78 calcXmx () {
79 source "$DIR""/calcmem.sh"
80 setEnvironment
81 parseXmx "$@"
82 if [[ $set == 1 ]]; then
83 return
84 fi
85 freeRam 4000m 84
86 z="-Xmx${RAM}m"
87 z2="-Xms${RAM}m"
88 }
89 calcXmx "$@"
90
91 countDupes() {
92 local CMD="java $EA $EOOM $z -cp $CP jgi.CountDuplicates $@"
93 echo $CMD >&2
94 eval $CMD
95 }
96
97 countDupes "$@"