Data Management
Interpret SAM Flags Without Double-Counting Alignment Records
The decision
Use a flag audit before defining an alignment filter or interpreting a record count. Decide whether your intended unit is an alignment record, a read or a sequencing template. The same underlying read can have multiple records; bit decoding cannot establish deduplication or sample identity.
Build the audit
- Write the inclusion rule in words before selecting flags. For example, distinguish unmapped records from secondary mappings.
- Use decimal integer flags from synthetic examples. Retain the original value beside the decoded bits.
- Decode independent bits rather than treating the integer as a category code.
- Inspect the multiple-segment bit before interpreting pair-specific flags.
- Keep secondary and supplementary classifications separate. Counts of flag categories can overlap.
- Test the proposed filtering rule with records that have several bits set, then apply an established alignment tool to the actual file locally.
Worked hypothetical example
The invented value 99 decomposes into 64 + 32 + 2 + 1. Value 147 is 128 + 16 + 2 + 1. Value 260 is 256 + 4: it belongs to both the secondary and unmapped record counts. Across these three supplied records, there is one unmapped record and one secondary record, but adding these counts would not give two distinct records.
Avoid the wrong conclusion
A proper-pair bit reflects the aligner’s decision, not proof of biological truth. The absence of an unmapped bit does not prove a high-quality alignment. Reserved bits are shown for inspection rather than discarded. For multi-segment technologies, “first” and “last” are safer labels than assuming every template has exactly two reads.
Reporting example: “We decoded three synthetic alignment records; overlapping flag counts were not interpreted as unique-template counts.” Document the actual filter expression separately from this demonstration.
Sources and checking
Primary documentation, checked 2 December 2026. Examples are hypothetical. This page does not claim human expert review.