minimap2(1)
๐ธ minimap2 โ the bestie guide ๐
minimap2(1) ยท part of the Bioinformatics tools family, and honestly? iconic.
โจ NAME โจ
minimap2 โ mapping and alignment between collections of DNA sequences. Yeah. That's the whole job. She maps, she aligns, she slays. ๐งฌ๐
๐ SYNOPSIS ๐
okay so here's the vibe, three whole modes:
* Indexing the target sequences (optional):
minimap2 [-x preset] -d target.mmi target.fa
minimap2 [-H] [-k kmer] [-w miniWinSize] [-I batchSize] -d
target.mmi target.fa
* Long-read alignment with CIGAR:
minimap2 -a [-x preset] target.mmi query.fa > output.sam
minimap2 -c [-H] [-k kmer] [-w miniWinSize] [...] target.fa
query.fa > output.paf
* Long-read overlap without CIGAR:
minimap2 -x ava-ont [-t nThreads] target.fa query.fa > output.paf
๐ฆ DESCRIPTION ๐ฆ
Minimap2 is a fast sequence mapping and alignment program that can find overlaps between long noisy reads, or map long reads or their assemblies to a reference genome โ optionally with detailed alignment (i.e. CIGAR). Obsessed with the "optionally", tbh.
Right now it works efficiently with query sequences from a few kilobases to ~100 megabases in length at a error rate ~15%. ~100 megabases bestie. She's built different.
Minimap2 outputs in the PAF or the SAM format. Pick your fighter. ๐
๐ OPTIONS ๐
๐ธ Indexing options
-k INTโ minimizer k-mer length[15]. The classic.-w INTโ minimizer window size[10]. A minimizer is the smallest k-mer in a window ofwconsecutive k-mers. So like, the main character k-mer of every little friend group.-j INTโ syncmer submer size[10]. Heads up:-jand-wwill override each other โ if-wis applied after-j, then-jwill have no effect, and vice versa. They're fighting, basically. Only one survives. ๐-Hโ use homopolymer-compressed (HPC) minimizers. An HPC sequence is constructed by contracting homopolymer runs to a single base, and an HPC minimizer is a minimizer on the HPC sequence. Compression era. โจ-I NUMโ load at mostNUMtarget bases into RAM for indexing[8G]. If there are more thanNUMbases intarget.fa, minimap2 needs to readquery.famultiple times to map it against each batch of target sequences โ which would create a multi-part index.NUMmay be ending withk/K/m/M/g/G. Also see option--split-prefix.
NB: mapping quality is incorrect given a multi-part index. Not a vibe. Know that going in. ๐ญ
--idx-no-seqโ don't store target sequences in the index. It saves disk space and memory, but the index generated with this option will not work with-aor-c. When base-level alignment is not requested, this option is automatically applied. So sometimes she just does it herself, no permission needed.-d FILEโ save the minimizer index oftarget.fatoFILE[no dump]. Minimap2 indexing is fast โ it can index the human genome in a couple of minutes. If even shorter startup time is desired, use this option to save the index. Indexing options are fixed in the index file. And when an index file is provided as the target sequences, options-H,-k,-w,-Iwill be effectively overridden by the options stored in the index file. The index ate and left no crumbs. ๐--alt FILEโ list of ALT contigs[null]--alt-drop FLOATโ drop ALT hits byFLOATfraction when ranking and computing mapping quality[0.15]
๐ฅ Mapping options
-f FLOAT|INT1[,INT2]โ if fraction, ignore topFLOATfraction of most frequent minimizers[0.0002]. If integer, ignore minimizers occuring more thanINT1times.INT2is only effective in the--sror-xsrmode, which sets the threshold for a second round of seeding. Two rounds of seeding? She's thorough. ๐-U INT1[,INT2]โ lower and upper bounds of k-mer occurrences[10,1000000]. The final k-mer occurrence threshold ismax{INT1, min{INT2, -f}}. This option prevents excessively small or large-festimated from the input reference. Available since r1034 and deprecating--min-occ-floorin earlier versions of minimap2. Rip to a real one.--q-occ-frac FLOATโ discard a query minimizer if its occurrence is higher thanFLOATfraction of query minimizers and than the reference occurrence threshold[0.01]. Set0to disable. Available since r1105.-e INTโ sample a high-frequency minimizer everyINTbasepairs[500]-g NUMโ stop chain enlongation if there are no minimizers withinNUM-bp[10k]-r NUM1[,NUM2]โ bandwidth for chaining and base alignment[500,20k].NUM1is used for initial chaining and alignment extension;NUM2for RMQ-based re-chaining and closing gaps in alignments.-n INTโ discard chains consisting of<INTnumber of minimizers[3]-m INTโ discard chains with chaining score<INT[40]. Chaining score equals the approximate number of matching bases minus a concave gap penalty. It is computed with dynamic programming. Math girlie behavior, we respect it. ๐งฎ-Dโ if query sequence name/length are identical to the target name/length, ignore diagonal anchors. This option also reduces DP-based extension along the diagonal.-Pโ retain all chains and don't attempt to set primary chains. Options-pand-Nhave no effect when this option is in use. Everyone's a main character now. โจ--dual=yes|noโ ifno, skip query-target pairs wherein the query name is lexicographically greater than the target name[yes]-Xโ equivalent to'-DP --dual=no --no-long-join'. Primarily used for all-vs-all read overlapping.-p FLOATโ minimal secondary-to-primary score ratio to output secondary mappings[0.8]. Between two chains overlaping over half of the shorter chain (controlled by-M), the chain with a lower score is secondary to the chain with a higher score. If the ratio of the scores is belowFLOAT, the secondary chain will not be outputted or extended with DP alignment later. This option has no effect when-Xis applied.-N INTโ output at mostINTsecondary alignments[5]. This option has no effect when-Xis applied.-G NUMโ maximum gap on the reference (effective with-xsplice/--splice). This option also changes the chaining and alignment band width toNUM. Increasing this option slows down spliced alignment.[200k]-F NUMโ maximum fragment length (aka insert size; effective with-xsr/--frag=yes)[800]-M FLOATโ mark as secondary a chain that overlaps with a better chain byFLOATor more of the shorter chain[0.5]--rmq=no|yesโ use the minigraph chaining algorithm[no]. The minigraph algorithm is better for aligning contigs through long INDELs. Situational queen. ๐ฆ--hard-mask-levelโ honor option-Mand disable a heurstic to save unmapped subsequences and disables--mask-len.--mask-len NUMโ keep an alignment if dropping it leaves an unaligned region on query longer thanINT[inf]. Effective without--hard-mask-level.--max-chain-skip INTโ a heuristics that stops chaining early[25]. Minimap2 uses dynamic programming for chaining, and the time complexity is quadratic in the number of seeds. This option makes minimap2 exits the inner loop if it repeatedly sees seeds already on chains. SetINTto a large number to switch off this heurstics. Escape hatch unlocked. ๐ช--max-chain-iter INTโ check up toINTpartial chains during chaining[5000]. This is a heuristic to avoid quadratic time complexity in the worst case. The worst case said "not today" and minimap2 said "bet".--chain-gap-scale FLOATโ scale of gap cost during chaining[1.0]--no-long-joinโ disable the long gap patching heuristic. When this option is applied, the maximum alignment gap is mostly controlled by-r.--spliceโ enable the splice alignment mode. ๐งฌ--srโ enable short-read alignment heuristics. In the short-read mode, minimap2 applies a second round of chaining with a higher minimizer occurrence threshold if no good chain is found. In addition, minimap2 attempts to patch gaps between seeds with ungapped alignment. She's doing overtime fr fr.--split-prefix STRโ prefix to create temporary files. Typically used for a multi-part index.--frag=no|yesโ whether to enable the fragment mode[no]--for-onlyโ only map to the forward strand of the reference sequences. For paired-end reads in the forward-reverse orientation, the first read is mapped to forward strand of the reference and the second read to the reverse stand.--rev-onlyโ only map to the reverse complement strand of the reference sequences.--heap-sort=no|yesโ ifyes, sort anchors with heap merge, instead of radix sort. Heap merge is faster for short reads, but slower for long reads.[no]Short-read girlies, this one's for you. ๐--no-pairingโ treat two reads in a pair as independent reads. The mate related fields in SAM are still properly populated. They're not together anymore but the paperwork is still filed. ๐ญ--no-hash-nameโ produce the same alignment for identical sequences regardless of their sequence names. No name bias, we love to see it. ๐
โญ Alignment options
-A INTโ matching score[2]-B INTโ mismatching penalty[4]-b INTโ mismatching penalty for transitions[same as -B]-O INT1[,INT2]โ gap open penalty[4,24]. IfINT2is not specified, it is set toINT1.-E INT1[,INT2]โ gap extension penalty[2,1]. A gap of lengthkcostsmin{O1+k*E1,O2+k*E2}. In the splice mode, the second gap penalties are not used.-J INTโ splice model[1].0for the original minimap2 splice model that always penalizes non-GT-AG splicing;1for the miniprot model that considers non-GT-AG. Option-Chas no effect with the default-J1.-J0.-C INTโ cost for a non-canonical GT-AG splicing (effective with--splice -J0)[0].-z INT1[,INT2]โ truncate an alignment if the running alignment score drops too quickly along the diagonal of the DP matrix (diagonal X-drop, or Z-drop)[400,200]. If the drop of score is aboveINT2, minimap2 will reverse complement the query in the related region and align again to test small inversions. Minimap2 truncates alignment if there is an inversion or the drop of score is greater thanINT1. DecreaseINT2to find small inversions at the cost of performance and false positives. IncreaseINT1to improves the contiguity of alignment at the cost of poor alignment in the middle. Tuning era, choose your struggle. ๐-s INTโ minimal peak DP alignment score to output[40]. The peak score is computed from the finalCIGAR. It is the score of the max scoring segment in the alignment and may be different from the total alignment score.
okay bestie that's the indexing, mapping and alignment tea so far โ but there's literally more coming, don't go anywhere ๐
-u CHARโ how to sniff out canonical splice sites (the GT-AG ones ๐ ).f= transcript strand only,b= both strands,n= don't even try to match GT-AG [n]--end-bonus INTโ score bonus when your alignment stretches all the way to the end of the query sequence [0].--score-N INTโ the score of a mismatch that involves ambiguous bases [1].--splice-flank=yes|noโ assume the base right after a GT donor site tends to be A/G (91% in human, 92% in mouse ๐) and the base right before an AG acceptor tends to be C/T [no]. This trend is evolutionarily conservative, all the way down to S. cerevisiae (PMID:18688272). Setting this option usually bumps junction accuracy up by several percent, so it's applied by default with--splice. BUT the SIRV control doesn't honor this trend (only ~60%), so this option reduces accuracy there. If you're benchmarking minimap2 on SIRV data, please add--splice-flank=noto the command line.--junc-bed FILEโ gene annotations in BED12 format (aka 12-column BED), or intron positions in 5-column BED. With this option, minimap2 prefers splicing where the annotations say. BED12 files can be converted from GTF/GFF3 withpaftools.js gff2bed anno.gtf[].--junc-bonus INTโ score bonus for a splice donor or acceptor found in an annotation (only effective with--junc-bed) [9].--end-seed-pen INTโ drop a terminal anchor ifs<log(g)+INT, where s is the local alignment score around the anchor and g the length of the terminal gap in the chain. Only effective with--splice. It helps you avoid tiny terminal exons [6].--no-end-fltโ don't filter seeds towards the ends of chains before doing base-level alignment.--cap-sw-mem NUMโ skip alignment if the DP matrix size is above NUM. Set to 0 to disable [100m].--cap-kalloc NUMโ free the thread-local kalloc memory reservoir if, after the alignment, the size of the reservoir is above NUM. Set to 0 to disable [0].
๐ฅ Input/output options ๐ค
-aโ generate CIGAR and output alignments in the SAM format. Minimap2 spits out PAF by default.-o FILEโ write those alignments to FILE [stdout].-Qโ ignore base quality in the input file.-Lโ write CIGAR with >65535 operators at theCGtag. Older tools literally cannot convert alignments with >65535 CIGAR ops to BAM ๐ญ. This option makes minimap2's SAM compatible with those older tools. Newer tools recognize this tag and reconstruct the real CIGAR in memory.-R STRโ SAM read group line in a format like@RG\tID:foo\tSM:bar[].-yโ copy input FASTA/Q comments to the output.-cโ generate CIGAR. In PAF, the CIGAR goes into thecgcustom tag.--cs[=STR]โ output thecstag. STR can be eithershortorlong. If no STR is given,shortis assumed. [none]--MDโ output theMDtag (peep the SAM spec for that one).--eqxโ output=/XCIGAR operators for sequence match/mismatch.-Yโ in SAM output, use soft clipping for supplementary alignments.--secondary-seqโ in SAM output, show query sequences for secondary alignments.--seed INTโ integer seed for randomizing equally best hits. Minimap2 hashes INT and the read name when choosing between equally best hits [11].-t INTโ number of threads [3]. Minimap2 uses at most three threads while indexing target sequences, and up to INT+1 threads when mapping (that extra thread is for I/O, which is frequently idle and takes barely any CPU time).-2โ use two I/O threads during mapping. By default minimap2 uses one I/O thread. When I/O is slow (like piping to gzip, or reading from a slow pipe), the I/O thread can become the bottleneck. Apply this option to use one thread for input and another for output, at the cost of increased peak RAM.-K NUMโ number of bases loaded into memory to process in a mini-batch [500M]. Same as option-I, it accepts a K/M/G/k/m/g suffix. A large NUM helps load balancing in multi-threading mode, at the cost of increased memory.--secondary=yes|noโ whether to output secondary alignments [yes]--max-qlen NUMโ filter out query sequences longer than NUM.--paf-no-hitโ in PAF, output unmapped queries; the strand and reference name fields get set to*.
โ ๏ธ Warning: some paftools.js commands may not work with such output for the moment.
--sam-hit-onlyโ in SAM, don't output unmapped reads.--versionโ print the version number to stdout
๐ Preset options ๐
-x STRโ preset []. This option applies multiple options all at once. It should be applied before other options, because options applied later will overwrite the values set by-x. Available STR values are:map-ontโ align noisy long reads of ~10% error rate to a reference genome. This is the default mode.lr:hqโ align accurate long reads (error rate <1%) to a reference genome (-k19 -w19 -U50,500 -g10k). This was recommended by ONT developers for recent Nanopore reads produced with chemistry v14 that can reach ~99% accuracy. It was shown to work better for accurate Nanopore reads thanmap-hifi.map-hifiโ align PacBio high-fidelity (HiFi) reads to a reference genome (-xlr:hq -A1 -B4 -O6,26 -E2,1 -s200). It differs fromlr:hqonly in scoring. It has not been tested whetherlr:hqwould work better for PacBio HiFi reads.map-pbโ align older PacBio continuous long (CLR) reads to a reference genome (-Hk19). Note that this data type is effectively deprecated by HiFi. Unless you work on very old data, you probably wantmap-hifiorlr:hqinstead.map-iclrโ align Illumina Complete Long Reads (ICLR) to a reference genome (-k19 -B6 -b4 -O10,50). Recommended by Illumina developers.asm5โ long assembly to reference mapping (-k19 -w19 -U50,500 --rmq -r1k,100k -g10k -A1 -B19 -O39,81 -E3,1 -s200 -z200 -N50). Typically the alignment will not extend into regions with 5% or higher sequence divergence. Use this preset if the average divergence is not much higher than 0.1%.asm10โ long assembly to reference mapping (-k19 -w19 -U50,500 --rmq -r1k,100k -g10k -A1 -B9 -O16,41 -E2,1 -s200 -z200 -N50). Use this if the average divergence is around 1%.asm20โ long assembly to reference mapping (-k19 -w10 -U50,500 --rmq -r1k,100k -g10k -A1 -B4 -O6,26 -E2,1 -s200 -z200 -N50). Use this if the average divergence is around several percent.spliceโ long-read spliced alignment (-k15 -w5 --splice -g2k -G200k -A1 -B2 -O2,32 -E1,0 -C9 -z200 -ub --junc-bonus=9 --cap-sw-mem=0 --splice-flank=yes). In splice mode: 1) long deletions are taken as introns and represented as theNCIGAR operator; 2) long insertions are disabled; 3) deletion and insertion gap costs are different during chaining; 4) the computation of themstag ignores introns to demote hits to pseudogenes.splice:hqโ spliced alignment for accurate long RNA-seq reads such as PacBio iso-seq (-xsplice -C5 -O6,24 -B4).srโ short-read alignment without splicing (-k21 -w11 --sr --frag=yes -A2 -B8 -O12,32 -E2,1 -b0 -r100 -p.5 -N20 -f1000,5000 -n2 -m25 -s40 -g100 -2K50m --heap-sort=yes --secondary=no).ava-pbโ PacBio CLR all-vs-all overlap mapping (-Hk19 -Xw5 -e0 -m100).ava-ontโ Oxford Nanopore all-vs-all overlap mapping (-k15 -Xw5 -e0 -m100 -r2k).
๐ Miscellaneous options ๐
--no-kallocโ use the libc default allocator instead of the kalloc thread-local allocator. This debugging option is mostly used with Valgrind to detect invalid memory accesses. Minimap2 runs slower with this option, especially in multi-threading mode.--print-qnameโ print query names to stderr, mostly so you can see which query is crashing minimap2 ๐.--print-seedsโ print seed positions to stderr, for debugging only.
โจ OUTPUT FORMAT โจ
Okay bestie, by default minimap2 drops mapping positions in the Pairwise mApping Format (PAF). PAF is a TAB-delimited text format, and each line has at least 12 fields. Here's the whole field menu, no gatekeeping:
- Col 1 โ
stringโ Query sequence name - Col 2 โ
intโ Query sequence length - Col 3 โ
intโ Query start coordinate (0-based) - Col 4 โ
intโ Query end coordinate (0-based) - Col 5 โ
charโ+if query/target on the same strand;-if opposite - Col 6 โ
stringโ Target sequence name - Col 7 โ
intโ Target sequence length - Col 8 โ
intโ Target start coordinate on the original strand - Col 9 โ
intโ Target end coordinate on the original strand - Col 10 โ
intโ Number of matching bases in the mapping - Col 11 โ
intโ Number bases, including gaps, in the mapping - Col 12 โ
intโ Mapping quality (0-255 with 255 for missing)
When alignment is available, column 11 gives the total number of sequence matches, mismatches and gaps in the alignment; column 10 divided by column 11 gives the BLAST-like alignment identity. When alignment is unavailable, these two columns are approximate. Periodt.
PAF may optionally have additional fields in the SAM-like typed key-value format. Minimap2 may output the following tags:
tpโAโ Type of aln: P/primary, S/secondary and I,i/inversioncmโiโ Number of minimizers on the chains1โiโ Chaining scores2โiโ Chaining score of the best secondary chainNMโiโ Total number of mismatches and gaps in the alignmentMDโZโ To generate the ref sequence in the alignmentASโiโ DP alignment scoreSAโZโ List of other supplementary alignmentsmsโiโ DP score of the max scoring segment in the alignmentnnโiโ Number of ambiguous bases in the alignmenttsโAโ Transcript strand (splice mode only)cgโZโ CIGAR string (only in PAF)csโZโ Difference stringdvโfโ Approximate per-base sequence divergencedeโfโ Gap-compressed per-base sequence divergencerlโiโ Length of query regions harboring repetitive seeds
The cs tag encodes difference sequences in the short form or the entire query AND reference sequences in the long form. It consists of a series of operations:
=โ regex[ACGTN]+โ Identical sequence (long form):โ regex[0-9]+โ Identical sequence length*โ regex[acgtn][acgtn]โ Substitution: ref to query+โ regex[acgtn]+โ Insertion to the reference-โ regex[acgtn]+โ Deletion from the reference~โ regex[acgtn]{2}[0-9]+[acgtn]{2}โ Intron length and splice signal
๐ง LIMITATIONS ๐ง
Not everything is perfect, and that's okay:
- Minimap2 may produce suboptimal alignments through long low-complexity regions where seed positions may be suboptimal. This should not be a big concern because even the optimal alignment may be wrong in such regions.
- Minimap2 requires
SSE2orNEONinstructions to compile. It is possible to add non-SSE2/NEON support, but it would make minimap2 slower by several times.
๐ SEE ALSO ๐
Go read miniasm(1), minimap(1), and bwa(1), bestie. iykyk.
This manual is serving minimap2-2.27 (r1193) energy, dated 12 March 2024 โ and yes, it's the minimap2(1) page. Bye bestie ๐
โจ๐ฆ
๐ฆ where this page comes from
- debian trixie: minimap2 2.27+dfsg-1+b3 ยท MIT
- ubuntu questing: minimap2 2.27+dfsg-1build2
- ubuntu resolute: minimap2 2.27+dfsg-1build4 ยท MIT
- ubuntu stonking: minimap2 2.27+dfsg-1build4 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms