Skip to content

Instantly share code, notes, and snippets.

@PlethoraChutney
Created December 2, 2022 04:55
Show Gist options
  • Save PlethoraChutney/afd93e630ea2860b42c715c2277bc5f2 to your computer and use it in GitHub Desktop.
Save PlethoraChutney/afd93e630ea2860b42c715c2277bc5f2 to your computer and use it in GitHub Desktop.
library(tidyverse)
data <- read_csv('~/Downloads/data-precs.csv')
counted <- data |>
filter(!is.na(res_id)) |>
select(pdb_id, name, secondary) |>
group_by(pdb_id) |>
mutate(
previous = lag(secondary)
) |>
filter(!is.na(previous) & !is.na(secondary)) |>
# filter(previous != secondary) |>
mutate(
previous = case_when(
previous == 'H' ~ 'alpha helix',
previous == 'B' ~ 'beta bridge',
previous == 'E' ~ 'beta ladder',
previous == 'G' ~ '310 helix',
previous == 'I' ~ 'pi helix',
previous == 'T' ~ 'H-bonded turn',
previous == 'S' ~ 'bend',
previous == '-' ~ 'loop'
),
secondary = case_when(
secondary == 'H' ~ 'alpha helix',
secondary == 'B' ~ 'beta bridge',
secondary == 'E' ~ 'beta ladder',
secondary == 'G' ~ '310 helix',
secondary == 'I' ~ 'pi helix',
secondary == 'T' ~ 'H-bonded turn',
secondary == 'S' ~ 'bend',
secondary == '-' ~ 'loop'
)
) |>
mutate(
transition = paste0(
previous, ' to ', secondary
)
) |>
group_by(secondary, previous) |>
count(name) |>
mutate(prop = n / sum(n))
counted |>
rename('From' = previous, 'To' = secondary) |>
mutate(From = paste('From', From), To = paste('to', To)) |>
ggplot(aes(x = name, y = prop)) +
theme_minimal() +
geom_col() +
facet_grid(cols = vars(From), rows = vars(To)) +
scale_y_continuous(breaks = c(0, 0.5, 1)) +
scale_x_discrete(guide = guide_axis(n.dodge = 2)) +
labs(
x = 'Amino acid name',
y = 'Proportion of transition',
caption = 'Data from Rosenberg, Marx, and Bronstein, 2022. https://doi.org/10.7910/DVN/5P81D4'
)
ggsave('secondary-structure-transitions.png', width = 12, height = 12, bg = 'white')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment