annotate dose_response.R @ 2:c122403ac78a draft

planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
author ufz
date Wed, 18 Dec 2024 09:11:40 +0000
parents 8a1b524ed9d8
children 2aa9da0a84a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
1 library(drc)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
2 library(ggplot2)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
3
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
4 fit_models <- function(data, concentration_col, response_col) {
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
5 models <- list(
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
6 LL.2 = drm(data[[response_col]] ~ data[[concentration_col]], data = data, fct = LL.2(), type = "binomial"),
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
7 LL.4 = drm(data[[response_col]] ~ data[[concentration_col]], data = data, fct = LL.4(), type = "binomial"),
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
8 W1.4 = drm(data[[response_col]] ~ data[[concentration_col]], data = data, fct = W1.4(), type = "binomial"),
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
9 W2.4 = drm(data[[response_col]] ~ data[[concentration_col]], data = data, fct = W2.4(), type = "binomial"),
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
10 BC.5 = drm(data[[response_col]] ~ data[[concentration_col]], data = data, fct = BC.5(), type = "binomial")
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
11 )
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
12 return(models)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
13 }
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
14
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
15 select_best_model <- function(models) {
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
16 aic_values <- sapply(models, AIC)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
17 best_model_name <- names(which.min(aic_values))
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
18 best_model <- models[[best_model_name]]
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
19 return(list(name = best_model_name, model = best_model))
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
20 }
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
21
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
22 calculate_ec_values <- function(model) {
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
23 ec50 <- ED(model, 50, type = "relative")
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
24 ec25 <- ED(model, 25, type = "relative")
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
25 ec10 <- ED(model, 10, type = "relative")
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
26 return(list(EC50 = ec50, EC25 = ec25, EC10 = ec10))
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
27 }
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
28
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
29 plot_dose_response <- function(model, data, ec_values, concentration_col, response_col, plot_file, compound_name, concentration_unit) {
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
30 # Generate a grid of concentration values for predictions
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
31 concentration_grid <- seq(min(data[[concentration_col]]), max(data[[concentration_col]]), length.out = 100)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
32 prediction_data <- data.frame(concentration_grid)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
33 colnames(prediction_data) <- concentration_col
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
34
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
35 # Compute predictions with confidence intervals
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
36 predictions <- predict(model, newdata = prediction_data, type = "response", interval = "confidence")
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
37 prediction_data$resp <- predictions[, 1]
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
38 prediction_data$lower <- predictions[, 2]
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
39 prediction_data$upper <- predictions[, 3]
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
40
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
41 print(prediction_data)
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
42
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
43 data$rep <- factor(data$rep)
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
44
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
45 # Create the plot
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
46 p <- ggplot(data, aes_string(x = concentration_col, y = response_col)) +
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
47 geom_point(aes(colour = rep)) + # Original data points
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
48 geom_line(data = prediction_data, aes_string(x = "conc", y = "resp"), color = "blue") + # Predicted curve
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
49 geom_ribbon(data = prediction_data, aes_string(x = "conc", ymin = "lower", ymax = "upper"), alpha = 0.2, fill = "blue") + # Confidence intervals
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
50 geom_vline(xintercept = ec_values$EC10[1], color = "green", linetype = "dashed") +
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
51 geom_vline(xintercept = ec_values$EC50[1], color = "red", linetype = "dashed") +
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
52 labs(
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
53 title = paste(compound_name, "- Dose-Response Curve"),
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
54 x = paste("Dose [", concentration_unit, "]"),
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
55 y = "Response %"
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
56 ) +
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
57 theme_minimal() +
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
58 theme(
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
59 panel.background = element_rect(fill = "white", color = NA),
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
60 plot.background = element_rect(fill = "white", color = NA)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
61 )
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
62
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
63 # Save the plot to a file
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
64 jpeg(filename = plot_file, width = 480, height = 480, res = 72)
1
8a1b524ed9d8 planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit dca5f947ae4c9697ac0cfce0b313170b541124e5
ufz
parents: 0
diff changeset
65 print(p)
8a1b524ed9d8 planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit dca5f947ae4c9697ac0cfce0b313170b541124e5
ufz
parents: 0
diff changeset
66 dev.off()
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
67 }
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
68
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
69 dose_response_analysis <- function(data, concentration_col, response_col, plot_file, ec_file, compound_name, concentration_unit) {
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
70 # Ensure column names are correctly selected
1
8a1b524ed9d8 planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit dca5f947ae4c9697ac0cfce0b313170b541124e5
ufz
parents: 0
diff changeset
71 concentration_col <- colnames(data)[as.integer(concentration_col)]
8a1b524ed9d8 planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit dca5f947ae4c9697ac0cfce0b313170b541124e5
ufz
parents: 0
diff changeset
72 response_col <- colnames(data)[as.integer(response_col)]
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
73
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
74 # Fit models and select the best one
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
75 models <- fit_models(data, concentration_col, response_col)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
76 best_model_info <- select_best_model(models)
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
77 best_model <- best_model_info$model
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
78 best_model_name <- best_model_info$name
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
79
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
80 # Calculate EC values
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
81 ec_values <- calculate_ec_values(best_model)
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
82
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
83 # Plot the dose-response curve
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
84 plot_dose_response(best_model, data, ec_values, concentration_col, response_col, plot_file, compound_name, concentration_unit)
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
85
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
86 # Get model summary and AIC value
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
87 model_summary <- summary(best_model)
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
88 model_aic <- AIC(best_model)
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
89
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
90 # Prepare EC values data frame with additional information
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
91 ec_data <- data.frame(
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
92 Metric = c("chemical_name", "EC10", "EC25", "EC50", "AIC"),
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
93 Value = c(compound_name, ec_values$EC10[1], ec_values$EC25[1], ec_values$EC50[1], model_aic)
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
94 )
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
95
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
96 # Write EC values, AIC, and model summary to the output file
1
8a1b524ed9d8 planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit dca5f947ae4c9697ac0cfce0b313170b541124e5
ufz
parents: 0
diff changeset
97 write.table(ec_data, ec_file, sep = "\t", row.names = FALSE, col.names = TRUE, quote = FALSE)
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
98
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
99 # Append the model summary to the file
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
100 cat("\nModel Summary:\n", file = ec_file, append = TRUE)
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
101 capture.output(model_summary, file = ec_file, append = TRUE)
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
102
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
103 return(list(best_model = best_model_name, ec_values = ec_values))
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
104 }
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
105
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
106 args <- commandArgs(trailingOnly = TRUE)
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
107
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
108 data_file <- args[1]
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
109 concentration_col <- args[2]
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
110 response_col <- args[3]
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
111 plot_file <- args[4]
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
112 ec_file <- args[5]
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
113 compound_name <- args[6]
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
114 concentration_unit <- args[7]
0
082e9d22c38d planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 3aebdcc7c5b266a30262402934ffaad2a58adbcb
ufz
parents:
diff changeset
115
1
8a1b524ed9d8 planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit dca5f947ae4c9697ac0cfce0b313170b541124e5
ufz
parents: 0
diff changeset
116 data <- read.csv(data_file, header = TRUE, sep = "\t")
2
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
117 print(data)
c122403ac78a planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator commit 61a3d9a20a9a90d551dd5f7503be781dc28f4b75
ufz
parents: 1
diff changeset
118 dose_response_analysis(data, concentration_col, response_col, plot_file, ec_file, compound_name, concentration_unit)