Skip to content

Instantly share code, notes, and snippets.

@crazyhottommy
Last active August 16, 2022 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyhottommy/992bb124be1d21d80a5ff3f43b35aff4 to your computer and use it in GitHub Desktop.
Save crazyhottommy/992bb124be1d21d80a5ff3f43b35aff4 to your computer and use it in GitHub Desktop.
convert MDS ELISA data to Prism ready format
install.packages(c("tidyverse", "janitor", "readxl"))
library(tidyverse)
library(janitor)
library(readxl)
convert_MDS_to_Prism<- function(infile_path, sheet_range, outfile_path){
if (!file.exists(infile_path)){
stop("the input file does not exist, please check your file name!")
}
data<- map(sheet_range, function(x) readxl::read_xlsx(infile_path, x, skip = 1)) %>%
bind_rows( .id = "sheet") %>%
janitor::clean_names() %>%
mutate(calc_concentration = str_replace(calc_concentration, "NaN", NA_character_)) %>%
mutate(calc_concentration = as.numeric(calc_concentration)) %>%
group_by(sheet, sample, assay) %>%
summarise(mean_conc = mean(calc_concentration, na.rm =TRUE)) %>%
pivot_wider(names_from = c(assay, sheet), values_from = mean_conc) %>%
janitor::clean_names() %>%
select(sample, order(colnames(.)))
write_csv(data, file = outfile_path)
message(paste0("please find the converted file at ", outfile_path))
}
infile<- "C:\\Users\\AlexandriaFusco\\Downloads\\CRS Data 06132022 Soluble Plate Data Record 08162022.xlsx"
outfile<- "C:\\Users\\AlexandriaFusco\\Downloads\\CRS Data 06132022 Soluble Plate Data Record 08162022.csv"
sheet_range<- 1:3
convert_MDS_to_Prism(infile_path = infile, sheet_range = sheet_range, outfile_path = outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment