1#!/usr/local/bin/bash
2
3usage(){
4echo "
5Written by Brian Bushnell
6Last modified August 1, 2016
7
8Description:  Generates a kmer uniqueness histogram, binned by file position.
9There are 3 columns for single reads, 6 columns for paired:
10count        number of reads or pairs processed
11r1_first     percent unique 1st kmer of read 1
12r1_rand      percent unique random kmer of read 1
13r2_first     percent unique 1st kmer of read 2
14r2_rand      percent unique random kmer of read 2
15pair         percent unique concatenated kmer from read 1 and 2
16
17Please read bbmap/docs/guides/CalcUniquenessGuide.txt for more information.
18
19Usage:	bbcountunique.sh in=<input> out=<output>
20
21Input parameters:
22in2=null            Second input file for paired reads
23interleaved=auto    Set true/false to override autodetection of the input file as paired interleaved.
24samplerate=1        Set to below 1 to sample a fraction of input reads.
25reads=-1            Only process this number of reads, then quit (-1 means all)
26
27Output parameters:
28out=<file>          File for output stats
29
30Processing parameters:
31k=25                Kmer length (range 1-31).
32interval=25000      Print one line to the histogram per this many reads.
33cumulative=f        Show cumulative numbers rather than per-interval numbers.
34percent=t           Show percentages of unique reads.
35count=f             Show raw counts of unique reads.
36printlastbin=f      (plb) Print a line for the final undersized bin.
37minprob=0           Ignore kmers with a probability of correctness below this (based on q-scores).
38
39Java Parameters:
40-Xmx                This will set Java's memory usage, overriding autodetection.
41                    -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs.
42                    The max is typically 85% of physical memory.
43-eoom               This flag will cause the process to exit if an
44                    out-of-memory exception occurs.  Requires Java 8u92+.
45-da                 Disable assertions.
46
47Please contact Brian Bushnell at bbushnell@lbl.gov if you encounter any problems.
48"
49}
50
51#This block allows symlinked shellscripts to correctly set classpath.
52pushd . > /dev/null
53DIR="${BASH_SOURCE[0]}"
54while [ -h "$DIR" ]; do
55  cd "$(dirname "$DIR")"
56  DIR="$(readlink "$(basename "$DIR")")"
57done
58cd "$(dirname "$DIR")"
59DIR="$(pwd)/"
60popd > /dev/null
61
62#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
63CP="$DIR""current/"
64
65z="-Xmx1g"
66z2="-Xms1g"
67set=0
68
69if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
70	usage
71	exit
72fi
73
74calcXmx () {
75	source "$DIR""/calcmem.sh"
76	setEnvironment
77	parseXmx "$@"
78	if [[ $set == 1 ]]; then
79	return
80	fi
81	freeRam 3200m 84
82	z="-Xmx${RAM}m"
83	z2="-Xms${RAM}m"
84}
85calcXmx "$@"
86
87bbcountunique() {
88	local CMD="java $EA $EOOM $z $z2 -cp $CP jgi.CalcUniqueness $@"
89	echo $CMD >&2
90	eval $CMD
91}
92
93bbcountunique "$@"
94