comparison dose_response.R @ 1:8a1b524ed9d8 draft

planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit dca5f947ae4c9697ac0cfce0b313170b541124e5
author ufz
date Tue, 08 Oct 2024 12:41:07 +0000
parents 082e9d22c38d
children c122403ac78a
comparison
equal deleted inserted replaced
0:082e9d22c38d 1:8a1b524ed9d8
43 theme( 43 theme(
44 panel.background = element_rect(fill = "white", color = NA), 44 panel.background = element_rect(fill = "white", color = NA),
45 plot.background = element_rect(fill = "white", color = NA) 45 plot.background = element_rect(fill = "white", color = NA)
46 ) 46 )
47 47
48 ggsave(filename = plot_file, plot = p, device = "jpg") 48 jpeg(filename = plot_file)
49 print(p)
50 dev.off()
49 } 51 }
50 52
51 dose_response_analysis <- function(data, concentration_col, response_col, plot_file, ec_file) { 53 dose_response_analysis <- function(data, concentration_col, response_col, plot_file, ec_file) {
54 concentration_col <- colnames(data)[as.integer(concentration_col)]
55 response_col <- colnames(data)[as.integer(response_col)]
52 models <- fit_models(data, concentration_col, response_col) 56 models <- fit_models(data, concentration_col, response_col)
53 best_model_info <- select_best_model(models) 57 best_model_info <- select_best_model(models)
54 ec_values <- calculate_ec_values(best_model_info$model) 58 ec_values <- calculate_ec_values(best_model_info$model)
55 plot_dose_response(best_model_info$model, data, ec_values, concentration_col, response_col, plot_file) 59 plot_dose_response(best_model_info$model, data, ec_values, concentration_col, response_col, plot_file)
56 60
57 ec_data <- data.frame( 61 ec_data <- data.frame(
58 EC10 = ec_values$EC10[1], 62 EC10 = ec_values$EC10[1],
59 EC25 = ec_values$EC25[1], 63 EC25 = ec_values$EC25[1],
60 EC50 = ec_values$EC50[1] 64 EC50 = ec_values$EC50[1]
61 ) 65 )
62 write.csv(ec_data, ec_file, row.names = FALSE) 66 write.table(ec_data, ec_file, sep = "\t", row.names = FALSE, col.names = TRUE, quote = FALSE)
63 67
64 return(list(best_model = best_model_info$name, ec_values = ec_values)) 68 return(list(best_model = best_model_info$name, ec_values = ec_values))
65 } 69 }
66 70
67 args <- commandArgs(trailingOnly = TRUE) 71 args <- commandArgs(trailingOnly = TRUE)
70 concentration_col <- args[2] 74 concentration_col <- args[2]
71 response_col <- args[3] 75 response_col <- args[3]
72 plot_file <- args[4] 76 plot_file <- args[4]
73 ec_file <- args[5] 77 ec_file <- args[5]
74 78
75 data <- read.csv(data_file, header = TRUE) 79 data <- read.csv(data_file, header = TRUE, sep = "\t")
76 dose_response_analysis(data, concentration_col, response_col, plot_file, ec_file) 80 dose_response_analysis(data, concentration_col, response_col, plot_file, ec_file)