samtools-consensus(1)
β¨ NAME β¨
okay so bestie, welcome to samtools-consensus(1) β the manual for samtools consensus, aka the tool that produces a consensus FASTA/FASTQ/PILEUP. itβs giving reference-building main character energy, no cap π
π SYNOPSIS π
samtools consensus [-saAMq] [-r region] [-f format] [-l line-len] [-d min-depth] [-C cutoff] [-c call-fract] [-H het-fract] in.bam
π¦ DESCRIPTION π¦
so the whole point: generate a consensus from a SAM, BAM, or CRAM file based on whatβs actually inside the alignment records. the consensus gets written as either FASTA, FASTQ, or a pileup-oriented format β and you pick which one with the -f FORMAT option. slay β¨
the default output for FASTA and FASTQ formats includes one base per non-gap consensus. so insertions with respect to the aligned reference will be included, and deletions get removed. this behaviour can be controlled with the --show-ins and --show-del options. this could be used to compute a new reference from sequences assemblies to realign against β iconic little trick π«Ά
the pileup-style format strictly adheres to one row per consensus location, differing from the one row per reference base used in the related samtools mpileup command. this means the base quality values for inserted columns are reported. the base quality value of gaps β either within an insertion or otherwise β are determined as the average of the surrounding non-gap bases. the columns shown are: reference name, position, nth base at that position (zero if not an insertion), consensus call, consensus confidence, sequences and quality values. note that even when a reference is supplied, the consensus base is always reported (if non-zero depth) in the 5th column. okay periodt, column five stays booked and busy π
two consensus calling algorithms are offered. the default computes a heterozygous consensus in a Bayesian manner, derived from the "Gap5" consensus algorithm. quality values are also tweaked to take into account other nearby low quality values. this can also be disabled with the --no-adj-qual option. lowkey thoughtful of it π
this method also utilises the mapping qualities, unless the --no-use-MQ option is used. mapping qualities are also auto-scaled to take into account the local reference variation by processing the MD:Z tag, unless --no-adj-MQ is used. mapping qualities can be capped between a minimum (--low-MQ) and maximum (--high-MQ), although the defaults are liberal and trust the data to be true. finally, an overall scale on the resulting mapping quality can be supplied (--scale-MQ, defaulting to 1.0). this has the effect of favouring more calls with a higher false positive rate (values greater than 1.0) or being more cautious with higher false negative rates and lower false positive (values less than 1.0). choose your fighter, bestie β
the second method is a simple frequency counting algorithm, summing either +1 for each base type or +qual if the --use-qual option is specified. this is enabled with the --mode simple option. cute and straightforward πΈ
the summed share of a specific base type is then compared against the total possible, and if this is above the --call-fract fraction parameter then the most likely base type is called, or "N" otherwise (or absent if it is a gap). the --ambig option permits generation of ambiguity codes instead of "N", provided the minimum fraction of the second most common base type to the most common is above the --het-fract fraction. iykyk π§
π OPTIONS π
π General options that apply to both algorithms π
-r REG,--region REGβ limit the query to region REG. this requires an index. it is incompatible with the--regions-fileoption. no sharing, bestie π--regions-file BED-FILEβ creates consensus sequences for each region listed in theBED-FILE, although not necessarily in the same chromosomal order. as with single region queries, without-athe sequences may be truncated or absent if not covered. note this does not deduplicate regions or merge overlapping regions. this requires an index. this is incompatible with the-roption. messy but valid π«Ά-f FMT,--format FMTβ produce format FMT, with"fastq","fasta"and"pileup"as permitted options.-l N,--line-len Nβ sets the maximum line length of line-wrappedfastaandfastqformats to N.-o FILE,--output FILEβ output consensus to FILE instead ofstdout.-m STR,--mode STRβ select the consensus algorithm. valid modes are"simple"frequency counting and the"bayesian"(Gap5) methods, with Bayesian being the default. (note case does not matter, so"Bayesian"is accepted too.) there are a variety of Bayesian methods. straight"bayesian"is the best set suitable for the other parameters selected. the choice of internal parameters may change depending on the"--P-indel"score. this method distinguishes between substitution and indel error rates. the old Samtools consensus in version1.16did not distinguish types of errors, but for compatibility the"bayesian_116"mode may be selected to replicate this. choosing a mode is literally a personality test π-aβ outputs all bases, from start to end of reference, even when the aligned data does not extend to the ends. this is most useful for construction of a full length reference sequence. full-length queen behavior π-a -a,-aaβ output absolutely all positions, including references with no data aligned against them. absolutely unbothered by empty coverage β¨--rf,--incl-flags STR|INTβ only include reads with at least oneFLAGbit set. defaults to zero, which filters no reads.--ff,--excl-flags STR|INTβ exclude reads with anyFLAGbit set. defaults to"UNMAP,SECONDARY,QCFAIL,DUP".--min-MQ INTβ filters out reads with a mapping quality below INT. this defaults to zero.--min-BQ INTβ filters out bases with a base quality below INT. this defaults to zero.--show-del yes/noβ whether to show deletions as"*"(yes) or to omit them from the output (no). defaults tono.--show-ins yes/noβ whether to show insertions in the consensus. defaults toyes.--mark-insβ insertions, when shown, are normally recorded in the consensus with plain 7-bit ASCII (ACGT, oracgtif heterozygous). however, this makes it impossible to identify the mapping between consensus coordinates and the original reference coordinates. iffastaoutput is selected then the option adds an underscore before every inserted base, plus a corresponding character in the quality forfastqformat. when used in conjunction with-a --show-del yes, this permits an easy derivation of the consensus to reference coordinate mapping. coordinate girlies rise π-A,--ambigβ enables IUPAC ambiguity codes in the consensus output. without this the output will be limited toA,C,G,T,Nand*.-d D,--min-depth Dβ the minimum depth required to make a call. defaults to1. failing this depth check will produce consensus"N", or absent if it is an insertion. note this check is performed after filtering by flags and mapping/base quality. order matters, bestie π₯-T ref.fa,--reference ref.faβ for base positions with zero coverage, use the supplied reference instead of"N". note this does not replace minimum depth or minimum quality filters, as the base is known but considered low quality, so the ambiguity is retained. she knows the tea but keeps the question mark π«Ά--ref-qual INTβ when--referenceis given, this specifies the quality value to use for reference-derived bases. this defaults to zero.
πΈ The following options apply only to the simple consensus mode πΈ
-q,--use-qualβ for the simple consensus algorithm, this enables use of base quality values. instead of summing1per base called, it sums the base quality instead. these sums are also used in the--call-fractand--het-fractparameters too. quality values are always used for the"Gap5"consensus method and this option has no effect. note currently quality values only affect SNPs and not inserted sequences, which still get scores with a fixed+1per base type occurrence. quality is having a moment, but only for SNPs π-H H,--het-fract Hβ for consensus columns containing multiple base types, if the second most frequent type is at least H fraction of the most common type, then a heterozygous base type will be reported in the consensus. otherwise the most common base is used, provided it meets the--call-fractparameter (otherwise"N"). the fractions computed may be modified by the use of quality values if the-qoption is enabled. note although IUPAC has ambiguity codes forA,C,G,Tvs any otherA,C,G,T, it does not have codes forA,C,G,Tvs gap (such as in a heterozygous deletion). given the lack of any official code, we use lower-case letter to symbolise a half-present base type. lowercase = half-present, iconic and slightly unhinged π-c C,--call-fract Cβ only used for the simple consensus algorithm. require at least C fraction of bases agreeing with the most likely consensus call to emit that base type. this defaults to0.75. failing this check will output"N".-@ NTHREADSβ specify the number of additional threads to use for computing the consensus. note if no index is present, threads will only be used for parallel decompression, meaning asking for more than2threads is unlikely to speed up processing. with an index, the consensus is computed for multiple regions simultaneously, offering near linear speed ups. multithreading girlies, assemble β‘-Z BASE_COUNTβ when using multiple threads, this specifies the number of bases per threading job. the default is500,000bp forfasta/fastqoutput and100,000forpileupoutput. larger blocks may yield improved threading performance at a cost of more memory.
π₯ The following options apply only to Bayesian consensus mode enabled (default on) π₯
-C C,--cutoff Cβ only used for the Gap5 consensus mode, which produces a Phred style score for the final consensus quality. if this is below C then the consensus is called as"N". the cutoff is giving strict gatekeeper energy πͺ--use-MQ,--no-use-MQβ enable or disable the use of mapping qualities. defaults to on.--adj-MQ,--no-adj-MQβ if mapping qualities are used, this controls whether they are scaled by the local number of mismatches to the reference. the reference is unknown by this tool, so this data is obtained from theMD:Zauxiliary tag (or ignored if not present). defaults to on. MD:Z stays doing the most, fr fr π--NM-halo INTβ how far to either side of the base call we peek when counting local mismatches β¨ like, it sets the radius of the vibe check around each base π--low-MQ MIN,--high-MQ MAXβ the floor and the ceiling for mapping quality. β οΈ Heads up bestie: these are not filters, they just cap the values from above and below. Defaults are0and60π--scale-MQ FLOATβ a general multiplicative mapping-quality scaling factor π¦ it globally raises or lowers the quality values that the consensus algorithm actually uses. Defaults to1.0, which is the "leave my values alone" setting π--P-het FLOATβ controls how likely any given position is to be a heterozygous site π this feeds the priors for the Bayesian calculations, and it makes barely any difference on deep data. Defaults to1e-3. Smaller numbers make the algorithm more likely to call a pure base type. NGL the algorithm always computes the probability of a base being homozygous vs heterozygous, no matter whether the output gets reported as ambiguous (it'll come out as"N"if it's deemed heterozygous and you didn't turn on--ambigmode) π--P-indel FLOATβ controls how likely small indels are π₯ again, priors for the Bayesian maths, and again it barely matters on deep data. Defaults to2e-4β¨--het-scale FLOATβ a multiplicative correction applied per base quality before it's added to the heterozygous hypotheses. Turning it down = fewer heterozygous calls. This often leads to a significant reduction in false positive het calls, at the cost of some increase in false negatives (aka mislabelling real heterozygous sites as homozygous π). It's usually a good idea to reduce this on instruments where a significant proportion of bases may be aligned in the wrong column due to insertions and deletions, which leads to alignment errors and reference bias. Think of it as a het sensitivity tuning knob ποΈ Defaults to1.0(nop).-p,--homopoly-fixβ some technologies that call runs of the same base type together always stick the lowest quality calls at one end π which causes drama when you reverse complement and compare alignments with indels. This option averages the qualities at both ends so orientation biases don't ruin your day. Recommended for old 454 or PacBio HiFi data sets π--homopoly-score FLOATβ the-poption also drops confidence values inside homopolymers, because there's an extra likelihood of sequence-specific errors. The quality values get multiplied by FLOAT. Defaults to0.5, but it's not used if-pwasn't specified. Lowkey convenient: adjusting this score automatically enables-pβ¨-t,--qual-calibration FILEβ loads a quality calibration table from FILE π the format is a series of lines with these fields, each line starting with the literal textQUAL:
QUAL value substitution undercall overcall
Lines starting with a # are ignored π
ββοΈ each line maps a recorded quality value to the Phred equivalent score for substitution, undercall and overcall errors. Quality values are expected to be sorted in increasing numerical order, but they're allowed to skip values. This lets the consensus algorithm know the most likely cause of an error, and whether the instrument is more likely to have indel errors (more common in some long-read technologies) or substitution errors (more common in clocked short-read instruments) π§
Some pre-defined calibration tables are built in π these are specified with a fake filename starting with a colon. See the -X option for more details.
Note: due to the additional heuristics the consensus algorithm applies, these recalibration tables are not a true reflection of the instrument error rates β they're a work in progress π§
-X,--config STRβ picks predefined sets of configuration parameters π acceptable values for STR are below, along with the exact list of parameters they're equivalent to:hiseqβ--qual-calibration :hiseqhifiβ--qual-calibration :hifi --homopoly-fix 0.3 --low-MQ 5 --scale-MQ 1.5 --het-scale 0.37r10.4_supβ--qual-calibration :r10.4_sup --homopoly-fix 0.3 --low-MQ 5 --scale-MQ 1.5 --het-scale 0.37r10.4_dupβ--qual-calibration :r10.4_dup --homopoly-fix 0.3 --low-MQ 5 --scale-MQ 1.5 --het-scale 0.37ultimaβ--qual-calibration :ultima --homopoly-fix 0.3 --low-MQ 10 --scale-MQ 2 --het-scale 0.37
π EXAMPLES π
- Make a modified FASTA reference that has a 1:1 coordinate correspondence with the original reference used in alignment π like, every coordinate lines up perfectly, no cap:
samtools consensus -a --show-ins no --show-del yes in.bam -o ref.fa
- Make a FASTQ file for the contigs with aligned data, insertions included π¦:
samtools consensus -f fastq in.bam -o cons.fq
π AUTHOR π
Written by James Bonfield from the Sanger Institute π«Ά absolute icon, we stan.
β SEE ALSO β
samtools(1), samtools-mpileup(1),
Samtools website: <http://www.htslib.org/> πΈ
okay that's the whole page bestie, go forth and call some consensus bases π
β¨ this one's samtools-1.24, dated 9 July 2026, and it's the samtools-consensus(1) manual page β periodt π
π¦ where this page comes from
- epel 10: samtools 1.24-2.el10_3 Β· MIT
- nixpkgs unstable: samtools 1.24
- Copyright (C) 2021-2025 Genome Research Ltd
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms