1#!/usr/local/bin/bash
2
3usage(){
4echo "
5Written by Brian Bushnell
6Last modified September 11, 2019
7
8Description:  Uses paired read insert sizes to estimate the correct
9length of scaffold gaps, and resizes incorrectly-sized gaps.
10
11Usage:  fixgaps.sh in=mapped.sam ref=scaffolds.fa out=fixed.fa
12
13Standard parameters:
14in=<file>       Reads mapped to the reference; should be sam or bam.
15ref=<file>      Reference; may be fasta or fastq.
16out=<file>      Modified reference; may be fasta or fastq.
17overwrite=f     (ow) Set to false to force the program to abort rather than
18                overwrite an existing file.
19
20Processing parameters:
21gap=10          Consider any consecutive streak of Ns at least this long to
22                be a scaffold break.  Gaps will not be resized to less than
23                this.
24border=0.4      Ignore the outermost (border*readlen) of an insert (read pair)
25                when incrementing coverage.  A higher value is more accurate
26                but requires more coverage and/or longer inserts.  Range: 0-1.
27mindepth=10     Minimum spanning read pairs to correct a gap.
28
29Java Parameters:
30-Xmx            This will set Java's memory usage, overriding autodetection.
31                -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will
32                specify 200 megs. The max is typically 85% of physical memory.
33-eoom           This flag will cause the process to exit if an out-of-memory
34                exception occurs.  Requires Java 8u92+.
35-da             Disable assertions.
36
37Please contact Brian Bushnell at bbushnell@lbl.gov if you encounter any problems.
38"
39}
40
41#This block allows symlinked shellscripts to correctly set classpath.
42pushd . > /dev/null
43DIR="${BASH_SOURCE[0]}"
44while [ -h "$DIR" ]; do
45  cd "$(dirname "$DIR")"
46  DIR="$(readlink "$(basename "$DIR")")"
47done
48cd "$(dirname "$DIR")"
49DIR="$(pwd)/"
50popd > /dev/null
51
52#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
53CP="$DIR""current/"
54
55z="-Xmx4g"
56z2="-Xms4g"
57set=0
58
59if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
60	usage
61	exit
62fi
63
64calcXmx () {
65	source "$DIR""/calcmem.sh"
66	setEnvironment
67	parseXmx "$@"
68	if [[ $set == 1 ]]; then
69		return
70	fi
71	freeRam 4000m 84
72	z="-Xmx${RAM}m"
73	z2="-Xms${RAM}m"
74}
75calcXmx "$@"
76
77fixgaps() {
78	local CMD="java $EA $EOOM $z -cp $CP consensus.FixScaffoldGaps $@"
79	echo $CMD >&2
80	eval $CMD
81}
82
83fixgaps "$@"
84