| 1 | #!/bin/bash |
| 2 | |
| 3 | usage(){ |
| 4 | echo " |
| 5 | Written by Brian Bushnell |
| 6 | Last modified November 12, 2024 |
| 7 | |
| 8 | Description: Performs high-speed alignment-free sequence quantification, |
| 9 | by counting the number of long kmers that match between a read and |
| 10 | a set of reference sequences. Designed for RNA-seq with alternative splicing. |
| 11 | Please read bbmap/docs/guides/SealGuide.txt for more information. |
| 12 | |
| 13 | Usage Examples (not comprehensive): |
| 14 | |
| 15 | Sequence quantification: |
| 16 | seal.sh in=<file> ref=<file> rpkm=rpkm.txt stats=stats.txt |
| 17 | or |
| 18 | seal.sh in=<file> ref=<file,file,file...> refstats=refstats.txt |
| 19 | |
| 20 | Splitting: |
| 21 | seal.sh in=<file> ref=<file,file,file...> pattern=out_%.fq outu=unmapped.fq |
| 22 | or |
| 23 | seal.sh in=<file> *.fasta pattern=out_%.fq outu=unmapped.fq |
| 24 | |
| 25 | Input may be fasta or fastq, compressed or uncompressed. |
| 26 | If you pipe via stdin/stdout, please include the file type; e.g. for gzipped |
| 27 | fasta input, set in=stdin.fa.gz |
| 28 | |
| 29 | |
| 30 | Input parameters: |
| 31 | in=<file> Main input. in=stdin.fq will pipe from stdin. |
| 32 | in2=<file> Input for 2nd read of pairs in a different file. |
| 33 | ref=<file,file> Comma-delimited list of reference files or directories. |
| 34 | Filenames may also be used without ref=, e.g. *.fa. |
| 35 | In addition to filenames, you may also use the keywords: |
| 36 | adapters, artifacts, phix, lambda, pjet, mtst, kapa. |
| 37 | literal=<seq,seq> Comma-delimited list of literal reference sequences. |
| 38 | touppercase=f (tuc) Change all bases upper-case. |
| 39 | interleaved=auto (int) t/f overrides interleaved autodetection. |
| 40 | Must be set mainually when streaming fastq input. |
| 41 | qin=auto Input quality offset: 33 (Sanger), 64, or auto. |
| 42 | reads=-1 If positive, quit after processing X reads or pairs. |
| 43 | copyundefined=f (cu) Process non-AGCT IUPAC reference bases by making all |
| 44 | possible unambiguous copies. Intended for short motifs |
| 45 | or adapter barcodes, as time/memory use is exponential. |
| 46 | |
| 47 | Output parameters: |
| 48 | out=<file> (outmatch) Write reads here that contain kmers matching |
| 49 | the reference. 'out=stdout.fq' will pipe to standard out. |
| 50 | out2=<file> (outmatch2) Use this to write 2nd read of pairs to a |
| 51 | different file. |
| 52 | outu=<file> (outunmatched) Write reads here that do not contain kmers |
| 53 | matching the database. |
| 54 | outu2=<file> (outunmatched2) Use this to write 2nd read of pairs to a |
| 55 | different file. |
| 56 | pattern=<file> Use this to write reads to one stream per ref sequence |
| 57 | match, replacing the % character with the sequence name. |
| 58 | For example, pattern=%.fq for ref sequences named dog and |
| 59 | cat would create dog.fq and cat.fq. |
| 60 | stats=<file> Write statistics about which contamininants were detected. |
| 61 | refstats=<file> Write statistics on a per-reference-file basis. |
| 62 | rpkm=<file> Write RPKM for each reference sequence (for RNA-seq). |
| 63 | dump=<file> Dump kmer tables to a file, in fasta format. |
| 64 | nzo=t Only write statistics about ref sequences with nonzero hits. |
| 65 | overwrite=t (ow) Grant permission to overwrite files. |
| 66 | showspeed=t (ss) 'f' suppresses display of processing speed. |
| 67 | ziplevel=2 (zl) Compression level; 1 (min) through 9 (max). |
| 68 | fastawrap=80 Length of lines in fasta output. |
| 69 | qout=auto Output quality offset: 33 (Sanger), 64, or auto. |
| 70 | statscolumns=5 (cols) Number of columns for stats output, 3 or 5. |
| 71 | 5 includes base counts. |
| 72 | rename=f Append matched reference sequence names to read headers. |
| 73 | addcount=t If renaming, include the ref hit counts. |
| 74 | tophitonly=f If renaming, only add the top hit. |
| 75 | refnames=f Use names of reference files rather than scaffold IDs. |
| 76 | With multiple reference files, this is more efficient |
| 77 | than tracking statistics on a per-sequence basis. |
| 78 | trd=f Truncate read and ref names at the first whitespace. |
| 79 | ordered=f Set to true to output reads in same order as input. |
| 80 | kpt=t (keepPairsTogether) Paired reads will always be assigned |
| 81 | to the same ref sequence. |
| 82 | |
| 83 | Processing parameters: |
| 84 | k=31 Kmer length used for finding contaminants. Contaminants |
| 85 | shorter than k will not be found. k must be at least 1. |
| 86 | rcomp=t Look for reverse-complements of kmers in addition to |
| 87 | forward kmers. |
| 88 | maskmiddle=t (mm) Treat the middle base of a kmer as a wildcard, to |
| 89 | increase sensitivity in the presence of errors. This may |
| 90 | also be set to a number, e.g. mm=3, to mask that many bp. |
| 91 | The default mm=t corresponds to mm=1 for odd-length kmers |
| 92 | and mm=2 for even-length kmers (as of v39.04), while |
| 93 | mm=f is always equivalent to mm=0. |
| 94 | minkmerhits=1 (mkh) A read needs at least this many kmer hits to be |
| 95 | considered a match. |
| 96 | minkmerfraction=0.0 (mkf) A reads needs at least this fraction of its total |
| 97 | kmers to hit a ref, in order to be considered a match. |
| 98 | hammingdistance=0 (hdist) Maximum Hamming distance for ref kmers (subs only). |
| 99 | Memory use is proportional to (3*K)^hdist. |
| 100 | qhdist=0 Hamming distance for query kmers; impacts speed, not memory. |
| 101 | editdistance=0 (edist) Maximum edit distance from ref kmers (subs and |
| 102 | indels). Memory use is proportional to (8*K)^edist. |
| 103 | forbidn=f (fn) Forbids matching of read kmers containing N. |
| 104 | By default, these will match a reference 'A' if hdist>0 |
| 105 | or edist>0, to increase sensitivity. |
| 106 | match=all Determines when to quit looking for kmer matches. Values: |
| 107 | all: Attempt to match all kmers in each read. |
| 108 | first: Quit after the first matching kmer. |
| 109 | unique: Quit after the first uniquely matching kmer. |
| 110 | ambiguous=random (ambig) Set behavior on ambiguously-mapped reads (with an |
| 111 | equal number of kmer matches to multiple sequences). |
| 112 | first: Use the first best-matching sequence. |
| 113 | toss: Consider unmapped. |
| 114 | random: Select one best-matching sequence randomly. |
| 115 | all: Use all best-matching sequences. |
| 116 | genesets=f Assign ambiguously-mapping reads to a newly created gene |
| 117 | set that they share for stats/rpkm output. May be slow. |
| 118 | clearzone=0 (cz) Threshhold for ambiguity. If the best match shares X |
| 119 | kmers with the read, the read will be considered |
| 120 | also ambiguously mapped to any sequence sharing at least |
| 121 | [X minus clearzone] kmers. |
| 122 | czf=0.0 (clearzonefraction) If positive, the actual clearzone used |
| 123 | for a read with N total kmers will be max(cz, czf*N). |
| 124 | ecco=f For overlapping paired reads only. Performs error- |
| 125 | correction with BBMerge prior to kmer operations. |
| 126 | |
| 127 | Containment parameters: |
| 128 | processcontainedref=f Require a reference sequence to be fully contained by |
| 129 | an input sequence |
| 130 | storerefbases=f Store reference bases so that ref containments can be |
| 131 | validated. If this is set to false and processcontainedref |
| 132 | is true, then it will only require that the read share the |
| 133 | same number of bases as are present in the ref sequence. |
| 134 | |
| 135 | Taxonomy parameters (only use when doing taxonomy): |
| 136 | tax=<file> Output destination for taxonomy information. |
| 137 | taxtree=<file> (tree) A serialized TaxTree (tree.taxtree.gz). |
| 138 | gi=<file> A serialized GiTable (gitable.int1d.gz). Only needed if |
| 139 | reference sequence names start with 'gi|'. |
| 140 | mincount=1 Only display taxa with at least this many hits. |
| 141 | maxnodes=-1 If positive, display at most this many top hits. |
| 142 | minlevel=subspecies Do not display nodes below this taxonomic level. |
| 143 | maxlevel=life Do not display nodes above this taxonomic level. |
| 144 | Valid levels are subspecies, species, genus, family, order, class, |
| 145 | phylum, kingdom, domain, life |
| 146 | |
| 147 | Speed and Memory parameters: |
| 148 | threads=auto (t) Set number of threads to use; default is number of |
| 149 | logical processors. |
| 150 | prealloc=f Preallocate memory in table. Allows faster table loading |
| 151 | and more efficient memory usage, for a large reference. |
| 152 | monitor=f Kill this process if CPU usage drops to zero for a long |
| 153 | time. monitor=600,0.01 would kill after 600 seconds |
| 154 | under 1% usage. |
| 155 | rskip=1 Skip reference kmers to reduce memory usage. |
| 156 | 1 means use all, 2 means use every other kmer, etc. |
| 157 | qskip=1 Skip query kmers to increase speed. 1 means use all. |
| 158 | speed=0 Ignore this fraction of kmer space (0-15 out of 16) in both |
| 159 | reads and reference. Increases speed and reduces memory. |
| 160 | Note: Do not use more than one of 'speed', 'qskip', and 'rskip'. |
| 161 | |
| 162 | Trimming/Masking parameters: |
| 163 | qtrim=f Trim read ends to remove bases with quality below trimq. |
| 164 | Performed AFTER looking for kmers. Values: |
| 165 | t (trim both ends), |
| 166 | f (neither end), |
| 167 | r (right end only), |
| 168 | l (left end only). |
| 169 | trimq=6 Regions with average quality BELOW this will be trimmed. |
| 170 | minlength=1 (ml) Reads shorter than this after trimming will be |
| 171 | discarded. Pairs will be discarded only if both are shorter. |
| 172 | maxlength= Reads longer than this after trimming will be discarded. |
| 173 | Pairs will be discarded only if both are longer. |
| 174 | minavgquality=0 (maq) Reads with average quality (after trimming) below |
| 175 | this will be discarded. |
| 176 | maqb=0 If positive, calculate maq from this many initial bases. |
| 177 | maxns=-1 If non-negative, reads with more Ns than this |
| 178 | (after trimming) will be discarded. |
| 179 | forcetrimleft=0 (ftl) If positive, trim bases to the left of this position |
| 180 | (exclusive, 0-based). |
| 181 | forcetrimright=0 (ftr) If positive, trim bases to the right of this position |
| 182 | (exclusive, 0-based). |
| 183 | forcetrimright2=0 (ftr2) If positive, trim this many bases on the right end. |
| 184 | forcetrimmod=0 (ftm) If positive, right-trim length to be equal to zero, |
| 185 | modulo this number. |
| 186 | restrictleft=0 If positive, only look for kmer matches in the |
| 187 | leftmost X bases. |
| 188 | restrictright=0 If positive, only look for kmer matches in the |
| 189 | rightmost X bases. |
| 190 | |
| 191 | Java Parameters: |
| 192 | -Xmx This will set Java's memory usage, overriding autodetection. |
| 193 | -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will specify 200 megs. |
| 194 | The max is typically 85% of physical memory. |
| 195 | -eoom This flag will cause the process to exit if an |
| 196 | out-of-memory exception occurs. Requires Java 8u92+. |
| 197 | -da Disable assertions. |
| 198 | |
| 199 | Please contact Brian Bushnell at [email protected] if you encounter any problems. |
| 200 | " |
| 201 | } |
| 202 | |
| 203 | #This block allows symlinked shellscripts to correctly set classpath. |
| 204 | pushd . > /dev/null |
| 205 | DIR="${BASH_SOURCE[0]}" |
| 206 | while [ -h "$DIR" ]; do |
| 207 | cd "$(dirname "$DIR")" |
| 208 | DIR="$(readlink "$(basename "$DIR")")" |
| 209 | done |
| 210 | cd "$(dirname "$DIR")" |
| 211 | DIR="$(pwd)/" |
| 212 | popd > /dev/null |
| 213 | |
| 214 | #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/" |
| 215 | CP="$DIR""current/" |
| 216 | |
| 217 | z="-Xmx1g" |
| 218 | z2="-Xms1g" |
| 219 | set=0 |
| 220 | |
| 221 | if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then |
| 222 | usage |
| 223 | exit |
| 224 | fi |
| 225 | |
| 226 | calcXmx () { |
| 227 | source "$DIR""/calcmem.sh" |
| 228 | setEnvironment |
| 229 | parseXmx "$@" |
| 230 | if [[ $set == 1 ]]; then |
| 231 | return |
| 232 | fi |
| 233 | freeRam 2000m 84 |
| 234 | z="-Xmx${RAM}m" |
| 235 | z2="-Xms${RAM}m" |
| 236 | } |
| 237 | calcXmx "$@" |
| 238 | |
| 239 | seal() { |
| 240 | local CMD="java $EA $EOOM $z $z2 -cp $CP jgi.Seal $@" |
| 241 | echo $CMD >&2 |
| 242 | eval $CMD |
| 243 | } |
| 244 | |
| 245 | seal "$@" |