1#!/usr/local/bin/bash
2
3usage(){
4echo "
5Written by Brian Bushnell
6Last modified August 29, 2017
7
8Description:  Generates synthetic contaminated partial genomes from clean genomes.
9Output is formatted as (prefix)_bases1_fname1_bases2_fname2_counter_(suffix).
10
11Usage:        makecontaminatedgenomes.sh in=<file> out=<pattern>
12
13I/O parameters:
14in=<file>       A file containing one input file path per line.
15out=<pattern>   A file name containing a # symbol (or other regex).
16                The regex will be replaced by source filenames.
17
18Processing Parameters:
19count=1         Number of output files to make.
20seed=-1         RNG seed; negative for a random seed.
21exp1=1          Exponent for genome 1 size fraction.
22exp2=1          Exponent for genome 2 size fraction.
23subrate=0       Rate to add substitutions to new genomes (0-1).
24indelrate=0     Rate to add substitutions to new genomes (0-1).
25regex=#         Use this substitution regex for replacement.
26delimiter=_     Use this delimiter in the new file names.
27
28Java Parameters:
29-Xmx            This will set Java's memory usage, overriding autodetection.
30                -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs.
31                    The max is typically 85% of physical memory.
32-eoom           This flag will cause the process to exit if an out-of-memory
33                exception occurs.  Requires Java 8u92+.
34-da             Disable assertions.
35
36Please contact Brian Bushnell at bbushnell@lbl.gov if you encounter any problems.
37"
38}
39
40#This block allows symlinked shellscripts to correctly set classpath.
41pushd . > /dev/null
42DIR="${BASH_SOURCE[0]}"
43while [ -h "$DIR" ]; do
44  cd "$(dirname "$DIR")"
45  DIR="$(readlink "$(basename "$DIR")")"
46done
47cd "$(dirname "$DIR")"
48DIR="$(pwd)/"
49popd > /dev/null
50
51#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
52CP="$DIR""current/"
53
54z="-Xmx4g"
55z2="-Xms4g"
56set=0
57
58if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
59	usage
60	exit
61fi
62
63calcXmx () {
64	source "$DIR""/calcmem.sh"
65	setEnvironment
66	parseXmx "$@"
67	if [[ $set == 1 ]]; then
68	return
69	fi
70	freeRam 4000m 42
71	z="-Xmx${RAM}m"
72}
73calcXmx "$@"
74
75makecontaminatedgenomes() {
76	local CMD="java $EA $EOOM $z -cp $CP jgi.MakeContaminatedGenomes $@"
77	echo $CMD >&2
78	eval $CMD
79}
80
81makecontaminatedgenomes "$@"
82