samtools-index(1)

πŸ¦‹ NAME πŸ¦‹

Okay bestie, this is the samtools-index(1) page, and it's literally about how samtools index indexes SAM/BAM/CRAM files. That's the whole assignment. πŸ’…

✨ SYNOPSIS ✨

samtools index -M [-bc] [-m INT] FILE FILE [FILE...]

samtools index [-bc] [-m INT] aln.sam|aln.bam|aln.cram [out.index]

πŸ’– DESCRIPTION πŸ’–

So here's the tea: you use this to index coordinate-sorted BGZIP-compressed SAM, BAM or CRAM files so they get fast random access. ✨

SAM girlies listen up: for SAM this only works if the file has been BGZF compressed first. No cap. 🫢

Also, the first synopsis with multiple input FILEs? That's only available with Samtools 1.16 or later. iykyk.

Why do you even want this index? Because when region arguments are used to limit samtools view and similar commands to particular regions of interest, this index is needed. Periodt.

When only one alignment file is being indexed, the output index filename can be specified via -o or as shown in the second synopsis. Cute, right? πŸŽ€

When no output filename is specified, here's the file-name lore:

  • for a CRAM file aln.cram, index file aln.cram.crai will be created;
  • for a BAM file aln.bam, either aln.bam.bai or aln.bam.csi will be created;
  • and for a compressed SAM file aln.sam.gz, either aln.sam.gz.bai or aln.sam.gz.csi will be created β€” with the .bai vs .csi choice depending on the index format selected.

Now the important size warning: the BAI index format can handle individual chromosomes up to 512 Mbp (2^29 bases) in length. If your input file might contain reads mapped to positions greater than that, you will need to use a CSI index. Not optional, bestie. 😭

🌸 OPTIONS 🌸

  • -b, --bai β€” create a BAI index. This is currently the default when no format options are used. πŸ’…
  • -c, --csi β€” create a CSI index. By default, the minimum interval size for the index is 2^14, which is the same as the fixed value used by the BAI format. ✨
  • -m, --min-shift INT β€” create a CSI index, with a minimum interval size of 2^INT. 🧚
  • -M β€” interpret all filename arguments as alignment files to be indexed individually. (Without -M, filename arguments are interpreted solely as per the second synopsis.) πŸ‘‘
  • -o, --output FILE β€” write the output index to FILE. (Currently may only be used when exactly one alignment file is being indexed.) πŸŽ€
  • -@, --threads INT β€” number of input/output compression threads to use in addition to main thread [0]. πŸ”₯

πŸ‘‘ AUTHOR πŸ‘‘

Written by Heng Li from the Sanger Institute. Iconic. πŸ’œ

πŸ¦‹ SEE ALSO πŸ¦‹

Samtools website: <http://www.htslib.org/> 🌈


okay bye bestie πŸ’‹ β€” this was samtools-1.24, dated 9 July 2026. samtools-index(1), out! 🫢

πŸ“¦ where this page comes from