samtools-flagstat(1)
β¨ samtools-flagstat β like, the whole manual page, bestie β¨
okay so this is part of samtools, the bioinformatics toolbox thingy, and honestly? it ate. let's get into it π«Ά
π NAME
samtools flagstat β counts the number of alignments for each FLAG type. that's it. that's the whole vibe check. it counts stuff by flag. slay. π₯
π SYNOPSIS
samtools flagstat in.sam|in.bam|in.cram
πΈ DESCRIPTION
so what it does is: it does a full pass through the input file to calculate and print statistics to stdout. like, it reads the whole thing. every single read. no skipping. main character energy fr. β¨
it gives you counts for each of 13 categories, based primarily on bit flags in the FLAG field. if you're sitting there like "what do the flags even mean", the info on the meaning of the flags is given in the SAM specification document <https://samtools.github.io/hts-specs/SAMv1.pdf>. go read it, it's giving homework but it's good for you π
each category in the output is broken down into QC pass and QC fail. in the default output format, these are presented as #PASS + #FAIL followed by a description of the category. iconic formatting tbh.
the first row of output gives the total number of reads that are QC pass and fail (according to flag bit 0x200). for example:
122 + 28 in total (QC-passed reads + QC-failed reads)
which would indicate that there are a total of 150 reads in the input file, 122 of which are marked as QC pass and 28 of which are marked as "not passing quality controls". the math is mathing π
following this, additional categories are given for reads which are:
- primary β neither
0x100(SECONDARY) nor0x800(SUPPLEMENTARY) bit set - secondary β
0x100(SECONDARY) bit set - supplementary β
0x800(SUPPLEMENTARY) bit set - duplicates β
0x400(DUP) bit set - primary duplicates β
0x400(DUP) bit set and neither0x100(SECONDARY) nor0x800(SUPPLEMENTARY) bit set - mapped β
0x4(UNMAP) bit not set - primary mapped β
0x4(UNMAP),0x100(SECONDARY) and0x800(SUPPLEMENTARY) bits not set - paired in sequencing β
0x1(PAIRED) bit set - read1 β both
0x1(PAIRED) and0x40(READ1) bits set - read2 β both
0x1(PAIRED) and0x80(READ2) bits set - properly paired β both
0x1(PAIRED) and0x2(PROPER_PAIR) bits set and0x4(UNMAP) bit not set - with itself and mate mapped β
0x1(PAIRED) bit set and neither0x4(UNMAP) nor0x8(MUNMAP) bits set - singletons β both
0x1(PAIRED) and0x8(MUNMAP) bits set and bit0x4(UNMAP) not set
and finally, two rows are given that additionally filter on the reference name (RNAME), mate reference name (MRNM), and mapping quality (MAPQ) fields. extra credit rows, lowkey:
- with mate mapped to a different chr β
0x1(PAIRED) bit set and neither0x4(UNMAP) nor0x8(MUNMAP) bits set andMRNMnot equal toRNAME - with mate mapped to a different chr (mapQ>=5) β
0x1(PAIRED) bit set and neither0x4(UNMAP) nor0x8(MUNMAP) bits set andMRNMnot equal toRNAMEandMAPQ >= 5
π ALTERNATIVE OUTPUT FORMATS
the -O option can be used to select two alternative formats for the output. two whole other aesthetics. choose your fighter π¦
using -O tsv selects a tab-separated values format that can easily be imported into spreadsheet software. yes, spreadsheet girlies, this one's for you π in this format the first column contains the values for QC-passed reads, the second column has the values for QC-failed reads and the third contains the category names.
using -O json generates an ECMA-404 JSON data interchange format object <https://www.json.org/>. the top-level object contains two named objects QC-passed reads and QC-failed reads. these contain the various categories listed above as names and the corresponding count as value. it's giving API-ready. ngl kinda obsessed π₯
for the default format, mapped shows the count as a percentage of the total number of QC-passed or QC-failed reads after the category name. for example:
32 + 0 mapped (94.12% : N/A)
the properly paired and singletons counts work in a similar way but the percentage is against the total number of QC-passed and QC-failed pairs. the primary mapped count is a percentage of the total number of QC-passed and QC-failed primary reads. okay so different denominators, don't get it twisted π
in the tsv and json formats, these percentages are listed in separate categories mapped %, primary mapped %, properly paired %, and singletons %. if the percentage cannot be calculated (because the total is zero) then in the default and tsv formats it will be reported as N/A. in the json format, it will be reported as a JSON null value. no dividing by zero here bestie, we're not doing that π
β OPTIONS β
-@ INTβ set number of additional threads to use when reading the file. more threads = more go brrr π§-O FORMATβ set the output format.FORMATcan be set todefault,jsonortsvto select the default, JSON or tab-separated values output format. if this option is not used, the default format will be selected. defaults gonna default π
π AUTHOR
written by Heng Li from the Sanger Institute. king behavior, honestly. π
π SEE ALSO
samtools website: <http://www.htslib.org/>
and that's the whole page, bestie π this one's samtools-1.24, dated 9 July 2026 β go forth and flagstat your little heart out, iykyk π
β¨πΈ
π¦ where this page comes from
- epel 10: samtools 1.24-2.el10_3 Β· MIT
- nixpkgs unstable: samtools 1.24
- Copyright (C) 2008-2011, 2013-2019, 2021, 2024 Genome Research Ltd
- copyright (C) 2010, 2011 Broad Institute
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms