Skip to content

Commit

Permalink
Merge pull request #81 from gdrplatform/GDR-2247
Browse files Browse the repository at this point in the history
Gdr 2247
  • Loading branch information
bczech authored Apr 2, 2024
2 parents a58f8d4 + 1c23669 commit 9a3b17f
Show file tree
Hide file tree
Showing 13 changed files with 2,503 additions and 20 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: gDRimport
Type: Package
Title: Package for handling the import of dose-response data
Version: 1.1.7
Date: 2024-03-07
Version: 1.1.8
Date: 2024-03-26
Authors@R: c(
person("Arkadiusz", "Gladki", role=c("aut", "cre"), email="[email protected]",
comment = c(ORCID = "0000-0002-7059-6378")),
Expand Down Expand Up @@ -59,7 +59,7 @@ biocViews: Software, Infrastructure, DataImport
VignetteBuilder: knitr
ByteCompile: TRUE
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
SwitchrLibrary: gDRimport
DeploySubPath: gDRimport
Encoding: UTF-8
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(get_test_D300_data)
export(get_test_EnVision_data)
export(get_test_Tecan_data)
export(get_test_data)
export(get_test_tsv_data)
export(import_D300)
export(is_readable_v)
export(load_data)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## gDRimport 1.1.8 - 2024-03-26
* fix issue with reading tsv files

## gDRimport 1.1.7 - 2024-03-07
* clean up the package

Expand Down
40 changes: 27 additions & 13 deletions R/load_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ load_data <-
treatments <- load_templates(df_template_files)
data <- load_results(results_file, instrument, headers = headers)

# check the all template files are available
# check the all template files are available
if (!all(unique(manifest[[headers[["template"]]]][manifest[[headers[["barcode"]]]] %in%
data[[headers[["barcode"]]]]])
%in% basename(template_filename))) {
Expand Down Expand Up @@ -268,6 +268,7 @@ load_results <-
stopifnot(any(inherits(df_results_files, "data.table"), checkmate::test_character(df_results_files)))
checkmate::assert_string(instrument, pattern = "^EnVision$|^long_tsv$|^Tecan$")
checkmate::assert_list(headers, null.ok = TRUE)

if (data.table::is.data.table(df_results_files)) {
# for the shiny app
results_file <- df_results_files$datapath
Expand All @@ -277,6 +278,10 @@ load_results <-
results_filename <- basename(results_file)
}
checkmate::assert_file_exists(results_file)

if (all(endsWith(results_file, ".tsv"))) {
instrument <- "long_tsv"
}

if (instrument == "EnVision") {
all_results <-
Expand Down Expand Up @@ -345,7 +350,6 @@ load_templates_tsv <-
df_type = "template"
)})

