| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | BBSplit |
| 6 | Written by Brian Bushnell, from Dec. 2010 - present |
| 7 | Last modified June 11, 2018 |
| 8 | |
| 9 | Description: Maps reads to multiple references simultaneously. |
| 10 | Outputs reads to a file for the reference they best match, with multiple options for dealing with ambiguous mappings. |
| 11 | |
| 12 | To index: bbsplit.sh build=<1> ref_x=<reference fasta> ref_y=<another reference fasta> |
| 13 | To map: bbsplit.sh build=<1> in=<reads> out_x=<output file> out_y=<another output file> |
| 14 | |
| 15 | To be concise, and do everything in one command: |
| 16 | bbsplit.sh ref=x.fa,y.fa in=reads.fq basename=o%.fq |
| 17 | |
| 18 | that is equivalent to |
| 19 | bbsplit.sh build=1 in=reads.fq ref_x=x.fa ref_y=y.fa out_x=ox.fq out_y=oy.fq |
| 20 | |
| 21 | By default paired reads will yield interleaved output, but you can use the # symbol to produce twin output files. |
| 22 | For example, basename=o%_#.fq will produce ox_1.fq, ox_2.fq, oy_1.fq, and oy_2.fq. |
| 23 | |
| 24 | |
| 25 | Indexing Parameters (required when building the index): |
| 26 | ref=<file,file> A list of references, or directories containing fasta files. |
| 27 | ref_<name>=<ref.fa> Alternate, longer way to specify references. e.g., ref_ecoli=ecoli.fa |
| 28 | These can also be comma-delimited lists of files; e.g., ref_a=a1.fa,a2.fa,a3.fa |
| 29 | build=<1> If multiple references are indexed in the same directory, each needs a unique build ID. |
| 30 | path=<.> Specify the location to write the index, if you don't want it in the current working directory. |
| 31 | |
| 32 | Input Parameters: |
| 33 | build=<1> Designate index to use. Corresponds to the number specified when building the index. |
| 34 | in=<reads.fq> Primary reads input; required parameter. |
| 35 | in2=<reads2.fq> For paired reads in two files. |
| 36 | qin=<auto> Set to 33 or 64 to specify input quality value ASCII offset. |
| 37 | interleaved=<auto> True forces paired/interleaved input; false forces single-ended mapping. |
| 38 | If not specified, interleaved status will be autodetected from read names. |
| 39 | |
| 40 | Mapping Parameters: |
| 41 | maxindel=<20> Don't look for indels longer than this. Lower is faster. Set to >=100k for RNA-seq. |
| 42 | minratio=<0.56> Fraction of max alignment score required to keep a site. Higher is faster. |
| 43 | minhits=<1> Minimum number of seed hits required for candidate sites. Higher is faster. |
| 44 | ambiguous=<best> Set behavior on ambiguously-mapped reads (with multiple top-scoring mapping locations). |
| 45 | best (use the first best site) |
| 46 | toss (consider unmapped) |
| 47 | random (select one top-scoring site randomly) |
| 48 | all (retain all top-scoring sites. Does not work yet with SAM output) |
| 49 | ambiguous2=<best> Set behavior only for reads that map ambiguously to multiple different references. |
| 50 | Normal 'ambiguous=' controls behavior on all ambiguous reads; |
| 51 | Ambiguous2 excludes reads that map ambiguously within a single reference. |
| 52 | best (use the first best site) |
| 53 | toss (consider unmapped) |
| 54 | all (write a copy to the output for each reference to which it maps) |
| 55 | split (write a copy to the AMBIGUOUS_ output for each reference to which it maps) |
| 56 | qtrim=<true> Quality-trim ends to Q5 before mapping. Options are 'l' (left), 'r' (right), and 'lr' (both). |
| 57 | untrim=<true> Undo trimming after mapping. Untrimmed bases will be soft-clipped in cigar strings. |
| 58 | |
| 59 | Output Parameters: |
| 60 | out_<name>=<file> Output reads that map to the reference <name> to <file>. |
| 61 | basename=prefix%suffix Equivalent to multiple out_%=prefix%suffix expressions, in which each % is replaced by the name of a reference file. |
| 62 | bs=<file> Write a shell script to 'file' that will turn the sam output into a sorted, indexed bam file. |
| 63 | scafstats=<file> Write statistics on how many reads mapped to which scaffold to this file. |
| 64 | refstats=<file> Write statistics on how many reads were assigned to which reference to this file. |
| 65 | Unmapped reads whose mate mapped to a reference are considered assigned and will be counted. |
| 66 | nzo=t Only print lines with nonzero coverage. |
| 67 | |
| 68 | ***** Notes ***** |
| 69 | Almost all BBMap parameters can be used; run bbmap.sh for more details. |
| 70 | Exceptions include the 'nodisk' flag, which BBSplit does not support. |
| 71 | BBSplit is recommended for fastq and fasta output, not for sam/bam output. |
| 72 | When the reference sequences are shorter than read length, use Seal instead of BBSplit. |
| 73 | |
| 74 | Java Parameters: |
| 75 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 76 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. |
| 77 | The max is typically 85% of physical memory. |
| 78 | -eoom This flag will cause the process to exit if an |
| 79 | out-of-memory exception occurs. Requires Java 8u92+. |
| 80 | -da Disable assertions. |
| 81 | |
| 82 | This list is not complete. For more information, please consult $DIRdocs/readme.txt |
| 83 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 84 | " |
| 85 | } |
| 86 | |
| 87 | #This block allows symlinked shellscripts to correctly set classpath. |
| 88 | pushd . > /dev/null |
| 89 | DIR="${BASH_SOURCE[0]}" |
| 90 | while [ -h "$DIR" ]; do |
| 91 | cd "$(dirname "$DIR")" |
| 92 | DIR="$(readlink "$(basename "$DIR")")" |
| 93 | done |
| 94 | cd "$(dirname "$DIR")" |
| 95 | DIR="$(pwd)/" |
| 96 | popd > /dev/null |
| 97 | |
| 98 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 99 | CP="$DIR""current/" |
| 100 | JNI="-Djava.library.path=""$DIR""jni/" |
| 101 | JNI="" |
| 102 | |
| 103 | z="-Xmx1g" |
| 104 | z2="-Xms1g" |
| 105 | set=0 |
| 106 | |
| 107 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 108 | usage |
| 109 | exit |
| 110 | fi |
| 111 | |
| 112 | calcXmx () { |
| 113 | source "$DIR""/calcmem.sh" |
| 114 | setEnvironment |
| 115 | parseXmx "$@" |
| 116 | if [[ $set == 1 ]]; then |
| 117 | return |
| 118 | fi |
| 119 | freeRam 3200m 84 |
| 120 | z="-Xmx${RAM}m" |
| 121 | z2="-Xms${RAM}m" |
| 122 | } |
| 123 | calcXmx "$@" |
| 124 | |
| 125 | function bbsplit() { |
| 126 | local CMD="java $EA $EOOM $z $z2 $JNI -cp $CP align2.BBSplitter ow=t fastareadlen=500 minhits=1 minratio=0.56 maxindel=20 qtrim=rl untrim=t trimq=6 $@" |
| 127 | echo $CMD >&2 |
| 128 | eval $CMD |
| 129 | } |
| 130 | |
| 131 | bbsplit "$@" |