plot_pwm_as_bars: Visualise a PWM as a stacked barplot

View source: R/pwm_utils.R

plot_pwm_as_barsR Documentation

Visualise a PWM as a stacked barplot

Description

This function is useful to visually explore the different contribution of pseudocounts and weighted background probabilities to a PWM. See exaples.

Usage

plot_pwm_as_bars(
  long_df,
  axis_txt_size = 10,
  alphabet_palette = c(t = "forestgreen", c = "dodgerblue", g = "orange", a =
    "firebrick3")
)

Arguments

long_df

A data.frame obtained with df2pwd(long_format = TRUE)

axis_txt_size

axis_txt_size Text size of axis labels. Default 10.

alphabet_palette

A colour palette vector with names matching the PWM alphabet

Value

A ggplot2 plot

Examples

df2pwm(data, ID_col = 'Species', alphabet = c('a', 'c', 'g', 't'), long_format = T) |>
  plot_pwm_as_bars() + ggtitle('uniform bg prob & default pseudocounts')
  
df2pwm(data, ID_col = 'Species', alphabet = c('a', 'c', 'g', 't'), long_format = T, pseudocount_letter = 0.05) |>
  plot_pwm_as_bars() + ggtitle('Uniform bg prob & small pseudocounts')
  
mm10_bg_prob <- c('a' = 0.2917, 't' = 0.2917, 'c' = 0.2083, 'g' = 0.2083 )
df2pwm(data, ID_col = 'Species', alphabet = c('a', 'c', 'g', 't'), long_format = T, 
       pseudocount_letter = 0.05, bg_prob_letter = mm10_bg_prob ) |>
       plot_pwm_as_bars() + ggtitle('mm10 bg prob & small pseudocounts')

# Get the alphabet and build a palette        
alphabet <- guess_alphabet(data = data, ID_col = 'Species')
plt <- palette.colors(n = length(alphabet))
names(plt) <- alphabet

df2pwm(data, ID_col = 'Species', long_format = T) |>
   plot_pwm_as_bars(alphabet_palette = plt)

Ni-Ar/niar documentation built on Feb. 3, 2025, 9:25 a.m.