Skip to content

Commit

Permalink
[FEAT] - remove QFeatures# pattern in assay's names
Browse files Browse the repository at this point in the history
  • Loading branch information
leopoldguyot committed Jul 15, 2024
1 parent b593b35 commit ada6132
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion R/server_module_box_readQFeatures.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ box_readqfeatures_server <- function(id, input_table, sample_table) {
for (i in seq_along(global_rv$qfeatures)) {
names(global_rv$qfeatures)[i] <- paste0(
names(global_rv$qfeatures)[i],
"_(QFeaturesGUI#0)"
"_(QFeaturesGUI#0)_initial_import"
)
}
removeModal()
Expand Down
3 changes: 2 additions & 1 deletion R/server_module_features_filtering_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ server_module_features_filtering_tab <- function(id, step_number) {
add_assays_to_global_rv,
component_name = "Add assays to global_rv",
processed_qfeatures = processed_assays(),
step_number = step_number
step_number = step_number,
type = "features_filtering"
)
removeModal()
})
Expand Down
12 changes: 10 additions & 2 deletions R/server_module_qc_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
server_module_qc_metrics <- function(id, assays_to_process, type) {
stopifnot(is.reactive(assays_to_process))
moduleServer(id, function(input, output, session) {
assays_choices_vector <- reactive({
original_names <- names(assays_to_process())
modified_names <- remove_QFeaturesGUI(original_names)
choices_vector <- setNames(original_names, modified_names)
return(choices_vector)
})
observe({
req(assays_choices_vector)
updateSelectInput(session,
"selected_assay",
choices = names(assays_to_process())
choices = names(assays_choices_vector())
)
})
single_assay <- reactive({
Expand All @@ -24,7 +31,8 @@ server_module_qc_metrics <- function(id, assays_to_process, type) {
# Warning appears here
# Warning message: 'experiments' dropped; see 'drops()'
# see with Chris
getWithColData(assays_to_process(), input$selected_assay)
getWithColData(assays_to_process(),
assays_choices_vector()[input$selected_assay])
})

server_module_pca_box(
Expand Down
3 changes: 2 additions & 1 deletion R/server_module_samples_filtering_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ server_module_samples_filtering_tab <- function(id, step_number) {
add_assays_to_global_rv,
component_name = "Add assays to global_rv",
processed_qfeatures = processed_assays(),
step_number = step_number
step_number = step_number,
type = "samples_filtering"
)
removeModal()
})
Expand Down
4 changes: 3 additions & 1 deletion R/server_module_summary_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ server_module_summary_tab <- function(id) {

output$qfeatures_plot <- renderPlotly({
if (length(global_rv$qfeatures) > 0) {
plot(global_rv$qfeatures,
empty_qfeatures <- global_rv$qfeatures[1,]
names(empty_qfeatures) <- remove_QFeaturesGUI(names(empty_qfeatures))
plot(empty_qfeatures,
interactive = TRUE
)
}
Expand Down
21 changes: 10 additions & 11 deletions R/utils_global.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,13 @@ loading <- function(msg) {
#' A function that remove the "(QFeaturesGUI#x)" suffix from a string
#' @param string `str` string to remove the suffix from
#' @return `str` the string without the suffix
#' @rdname INTERNAL_remove_scpGUI
#' @rdname INTERNAL_remove_QFeaturesGUI
#' @keywords internal
#'
#'
remove_scpGUI <- function(string) {
return(gsub("\\_(QFeaturesGUI#[0-9]+\\)", "", string))
remove_QFeaturesGUI <- function(string) {
return(gsub("_\\(QFeaturesGUI#[0-9]+\\)", "", string))
}

#' PCA Methods Wrapper
#'
#' This function performs Principal Component Analysis (PCA) on a SingleCellExperiment object using the specified method.
Expand Down Expand Up @@ -296,14 +295,14 @@ pca_plotly <- function(df, pca_result, color_name, show_legend) {
#' @return (NULL) does not return anything but will add the assays to the global_rv qfeatures object
#' @importFrom QFeatures addAssayLink

add_assays_to_global_rv <- function(processed_qfeatures, step_number) {
add_assays_to_global_rv <- function(processed_qfeatures, step_number, type) {
print(names(processed_qfeatures))
for (name in names(processed_qfeatures)) {
new_name <- gsub(
pattern = paste0("_(QFeaturesGUI#", step_number - 1, ")"),
replacement = paste0("_(QFeaturesGUI#", step_number, ")"),
x = name,
fixed = TRUE
)
new_name <- paste0(
strsplit(name, "_(QFeaturesGUI#", fixed = TRUE)[[1]][[1]],
"_(QFeaturesGUI#", step_number, ")",
"_", type, "_", step_number)

global_rv$qfeatures[[new_name]] <- processed_qfeatures[[name]]

global_rv$qfeatures <- addAssayLink(
Expand Down
2 changes: 1 addition & 1 deletion R/utils_import_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ qfeatures_to_df <- function(qfeatures) {
"ncols" = rep.int(0, length(qfeatures))
)
for (i in seq_along(qfeatures)) {
df[i, "Name"] <- names(qfeatures)[[i]]
df[i, "Name"] <- remove_QFeaturesGUI(names(qfeatures)[[i]])
df[i, "Class"] <- class(qfeatures[[i]])[[1]]
df[i, "nrows"] <- nrow(qfeatures[[i]])[[1]]
df[i, "ncols"] <- ncol(qfeatures[[i]])[[1]]
Expand Down

0 comments on commit ada6132

Please sign in to comment.