From be87a321a4cadb9acd7d761bcd9b052aadcad51d Mon Sep 17 00:00:00 2001 From: marcelcosta Date: Thu, 23 Oct 2025 11:39:59 +0200 Subject: [PATCH] Virus-CellLine-transform script --- Virus-CellLine-transform.R | 132 +++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 Virus-CellLine-transform.R diff --git a/Virus-CellLine-transform.R b/Virus-CellLine-transform.R new file mode 100644 index 0000000..30d0c7a --- /dev/null +++ b/Virus-CellLine-transform.R @@ -0,0 +1,132 @@ +library(readxl) +library(tidyverse) +library(openxlsx) + +old.table<-as.data.frame(read_excel("Nitrogen_Virus_transform.xlsx")) +old.table[grepl("^[0-9]*$", old.table$Passage),"Passage"]<-as.character(as.Date(as.numeric(old.table[grepl("^[0-9]*$", old.table$Passage),"Passage"]), origin = "1899-12-30")) + +table.list<-old.table %>% + group_by(Caja) %>% + group_split() +names(table.list)<-unique(old.table$Caja) +names(table.list) + +caja_order.df<-data.frame( + caja=names(table.list), + Rack=gsub(" #[0-9]*$","",names(table.list)), + ncaja=as.numeric(gsub("[A-Z]*-[0-9]* #","",names(table.list))) +) +caja_order<-caja_order.df %>% arrange(Rack, ncaja) %>% pull(caja) +table.list<-table.list[caja_order] + +View(table.list[[1]]) + +caja.list<-list() +for (i in names(table.list)){ + m0<-matrix(nrow = 30, ncol=10, byrow = T) + m0[seq(from=1, to=30, by=3),]<-matrix(data=pull(table.list[[i]],Cell.line), nrow = 10, ncol=10, byrow = T) + m0[seq(from=2, to=30, by=3),]<-matrix(data=pull(table.list[[i]],Info.Descongelacion), nrow = 10, ncol=10, byrow = T) + m0[seq(from=3, to=30, by=3),]<-matrix(data=pull(table.list[[i]],Passage), nrow = 10, ncol=10, byrow = T) + caja.list[[i]]<-m0 +} + +wb <- openxlsx::createWorkbook() + +for (i in names(caja.list)){ + + addWorksheet( + wb = wb, + sheetName = i + ) + + rangeRows<-1:30 + rangeCols<-1:10 + + ## left borders + openxlsx::addStyle( + wb = wb, + sheet = i, + style = openxlsx::createStyle( + border = c("left"), + borderStyle = c("thick") + ), + rows = rangeRows, + cols = rangeCols[1], + stack = TRUE, + gridExpand = TRUE + ) + + ##right borders + openxlsx::addStyle( + wb = wb, + sheet = i, + style = openxlsx::createStyle( + border = c("right"), + borderStyle = c("thick") + ), + rows = rangeRows, + cols = tail(rangeCols, 1), + stack = TRUE, + gridExpand = TRUE + ) + + ## top borders + openxlsx::addStyle( + wb = wb, + sheet = i, + style = openxlsx::createStyle( + border = c("top"), + borderStyle = c("thick") + ), + rows = rangeRows[1], + cols = rangeCols, + stack = TRUE, + gridExpand = TRUE + ) + + ##bottom borders + openxlsx::addStyle( + wb = wb, + sheet = i, + style = openxlsx::createStyle( + border = c("bottom"), + borderStyle = c("thick") + ), + rows = tail(rangeRows, 1), + cols = rangeCols, + stack = TRUE, + gridExpand = TRUE + ) + + ##row cells + openxlsx::addStyle( + wb = wb, + sheet = i, + style = openxlsx::createStyle( + border = c("bottom"), + borderStyle = c("thin") + ), + rows = seq(from=3, to=27, by=3), + cols = rangeCols, + stack = TRUE, + gridExpand = TRUE + ) + + ##column cells + openxlsx::addStyle( + wb = wb, + sheet = i, + style = openxlsx::createStyle( + border = c("right"), + borderStyle = c("thin") + ), + rows = 1:30, + cols = 1:9, + stack = TRUE, + gridExpand = TRUE + ) + + writeData(wb, sheet=i, x=caja.list[[i]], colNames = FALSE) +} + +saveWorkbook(wb, "Nitrogen_Virus.xlsx", overwrite = TRUE)