Skip to content

Commit

Permalink
Fix tool input in the dose response curve tool (Helmholtz-UFZ#90)
Browse files Browse the repository at this point in the history
* Fix the replicate column in the drc tool, removed the fixed column header, improved the help section

* Update tools/tox_tools/dose_responses/dose_response.xml

* Running the test in biocontainers

* Correct the replicate legend label

* Correct the replicate aesthetic in the plot

---------

Co-authored-by: M Bernt <[email protected]>
  • Loading branch information
rmassei and bernt-matthias authored Jan 21, 2025
1 parent ad0bd0e commit 707eca8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tools/tox_tools/baseline_calculator/.shed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ long_description: Toxicity prediction using QSAR models. Possible to select pre-
name: baseline_toxicity_calculator
owner: mbernt
homepage_url: https://github.com/bernt-matthias/mb-galaxy-tools
remote_repository_url: https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator
remote_repository_url: https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/tox_tools/baseline_calculator
2 changes: 1 addition & 1 deletion tools/tox_tools/dose_responses/.shed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ long_description: The Tool analyze, and visualize the relationship between diffe
name: dose_response_analysis_tool
owner: ufz
homepage_url: https://github.com/bernt-matthias/mb-galaxy-tools
remote_repository_url: https://github.com/bernt-matthias/mb-galaxy-tools/tools/tox_tools/baseline_calculator
remote_repository_url: https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/tox_tools/dose_responses
30 changes: 17 additions & 13 deletions tools/tox_tools/dose_responses/dose_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ calculate_ec_values <- function(model) {
return(list(EC50 = ec50, EC25 = ec25, EC10 = ec10))
}

plot_dose_response <- function(model, data, ec_values, concentration_col, response_col, plot_file, compound_name, concentration_unit) {
plot_dose_response <- function(model, data, ec_values, concentration_col, response_col, replicate_col, plot_file, compound_name, concentration_unit) {
# Generate a grid of concentration values for predictions
concentration_grid <- seq(min(data[[concentration_col]]), max(data[[concentration_col]]), length.out = 100)
prediction_data <- data.frame(concentration_grid)
Expand All @@ -40,19 +40,21 @@ plot_dose_response <- function(model, data, ec_values, concentration_col, respon

print(prediction_data)

data$rep <- factor(data$rep)
# Ensure replicate_col is treated as a factor
data[[replicate_col]] <- factor(data[[replicate_col]])

# Create the plot
p <- ggplot(data, aes_string(x = concentration_col, y = response_col)) +
geom_point(aes(colour = rep)) + # Original data points
geom_line(data = prediction_data, aes_string(x = "conc", y = "resp"), color = "blue") + # Predicted curve
geom_ribbon(data = prediction_data, aes_string(x = "conc", ymin = "lower", ymax = "upper"), alpha = 0.2, fill = "blue") + # Confidence intervals
geom_point(aes_string(colour = replicate_col)) + # Original data points
geom_line(data = prediction_data, aes_string(x = concentration_col, y = response_col), color = "blue") + # Predicted curve
geom_ribbon(data = prediction_data, aes_string(x = concentration_col, ymin = "lower", ymax = "upper"), alpha = 0.2, fill = "blue") + # Confidence intervals
geom_vline(xintercept = ec_values$EC10[1], color = "green", linetype = "dashed") +
geom_vline(xintercept = ec_values$EC50[1], color = "red", linetype = "dashed") +
labs(
title = paste(compound_name, "- Dose-Response Curve"),
x = paste("Dose [", concentration_unit, "]"),
y = "Response %"
y = "Response %",
colour = "Replicates"
) +
theme_minimal() +
theme(
Expand All @@ -66,10 +68,11 @@ plot_dose_response <- function(model, data, ec_values, concentration_col, respon
dev.off()
}

dose_response_analysis <- function(data, concentration_col, response_col, plot_file, ec_file, compound_name, concentration_unit) {
dose_response_analysis <- function(data, concentration_col, response_col, replicate_col, plot_file, ec_file, compound_name, concentration_unit) {
# Ensure column names are correctly selected
concentration_col <- colnames(data)[as.integer(concentration_col)]
response_col <- colnames(data)[as.integer(response_col)]
replicate_col <- colnames(data)[as.integer(replicate_col)]

# Fit models and select the best one
models <- fit_models(data, concentration_col, response_col)
Expand All @@ -81,7 +84,7 @@ dose_response_analysis <- function(data, concentration_col, response_col, plot_f
ec_values <- calculate_ec_values(best_model)

# Plot the dose-response curve
plot_dose_response(best_model, data, ec_values, concentration_col, response_col, plot_file, compound_name, concentration_unit)
plot_dose_response(best_model, data, ec_values, concentration_col, response_col, replicate_col, plot_file, compound_name, concentration_unit)

# Get model summary and AIC value
model_summary <- summary(best_model)
Expand All @@ -108,11 +111,12 @@ args <- commandArgs(trailingOnly = TRUE)
data_file <- args[1]
concentration_col <- args[2]
response_col <- args[3]
plot_file <- args[4]
ec_file <- args[5]
compound_name <- args[6]
concentration_unit <- args[7]
replicate_col <- args[4]
plot_file <- args[5]
ec_file <- args[6]
compound_name <- args[7]
concentration_unit <- args[8]

data <- read.csv(data_file, header = TRUE, sep = "\t")
print(data)
dose_response_analysis(data, concentration_col, response_col, plot_file, ec_file, compound_name, concentration_unit)
dose_response_analysis(data, concentration_col, response_col, replicate_col, plot_file, ec_file, compound_name, concentration_unit)
35 changes: 27 additions & 8 deletions tools/tox_tools/dose_responses/dose_response.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<description>for Toxicological Risk Assessment</description>
<macros>
<token name="@TOOL_VERSION@">3.0.1</token>
<token name="@VERSION_SUFFIX@">3</token>
<token name="@VERSION_SUFFIX@">4</token>
</macros>
<creator>
<organization name="Helmholtz Centre for Environmental Research - UFZ, Department of Ecotoxicology"
Expand All @@ -19,6 +19,7 @@
'$input_csv'
'$concentration_column'
'$response_column'
'$replicate_column'
'$plot_output'
'$ec_output'
'$compound_name'
Expand All @@ -29,6 +30,7 @@
<param name="input_csv" type="data" format="tabular" label="Dose-Response Tabular Input"/>
<param name="concentration_column" type="data_column" data_ref="input_csv" label="Dose/Concentration Column Index" help="Index of the column for concentration values"/>
<param name="response_column" type="data_column" data_ref="input_csv" label="Response Column Index" help="Index of the column for response values"/>
<param name="replicate_column" type="data_column" data_ref="input_csv" label="Replicate Column Index" help="Index of the column for replicate values"/>
<param name="compound_name" type="text" label="Compound Name" help="Name of the compound to analyze">
<validator type="regex" message="Enter a valid compound name">^^[a-zA-Z0-9\[\]()_-]+$</validator>
</param>
Expand All @@ -45,6 +47,7 @@
<param name="input_csv" value="drc_input.tsv"/>
<param name="concentration_column" value="2"/>
<param name="response_column" value="3"/>
<param name="replicate_column" value="1"/>
<param name="compound_name" value="test-chemical"/>
<param name="concentration_unit" value="mg/L"/>
<output name="plot_output" value="image_output.jpg" ftype="jpg">
Expand All @@ -57,14 +60,30 @@
</test>
</tests>
<help><![CDATA[
This tool performs dose-response analysis on the provided CSV file,
generates a dose-response plot, and calculates EC values (EC10, EC25, EC50).
This tool performs dose-response analysis on the provided CSV/TSV file,
generates a dose-response plot, and calculates three Effect Concentrations (EC) values (EC10, EC25, EC50).
The tool further calculate the AIC and the model summary.
The tool need three inputs from the CSV/TSV file:
- One column with the replicate number
- One column with concentrations values
- One column with biological response
An exemplary input might look like:
+------------+---------------+---------------+
| rep | conc | resp |
+============+===============+===============+
| 1 | 0 | 0 |
+------------+---------------+---------------+
| 2 | 10 | 50 |
+------------+---------------+---------------+
| 1 | 5 | 10 |
+------------+---------------+---------------+
**NOTE: Input Table must have column headers!**
- `input_csv`: A TSV file containing the dose-response data.
- `concentration_column`: The name of the column in the CSV file that contains the concentration values.
- `response_column`: The name of the column in the CSV file that contains the response values
- `plot_output`: A JPG image file of the dose-response plot.
- `ec_output`: A tabular file containing the calculated EC values.
]]></help>
<citations>
<citation type="doi">10.1371/journal.pone.0146021</citation>
Expand Down
Binary file modified tools/tox_tools/dose_responses/test-data/image_output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 707eca8

Please sign in to comment.