Skip to content

Commit

Permalink
Add data_ref for data_column parameter (Helmholtz-UFZ#55)
Browse files Browse the repository at this point in the history
* add data_ref for data_column parameter

* add lint skip

* fix test columns

* columns are 1 based

* Update dose_response.xml

* Update test_summary.tsv

* Update dose_response.R

* Update test_summary.tsv

* Update dose_response.R

* Update dose_response.R

* Fixed error on invalid type for the conc column

* xml fix and R script adjustement for output file path

* Changed the saving plot data function

* fix test, reformulate description

and remove lint skip

---------

Co-authored-by: Riccardo Massei <[email protected]>
Co-authored-by: Riccardo Massei <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent dddf8b4 commit 2dca03f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
10 changes: 7 additions & 3 deletions tools/tox_tools/dose_responses/dose_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ plot_dose_response <- function(model, data, ec_values, concentration_col, respon
plot.background = element_rect(fill = "white", color = NA)
)

ggsave(filename = plot_file, plot = p, device = "jpg")
jpeg(filename = plot_file)
print(p)
dev.off()
}

dose_response_analysis <- function(data, concentration_col, response_col, plot_file, ec_file) {
concentration_col <- colnames(data)[as.integer(concentration_col)]
response_col <- colnames(data)[as.integer(response_col)]
models <- fit_models(data, concentration_col, response_col)
best_model_info <- select_best_model(models)
ec_values <- calculate_ec_values(best_model_info$model)
Expand All @@ -59,7 +63,7 @@ dose_response_analysis <- function(data, concentration_col, response_col, plot_f
EC25 = ec_values$EC25[1],
EC50 = ec_values$EC50[1]
)
write.csv(ec_data, ec_file, row.names = FALSE)
write.table(ec_data, ec_file, sep = "\t", row.names = FALSE, col.names = TRUE, quote = FALSE)

return(list(best_model = best_model_info$name, ec_values = ec_values))
}
Expand All @@ -72,5 +76,5 @@ response_col <- args[3]
plot_file <- args[4]
ec_file <- args[5]

data <- read.csv(data_file, header = TRUE)
data <- read.csv(data_file, header = TRUE, sep = "\t")
dose_response_analysis(data, concentration_col, response_col, plot_file, ec_file)
27 changes: 16 additions & 11 deletions tools/tox_tools/dose_responses/dose_response.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<tool id="dr_curve" name="Dose Response Curve for Toxicological Risk Assessment" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.0">
<description>Toxicity prediction tool - Dose response Curve</description>
<description>for Toxicological Risk Assessment</description>
<macros>
<token name="@TOOL_VERSION@">3.0_1</token>
<token name="@VERSION_SUFFIX@">0</token>
<token name="@TOOL_VERSION@">3.0.1</token>
<token name="@VERSION_SUFFIX@">1</token>
</macros>
<creator>
<organization name="Helmholtz Centre for Environmental Research - UFZ, Department of Ecotoxicology"
Expand All @@ -26,30 +26,35 @@
<inputs>
<param name="input_csv" type="data" format="tabular" label="Concentration - Response Tabular Input"/>
<param name="concentration_column" type="data_column" data_ref="input_csv" label="Concentration Column" help="Name of the column for concentration values"/>
<param name="response_column" type="data_column" label="Response Column" help="Name of the column for response values"/>
<param name="response_column" type="data_column" data_ref="input_csv" label="Response Column" help="Name of the column for response values"/>
</inputs>
<outputs>
<data name="plot_output" format="jpg" label="Dose Response Plot"/>
<data name="ec_output" format="tabular" label="${tool.name} on ${on_string}: EC Values"/>
</outputs>
<tests>
<test>
<param name="input_csv" value="test_summary.tsv"/>
<param name="concentration_column" value="concentration"/>
<param name="response_column" value="lethal"/>
<output name="plot_output" value="result.jpeg" ftype="jpg"/>
<output name="ec_output" value="results_EC.csv" ftype="csv" />
<param name="input_csv" value="drc_input.tsv"/>
<param name="concentration_column" value="1"/>
<param name="response_column" value="2"/>
<output name="plot_output" ftype="jpg">
<assert_contents>
<has_image_width width="480"/>
<has_image_height height="480"/>
</assert_contents>
</output>
<output name="ec_output" value="drc_EC_output.tsv" ftype="tabular" />
</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).
- `input_csv`: A CSV file containing the dose-response data.
- `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 CSV file containing the calculated EC values.
- `ec_output`: A tabular file containing the calculated EC values.
]]></help>
<citations>
<citation type="doi">10.1371/journal.pone.0146021</citation>
Expand Down
2 changes: 2 additions & 0 deletions tools/tox_tools/dose_responses/test-data/drc_EC_output.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EC10 EC25 EC50
5.08340659604631 10.6579575265526 22.3456566952853
8 changes: 8 additions & 0 deletions tools/tox_tools/dose_responses/test-data/drc_input.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
conc resp
0 0
5 0.1
10 0.3
25 0.5
50 0.6
75 0.9
100 1
7 changes: 0 additions & 7 deletions tools/tox_tools/dose_responses/test-data/test_summary.csv

This file was deleted.

7 changes: 0 additions & 7 deletions tools/tox_tools/dose_responses/test-data/test_summary.tsv

This file was deleted.

0 comments on commit 2dca03f

Please sign in to comment.