1#!/usr/local/bin/bash
2
3usage(){
4echo "
5Written by Brian Bushnell
6Last modified December 19, 2019
7
8Description:  Merges multiple sketches into a single sketch.
9
10Please read bbmap/docs/guides/BBSketchGuide.txt for more information.
11
12Usage:           mergesketch.sh in=a.sketch,b.sketch out=c.sketch
13With wildcards:  mergesketch.sh *.sketch out=c.sketch
14
15Standard parameters:
16in=<file>       Input sketches or fasta files; may be a comma-delimited
17                list.  in= is optional so wildcards may be used.
18out=<file>      Output sketch.
19amino=f         Use amino acid mode.
20
21Sketch-making parameters:
22mode=single     Possible modes, for fasta input:
23                   single: Generate one sketch per file.
24                   sequence: Generate one sketch per sequence.
25autosize=t      Produce an output sketch of whatever size the union
26                happens to be.
27size=           Restrict output sketch to this upper bound of size.
28k=32,24         Kmer length, 1-32.
29keyfraction=0.2 Only consider this upper fraction of keyspace.
30minkeycount=1   Ignore kmers that occur fewer times than this.  Values
31                over 1 can be used with raw reads to avoid error kmers.
32depth=f         Retain kmer counts if available.
33
34Metadata parameters: (if blank the values of the first sketch will be used)
35taxid=-1        Set the NCBI taxid.
36imgid=-1        Set the IMG id.
37spid=-1         Set the JGI sequencing project id.
38name=           Set the name (taxname).
39name0=          Set name0 (normally the first sequence header).
40fname=          Set fname (normally the file name).
41meta_=          Set an arbitrary metadata field.
42                For example, meta_Month=March.
43
44Java Parameters:
45-Xmx            This will set Java's memory usage, overriding autodetection.
46                -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs.
47                    The max is typically 85% of physical memory.
48-eoom           This flag will cause the process to exit if an out-of-memory
49                exception occurs.  Requires Java 8u92+.
50-da             Disable assertions.
51
52For more detailed information, please read /bbmap/docs/guides/BBSketchGuide.txt.
53Please contact Brian Bushnell at bbushnell@lbl.gov if you encounter any problems.
54"
55}
56
57#This block allows symlinked shellscripts to correctly set classpath.
58pushd . > /dev/null
59DIR="${BASH_SOURCE[0]}"
60while [ -h "$DIR" ]; do
61  cd "$(dirname "$DIR")"
62  DIR="$(readlink "$(basename "$DIR")")"
63done
64cd "$(dirname "$DIR")"
65DIR="$(pwd)/"
66popd > /dev/null
67
68#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
69CP="$DIR""current/"
70
71z="-Xmx4g"
72z2="-Xms4g"
73set=0
74
75if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
76	usage
77	exit
78fi
79
80calcXmx () {
81	source "$DIR""/calcmem.sh"
82	setEnvironment
83	parseXmx "$@"
84	if [[ $set == 1 ]]; then
85		return
86	fi
87	freeRam 3200m 84
88	z="-Xmx${RAM}m"
89	z2="-Xms${RAM}m"
90}
91calcXmx "$@"
92
93sendsketch() {
94	local CMD="java $EA $EOOM $z -cp $CP sketch.MergeSketch $@"
95#	echo $CMD >&2
96	eval $CMD
97}
98
99sendsketch "$@"
100