Skip to contents

This function visualizes recurrent mutations from a data frame. It first calculates the frequency of each mutation at specific genomic positions and then generates a lollipop plot for each group (e.g., chromosome) displaying mutations that meet a minimum recurrence threshold.

Usage

plot_lollipop(
  mutations,
  min_recurrence = 2,
  group_by_col = "dose_group",
  custom_palette = NULL
)

Arguments

mutations

A data frame containing mutation data. It must contain columns for genomic start position (start), variation_type, normalized_subtype, and a column to group by (see group_by_col).

min_recurrence

An integer specifying the minimum number of times a mutation must be observed at the same position to be plotted. Defaults to 2.

group_by_col

A string specifying the column name to group mutations by, typically representing chromosomes or contigs (e.g., "seqnames", "chr"). Defaults to "seqnames".

custom_palette

A named character vector for coloring the mutation subtypes. The names should match the levels in normalized_subtype. If NULL (default), a default palette is used.

Value

A list of ggplot objects. Each element of the list is a lollipop plot for a specific region (e.g., a chromosome) and is named accordingly.

Examples

if (requireNamespace("dplyr", quietly = TRUE) &&
    requireNamespace("ggplot2", quietly = TRUE)) {

example_file <- system.file("extdata", "Example_files",
                            "example_mutation_data_filtered.rds",
                            package = "MutSeqR")
example_data <- readRDS(example_file)
example_data$dose_group <- factor(example_data$dose_group,
                                  levels = c("Control", "Low",
                                             "Medium", "High"))

  # 2. Generate the plots
  plot_list <- plot_lollipop(mutations = example_data, min_recurrence = 2)

  # 3. Display a plot for a specific chromosome
  # print(plot_list$chr1)
  # print(plot_list$chr2)
}