Skip to content

Commit 4adbc26

Browse files
committed
fix feature name and display issue, added example
1 parent 3b19e8e commit 4adbc26

File tree

8 files changed

+287
-26
lines changed

8 files changed

+287
-26
lines changed

R/barplot_server.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#' @param id Module ID
55
#' @param plot_data_function A shiny::reactive that returns a function
66
#' The function must take an argument called ".feature_class" and return a
7-
#' dataframe with columns "sample_name", "feature_name", "feature_value",
8-
#' "group_name", and optionally "group_description"
7+
#' dataframe with columns "sample_name", "feature_name", "feature_display",
8+
#' "feature_value", "group_name", and optionally "group_description"
99
#' @param feature_classes A shiny::reactive that returns a vector of strings.
1010
#' One of these strings are passed to plot_data_function
1111
#' @param barplot_xlab A shiny::reactive that returns a string
@@ -77,7 +77,7 @@ barplot_server <- function(
7777
source_name = barplot_source_name(),
7878
x_col = "group_name",
7979
y_col = "MEAN",
80-
color_col = "feature_name",
80+
color_col = "feature_display",
8181
error_col = "SE",
8282
text_col = "text",
8383
xlab = barplot_xlab(),
@@ -117,9 +117,9 @@ barplot_server <- function(
117117
shiny::req(barplot_data(), selected_group())
118118
barplot_data() %>%
119119
dplyr::filter(.data$group_name == selected_group()) %>%
120-
dplyr::select("sample_name", "group_name", "feature_name", "feature_value") %>%
120+
dplyr::select("sample_name", "group_name", "feature_display", "feature_value") %>%
121121
tidyr::pivot_wider(
122-
., values_from = "feature_value", names_from = "feature_name"
122+
., values_from = "feature_value", names_from = "feature_display"
123123
)
124124
})
125125

R/barplot_server_functions.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ build_barplot_data <- function(plot_data_function, feature_class_choice){
55
c(
66
"sample_name",
77
"feature_name",
8+
"feature_display",
89
"feature_value",
910
"group_name",
1011
"group_description"
@@ -14,16 +15,16 @@ build_barplot_data <- function(plot_data_function, feature_class_choice){
1415

1516
summarise_barplot_se <- function(data, title){
1617
data %>%
17-
dplyr::select("group_name", "feature_name", "feature_value") %>%
18+
dplyr::select("group_name", "feature_display", "feature_value") %>%
1819
tidyr::drop_na() %>%
19-
dplyr::group_by_at(dplyr::vars("group_name", "feature_name")) %>%
20+
dplyr::group_by_at(dplyr::vars("group_name", "feature_display")) %>%
2021
dplyr::summarise(
2122
"MEAN" = mean(.data$feature_value),
2223
"SE" = .data$MEAN / sqrt(dplyr::n()),
2324
.groups = "drop"
2425
) %>%
2526
create_plotly_text(
26-
.data$feature_name,
27+
.data$feature_display,
2728
.data$group_name,
2829
c("MEAN", "SE"),
2930
title

R/example_data.R

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ example_starwars_data <- function(){
1111
) %>%
1212
tidyr::pivot_longer(
1313
-c("sample_name", "group_name"), names_to = "feature_name", values_to = "feature_value"
14-
)
14+
) %>%
15+
dplyr::mutate("feature_display" = .data$feature_name)
1516
}
1617

1718
example_starwars_data_func <- function(.feature_class){
@@ -62,7 +63,7 @@ example_iris_data_func <- function(.feature_class = NULL, .feature = NULL){
6263
dplyr::select(iris_data, -"feature_class")
6364
}
6465

65-
# heatmap examples ----
66+
# pcawg examples ----
6667

6768
get_pcawg_feature_class_list <- function(){
6869
features <-
@@ -246,3 +247,53 @@ get_feature_values_by_feature_no_data <- function(.feature){
246247
"group_color" = character()
247248
)
248249
}
250+
251+
# TCGA
252+
253+
get_tcga_feature_values_by_feature <- function(.feature){
254+
feature_data <-
255+
iatlas.api.client::query_feature_values(
256+
cohorts = "TCGA", features = .feature
257+
) %>%
258+
dplyr::select(
259+
"sample_name" = "sample",
260+
"feature_name",
261+
"feature_display",
262+
"feature_value"
263+
)
264+
265+
group_data <-
266+
iatlas.api.client::query_tag_samples(
267+
cohorts = "TCGA", parent_tags = "Immune_Subtype"
268+
) %>%
269+
dplyr::select(
270+
"sample_name",
271+
"group_name" = "tag_short_display",
272+
"group_description" = "tag_characteristics",
273+
"group_color" = "tag_color"
274+
)
275+
276+
dplyr::inner_join(
277+
feature_data,
278+
group_data,
279+
by = "sample_name"
280+
)
281+
}
282+
283+
get_tcga_cell_proportions <- function(.feature_class){
284+
result <-
285+
get_tcga_feature_values_by_feature(
286+
c("leukocyte_fraction", "Stromal_Fraction", "Tumor_fraction")
287+
) %>%
288+
dplyr::select(
289+
"sample_name",
290+
"group_name",
291+
"feature_name",
292+
"feature_display",
293+
"feature_value",
294+
"group_description"
295+
)
296+
}
297+
298+
299+

app/server.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ server <- function(input, output, session) {
3232
y_feature_input = shiny::reactive("Petal.Width")
3333
)
3434

35+
barplot_server(
36+
"barplot5",
37+
shiny::reactive(get_tcga_cell_proportions),
38+
barplot_xlab = shiny::reactive("Fraction type by group"),
39+
barplot_ylab = shiny::reactive("Fraction mean"),
40+
barplot_label = shiny::reactive("Fraction"),
41+
drilldown = shiny::reactive(T),
42+
y_feature_input = shiny::reactive("Leukocyte Fraction"),
43+
x_feature_input = shiny::reactive("Stromal Fraction")
44+
)
45+
3546
distributions_plot_server(
3647
"distplot1",
3748
plot_data_function = shiny::reactive(example_iris_data_func),

app/ui.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ ui <- function() {
1010
barplot_ui("barplot1", title = "Example 1"),
1111
barplot_ui("barplot2", title = "Example 2"),
1212
barplot_ui("barplot3", title = "Example 3"),
13-
barplot_ui("barplot4", title = "Example 4")
13+
barplot_ui("barplot4", title = "Example 4"),
14+
barplot_ui("barplot5", title = "Example 5")
1415
),
1516
shiny::tabPanel(
1617
"Distribution Plots",

man/barplot_server.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)