| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified February 10, 2020 |
| 7 | |
| 8 | Description: Generates the consensus sequence of a reference |
| 9 | using aligned sequences. This can be used for polishing assemblies, |
| 10 | making representative ribosomal sub units, correcting PacBio reads, etc. |
| 11 | |
| 12 | If unaligned sequences are used as input, they should be in fasta or fastq |
| 13 | format, and they will be aligned to the first reference sequence. |
| 14 | |
| 15 | Usage: consensus.sh in=mapped.sam ref=ref.fa out=consensus.fa |
| 16 | |
| 17 | Recommended settings for assembly polishing via Illumina reads: mafsub=0.5 |
| 18 | |
| 19 | |
| 20 | Standard parameters: |
| 21 | in=<file> Reads mapped to the reference; should be sam or bam. |
| 22 | ref=<file> Reference; may be fasta or fastq. |
| 23 | out=<file> Modified reference; may be fasta or fastq. |
| 24 | outm=<file> Optional output for binary model file. |
| 25 | Preferred extension is .alm. |
| 26 | inm=<file> Optional input model file for statistics. |
| 27 | hist=<file> Optional score histogram output. |
| 28 | overwrite=f (ow) Set to false to force the program to abort rather than |
| 29 | overwrite an existing file. |
| 30 | |
| 31 | Processing parameters: |
| 32 | mindepth=2 Do not change to alleles present at depth below this. |
| 33 | mafsub=0.25 Do not incorporate substitutions below this allele fraction. |
| 34 | mafdel=0.50 Do not incorporate deletions below this allele fraction. |
| 35 | mafins=0.50 Do not incorporate insertions below this allele fraction. |
| 36 | mafn=0.40 Do not change Ns (noref) to calls below this allele fraction. |
| 37 | usemapq=f Include mapq as a positive factor in edge weight. |
| 38 | nonly=f Only change Ns to different bases. |
| 39 | noindels=f Don't allow indels. |
| 40 | ceiling= If set, alignments will be weighted by their inverse identity. |
| 41 | For example, at ceiling=105, a read with 96% identity will get |
| 42 | bonus weight of 105-96=9 while a read with 70% identity will |
| 43 | get 105-70=35. This favors low-identity reads. |
| 44 | name= Set the output sequence name (for a single output sequence). |
| 45 | |
| 46 | Java Parameters: |
| 47 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 48 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will |
| 49 | specify 200 megs. The max is typically 85% of physical memory. |
| 50 | -eoom This flag will cause the process to exit if an out-of-memory |
| 51 | exception occurs. Requires Java 8u92+. |
| 52 | -da Disable assertions. |
| 53 | |
| 54 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 55 | " |
| 56 | } |
| 57 | |
| 58 | #This block allows symlinked shellscripts to correctly set classpath. |
| 59 | pushd . > /dev/null |
| 60 | DIR="${BASH_SOURCE[0]}" |
| 61 | while [ -h "$DIR" ]; do |
| 62 | cd "$(dirname "$DIR")" |
| 63 | DIR="$(readlink "$(basename "$DIR")")" |
| 64 | done |
| 65 | cd "$(dirname "$DIR")" |
| 66 | DIR="$(pwd)/" |
| 67 | popd > /dev/null |
| 68 | |
| 69 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 70 | CP="$DIR""current/" |
| 71 | |
| 72 | z="-Xmx4g" |
| 73 | z2="-Xms4g" |
| 74 | set=0 |
| 75 | |
| 76 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 77 | usage |
| 78 | exit |
| 79 | fi |
| 80 | |
| 81 | calcXmx () { |
| 82 | source "$DIR""/calcmem.sh" |
| 83 | setEnvironment |
| 84 | parseXmx "$@" |
| 85 | if [[ $set == 1 ]]; then |
| 86 | return |
| 87 | fi |
| 88 | freeRam 4000m 84 |
| 89 | z="-Xmx${RAM}m" |
| 90 | z2="-Xms${RAM}m" |
| 91 | } |
| 92 | calcXmx "$@" |
| 93 | |
| 94 | #Note that this needs -Xss flag to prevent serialization stack overflow |
| 95 | consensus() { |
| 96 | local CMD="java $EA $EOOM $z -Xss8m -cp $CP consensus.ConsensusMaker $@" |
| 97 | echo $CMD >&2 |
| 98 | eval $CMD |
| 99 | } |
| 100 | |
| 101 | consensus "$@" |