| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified March 31, 2025 |
| 7 | |
| 8 | Description: Bins contigs using coverage and kmer frequencies. |
| 9 | If reads or covstats are provided, coverage will be calculated from those; |
| 10 | otherwise, it will be parsed from contig headers. Coverage can be parsed |
| 11 | from Spades or Tadpole contig headers; alternatively, renamebymapping.sh |
| 12 | can be used to annotate the headers with coverage from multiple sam files. |
| 13 | Any number of sam files may be used (from different samples of the same |
| 14 | environment, usually). The more sam files, the more accurate, though |
| 15 | some stringency (depthratio and maxcovariance) may need to be relaxed |
| 16 | with large numbers of sam files (more than 4). Ideally, sam files will |
| 17 | be generated from paired reads like this: |
| 18 | bbmap.sh ref=contigs.fa in=reads.fq ambig=random mateqtag minid=0.9 maxindel=10 out=mapped.sam |
| 19 | For PacBio-only metagenomes, it is best to generate synthetic paired |
| 20 | reads from the PacBio CCS reads, and align those. |
| 21 | |
| 22 | Usage: quickbin.sh in=contigs.fa out=bins/bin_%.fa *.sam covout=cov.txt |
| 23 | or |
| 24 | quickbin.sh in=contigs.fa out=bins/bin_%.fa cov=cov.txt |
| 25 | or |
| 26 | quickbin.sh contigs.fa out=bins *.sam |
| 27 | |
| 28 | File parameters: |
| 29 | in=<file> Assembly input; only required parameter. Files named *.fa |
| 30 | or *.fasta do not need 'in='. |
| 31 | reads=<file> Read input (fastq or sam). Multiple sam files may be used, |
| 32 | comma-delimited, or as plain arguments without 'reads='. |
| 33 | Multiple files will be assumed to be independent samples. |
| 34 | cov=<file> Cov file generated by QuickBin from sam files. Files |
| 35 | named cov*.txt do not need 'cov='. |
| 36 | out=<pattern> Output pattern. If this contains a % symbol, like bin%.fa, |
| 37 | one file will be created per bin. If not, all contigs will |
| 38 | be written to the same file, with the name modified to |
| 39 | indicate their bin number. A term without a '.' symbol |
| 40 | like 'out=output' will be considered a directory. |
| 41 | |
| 42 | Size parameters: |
| 43 | mincluster=50k Minimum output cluster size in base pairs; smaller clusters |
| 44 | will share a residual file. |
| 45 | mincontig=100 Don't load contigs smaller than this; reduces memory usage. |
| 46 | minseed=3000 Minimum contig length to create a new cluster; reducing this |
| 47 | can increase speed dramatically for large metagenomes, |
| 48 | increase sensitivity for small contigs, and slightly increase |
| 49 | contamination. In particular, large metagenomes with only |
| 50 | 1 sample will run slowly if this is below 2000; with |
| 51 | at least 3 samples the speed should not be affected much. |
| 52 | minresidue=200 Discard unclustered contigs shorter than this; reduces memory. |
| 53 | |
| 54 | Stringency parameters: |
| 55 | normal Default stringency is 'normal'. All settings, in order of |
| 56 | increasing sensitivity, are: xstrict, ustrict, vstrict, |
| 57 | strict, normal, loose, vloose, uloose, xloose. 'normal' |
| 58 | aims at under 1% contamination; 'uloose' is more comparable |
| 59 | in stringency to other binners. To set a stringency just add |
| 60 | that flag (without an = sign). Acceptable shorthand is |
| 61 | xs, us, vs, s, n, l, vl, ul, xl. |
| 62 | |
| 63 | Quantization parameters: |
| 64 | gcwidth=0.02 Width of GC matrix gridlines. Smaller is faster. |
| 65 | depthwidth=0.5 Width of depth matrix gridlines. Smaller is faster. This |
| 66 | is on a log2 scale so 0.5 would mean 2 gridlines per power |
| 67 | of 2 depth - lines at 0.707, 1, 1.414, 2, 2.818, 4, etc. |
| 68 | Note: Halving either quantization parameter can roughly double speed, |
| 69 | but will decrease recovery of shorter contigs. |
| 70 | |
| 71 | Neural network parameters: |
| 72 | net=auto Specify a neural network file to use. |
| 73 | cutoff=0.56 Neural network output threshold; higher increases specificity, |
| 74 | lower increases sensitivity. |
| 75 | |
| 76 | Edge-processing parameters: |
| 77 | e1=0 Edge-first clustering passes; may increase speed |
| 78 | at the cost of purity. |
| 79 | e2=4 Later edge-based clustering passes. |
| 80 | edgeStringency1=0.25 Stringency for edge-first clustering; |
| 81 | lower is more stringent. |
| 82 | edgeStringency2=2 Stringency for later edge-based clustering. |
| 83 | maxEdges=3 Follow up to this many edges per contig. |
| 84 | minEdgeWeight=2 Ignore edges made from fewer read pairs. |
| 85 | minEdgeRatio=0.4 Ignore edges under this fraction of max edge weight. |
| 86 | minmapq=20 Ignore reads mapping with mapq below this for the |
| 87 | purpose of making edges. They are still used for depth. |
| 88 | goodEdgeMult=1.4 Merge stringency multiplier for contigs joined by |
| 89 | an edge; lower is more stringent. |
| 90 | |
| 91 | Other parameters: |
| 92 | sketchoutput=f Use SendSketch to identify taxonomy of output clusters. |
| 93 | validate=f If contig headers have a term such as 'tid_1234', this |
| 94 | will be parsed and used to evaluate correctness. |
| 95 | |
| 96 | Java Parameters: |
| 97 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 98 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will |
| 99 | specify 200 megs. The max is typically 85% of physical memory. |
| 100 | -eoom This flag will cause the process to exit if an out-of-memory |
| 101 | exception occurs. Requires Java 8u92+. |
| 102 | -da Disable assertions. |
| 103 | |
| 104 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 105 | " |
| 106 | } |
| 107 | |
| 108 | #This block allows symlinked shellscripts to correctly set classpath. |
| 109 | pushd . > /dev/null |
| 110 | DIR="${BASH_SOURCE[0]}" |
| 111 | while [ -h "$DIR" ]; do |
| 112 | cd "$(dirname "$DIR")" |
| 113 | DIR="$(readlink "$(basename "$DIR")")" |
| 114 | done |
| 115 | cd "$(dirname "$DIR")" |
| 116 | DIR="$(pwd)/" |
| 117 | popd > /dev/null |
| 118 | |
| 119 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 120 | CP="$DIR""current/" |
| 121 | |
| 122 | z="-Xmx4g" |
| 123 | z2="-Xms4g" |
| 124 | set=0 |
| 125 | |
| 126 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 127 | usage |
| 128 | exit |
| 129 | fi |
| 130 | |
| 131 | calcXmx () { |
| 132 | source "$DIR""/calcmem.sh" |
| 133 | setEnvironment |
| 134 | parseXmx "$@" |
| 135 | if [[ $set == 1 ]]; then |
| 136 | return |
| 137 | fi |
| 138 | freeRam 4000m 84 |
| 139 | z="-Xmx${RAM}m" |
| 140 | z2="-Xms${RAM}m" |
| 141 | } |
| 142 | calcXmx "$@" |
| 143 | |
| 144 | quickbin() { |
| 145 | local CMD="java $EA $EOOM $SIMD $z -cp $CP bin.QuickBin $@" |
| 146 | echo $CMD >&2 |
| 147 | eval $CMD |
| 148 | } |
| 149 | |
| 150 | quickbin "$@" |