Here we are demonstrating the feasibility of analyzing genomic data using Stan. The first use case is to analyze somatic mutations for association with survival, after adjusting for key clinical variables with known prognostic status.

knitr::opts_chunk$set(fig.width=8, fig.height=6, fig.path='Figs/',
                      echo=TRUE, warning=FALSE, message=FALSE)

# library(SuMu)
devtools::load_all('.')
library(zoo)
library(dplyr)
library(survminer)
library(survival)
library(ggplot2)
library(scales)
library(tidyr)
library(rstanarm)
options(mc.cores = 4)

Clinical Data

First, download the clinical data. Here we are using the TCGA skin cutaneous melanoma (SKCM) cohort.

clin_df <- SuMu::get_tcga_clinical(cohort = "SKCM")

## format some clinical data variables

clin_df2 <- clin_df %>% 
  dplyr::mutate(stage_part1 = gsub(pathologic_stage,
                                   pattern = '(Stage [0I]+).*',
                                   replacement = '\\1'),
                diagnosis_year_group = cut(year_of_initial_pathologic_diagnosis,
                                           breaks = c(1975, 1990, 1995, 2000,
                                                      2005, 2010, 2015, 2020),
                                           include.lowest = TRUE),
                os_10y = ifelse(OS_IND == 1 & OS <= 10*365.25, 1, 0),
                sample = sampleID
                )

Review clinical data

For this analysis we will consider the survival time in r print(unique(clin_df['OS_UNIT'])) since initial pathologic diagnosis.

fit <- survfit(Surv(OS, OS_IND) ~ 1,
                  data = clin_df2)
survminer::ggsurvplot(fit) + 
  ggtitle('Survival since diagnosis in full cohort')

Plotting by stage, although the time of 'stage' determination may be confounded if not collected at time of initial diagnosis.

fit <- survfit(Surv(OS, OS_IND) ~ pathologic_stage,
                  data = clin_df2)
survminer::ggsurvplot(fit, legend = "right")

There also seem to be differences by tumor type.

fit <- survfit(Surv(OS, OS_IND) ~ sample_type,
                  data = clin_df2)
survminer::ggsurvplot(fit, legend = "right")

(Aside: I wonder how similar tumor type is to sample type? For example, we could have a metastatic patient where the sample was obtained from the primary tumor. We will want to adjust our genetic data analysis for the sample type but may want to estimate prognosis according to the tumor type?)

A variable like year_of_initial_pathologic_diagnosis is guaranteed to be unconfounded since we can safely assume it was collected at the time of diagnosis.

fit <- survfit(Surv(OS, OS_IND) ~ diagnosis_year_group,
                  data = clin_df2)
survminer::ggsurvplot(fit, legend = 'right')

This makes it pretty clear that we have a strong "survival" bias to our data. This would suggest that, among people whose diagnosis was made in the 90s, only those who survived long enough to be enrolled were included in the study.

Let's look at a histogram of years of initial diagnosis.

ggplot(clin_df2, aes(x = year_of_initial_pathologic_diagnosis,
                     fill = diagnosis_year_group)) + 
  geom_histogram() + 
  theme_minimal()

Let's look at the time since initial diagnosis (presumably, the time from enrollment to diagnosis).


Finally, we can visualize a more comprehesive set of clinical variables.

fit <- survival::coxph(Surv(OS, OS_IND) ~
                         age_at_initial_pathologic_diagnosis + 
                         sample_type +
                         breslow_depth_value + initial_weight + 
                         strata(year_of_initial_pathologic_diagnosis),
               data = clin_df2)
print(fit)

Somatic Mutations Data

We can download the somatic mutations to supplement the phenotypes.

mut_df <- SuMu::get_tcga_somatic_mutations(cohort = "SKCM") %>%
  dplyr::mutate(gene_aa = paste0(gene, ":",Amino_Acid_Change),
                gene_effect = paste0(gene, ":",effect)
                )

Check the most frequent mutations.

