Shazam: Mutation analysis

Basic mutational load calculations are provided by the observedMutations function. observedMutations provides multiple options to control how mutations are calculated. Mutations can be calculated as either counts or frequencies, divided into replacement (R) and silent (S) mutations, and subset into FWR and CDR specific mutations. Additionally, alternative mutational definitions may be considered based on the physicochemical properties of translated codons.

Example data

A small example AIRR Rearrangement database is included in the alakazam package. Analyzing mutations requires the following fields (columns) to be present in the table:

# Import required packages
library(alakazam)
library(dplyr)
library(ggplot2)
library(shazam)

# Load and subset example data
data(ExampleDb, package="alakazam")
db <- subset(ExampleDb, c_call %in% c("IGHA", "IGHG") & sample_id == "+7d")

Calculate the counts and frequencies of mutations over the entire sequence

When calling observedMutations with regionDefinition=NULL, the entire input sequence (sequenceColumn) is compared to the germline sequence (germlineColumn) to identify R and S mutations. If frequency=TRUE, the number of mutations is expressed as the frequency of mutations over the total number of positions that are non-N in both the input and the germline sequences.

In the example below, the counts (frequency=FALSE ) and frequencies (frequency=TRUE) of R and S mutations are calculated separately. New columns containing mutation counts are appended to the input data.frame with names in the form mu_count_<Region>_<R/S>. Mutation frequencies appear in new columns named mu_freq_<Region>_<R/S>.

# Calculate R and S mutation counts
db_obs <- observedMutations(db, sequenceColumn="sequence_alignment",
                            germlineColumn="germline_alignment_d_mask",
                            regionDefinition=NULL,
                            frequency=FALSE, 
                            nproc=1)
# Show new mutation count columns
db_obs %>% 
    select(sequence_id, starts_with("mu_count_")) %>%
    head(n=4)

# Calculate R and S mutation frequencies
db_obs <- observedMutations(db_obs, sequenceColumn="sequence_alignment",
                            germlineColumn="germline_alignment_d_mask",
                            regionDefinition=NULL,
                            frequency=TRUE, 
                            nproc=1)
# Show new mutation frequency columns
db_obs %>% 
    select(sequence_id, starts_with("mu_freq_")) %>%
    head(n=4)

Specifying the combine=TRUE argument will aggregate all mutation columns into a single value.

# Calculate combined R and S mutation frequencies
db_obs <- observedMutations(db, sequenceColumn="sequence_alignment",
                            germlineColumn="germline_alignment_d_mask",
                            regionDefinition=NULL,
                            frequency=TRUE, 
                            combine=TRUE,
                            nproc=1)
# Show new mutation frequency columns
db_obs %>% 
    select(sequence_id, starts_with("mu_freq")) %>%
    head(n=4)

We can plot the mutation frequencies and explore differences between samples or isotypes.

g1 <- ggplot(db_obs, aes(x=c_call, y=mu_freq, fill=c_call)) +
        geom_boxplot() + 
        labs(title = "Total mutations", 
             x = "Isotype", y = "Mutation frequency") +
        scale_fill_manual(name="Isotype", values=IG_COLORS, limits=force) +
        theme_bw() 
plot(g1)

Calculate mutations within subregions

To restrict the mutational analysis to a particular area in the sequence, the regionDefinition argument needs to be assigned a RegionDefinition object, which simply defines the subregion boundaries of the Ig sequence. For convenience, shazam provides a set of such objects, for which an overview is provided via ?IMGT_SCHEMES. Each of these objects cover the IMGT numbered V segment up to nucleotide position 312. Different objects treat regions within the V segment with varying granularity:

When supplying one of these objects to regionDefinition, and with combined=FALSE, the resultant mutation counts/frequencies will be tabulated in a way consistent with the granularity of the object's region definition. For example,

In the following example, we will explore the mutation frequency in the V-segment using two of the region definitions.

# Calculate R and S mutation counts for individual CDRs and FWRs
db_obs_v <- observedMutations(db, sequenceColumn="sequence_alignment",
                              germlineColumn="germline_alignment_d_mask",
                              regionDefinition=IMGT_V_BY_REGIONS,
                              frequency=FALSE, 
                              nproc=1)
# Show new FWR mutation columns
db_obs_v %>% 
    select(sequence_id, starts_with("mu_count_fwr")) %>%
    head(n=4)

# Calculate aggregate CDR and FWR V-segment R and S mutation frequencies
db_obs_v <- observedMutations(db_obs_v, sequenceColumn="sequence_alignment",
                              germlineColumn="germline_alignment_d_mask",
                              regionDefinition=IMGT_V,
                              frequency=TRUE, 
                              nproc=1)
# Show new CDR and FWR mutation frequency columns
db_obs_v %>% 
    select(sequence_id, starts_with("mu_freq_")) %>%
    head(n=4)

Plot a comparison between CDR silent and replacement mutations.

g2 <- ggplot(db_obs_v, aes(x=c_call, y=mu_freq_cdr_s, fill=c_call)) +
        geom_boxplot() + 
        labs(title = "CDR silent mutations", 
             x = "Isotype", y = "Mutation frequency") +
        scale_fill_manual(name="Isotype", values=IG_COLORS, limits=force) +
        theme_bw()
g3 <- ggplot(db_obs_v, aes(x=c_call, y=mu_freq_cdr_r, fill=c_call)) +
        geom_boxplot() + 
        labs(title = "CDR replacement mutations", 
           x = "Isotype", y = "Mutation frequency") +
        scale_fill_manual(name="Isotype", values=IG_COLORS, limits=force) +
        theme_bw()
alakazam::gridPlot(g2, g3, ncol=2)

Use amino acid physicochemical properties to define mutations

By default, replacement and silent mutations are determined by exact amino acid identity; this can be changed by setting the mutationDefinition argument. For convenience, shazam provides a set of MutationDefinition objects defining changes in amino acid charge, hydrophobicity, polarity and volume.

In the following example, replacement mutations are defined as amino acid changes that lead to a change in charge (mutationDefinition=CHARGE_MUTATIONS). Mutations that do not alter the charge classification of a translated codon will be considered silent mutations.

# Calculate charge mutation frequency for the full sequence
db_obs_ch <- observedMutations(db, sequenceColumn="sequence_alignment",
                               germlineColumn="germline_alignment_d_mask",
                               regionDefinition=NULL,
                               mutationDefinition=CHARGE_MUTATIONS,
                               frequency=TRUE, 
                               nproc=1)
# Show new charge mutation frequency columns
db_obs_ch %>% 
    select(sequence_id, starts_with("mu_freq_")) %>%
    head(n=4)

We can make a plot to visualize if mutations that change the sequence charge are more frequent in one isotype.

g4 <- ggplot(db_obs_ch, aes(x=c_call, y=mu_freq_seq_r, fill=c_call)) +
        geom_boxplot() + 
        labs(title="Charge replacement mutations", 
             x="Isotype", y="Mutation frequency") +
        scale_fill_manual(name="Isotype", values=IG_COLORS, limits=force) + 
        theme_bw()
plot(g4)


Try the shazam package in your browser

Any scripts or data that you put into this service are public.

shazam documentation built on Oct. 3, 2023, 1:06 a.m.