LEVIATHAN SYSTEMS

AI Infrastructure

SAM CIGAR: One Alignment Has Several Different Lengths

Technical contentPublished Updated

A SAM alignment's stored sequence length, reference span and query-to-reference paired positions can differ legitimately. CIGAR describes which operations advance each coordinate. In the fictional example below, 26 stored bases span 22 reference positions but provide only 19 query/reference pairs. Decide which population an AI input or coverage claim requires before treating any one of those numbers as its size.

Identify which coordinate the consumer uses

A genomics-AI provider may offer an input indexed by read bases, by reference positions or by alignment pairs. Those are different deliverables even when derived from the same alignment. A sequence-length total cannot stand in for a reference-window size without explaining the correspondence.

This explanation uses SAM/BAM specification 1.6, the printing dated August 12, 2025, repository version b5341fb. Its CIGAR operations describe movement along the query and reference. The existing FASTQ quality article concerns how supplied per-base quality characters are interpreted. Here the question is where sequence positions belong after alignment, not how their qualities are decoded.

The examples are invented arithmetic for reviewing supplied data representations. They contain no human sequence, aligner run, biological finding or clinical recommendation. A representation can be internally coherent while its biological placement remains unvalidated.

References: [SAM]

Follow a query cursor and a reference cursor

Imagine two cursors. One tracks the next stored query base; the other tracks the next reference position. An insertion moves only the query cursor. A deletion moves only the reference cursor. Soft-clipped bases remain in the stored sequence but do not advance the reference. Alignment operators M, = and X advance both.

HTSlib 1.22's sam.h exposes this two-axis distinction in bam_cigar_type, with separate query-consumption and reference-consumption bits. It is a classification of operations, not a measurement of biological correctness. The same source identifies hard clipping and padding as consuming neither axis. Hard-clipped bases are absent from the stored sequence; they cannot be recovered by allocating extra reference positions.

M is deliberately less specific than its name can suggest: SAM permits it for either a sequence match or mismatch. The = and X operators distinguish the two. Consequently, a summary that adds M lengths and calls the result confirmed matching bases has introduced a claim absent from that CIGAR.

References: [SAM][HTS]

SAM-C36: 26 stored bases span 22 reference positions

Stipulate one mapped, forward-orientation alignment against an identified fictional reference. POS is 101, and CIGAR is 5S10M2I5M3D4M. A stored SEQ is present. Query indices below are zero-based; reference positions use SAM's one-based inclusive convention.

The first five stored bases are soft clipped. The next ten pair with reference positions 101 through 110. Two further query bases form an insertion, leaving the next reference position at 111. Five more pairs reach reference position 115. A deletion then advances across 116 through 118 without consuming query bases. The final four pairs occupy 119 through 122.

Stored sequence consumption is 5 + 10 + 2 + 5 + 4 = 26. Reference consumption is 10 + 5 + 3 + 4 = 22. Its inclusive interval is therefore [101,122], since 101 + 22 - 1 = 122. The positions consuming both axes total 10 + 5 + 4 = 19.

These totals reconcile the same representation. Seven stored bases lack reference-position pairs in this record: five soft clips and two inserted bases. Three positions inside the reference span lack query bases because of the deletion. There is no arithmetic requirement for 26, 22 and 19 to agree.

References: [SAM][HTS]

Scroll the table horizontally on smaller screens.

SAM-C36: original cursor accounting, with no sequence values supplied
OperationStored query indicesReference positionsPaired positionsSource
5S0–4None0Planning analysis
10M5–14101–11010Planning analysis
2I15–16None; next remains 1110Planning analysis
5M17–21111–1155Planning analysis
3DNone116–1180Planning analysis
4M22–25119–1224Planning analysis

All coordinates and lengths are stipulated. Paired positions do not identify which bases match; no sequence or reference letters were supplied.

A longer span can contain fewer stored bases

For a separate fictional record, keep POS 101 but use CIGAR 12M100N8M. It has 20 stored query bases and a reference span of 12 + 100 + 8 = 120 positions, ending at 220. Its paired blocks cover 101–112 and 213–220. Positions 113–212 are skipped by N.

That 120-position interval is over five times the 22-position span in SAM-C36, although this record stores fewer bases: 20 rather than 26. Neither a long interval nor an interval-shaped export demonstrates a read with one supplied base at every reference position.