mut_df_missense = mut_df %>% dplyr::filter(effect == "Missense_Mutation")
mut_df_missense$gene_aa = paste0(mut_df_missense$gene, ":", mut_df_missense$Amino_Acid_Change)
mut_df_missense %>% select(gene_aa) %>% table %>% sort %>% rev %>% as.data.frame %>% head(10)

Copy Number and Gene Expression Data

We can also download gene expression and gene-level copy number data.

exp_data = get_tcga_gene_expression(cohort = "SKCM")
cnv_gene = get_tcga_copy_number_gene(cohort = "SKCM")

Gene expression and copy number data should correlate. We can check.

# convert to matrix
exp_mat = exp_data %>% as.data.frame %>% tibble::column_to_rownames("sample") %>% as.matrix
dim(exp_mat)
cnv_mat = cnv_gene %>% as.data.frame %>% tibble::column_to_rownames("Gene Symbol") %>% as.matrix
dim(cnv_mat)

# get genes and samples with both expression and copy number data
common_samples = intersect(colnames(cnv_mat), colnames(exp_mat))
common_genes = intersect(rownames(cnv_mat), rownames(exp_mat))

# subset to common genes and samples
exp_mat = exp_mat[common_genes, common_samples]
dim(exp_mat)
cnv_mat = cnv_mat[common_genes, common_samples]
dim(cnv_mat)

# get highly expressed genes
top_genes = rowMeans(exp_mat) %>% sort %>% rev %>% head(5000) %>% names %>% sort

# select 10 random samples
random_samples = sample(common_samples, 10)

# keep only highly expressed genes
exp_mat = exp_mat[top_genes, random_samples]
dim(exp_mat)
cnv_mat = cnv_mat[top_genes, random_samples]
dim(cnv_mat)

# run correlations
diag(cor(cnv_mat, exp_mat)) %>% round(3) %>% as.data.frame

There is some correlation between expression and copy number data as expected.

Fit a glm model to mutation counts

Here we do not adjust for clinical covariates, in order to demonstrate the functionality of the package.

# subset mutations to just chr7 (BRAF) to keep it small for testing
top_genes <- mut_df %>%
  dplyr::filter(effect == "Missense_Mutation") %>%
  dplyr::select(gene) %>%
  dplyr::group_by(gene) %>%
  dplyr::mutate(gene_count = n()) %>%
  dplyr::ungroup() %>%
  dplyr::distinct(gene, .keep_all = TRUE) %>%
  dplyr::arrange(-gene_count) %>%
  head(10) %>%
  .$gene

mut_df_subset = mut_df %>% dplyr::filter(gene %in% top_genes)

# base rstanarm function
glmfit <- fit_rstanarm(
  data = clin_df2,
  formula = os_10y ~ 1 + `__BIOM`,
  biomarker_data = mut_df_subset,
  biomarker_formula = 1 ~ gene_effect,
  id = 'sample',
  stanfit_func = rstanarm::stan_glm,
  biomarker_placeholder = '__BIOM'
  )
# (not tested)
# new fit-glm function
glmfit <- fit_glm(
  data = clin_df2 %>% dplyr::select(os_10y, sample),
  formula = os_10y ~ .,
  biomarker_data = mut_df_subset,
  biomarker_formula = 1 ~ gene_effect,
  id = 'sample',
  stanfit_func = NULL)

Visualize results

summary_table=feature_table(glmfit)
feature_graph(glmfit)
view_feature(mutation_matrix,clin_df2,gsub("`","",rownames(summary_table)[1]))
view_feature(mutation_matrix,clin_df2,gsub("`","",rownames(summary_table)[nrow(summary_table)]))

Calculate AUC

auc(glm_df, "os_10y", glmfit)
auc(glm_df, "os_10y", glmfit, h_gram = T)
auc(glm_df, "os_10y", glmfit, roc_plot = T)


NCBI-Hackathons/SuMu documentation built on May 31, 2019, 8:02 a.m.