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