The second record's 100 skipped positions also cannot be counted as 100 newly sequenced bases. Conversely, deleting those positions from a reference-indexed export would change its coordinate representation unless the export retained a way to reconstruct the gaps. This is an input-definition choice, not an instruction to alter either record.

Keep the distinction attached to the consumer's task. A read-indexed feature sequence may need the inserted and soft-clipped positions; a reference-indexed input may need explicit gap semantics. A consumer using only paired positions requests another population. The example chooses no model architecture or biological interpretation for them.

References: [HTS]

Coverage needs its own counting definition

A reference span is a useful geometric extent, but it is not a coverage report. The samtools 1.24 coverage manual defines coverage as a percentage of positions with at least one aligned base and reports read count, covered bases and mean depth separately. Those outputs already distinguish several populations.

The samtools 1.24 depth manual, dated July 9, 2026, documents default omission of deletion positions from depth and a different deletion-counting policy when requested. It also describes read-flag, quality and overlapping-pair rules. Thus a reported depth value needs its actual counting policy; the CIGAR span alone cannot establish what that report counted. No command or recommended setting is provided here.

For SAM-C36, merely dividing 19 paired positions by its 22-position span yields 86.36% to two decimal places. That is an explicitly defined geometric ratio for one invented record, not a samtools result. It ignores filters, other reads and all base identities. Naming it a measured regional coverage percentage would exceed the example.

Likewise, counting two alignment records does not by itself establish two independent biological molecules. The record population and any duplicate, secondary or supplementary handling belong to the actual analysis definition, rather than being inferred from a row count.

References: [COV][DEPTH]

Choose the return that answers the AI input requirement

Suppose a fictional buyer asks for all 26 stored bases in SAM-C36 with their alignment relationship. Offer A returns only the 19 paired positions. Its output can be useful, but it omits the two inserted and five soft-clipped bases required by this stated request. Calling A aligned input does not resolve that omission.

Offer B retains the 26 stored positions together with the identified reference, POS and operation sequence needed to distinguish paired, inserted and clipped positions. If its delivered values and correspondence support that description, it answers this representation requirement. It still supplies no independent proof that the alignment placement is correct.

Now change the request to a reference-indexed window [101,122]. Twenty-six query values cannot simply be treated as a dense 22-position array. The provider needs to explain the three deletion positions, the inserted bases' separate relationship and any omitted soft clips. A documented derived representation may satisfy that revised request; literal preservation of every source field is not universally necessary. What matters is whether its retained distinctions meet the declared task.

Compare proposals against the same requested population, rather than rewarding the largest length. Storage bytes, compression, GPU memory demand and processing throughput require their own evidence. None follows from these small coordinate counts.

Keep the physical installation requirement separate

If the selected compute and storage equipment also requires physical installation, the existing Rack-and-Stack & Colocation Installation service is a route to discuss equipment mounting, IT connections, labels and agreed handoff records. Share a nonconfidential equipment, rack, site and connection outline to establish scope and availability.

Bioinformatics, alignment interpretation, data preparation and model acceptance remain with the appointed data and software specialists. A physical installation inquiry does not commission those services.

Primary sources

  1. [SAM] SAM/BAM Format Specification 1.6, printing b5341fb, August 12, 2025Checked 2026-10-20. Sections 1.2 and 1.4 define coordinates, POS, CIGAR consumption, stored sequence length and M versus =/X. The dated printing was actually read; synthetic records are not aligner output.
  2. [HTS] HTSlib 1.22 sam.h: bam_cigar_type and operation-consumption tableChecked 2026-10-20. Version-pinned source distinguishes query/reference consumption for each CIGAR operation, including clipping, padding and skipped reference regions. No library execution or decoder implementation is claimed.
  3. [COV] samtools 1.24 coverage manual, released July 9, 2026Checked 2026-10-20. Names the covered-position, read-count, mean-depth and filtering populations; no report was generated and no threshold is recommended.
  4. [DEPTH] samtools 1.24 depth manual, released July 9, 2026Checked 2026-10-20. Documents deletion, quality, flag and overlapping-pair counting behavior. These are scope qualifications for supplied evidence, not instructions to run or configure a tool.

Does the chosen equipment need physical installation?

Share a nonconfidential equipment, rack, site and IT connection outline to discuss a separately scoped physical installation and handoff.

Discuss a ProjectEmail Project Scope