# Function that import all data (take a lot of time)
import_raw_data_microarray <- function(path_i, path_info_range_i, sheet_i, begin_end_line){
# Import info ####
column_global_info <- c("A", "I")
range_global_info = paste0(column_global_info[1],begin_end_line[1],":", column_global_info[2],begin_end_line[2])
cat("Read global info excel sheet (", range_global_info, ")\n")
df_info = read_excel(path_i, sheet = sheet_i, range = range_global_info, col_names = T) %>%
as.data.frame() %>%
dplyr::rename(
id_probe="N°",
other_description1 =...7,
other_description2 =...9) %>%
dplyr::select(-...6)
# import the column where the data is located ####
compile_raw_data <- as.data.frame(matrix(data = NA,nrow = as.numeric(begin_end_line[2]) - as.numeric(begin_end_line[1]) ,ncol = 0))
df_info_range = read_excel(path_info_range_i, col_names = T)
n <- nrow(df_info_range)
pb <- progress_bar$new(
format = "[:bar] :percent | Elapsed time :elapsed | Estimated time :eta",
total = n,
clear = FALSE,
width = 80
)
start_time <- Sys.time()
df_info_sample_clean_compile <- as.data.frame(matrix(data = NA, nrow = 0, ncol = 13))
colnames(df_info_sample_clean_compile) <- c("date", "rep", "project_nb", "project", "sample_type", "num_combination", "sample_name", "color", "sample_num", "simplify_condition", "genotype", "sulfur_condition", "sample_id")
for (i in 1:n) {
column_red_green <- c(df_info_range$red_column[i], df_info_range$green_column[i])
num_combination <- df_info_range$num_combination[i]
begin_end_line_info <- c("3", "12")
range_info <- paste0(column_red_green[1], begin_end_line_info[1], ":", column_red_green[2], begin_end_line_info[2])
cat("Read info of the sample", range_info, "\n")
df_info_sample <- read_excel(path_i, sheet = sheet_i, range = range_info, col_names = FALSE) %>%
as.data.frame() %>%
dplyr::rename(
col1 = ...1,
col2 = ...2
)
df_info_sample_clean <- as.data.frame(matrix(data = NA, nrow = 2, ncol = 13))
colnames(df_info_sample_clean) <- c("date", "rep", "project_nb", "project", "sample_type", "num_combination", "sample_name", "color", "sample_num", "simplify_condition", "genotype", "sulfur_condition", "sample_id")
df_info_sample_clean$date <- c(df_info_sample$col1[1], df_info_sample$col2[1])
df_info_sample_clean$rep <- c(df_info_sample$col1[2], df_info_sample$col2[2])
df_info_sample_clean$project_nb <- c(df_info_sample$col1[5], df_info_sample$col2[5])
df_info_sample_clean$project <- c(df_info_sample$col1[6], df_info_sample$col2[6])
df_info_sample_clean$num_combination <- num_combination
df_info_sample_clean$sample_type <- c(df_info_sample$col1[7], df_info_sample$col2[7])
df_info_sample_clean$sample_name <- c(df_info_sample$col1[8], df_info_sample$col2[9])
df_info_sample_clean$color <- c(df_info_sample$col1[10], df_info_sample$col2[10])
df_info_sample_clean <- df_info_sample_clean %>%
dplyr::mutate(
sample_num = str_extract(sample_name, "^[0-9_.]+"),
sample_num = str_replace_all(sample_num, c("\\_" = "\\.")),
simplify_condition = str_extract(sample_name, "WT[+-]|Mut[+-]"),
simplify_condition = str_replace_all(simplify_condition, c("\\+" = "_SS", "\\-" = "_SD")),
sulfur_condition = str_sub(simplify_condition, -2, -1),
genotype = ifelse(sample_num %in% c(1.1, 2.2, 3.3, 4.4, 17.1, 18.2, 19.3, 20.4), "WT2", sample_num),# Add genotype
genotype = ifelse(sample_num %in% c(5.1, 6.2, 7.3, 8.4, 21.1, 22.2, 23.3, 24.4), "E568K", genotype),# Add genotype
genotype = ifelse(sample_num %in% c(9.5, 10.6, 11.7, 12.8, 25.5, 26.6, 27.7, 28.8), "WT1", genotype),# Add genotype
genotype = ifelse(sample_num %in% c(13.5, 14.6, 15.7, 16.8, 29.5, 30.6, 31.7, 32.8), "W78*", genotype),# Add genotype
sample_id = paste(sep = "_", simplify_condition, sample_num, rep, color, num_combination)
)
range_i <- paste0(column_red_green[1], begin_end_line[1], ":", column_red_green[2], begin_end_line[2])
# Importer les données rouges/vertes pour les deux échantillons
cat("Read raw data range ",range_i, " \n")
df_x <- read_excel(path_i, sheet = sheet_i, range = range_i, col_names = TRUE) %>% as.data.frame()
# Vérification des noms de colonnes
if (colnames(df_x)[1] != "Red" & colnames(df_x)[2] != "Green" & length(colnames(df_x))!=2) {
stop("Column name needs to be Red or Green")
}
colnames(df_x)[1] = df_info_sample_clean$sample_id[1]
colnames(df_x)[2] = df_info_sample_clean$sample_id[2]
compile_raw_data = cbind(compile_raw_data, df_x)
df_info_sample_clean_compile = rbind(df_info_sample_clean_compile, df_info_sample_clean)
pb$tick()
elapsed_time <- Sys.time() - start_time
}
global_df <- cbind(df_info , compile_raw_data)
return(list(
global_df = global_df,
df_info_sample_clean_compile = df_info_sample_clean_compile
))
}