Skip to content

Commit

Permalink
added renaming from template functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgherardini committed Jan 12, 2022
1 parent 735567e commit 89c5fee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: premessa
Type: Package
Title: R package for pre-processing of flow and mass cytometry data
Version: 0.3.0
Version: 0.3.1
Author: "Pier Federico Gherardini <federico.gherardini@gmail.com> [aut, cre]"
Description: This package includes panel editing/renaming for FCS files, bead-based normalization and debarcoding.
Imports: shiny (>= 0.14), flowCore, reshape, ggplot2, hexbin, gridExtra, rhandsontable, jsonlite, data.table, shinyjqui
Expand Down
29 changes: 28 additions & 1 deletion inst/paneleditor_shinyGUI/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ render_paneleditor_ui <- function(working.directory, ...) {renderUI({
column(6,
textInput("paneleditorui_output_folder", label = "Output folder name", value = "renamed")
),
column(3,
actionButton("paneleditorui_load_template", "Load template")
),
column(3,
actionButton("paneleditorui_process_files", "Process files")
)
Expand All @@ -33,7 +36,19 @@ get_panel_table <- function(files.list) {
return(panel.table)
}


rename_from_template <- function(tab, template.file.path) {
template <- read.csv(template.file.path, header = FALSE)
if(ncol(template) < 2)
stop("Template file format incorrect")
names.map <- setNames(template[, 2], template[, 1])
names.map <- names.map[names(names.map) %in% row.names(tab)]
fcs.cols <- grep("FCS$", names(tab), ignore.case = TRUE)
w.na <- is.na(tab[names(names.map), fcs.cols])
tab[names(names.map), fcs.cols] <- names.map
tab[names(names.map), fcs.cols][w.na] <- NA
tab[, "Most common"] <- premessa:::get_common_names(tab)
return(tab)
}

shinyServer(function(input, output, session) {
working.directory <- dirname(file.choose())
Expand Down Expand Up @@ -80,6 +95,18 @@ shinyServer(function(input, output, session) {
output$paneleditorui_panel_table <- rhandsontable::renderRHandsontable({
temp <- panel.table

if(!is.null(input$paneleditorui_load_template) && input$paneleditorui_load_template != 0) {
temp <- tryCatch(rename_from_template(temp, file.choose()),
error = function(cond) {
showModal(modalDialog(
title = "Panel editor error",
"Template file format incorrect. Should be a CSV with two columns:", br(),
"CHANNEL-NAME,PARAMETER-NAME"
))
temp
})
}

for(i in 1:ncol(temp))
temp[, i][is.na(temp[, i])] <- "absent"

Expand Down

0 comments on commit 89c5fee

Please sign in to comment.