|
1 | | - |
2 | 1 | #' Get subset of deconvolution results |
3 | 2 | #' |
4 | 3 | #' This function returns the requested deconvolution results as a list |
@@ -44,66 +43,56 @@ returnSelectedDeconvolutions <- function(deconv_select, deconv_list) { |
44 | 43 | #' @examples |
45 | 44 | #' # CosTODO |
46 | 45 | # plot_benchmark <- function(deconvolutions) { |
47 | | -# # import and preformat data |
48 | | -# |
49 | | -# # deconvolution_list <- list() |
50 | | -# # for (deconvolution in deconv_select) { |
51 | | -# # # deconvolution_list[length(deconvolution_list) + 1] <- deconv_list[[deconvolution]][1] |
52 | | -# # deconvolution_list[deconvolution] <- deconv_list[[deconvolution]][1] |
53 | | -# # } |
54 | | -# |
55 | | -# # add samples and deconvolution method |
56 | | -# deconvolutions <- lapply(deconvolutions, function(x) cbind(x, sample = rownames(x))) |
57 | | -# deconvolutions <- lapply(names(deconvolutions), function(x) { |
58 | | -# cbind(deconvolutions[[x]], method = rep(x, nrow(deconvolutions[[x]]))) |
59 | | -# }) |
60 | | -# |
61 | | -# deconvolutions <- lapply(deconvolutions, function(x) { |
62 | | -# tidyr::pivot_longer(data.frame(x), !c("sample", "method"), |
63 | | -# names_to = "cell_type", values_to = "predicted_fraction" |
64 | | -# ) |
65 | | -# }) |
66 | | -# |
67 | | -# # combine to one dataframe |
68 | | -# data <- do.call("rbind", deconvolutions) |
69 | | -# |
70 | | -# # preformat reference data |
71 | | -# ref <- omnideconv::RefData |
72 | | -# ref$sample <- rownames(ref) |
73 | | -# ref <- tidyr::pivot_longer(ref, !sample, names_to = "cell_type", values_to = "true_fraction") |
74 | | -# |
75 | | -# # merge the reference data with the deconvolution results |
76 | | -# data <- merge(ref, data, by = c("sample", "cell_type")) |
77 | | -# |
78 | | -# # change datatype to numeric |
79 | | -# data$predicted_fraction <- as.numeric(data$predicted_fraction) |
80 | | -# data$true_fraction <- as.numeric(data$true_fraction) |
81 | | -# |
82 | | -# # calculate max width/heigth -> plot symmetric and line @ 45 Degrees |
83 | | -# max_value <- max(max(data$true_fraction), max(data$predicted_fraction)) + 0.1 |
84 | | -# |
85 | | -# # create plot |
86 | | -# plot <- ggplot(data, aes( |
87 | | -# x = .data$true_fraction, y = predicted_fraction, color = cell_type, |
88 | | -# text = paste0("Sample: ", sample, "\nTrue: ", true_fraction, "\nPredicted: ", predicted_fraction) |
89 | | -# )) + |
90 | | -# geom_point(size = 4) + |
91 | | -# facet_wrap(~method) + |
92 | | -# geom_abline(color = "black") + |
93 | | -# labs(x = "True Fraction", y = "predicted Fraction", color = "cell type") + |
94 | | -# coord_cartesian(xlim = c(0, max_value), ylim = c(0, max_value)) |
95 | | -# |
96 | | -# # render |
97 | | -# plotly::ggplotly(plot, tooltip = c("text")) |> |
98 | | -# plotly::config( |
99 | | -# displaylogo = FALSE, showTips = FALSE, toImageButtonOptions = list(filename = paste0("plotMethod", "_plot")), |
100 | | -# modeBarButtonsToRemove = list( |
101 | | -# "hoverClosestCartesian", |
102 | | -# "hoverCompareCartesian", |
103 | | -# "zoomIn2d", "zoomOut2d", |
104 | | -# "lasso2d", "zoom2d", |
105 | | -# "pan2d", "autoScale2d", "select2d" |
106 | | -# ) |
107 | | -# ) |> |
108 | | -# plotly::layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE)) |
| 46 | +#' # # import and preformat data |
| 47 | +#' # # deconvolution_list <- list() |
| 48 | +#' # # for (deconvolution in deconv_select) { |
| 49 | +#' # # # deconvolution_list[length(deconvolution_list) + 1] <- deconv_list[[deconvolution]][1] |
| 50 | +#' # # deconvolution_list[deconvolution] <- deconv_list[[deconvolution]][1] |
| 51 | +#' # # } |
| 52 | +#' # # add samples and deconvolution method |
| 53 | +#' # deconvolutions <- lapply(deconvolutions, function(x) cbind(x, sample = rownames(x))) |
| 54 | +#' # deconvolutions <- lapply(names(deconvolutions), function(x) { |
| 55 | +#' # cbind(deconvolutions[[x]], method = rep(x, nrow(deconvolutions[[x]]))) |
| 56 | +#' # }) |
| 57 | +#' # deconvolutions <- lapply(deconvolutions, function(x) { |
| 58 | +#' # tidyr::pivot_longer(data.frame(x), !c("sample", "method"), |
| 59 | +#' # names_to = "cell_type", values_to = "predicted_fraction" |
| 60 | +#' # ) |
| 61 | +#' # }) |
| 62 | +#' # # combine to one dataframe |
| 63 | +#' # data <- do.call("rbind", deconvolutions) |
| 64 | +#' # # preformat reference data |
| 65 | +#' # ref <- omnideconv::RefData |
| 66 | +#' # ref$sample <- rownames(ref) |
| 67 | +#' # ref <- tidyr::pivot_longer(ref, !sample, names_to = "cell_type", values_to = "true_fraction") |
| 68 | +#' # # merge the reference data with the deconvolution results |
| 69 | +#' # data <- merge(ref, data, by = c("sample", "cell_type")) |
| 70 | +#' # # change datatype to numeric |
| 71 | +#' # data$predicted_fraction <- as.numeric(data$predicted_fraction) |
| 72 | +#' # data$true_fraction <- as.numeric(data$true_fraction) |
| 73 | +#' # # calculate max width/heigth -> plot symmetric and line @ 45 Degrees |
| 74 | +#' # max_value <- max(max(data$true_fraction), max(data$predicted_fraction)) + 0.1 |
| 75 | +#' # # create plot |
| 76 | +#' # plot <- ggplot(data, aes( |
| 77 | +#' # x = .data$true_fraction, y = predicted_fraction, color = cell_type, |
| 78 | +#' # text = paste0("Sample: ", sample, "\nTrue: ", true_fraction, "\nPredicted: ", predicted_fraction) |
| 79 | +#' # )) + |
| 80 | +#' # geom_point(size = 4) + |
| 81 | +#' # facet_wrap(~method) + |
| 82 | +#' # geom_abline(color = "black") + |
| 83 | +#' # labs(x = "True Fraction", y = "predicted Fraction", color = "cell type") + |
| 84 | +#' # coord_cartesian(xlim = c(0, max_value), ylim = c(0, max_value)) |
| 85 | +#' # # render |
| 86 | +#' # plotly::ggplotly(plot, tooltip = c("text")) |> |
| 87 | +#' # plotly::config( |
| 88 | +#' # displaylogo = FALSE, showTips = FALSE, toImageButtonOptions = list(filename = paste0("plotMethod", "_plot")), |
| 89 | +#' # modeBarButtonsToRemove = list( |
| 90 | +#' # "hoverClosestCartesian", |
| 91 | +#' # "hoverCompareCartesian", |
| 92 | +#' # "zoomIn2d", "zoomOut2d", |
| 93 | +#' # "lasso2d", "zoom2d", |
| 94 | +#' # "pan2d", "autoScale2d", "select2d" |
| 95 | +#' # ) |
| 96 | +#' # ) |> |
| 97 | +#' # plotly::layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE)) |
109 | 98 | # } |
0 commit comments