Skip to content

Commit

Permalink
Merge pull request openbiox#337 from lishensuo/master
Browse files Browse the repository at this point in the history
improve UI of TPC modules
  • Loading branch information
lishensuo authored Jul 8, 2024
2 parents 4716bd1 + 500746e commit e55a5fb
Show file tree
Hide file tree
Showing 28 changed files with 218 additions and 52 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export(vis_gene_drug_response_asso)
export(vis_gene_drug_response_diff)
export(vis_gene_immune_cor)
export(vis_gene_msi_cor)
export(vis_gene_pw_cor)
export(vis_gene_stemness_cor)
export(vis_gene_tmb_cor)
export(vis_identifier_cor)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added gene and pathway cross-omics analysis functions/modules.
- Added `app_run2()` function for custom app start with lightweight modules.
- Fixed `pdf()` parameter for KM plot
- Improve the UI of Custom TPC Modules.

# UCSCXenaShiny 2.1.0

Expand Down
24 changes: 13 additions & 11 deletions R/query_general.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,14 @@ query_general_id = function(){

#### PCAWG ID
pcawg_id_option = tcga_id_option
pcawg_id_referrence = load_data("pcawg_identifier")
# pcawg_id_referrence = load_data("pcawg_identifier")
pcawg_id_referrence = load_data("v2_pcawg_id")
pcawg_id_option$`Molecular profile` = list(
`mRNA Expression` = list(all = sort(pcawg_id_referrence$id_gene$Level3), default = "TP53"),
`Promoter Activity` = list(all = sort(pcawg_id_referrence$id_pro$Level3), default = "prmtr.1"),
`Gene Fusion` = list(all = sort(pcawg_id_referrence$id_fusion$Level3), default = "SAMD11"),
`miRNA Expression` = list(all = sort(pcawg_id_referrence$id_mi$Level3), default = "hsa-let-7a-2-3p"),
`APOBEC Mutagenesis` = list(all = sort(pcawg_id_referrence$id_maf$Level3), default = "A3A_or_A3B")
`mRNA Expression` = list(all = sort(v2_pcawg_id$L3[v2_pcawg_id$L2=="Gene"]), default = "TP53"),
`Promoter Activity` = list(all = sort(v2_pcawg_id$L3[v2_pcawg_id$L2=="Promoter"]), default = "prmtr.1"),
`Gene Fusion` = list(all = sort(v2_pcawg_id$L3[v2_pcawg_id$L2=="Fusion"]), default = "SAMD11"),
`miRNA Expression` = list(all = sort(v2_pcawg_id$L3[v2_pcawg_id$L2=="miRNA"]), default = "hsa-let-7a-2-3p"),
`APOBEC Mutagenesis` = list(all = sort(v2_pcawg_id$L3[v2_pcawg_id$L2=="Muta"]), default = "A3A_or_A3B")
)
pcawg_id_option$`Tumor index` = list(
`Tumor Purity` = list(all = c("purity", "ploidy", "purity_conf_mad", "wgd_status", "wgd_uncertain"),
Expand All @@ -197,12 +198,13 @@ query_general_id = function(){

#### CCLE ID
ccle_id_option = list()
ccle_id_referrence = load_data("ccle_identifier")
# ccle_id_referrence = load_data("ccle_identifier")
ccle_id_referrence = load_data("v2_ccle_id")
ccle_id_option$`Molecular profile` = list(
`mRNA Expression` = list(all = sort(ccle_id_referrence$id_gene$Level3), default = "TP53"),
`Protein Expression` = list(all = sort(ccle_id_referrence$id_pro$Level3), default = "14-3-3_beta"),
`Copy Number Variation` = list(all = sort(ccle_id_referrence$id_cnv$Level3), default = "TP53"),
`Mutation status` = list(all = sort(ccle_id_referrence$id_mut$Level3), default = "TP53")
`mRNA Expression` = list(all = sort(v2_pcawg_id$L3[v2_pcawg_id$L2=="Gene"]), default = "TP53"),
`Protein Expression` = list(all = sort(v2_ccle_id$L3[v2_ccle_id$L2=="Protein"]), default = "14-3-3_beta"),
`Copy Number Variation` = list(all = sort(v2_pcawg_id$L3[v2_pcawg_id$L2=="Gene"]), default = "TP53"),
`Mutation status` = list(all = sort(v2_pcawg_id$L3[v2_pcawg_id$L2=="Gene"]), default = "TP53")
)
ccle_id_option$`Tumor index` = list(
`Tumor Purity` = list(all = c("Purity", "Ploidy", "Genome Doublings", "Lineage"),
Expand Down
106 changes: 106 additions & 0 deletions R/vis_gene_pw_cor.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#' Visualize Correlation between Gene and Pathway signature Score
#' @param Gene a molecular identifier (e.g., "TP53") or a formula
#' specifying genomic signature ("TP53 + 2 * KRAS - 1.3 * PTEN").
#' @param data_type choose gene profile type, including
#' "mRNA", "transcript", "protein", "mutation", "cnv", "methylation", "miRNA".
#' @param pw_name the queried Pathway name, see the supported pathway from 'load("toil_sig_score")'default is NULL
#' @param cancer_choose select cancer cohort(s)
#' @param use_regline if TRUE, add regression line.
#' @param cor_method select correlation coefficient (pearson/spearman)
#' @param use_all use all sample, default FALSE.
#' @param alpha dot alpha.
#' @param color dot color.
#' @param filter_tumor whether use tumor sample only, default TRUE
#' @param opt_pancan specify one dataset for some molercular profiles

#' @return a `ggplot` object or dataframe
#' @examples
#' \dontrun{
#' vis_gene_pw_cor(Gene = "TP53", data_type = "mRNA",
#' pw_name = "HALLMARK_ADIPOGENESIS",
#' cancer_choose = "BRCA")
#' }

#' @export
#'
vis_gene_pw_cor <- function(Gene = "TP53",
data_type = "mRNA",
pw_name = "HALLMARK_ADIPOGENESIS",
cancer_choose = "GBM",
use_regline = TRUE,
cor_method = "spearman",
use_all = FALSE,
alpha = 0.5,
color = "#000000",
filter_tumor = TRUE,
opt_pancan = .opt_pancan){
if (!file.exists(file.path(get_zenodo_dir(), "tcga_PW.rda"))) {
print("This is the first download from zenodo, please wait a few minutes.")
}
toil_sig_score <- load_data("tcga_PW")
toil_sig_meta <- load_data("tcga_PW_meta")
if (!is.null(pw_name)) {
if (!(pw_name %in% toil_sig_meta$ID)) {
stop("You need provide valid pathway name (see load_data('tcga_PW_meta'))")
}
}
# gene expression
t1 <- query_pancan_value(Gene, data_type = data_type, opt_pancan = opt_pancan)
if (is.null(t1[[1]])) {
warning("No data available", immediate. = TRUE)
return(NULL)
}
if (is.list(t1)) t1 <- t1[[1]]
if (all(is.na(t1))) {
message("All NAs returned, return NULL instead.")
return(NULL)
}
message(paste0("Get data value for ", Gene))
s <- data.frame(Sample = names(t1), values = t1)


# message("Mode-3: one specific pathway correlated to one specific cancer")
toil_sig_score <- load_data("tcga_PW")

tcga_gtex <- load_data("tcga_gtex")
if(use_all){
cancer_choose2 = as.character(unique(tcga_gtex$tissue))
} else {
cancer_choose2 = cancer_choose
}
if(filter_tumor){
filter_tumor2 = 'tumor'
} else {
filter_tumor2 = c('tumor','normal')
}
tcga_sp <- tcga_gtex %>%
dplyr::filter(.data$type2 == filter_tumor2) %>%
dplyr::filter(.data$tissue %in% cancer_choose2) %>%
dplyr::pull(sample) %>%
as.character()

res_pan_spe <- toil_sig_score[rownames(toil_sig_score) %in% tcga_sp, pw_name, drop = F] %>%
as.data.frame() %>% tibble::rownames_to_column("Sample") %>%
tidyr::pivot_longer(!"Sample", names_to = "pw_name", values_to = "pw_score") %>%
dplyr::left_join(s) %>%
dplyr::mutate(identifier = Gene, .before = 1) %>%
dplyr::mutate(Cancer = tcga_gtex$tissue[match(.data$Sample, tcga_gtex$sample)], .before = 3) %>%
tibble()

cor_res <- ezcor(data = as.data.frame(res_pan_spe), var1 = "values", var2 = "pw_score", cor_method = cor_method)
p <- ggplot2::ggplot(res_pan_spe, aes_string(x = "values", y = "pw_score")) +
ggplot2::geom_point(shape = 16, size = 3, show.legend = FALSE, alpha = alpha, color = color) +
ggplot2::theme_minimal() +
ggplot2::labs(x = paste(Gene, data_type), y = pw_name) +
ggplot2::annotate(
"text",
-Inf, Inf,
hjust = -0.1, vjust = 1,
label = paste0("Cor: ", round(cor_res$cor, 2), " ", cor_res$pstar),
size = 8, colour = "black"
)

if (use_regline) p <- p + ggplot2::geom_smooth(method = stats::lm)

return(p)
}
7 changes: 5 additions & 2 deletions R/vis_pcawg_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ vis_pcawg_gene_cor <- function(Gene1 = "CSF1R",
# t1 <- query_pcawg_pancan_value(Gene1, data_type1)
t1 <- query_pancan_value(Gene1, data_type1, database = "pcawg", opt_pancan=opt_pancan)



unit1 <- switch(data_type1,
cnv = NULL,
mutation = NULL,
Expand Down Expand Up @@ -422,6 +420,11 @@ vis_pcawg_gene_cor <- function(Gene1 = "CSF1R",
df %>% dplyr::filter(.data$type2 == "tumor") -> df
}

if(nrow(df)==0){
warning("No intersected samples for the two identifiers in the cohort")
return(NULL)
}

# print(dim(df))

if (purity_adj) {
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ reference:
- vis_gene_stemness_cor
- vis_gene_tmb_cor
- vis_gene_msi_cor
- vis_gene_pw_cor
- vis_pancan_anatomy
- vis_toil_TvsN
- vis_toil_TvsN_cancer
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-1-tcga-01-TN.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ui.modules_1_tcga_01 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-1-tcga-02-Anatomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ui.modules_1_tcga_02 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-1-tcga-03-Cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ui.modules_1_tcga_03 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-1-tcga-04-TIL.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ui.modules_1_tcga_04 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
8 changes: 4 additions & 4 deletions inst/shinyapp/modules/02_quick/modules-1-tcga-05-Immune.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ ui.modules_1_tcga_05 = function(id){
h4("3. Select TIL cell types"),
selectInput(
ns("immune_sig"), NULL,
choices = "Cibersort",
selected = c("Yasin", "Wolf", "Attractors", "ICR",
"c7atoms", "Bindea", "Cibersort")
choices = c("Yasin", "Wolf", "Attractors", "ICR",
"c7atoms", "Bindea", "Cibersort"),
selected = "Cibersort"
),
h4("4. Select correlation method"),
awesomeRadio(
Expand Down Expand Up @@ -92,7 +92,7 @@ ui.modules_1_tcga_05 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
6 changes: 3 additions & 3 deletions inst/shinyapp/modules/02_quick/modules-1-tcga-06-Idx.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ ui.modules_1_tcga_06 = function(id){
h4("3. Select fearture type"),
selectInput(
ns("Type"), NULL,
choices = "Stemness",
selected = c("Stemness", "TMB", "MSI")
choices = c("Stemness", "TMB", "MSI"),
selected = "Stemness"
),
h4("4. Select correlation method"),
awesomeRadio(
Expand Down Expand Up @@ -88,7 +88,7 @@ ui.modules_1_tcga_06 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-1-tcga-07-PW.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ ui.modules_1_tcga_07 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-1-tcga-08-Mut.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ui.modules_1_tcga_08 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
4 changes: 2 additions & 2 deletions inst/shinyapp/modules/02_quick/modules-1-tcga-09-KM.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ui.modules_1_tcga_09 = function(id){
bsTooltip(ns("groupby"), "Only valid for continuous variable, other than molecules from Copy Number Variation/Mutation status",
placement = "right", trigger = "hover", options = list(container = "body")),
shinyWidgets::actionBttn(
inputId = ns("submit_bt"), label = "Submit",
inputId = ns("submit_bt"), label = "Go!",
style = "gradient",
icon = icon("check"),
color = "primary",
Expand Down Expand Up @@ -107,7 +107,7 @@ ui.modules_1_tcga_09 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:670px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-1-tcga-10-Cox.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ui.modules_1_tcga_10 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
6 changes: 3 additions & 3 deletions inst/shinyapp/modules/02_quick/modules-1-tcga-11-Dim.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ ui.modules_1_tcga_11 = function(id){
status = "warning",
background = "gray",
collapsible = FALSE,
style = "height:805px",
style = "height:600px",
footer = "TIPs: Click the bottom button to execute/update the analysis."
),
box(out_ui,
Expand All @@ -196,8 +196,8 @@ ui.modules_1_tcga_11 = function(id){
status = "warning",
background = "gray",
collapsible = FALSE,
style = "height:805px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-2-pcawg-01-TN.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ui.modules_2_pcawg_01 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
10 changes: 6 additions & 4 deletions inst/shinyapp/modules/02_quick/modules-2-pcawg-02-Cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ui.modules_2_pcawg_02 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down Expand Up @@ -155,9 +155,11 @@ server.modules_2_pcawg_02 = function(input, output, session){
color = input$color,
alpha = input$alpha
)
p <- p + themes_list[[input$theme]] +
theme(text = element_text(size = 20),
legend.position = "none")
if(!is.null(p)){
p <- p + themes_list[[input$theme]] +
theme(text = element_text(size = 20),
legend.position = "none")
}
return(p)
})

Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-2-pcawg-03-KM.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ui.modules_2_pcawg_03 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:670px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-2-pcawg-04-Cox.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ui.modules_2_pcawg_04 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyapp/modules/02_quick/modules-3-ccle-01-Dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ui.modules_3_ccle_01 = function(id){
background = "gray",
collapsible = FALSE,
style = "height:600px",
footer = "TIPs: Pull the sidebar to adjsut plot parameters or download results through the top-right widget.",
footer = "TIPs: Pull the sidebar to adjust plot parameters or download results through the top-right widget.",
sidebar = boxSidebar(
id = ns("sidebar"),
width = 50,
Expand Down
Loading

0 comments on commit e55a5fb

Please sign in to comment.