Cigar Strings For Dummies
Mar 28, 2017
Smoke and CIGAR (strings)
The ‘CIGAR’ (Compact Idiosyncratic Gapped Alignment Report) string is how the SAM/BAM format represents spliced alignments. Understanding the CIGAR string will help you understand how your query sequence aligns to the reference genome. For example, the position stored is the left most coordinate of the alignment. To get to the right coordinate, you have to parse the CIGAR string.
Let’s consider a few concrete examples. First example: The shown alignment will give position = 2 (0-based!) and CIGAR = 6M:
AAGTCTAGAA (ref)
GTCTAG (query)
CIGAR strings have a number of operators:
M Match Exact match of x positions
N Alignment gap Next x positions on ref don’t match
D Deletion Next x positions on ref don’t match
I Insertion Next x positions on query don’t match
For CIGAR =’6M’, this means there are 6 exact matches to the reference. So if we are starting at position=2, with 6 exact matches, we would end at position 7 (again 0-based):
0123456789
AAGTCTAGAA (ref)
GTCTAG (query)
Second example: The shown alignment will give position=2 (0-based) and CIGAR=3M2I3M:
0123456789
AAGTC TAGAA (ref)
GTCGATAG (query)
Here, two nucleotides (‘GA’) are inserted into the query. So if we are starting at position=2, based on the CIGAR string, we have 3 exact matches, 2 insertions, then 3 more exact matches, resulting in an end position of 9.
Third example: The shown alignment will give position=2 and CIGAR=2M1D3M:
0123456789
AAGTCTAGAA (ref)
GT TAG (query)
Note there is a deletion on the query. The ‘C’ in the reference sequence has no match. So if we are starting at position=2, based on the CIGAR string, we have 2 exact matches, 1 deletion, then 3 more exact matches, resulting in an end position of 7 relative to the reference.
Fourth example: The shown alignment will give position=3 and CIGAR=3M7N4M:
01234567890123456
CCCTACGTCCCAGTCAC (ref)
TAC TCAC (query)
This is a gapped alignment (due to a splicing event in RNAseq). So if we are starting at position=3, based on the CIGAR string, we have 3 exact matches, 7 gaps, then 4 more exact matches, resulting in an end position of 16.
Additional resources
- Older
- Newer
RECENT POSTS
- Using AI to find heterogeneous scientific speakers on 04 November 2024
- The many ways to calculate Moran's I for identifying spatially variable genes in spatial transcriptomics data on 29 August 2024
- Characterizing spatial heterogeneity using spatial bootstrapping with SEraster on 23 July 2024
- I use R to (try to) figure out which hospital I should go to for shoppable medical services by comparing costs through analyzing Hospital Price Transparency data on 22 April 2024
- Cross modality image alignment at single cell resolution with STalign on 11 April 2024
- Spatial Transcriptomics Analysis Of Xenium Lymph Node on 24 March 2024
- Querying Google Scholar with Rvest on 18 March 2024
- Alignment of Xenium and Visium spatial transcriptomics data using STalign on 27 December 2023
- Aligning 10X Visium spatial transcriptomics datasets using STalign with Reticulate in R on 05 November 2023
- Aligning single-cell spatial transcriptomics datasets simulated with non-linear disortions on 20 August 2023