Last updated: 2019-11-13
Checks: 7 0
Knit directory: transcriptome_cll/
This reproducible R Markdown analysis was created with workflowr (version 1.4.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20190511)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/figure/
Untracked files:
Untracked: data/c2.cp.kegg.v6.0.symbols.gmt
Untracked: data/ddsrnaCLL_150218.RData
Untracked: output/diff_genes/
Untracked: output/diff_meth.rds
Untracked: output/diff_meth_IGHV.rds
Untracked: output/diff_meth_IP_vs_all.rds
Untracked: output/figures/
Untracked: output/res_epistatsis_ighv_tri12.rds
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view them.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | 7913207 | aluetge | 2019-11-13 | wflow_publish(c(“analysis/methylation_IP_vs_all.Rmd”, “analysis/methylation_HP_vs_IP.Rmd”, “analysis/index.Rmd”)) |
Analyse genes associated with methylation groups
libraries
library(tidyverse)
library(ggplot2)
library(DESeq2)
library(ggpubr)
library(ComplexHeatmap)
library(RColorBrewer)
library(circlize)
library(here)
library(piano)
data
data_dir <- here("data")
output_dir <- here("output")
figure_dir <- here("output/figures")
#dds data set. gene expression data + patmetadata
load(paste0(data_dir, "/ddsrnaCLL_150218.RData"))
#arrange columns
mutStatus <- data.frame(colData(ddsCLL)) %>% arrange(Methylation) %>% filter(!is.na(Methylation)) %>% mutate("IP" = ifelse(Methylation %in% c("LP", "HP"), 0, 1))
colnames(ddsCLL) <-colData(ddsCLL)$PatID
ddsCLL <- ddsCLL[, mutStatus$PatID]
colData(ddsCLL)$IP <- mutStatus$IP
table(colData(ddsCLL)$IP)
0 1
141 32
Normalize
#expression data
ddsCLL <- estimateSizeFactors(ddsCLL)
RNAnorm <- varianceStabilizingTransformation(ddsCLL, blind = T)
Clustering on the most variable genes already split methylation groups. How do methylation groups affect highly variable genes? Can we distinguish all 3 groups?
PCA
#Plot PCA
exprMat <- assay(RNAnorm)
#top 5000 most variant genes
sds <- rowSds(exprMat)
exprMat <- exprMat[order(sds, decreasing = T)[1:150],]
#Calculate PCA
pcaRes <- prcomp(t(exprMat), scale =T)
varExp <- (pcaRes$sdev^2 / sum(pcaRes$sdev^2)) * 100
pcaTab <- data.frame(pcaRes$x[,c(1:10)])
names(varExp) <- colnames(pcaRes$x)
#add background information
pcaTab <- cbind(pcaTab, data.frame(colData(RNAnorm)))
#plot PCA and color samples based on annotations
annocol <- get_palette("jco", 10)
p <- ggscatter(pcaTab, x = "PC1", y = "PC2", color = "Methylation", palette = c( annocol[7], annocol[5], annocol[6]),
ylab = sprintf("PC2 (%2.1f%%)",varExp[2]), xlab = sprintf("PC1 (%2.1f%%)",varExp[1]), legend = "right", main = "PCA Methylation groups") + coord_fixed()
p
#ggsave(file=paste0(figure_dir, "/pca_Meth_IP_all_top150.svg"), plot=p, width=5, height=5)
deseq2
###Deseq
ddsCLL <- estimateSizeFactors(ddsCLL)
# deseq2 function
diff <- function(cond){
ddsCLL_new <- ddsCLL[,!is.na(colData(ddsCLL)[,cond])]
design(ddsCLL_new) <- as.formula(paste("~ ", paste(cond)))
rnaRaw <- DESeq(ddsCLL_new, betaPrior = FALSE)
res <- results(rnaRaw)
resOrdered <- res[order(res$pvalue),]
}
diff_meth <- diff("IP")
saveRDS(diff_meth, file= paste0(output_dir,"/diff_meth_IP_vs_all.rds"))
Filter differentially expressed genes
diff_meth <- readRDS(paste0(output_dir,"/diff_meth_IP_vs_all.rds"))
dataTab <- data.frame(diff_meth)
dataTab$ID <- rownames(dataTab)
#filter using pvalues
dataTab <- dataTab %>%
arrange(padj) %>%
mutate(Symbol = rowData(ddsCLL[ID,])$symbol)
dataTab <- dataTab[!duplicated(dataTab$Symbol),]
dataTab <- dataTab[!is.na(dataTab$Symbol),]
rownames(dataTab) <- dataTab$ID
write.csv(dataTab, file=paste0(output_dir, "/diff_genes/meth_IP_vs_all_diffGenes.csv"))
#arrange columns
mutStatus <- data.frame(colData(ddsCLL)) %>% arrange(Methylation)
colnames(ddsCLL) <-colData(ddsCLL)$PatID
ddsCLL <- ddsCLL[, mutStatus$PatID]
#Differentially expressed genes
genes <- dataTab %>% filter(padj <= 0.01, abs(stat) > 6)
exprMat <- assay(RNAnorm)
exprMat<- exprMat[genes$ID,]
#scale gene expression
colnames(exprMat) <- colData(ddsCLL)$PatID
exprMat.new <- log2(exprMat)
exprMat.new <- t(scale(t(exprMat.new)))
exprMat.new[exprMat.new > 4] <- 4
exprMat.new[exprMat.new < -4] <- -4
#colors
colors <- colorRampPalette(rev( brewer.pal(10,"RdBu")) )(20)
annocol <- get_palette("jco", 10)
annocolor <- list(Methylation = c("IP" = annocol[5], "LP" = annocol[6], "HP" = annocol[7]), IGHV = c("M" = annocol[1], "U" = annocol[2]))
#Annotation
feature <- as.data.frame(colData(ddsCLL)[,c("Methylation", "IGHV")])
colnames(feature) <- c("Methylation", "IGHV")
#gene symbol as rownames
rownames(exprMat.new) <- rowData(RNAnorm[rownames(exprMat),])$symbol
ha_col <- HeatmapAnnotation(df = feature, col = annocolor, annotation_height = unit(c(rep(1.3, 2)), "cm"), annotation_legend_param = list(title_gp = gpar(fontsize = 40), labels_gp = gpar(fontsize = 35), grid_height = unit(1.9, "cm"), grid_width = unit(1.9, "cm")))
h1 <- Heatmap(exprMat.new ,
km = 2,
cluster_columns = F,
clustering_distance_rows = "pearson",
clustering_method_rows = "ward.D2",
column_title ="Gene signature methylation groups ",
col = colors,
column_title_gp = gpar(fontsize = 50, fontface = "bold"),
heatmap_legend_param = list(title = "expr",
title_gp = gpar(fontsize = 40),
grid_height = unit(1.9, "cm"),
grid_width = unit(1.9, "cm"),
gap = unit(2, "cm"),
labels_gp = gpar(fontsize = 35)),
show_row_dend = FALSE,
show_column_names = FALSE ,
show_row_names = FALSE,
row_names_gp = gpar(fontsize = 21),
top_annotation = ha_col)
#Annotate top 50 genes
sub_names <- genes[1:50,"Symbol"]
sub_names <- sub_names[-which(sub_names %in% "")]
geneIDs <- which(rownames(exprMat.new) %in% sub_names)
labels <- rownames(exprMat.new)[geneIDs]
ha_genes <- rowAnnotation(link = row_anno_link(at = geneIDs, labels = labels, labels_gp = gpar(fontsize = 35)), width = unit(9, "cm"))
Warning: anno_link() is deprecated, please use anno_mark() instead.
#svg(filename=paste0(figure_dir, "/gene_expr_Methylation_IP_all.svg"), width=30, height=35)
#pdf(file=paste0(figure_dir,"/gene_expr_Methylation_IP_all.pdf"), width=30, height=45)
draw( h1 + ha_genes)
#dev.off()
#function to create stripchart plots for specific genes
gene_count <- function(gene_nam){
geneEnsID <- rownames(ddsCLL)[which(rowData(ddsCLL)$symbol %in% gene_nam)]
geneNum <- exprMat[geneEnsID,]
mutPat <- as.data.frame(colData(ddsCLL)[, c("Methylation")])
colnames(mutPat) <- c("genotype")
geneDat <- cbind(mutPat, geneNum)
colnames(geneDat) <- c("genotype", "counts")
p <- ggstripchart(geneDat, x = "genotype", y = "counts",
color = "genotype",
palette = "jco",
add = "mean_sd",
title = paste(gene_nam),
ylab = "normalized counts")
# ggsave(file=paste0(figure_dir, "/methylation_IP_all/genetic_interaction_", gene_nam, ".svg"), plot=p, width=6, height=5)
p
}
geneList <- sub_names[1:30]
lapply(geneList, gene_count)
[[1]]
[[2]]
[[3]]
[[4]]
[[5]]
[[6]]
[[7]]
[[8]]
[[9]]
[[10]]
[[11]]
[[12]]
[[13]]
[[14]]
[[15]]
[[16]]
[[17]]
[[18]]
[[19]]
[[20]]
[[21]]
[[22]]
[[23]]
[[24]]
[[25]]
[[26]]
[[27]]
[[28]]
[[29]]
[[30]]
gene_count("SOX11")
variant <- "IP"
gmtFile <- loadGSC(paste0(data_dir,"/c2.cp.kegg.v6.0.symbols.gmt"), type="gmt")
diff_res <- dataTab
diff_res <- diff_res[-which(diff_res$Symbol %in% c("", NA)),]
#get genes and pvalues
geneNam <- diff_res$Symbol
pVal <- diff_res$padj
logFold <- diff_res$log2FoldChange
stat <- diff_res$stat
gsTab <- data.frame(gene = geneNam, stat = stat)
gsaTab <- data.frame(row.names = gsTab$gene, stat = gsTab$stat)
res <- runGSA(geneLevelStats = gsaTab,
geneSetStat = "gsea",
adjMethod = "fdr", gsc=gmtFile,
signifMethod = "geneSampling",
nPerm = 50000,
gsSizeLim=c(1, Inf))
Running gene set analysis:
Checking arguments...done!
*** Please note that running the GSEA-method may take a substantial amount of time! ***
Final gene/gene-set association: 4271 genes and 186 gene sets
Details:
Calculating gene set statistics from 4271 out of 21668 gene-level statistics
Using all 21668 gene-level statistics for significance estimation
Removed 995 genes from GSC due to lack of matching gene statistics
Removed 0 gene sets containing no genes after gene removal
Removed additionally 0 gene sets not matching the size limits
Loaded additional information for 186 gene sets
Calculating gene set statistics...done!
Calculating gene set significance...done!
Adjusting for multiple testing...done!
Res_up <- arrange(GSAsummaryTable(res), `p adj (dist.dir.up)`)
Res_dn <- arrange(GSAsummaryTable(res), `p adj (dist.dir.dn)`)
#Plot
resPlot <- Res_dn[, c(1:3,7,8,9)]
colnames(resPlot) <- c("pathway", "gene_number", "stat", "p.adj","genes_up" , "genes_dn")
enrichPlot <- resPlot %>% filter(p.adj < 0.1) %>% mutate(log10Padj = -log10(p.adj)) #%>% mutate(genes = ifelse(gene_number > 5, ">5", "<=5"))
enrichPlot$log10Padj[which(enrichPlot$log10Padj == Inf)] <- 5
p <- ggbarplot(enrichPlot, x = "pathway", y = "log10Padj",
fill = "gene_number",
color = "white",
palette = "gsea",
sort.val = "asc",
sort.by.groups = FALSE,
ylab = "-log10(padj)",
legend.title = "#diff.genes",
rotate = TRUE,
font.x = 20, font.y = 20, font.legend = 20, legend = "right",
title = "Methylation groups - Kegg",
ggtheme = theme_pubr()) +
font("xy.text", size = 16) +
font("title", size = 20, face = "bold")
ggsave(file=paste0(figure_dir, "/GSEA_Meth_IP_vs_all_Kegg.svg"), plot=p, width=14, height=7)
p
sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS
Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
locale:
[1] LC_CTYPE=de_DE.UTF-8 LC_NUMERIC=C
[3] LC_TIME=de_DE.UTF-8 LC_COLLATE=de_DE.UTF-8
[5] LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=de_DE.UTF-8
[7] LC_PAPER=de_DE.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid parallel stats4 stats graphics grDevices utils
[8] datasets methods base
other attached packages:
[1] gdtools_0.1.9 piano_2.0.2
[3] here_0.1 circlize_0.4.6
[5] RColorBrewer_1.1-2 ComplexHeatmap_2.0.0
[7] ggpubr_0.2 magrittr_1.5
[9] DESeq2_1.24.0 SummarizedExperiment_1.14.0
[11] DelayedArray_0.10.0 BiocParallel_1.18.0
[13] matrixStats_0.54.0 Biobase_2.44.0
[15] GenomicRanges_1.36.0 GenomeInfoDb_1.20.0
[17] IRanges_2.18.1 S4Vectors_0.22.0
[19] BiocGenerics_0.30.0 forcats_0.4.0
[21] stringr_1.4.0 dplyr_0.8.1
[23] purrr_0.3.2 readr_1.3.1
[25] tidyr_0.8.3 tibble_2.1.3
[27] ggplot2_3.1.1 tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] readxl_1.3.1 backports_1.1.4 Hmisc_4.2-0
[4] fastmatch_1.1-0 workflowr_1.4.0 plyr_1.8.4
[7] igraph_1.2.4.1 lazyeval_0.2.2 shinydashboard_0.7.1
[10] splines_3.6.0 digest_0.6.19 htmltools_0.3.6
[13] gdata_2.18.0 checkmate_1.9.3 memoise_1.1.0
[16] cluster_2.1.0 limma_3.40.2 annotate_1.62.0
[19] modelr_0.1.4 svglite_1.2.2 colorspace_1.4-1
[22] blob_1.1.1 rvest_0.3.4 haven_2.1.0
[25] xfun_0.7 crayon_1.3.4 RCurl_1.95-4.12
[28] jsonlite_1.6 genefilter_1.66.0 survival_2.44-1.1
[31] glue_1.3.1 gtable_0.3.0 zlibbioc_1.30.0
[34] XVector_0.24.0 GetoptLong_0.1.7 shape_1.4.4
[37] scales_1.0.0 DBI_1.0.0 relations_0.6-8
[40] Rcpp_1.0.1 xtable_1.8-4 htmlTable_1.13.1
[43] clue_0.3-57 foreign_0.8-71 bit_1.1-14
[46] Formula_1.2-3 DT_0.7 htmlwidgets_1.3
[49] httr_1.4.0 fgsea_1.10.0 gplots_3.0.1.1
[52] acepack_1.4.1 pkgconfig_2.0.2 XML_3.98-1.20
[55] nnet_7.3-12 locfit_1.5-9.1 labeling_0.3
[58] tidyselect_0.2.5 rlang_0.3.4 later_0.8.0
[61] AnnotationDbi_1.46.0 visNetwork_2.0.7 munsell_0.5.0
[64] cellranger_1.1.0 tools_3.6.0 cli_1.1.0
[67] generics_0.0.2 RSQLite_2.1.1 broom_0.5.2
[70] evaluate_0.14 yaml_2.2.0 knitr_1.23
[73] bit64_0.9-7 fs_1.3.1 caTools_1.17.1.2
[76] nlme_3.1-140 whisker_0.3-2 mime_0.7
[79] slam_0.1-45 xml2_1.2.0 compiler_3.6.0
[82] rstudioapi_0.10 png_0.1-7 marray_1.62.0
[85] geneplotter_1.62.0 stringi_1.4.3 lattice_0.20-38
[88] Matrix_1.2-17 ggsci_2.9 shinyjs_1.0
[91] pillar_1.4.1 GlobalOptions_0.1.0 data.table_1.12.2
[94] bitops_1.0-6 httpuv_1.5.1 R6_2.4.0
[97] latticeExtra_0.6-28 promises_1.0.1 KernSmooth_2.23-15
[100] gridExtra_2.3 gtools_3.8.1 assertthat_0.2.1
[103] rprojroot_1.3-2 rjson_0.2.20 withr_2.1.2
[106] GenomeInfoDbData_1.2.1 hms_0.4.2 rpart_4.1-15
[109] rmarkdown_1.13 git2r_0.25.2 sets_1.0-18
[112] shiny_1.3.2 lubridate_1.7.4 base64enc_0.1-3