metadata_fields <- NULL
all_templates <- read_in_tsv_template_files(template_file, template_filename, templates)
futile.logger::flog.info("Templates loaded successfully!")
all_templates
Expand All @@ -358,10 +362,11 @@ load_templates_tsv <-
#' @param templates list with templates data
#' @keywords load_files
#'
#' @return data.table with templates dataa
#' @return data.table with templates data
#'
read_in_tsv_template_files <- function(template_file, template_filename, templates) {
tmpl_l <- lapply(template_file, function(iF) {
metadata_fields <- NULL
tmpl_l <- lapply(seq_along(template_file), function(iF) {
futile.logger::flog.info("Loading %s", template_filename[iF])
# 1) check that the sheet names are ok and 2) identify drug_identifier sheet (case insensitive)
Gnumber_idx <- grep(paste0(gDRutils::get_env_identifiers("drug"), "$"),
Expand Down Expand Up @@ -406,6 +411,7 @@ read_in_tsv_template_files <- function(template_file, template_filename, templat
df_template$Template <- template_filename[iF]
colnames(df_template) <-
check_metadata_names(colnames(df_template), df_name = template_filename[iF])
df_template
})
do.call(rbind, tmpl_l)
}
Expand Down Expand Up @@ -665,9 +671,12 @@ load_results_tsv <-
results_filename <- basename(results_file)

all_results <- read_in_result_files(results_file, results_filename, headers)

cols_subset <- intersect(c(headers[["barcode"]], gDRutils::get_env_identifiers("well_position")),
names(all_results))

if (dim(unique(all_results[, c(headers[["barcode"]], gDRutils::get_env_identifiers("well_position"))]))[1] !=
dim(all_results[, c(headers[["barcode"]], gDRutils::get_env_identifiers("well_position"))])[1]) {
if (dim(unique(all_results[, cols_subset, with = FALSE]))[1] !=
dim(all_results[, cols_subset, with = FALSE])[1]) {
futile.logger::flog.error("Multiple rows with the same Barcode and Well across all files")
}

Expand All @@ -687,8 +696,8 @@ load_results_tsv <-
read_in_result_files <- function(results_file, results_filename, headers) {

# read all files
res_l <- lapply(results_file, function(iF) {
futile.logger::flog.info("Reading file", results_file[iF])
res_l <- lapply(seq_along(results_file), function(iF) {
futile.logger::flog.info("Reading file %s", results_file[iF])
tryCatch({
df <-
stats::na.omit(data.table::fread(
Expand Down Expand Up @@ -716,15 +725,20 @@ read_in_result_files <- function(results_file, results_filename, headers) {
futile.logger::flog.error("%s needs to be a column of %s", coln, results_filename[iF])
}
}
if (dim(unique(df[, c(headers[["barcode"]], gDRutils::get_env_identifiers("well_position"))]))[1] !=
dim(df[, c(headers[["barcode"]], gDRutils::get_env_identifiers("well_position"))])[1]) {

cols_subset <- intersect(c(headers[["barcode"]], gDRutils::get_env_identifiers("well_position")),
names(df))
if (dim(unique(df[, cols_subset, with = FALSE]))[1] !=
dim(df[, cols_subset, with = FALSE])[1]) {
futile.logger::flog.error("Multiple rows with the same Barcode and Well in %s",
results_filename[iF])
}
if (!("BackgroundValue" %in% colnames(df)))
if (!("BackgroundValue" %in% colnames(df))) {
df$BackgroundValue <- 0
futile.logger::flog.info("File %s read; %d wells", results_filename[iF], nrow(df))
futile.logger::flog.info("File done")
futile.logger::flog.info("File %s read; %d wells", results_filename[iF], nrow(df))
futile.logger::flog.info("File done")
}
df
})
all_results <- do.call(rbind, res_l)
}
Expand Down
24 changes: 23 additions & 1 deletion R/testdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,26 @@ get_test_EnVision_data <- function() {
t_files = grep("\\/Project40.+.xlsx$", fls, value = TRUE),
ref_l_path = file.path(ddir, "ref_l.qs")
)
}
}


#' get test tsv data
#'
#' @examples
#' get_test_tsv_data()
#
#' @keywords test_data
#' @export
#'
#' @return list with with input data (manifest/template/result paths)
#' and related reference data (.qs file paths)
get_test_tsv_data <- function() {
ddir <- system.file(package = "gDRimport", "extdata", "data5")
fls <- list.files(ddir, full.names = TRUE)
list(
m_file = grep("\\/Manifest.tsv$", fls, value = TRUE),
r_files = grep("\\RawData.tsv$", fls, value = TRUE),
t_files = grep("\\Template.+.tsv$", fls, value = TRUE),
ref_l_path = file.path(ddir, "ref_l.qs")
)
}
9 changes: 9 additions & 0 deletions inst/extdata/data5/Manifest.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Barcode Template Duration clid
Plate1 Template_trt.tsv 72 CL_B
Plate2 Template_trt.tsv 72 CL_B
Plate3 Template_trt.tsv 72 CL_B
Plate4 Template_trt.tsv 72 CL_A
Plate5 Template_trt.tsv 72 CL_A
Plate6 Template_trt.tsv 72 CL_A
Plate7 Template_untrt.tsv 0 CL_B
Plate8 Template_untrt.tsv 0 CL_A
Loading

0 comments on commit 9a3b17f

Please sign in to comment.