1#!/usr/local/bin/bash
2
3usage(){
4echo "
5Written by Brian Bushnell
6Last modified April 1, 2020
7
8Description:  Renames reads to <prefix>_<number> where you specify the prefix
9and the numbers are ordered.  There are other renaming modes too.
10If reads are paired, pairs should be processed together; if reads are
11interleaved, the interleaved flag should be set.  This ensures that if a
12read number (such as 1: or 2:) is added, it will be added correctly.
13
14Usage:  rename.sh in=<file> in2=<file2> out=<outfile> out2=<outfile2> prefix=<>
15
16in2 and out2 are for paired reads and are optional.
17If input is paired and there is only one output file, it will be written interleaved.
18
19Parameters:
20prefix=             The string to prepend to existing read names.
21ow=f                (overwrite) Overwrites files that already exist.
22zl=4                (ziplevel) Set compression level, 1 (low) to 9 (max).
23int=f               (interleaved) Determines whether INPUT file is considered interleaved.
24fastawrap=70        Length of lines in fasta output.
25minscaf=1           Ignore fasta reads shorter than this.
26qin=auto            ASCII offset for input quality.  May be 33 (Sanger), 64 (Illumina), or auto.
27qout=auto           ASCII offset for output quality.  May be 33 (Sanger), 64 (Illumina), or auto (same as input).
28ignorebadquality=f  (ibq) Fix out-of-range quality values instead of crashing with a warning.
29
30Renaming modes (if not default):
31renamebyinsert=f    Rename the read to indicate its correct insert size.
32renamebymapping=f   Rename the read to indicate its correct mapping coordinates.
33renamebytrim=f      Rename the read to indicate its correct post-trimming length.
34addprefix=f         Rename the read by prepending the prefix to the existing name.
35prefixonly=f        Only use the prefix; don't add _<number>
36addunderscore=t     Add an underscore after the prefix (if there is a prefix).
37addpairnum=t        Add a pairnum (e.g. ' 1:') to paired reads in some modes.
38fixsra=f            Fixes headers of SRA reads renamed from Illumina.
39                    Specifically, it converts something like this:
40                    SRR17611.11 HWI-ST79:17:D091UACXX:4:1101:210:824 length=75
41                    ...into this:
42                    HWI-ST79:17:D091UACXX:4:1101:210:824 1:
43
44Sampling parameters:
45reads=-1            Set to a positive number to only process this many INPUT reads (or pairs), then quit.
46
47Java Parameters:
48-Xmx                This will set Java's memory usage, overriding autodetection.
49                    -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs.
50                    The max is typically 85% of physical memory.
51-eoom               This flag will cause the process to exit if an
52                    out-of-memory exception occurs.  Requires Java 8u92+.
53-da                 Disable assertions.
54
55Please contact Brian Bushnell at bbushnell@lbl.gov if you encounter any problems.
56"
57}
58
59#This block allows symlinked shellscripts to correctly set classpath.
60pushd . > /dev/null
61DIR="${BASH_SOURCE[0]}"
62while [ -h "$DIR" ]; do
63  cd "$(dirname "$DIR")"
64  DIR="$(readlink "$(basename "$DIR")")"
65done
66cd "$(dirname "$DIR")"
67DIR="$(pwd)/"
68popd > /dev/null
69
70#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
71CP="$DIR""current/"
72
73z="-Xmx1g"
74set=0
75
76if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
77	usage
78	exit
79fi
80
81calcXmx () {
82	source "$DIR""/calcmem.sh"
83	setEnvironment
84	parseXmx "$@"
85}
86calcXmx "$@"
87
88function rename() {
89	local CMD="java $EA $EOOM $z -cp $CP jgi.RenameReads $@"
90	echo $CMD >&2
91	eval $CMD
92}
93
94rename "$@"
95