| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified November 8, 2018 |
| 7 | |
| 8 | Description: Realigns mapped reads to a reference. |
| 9 | |
| 10 | Usage: bbrealign.sh in=<file> ref=<file> out=<file> |
| 11 | |
| 12 | Input may be a sorted or unsorted sam or bam file. |
| 13 | The reference should be fasta. |
| 14 | |
| 15 | I/O parameters: |
| 16 | in=<file> Input reads. |
| 17 | out=<file> Output reads. |
| 18 | ref=<file> Reference fasta. |
| 19 | overwrite=f (ow) Set to false to force the program to abort rather than |
| 20 | overwrite an existing file. |
| 21 | |
| 22 | Trimming parameters: |
| 23 | border=0 Trim at least this many bases on both ends of reads. |
| 24 | qtrim=r Quality-trim reads on this end |
| 25 | r: right, l: left, rl: both, f: don't quality-trim. |
| 26 | trimq=10 Quality-trim bases below this score. |
| 27 | |
| 28 | Realignment parameters: |
| 29 | unclip=f Convert clip symbols from exceeding the ends of the |
| 30 | realignment zone into matches and substitutitions. |
| 31 | repadding=70 Pad alignment by this much on each end. Typically, |
| 32 | longer is more accurate for long indels, but greatly |
| 33 | reduces speed. |
| 34 | rerows=602 Use this many rows maximum for realignment. Reads longer |
| 35 | than this cannot be realigned. |
| 36 | recols=2000 Reads may not be aligned to reference seqments longer |
| 37 | than this. Needs to be at least read length plus |
| 38 | max deletion length plus twice padding. |
| 39 | msa= Select the aligner. Options: |
| 40 | MultiStateAligner11ts: Default. |
| 41 | MultiStateAligner9PacBio: Use for PacBio reads, or for |
| 42 | Illumina reads mapped to PacBio/Nanopore reads. |
| 43 | |
| 44 | Sam-filtering parameters: |
| 45 | minpos= Ignore alignments not overlapping this range. |
| 46 | maxpos= Ignore alignments not overlapping this range. |
| 47 | minreadmapq=4 Ignore alignments with lower mapq. |
| 48 | contigs= Comma-delimited list of contig names to include. These |
| 49 | should have no spaces, or underscores instead of spaces. |
| 50 | secondary=f Include secondary alignments. |
| 51 | supplimentary=f Include supplimentary alignments. |
| 52 | invert=f Invert sam filters. |
| 53 | |
| 54 | Java Parameters: |
| 55 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 56 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will |
| 57 | specify 200 megs. The max is typically 85% of physical memory. |
| 58 | -eoom This flag will cause the process to exit if an out-of-memory |
| 59 | exception occurs. Requires Java 8u92+. |
| 60 | -da Disable assertions. |
| 61 | |
| 62 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 63 | " |
| 64 | } |
| 65 | |
| 66 | #This block allows symlinked shellscripts to correctly set classpath. |
| 67 | pushd . > /dev/null |
| 68 | DIR="${BASH_SOURCE[0]}" |
| 69 | while [ -h "$DIR" ]; do |
| 70 | cd "$(dirname "$DIR")" |
| 71 | DIR="$(readlink "$(basename "$DIR")")" |
| 72 | done |
| 73 | cd "$(dirname "$DIR")" |
| 74 | DIR="$(pwd)/" |
| 75 | popd > /dev/null |
| 76 | |
| 77 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 78 | CP="$DIR""current/" |
| 79 | |
| 80 | z="-Xmx4g" |
| 81 | z2="-Xms4g" |
| 82 | set=0 |
| 83 | |
| 84 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 85 | usage |
| 86 | exit |
| 87 | fi |
| 88 | |
| 89 | calcXmx () { |
| 90 | source "$DIR""/calcmem.sh" |
| 91 | setEnvironment |
| 92 | parseXmx "$@" |
| 93 | if [[ $set == 1 ]]; then |
| 94 | return |
| 95 | fi |
| 96 | freeRam 4000m 84 |
| 97 | z="-Xmx${RAM}m" |
| 98 | z2="-Xms${RAM}m" |
| 99 | } |
| 100 | calcXmx "$@" |
| 101 | |
| 102 | bbrealign() { |
| 103 | local CMD="java $EA $EOOM $z $z2 -cp $CP var2.Realign $@" |
| 104 | echo $CMD >&2 |
| 105 | eval $CMD |
| 106 | } |
| 107 | |
| 108 | bbrealign "$@" |