Skip to content

Instantly share code, notes, and snippets.

@lovrot
Last active February 22, 2019 13:02
Show Gist options
  • Save lovrot/553d83fd8ed26a651c56057d21d60f29 to your computer and use it in GitHub Desktop.
Save lovrot/553d83fd8ed26a651c56057d21d60f29 to your computer and use it in GitHub Desktop.
Retrive METABRIC data from cBioPortal
library(dplyr)
library(tidyr)
library(ggplot2)
library(cgdsr)
ggplot2::theme_set(theme_classic())
conn <- CGDS("http://www.cbioportal.org/")
test(conn)
## Inital look at availability
x1 <- getCancerStudies(conn)
rownames(x1) <- x1$cancer_study_id
x1[, "name", drop = FALSE]
subset(x1, grepl("brca", cancer_study_id), "name")
x2 <- getCaseLists(conn, "brca_metabric")
x2$case_list_id
x3 <- getGeneticProfiles(conn, "brca_metabric")
x3$genetic_profile_id
## Retrieve data from cBioPortal
df_clin <- getClinicalData(conn,
caseList = "brca_metabric_all")
df_clin$subjid <- row.names(df_clin)
df_mrna <- getProfileData(conn,
genes = c("ESR1", "ERBB2"),
geneticProfiles = "brca_metabric_mrna",
caseList = "brca_metabric_all")
names(df_mrna) <- paste0(names(df_mrna), "_mrna")
df_mrna$subjid <- row.names(df_mrna)
df_cna <- getProfileData(conn,
genes = c("ESR1", "ERBB2"),
geneticProfiles = "brca_metabric_cna",
caseList = "brca_metabric_all")
names(df_cna) <- paste0(names(df_cna), "_cna")
df_cna$subjid <- row.names(df_cna)
df <- df_clin %>%
left_join(df_mrna, by = "subjid") %>%
left_join(df_cna, by = "subjid")
colcna <- c(rev(RColorBrewer::brewer.pal(5, "RdYlBu")), "grey")
names(colcna) <- c(as.character(-2:2), "NaN")
## Look at data
summary(df)
gg1 <- df %>%
ggplot(aes(x = THREEGENE, fill = factor(ERBB2_cna))) +
geom_bar(position = "fill") +
scale_fill_manual(values = colcna) +
labs(y = "Proportion") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
gg2 <- df %>%
ggplot(aes(x = factor(ERBB2_cna), y = ERBB2_mrna)) +
geom_boxplot(aes(fill = factor(ERBB2_cna))) +
scale_fill_manual(values = colcna, guide = FALSE)
cowplot::plot_grid(gg1, gg2, labels = "AUTO")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment