Skip to content

Commit

Permalink
Merge pull request #43 from RECETOX/bugfix_chunk_with_no_isotopes
Browse files Browse the repository at this point in the history
Fixed bug which caused isofiltr to fail is some subsection of input has no isotope pairs
  • Loading branch information
hechth authored Aug 15, 2024
2 parents d313f04 + 65b9995 commit 79e56fc
Show file tree
Hide file tree
Showing 7 changed files with 3,222 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Imports: dplyr (>= 0.7.6),
ggplot2 (>= 3.0.0),
colorRamps (>= 2.3)
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests: knitr,
rmarkdown,
patrick (>= 0.2.0)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export(create_pairs)
export(extract_mono_and_iso_pairs)
export(filter_and_arrange_data)
export(filter_pairs)
export(filtered_data_is_empty)
export(merge_and_filter_abundances)
export(merge_and_filter_pairs)
export(processMassList)
Expand Down
15 changes: 15 additions & 0 deletions R/IsoFiltR.R
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ merge_and_filter_abundances <- function(final_pair2, end_data) {
return(aligned_data)
}

#' Return TRUE if any of the elements in the list has a length of 0, otherwise FALSE
#' @param filtered_data Filtered data with mono-iso links.
#' @return TRUE if any of the links is 0, otherwise FALSE.
#' @export
filtered_data_is_empty<- function(filtered_data) {
return(any(lapply(filtered_data, length) == 0))
}

#' Process carbon isotoping data
#'
#' This function processes carbon isotoping data using specified parameters and filtering criteria.
Expand Down Expand Up @@ -394,6 +402,13 @@ process_carbon_isotoping <- function(raw_data, carb_error, carb_ratio, end_data)
extracted_pair$iso_pair
)

if(filtered_data_is_empty(filtered_data)) {
return(list(
MonoC = raw_data, # treat all data as mono and return it.
IsoC1 = data.frame(Exp_mass = c(), Abundance = c(), RT = c()),
IsoC2 = data.frame(Exp_mass = c(), Abundance = c(), RT = c())))
}

iso1 <- data.frame(Mono_mass = filtered_data$Iso_mass1, Tag = "Iso1")
iso1 <- rbind(iso1, data.frame(Mono_mass = -42, Tag = "Iso1"))

Expand Down
24 changes: 24 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
Package Updates

unreleased

- Fixed bug which caused isofiltr to fail is some subsection of input has no isotope pairs #43


07/25/2024 (Version 1.0.3)
- Initial refactoring and added tests by @hechth in #23
- Rmd document describing the MFAssignR workflow added by @KristinaGomoryova in #20
- Cleanup by @hechth in #26
- Implement unit tests for the HistNoise module by @wverastegui in #25
- Added Codecov CI by @zargham-ahmad in #28
- Removed SNplot duplicate by @hechth in #27
- Unexplained numbers turned into variables by @KristinaGomoryova in #29
- Implement unit tests for the RecalFunctions module by @wverastegui in #30
- test for the MfassignCHO function by @KristinaGomoryova in #31
- Refactored IsoFiltR.R by @zargham-ahmad in #35
- Removed Halogen specific files and combined functionality where possible by @hechth in #32
- Refactored the RecalList function in the RecalFunctions module by @wverastegui in #33
- Refactor the Recal function in the RecalFunctions module by @wverastegui in #36
- Package reorganization by @KristinaGomoryova in #34
- Pulling changes from uptsream by @hechth in #38
- Failing tests corrected by @KristinaGomoryova in #42


05/25/2023 (Version 1.0.2)
- Fixed an issue with IsoFiltR that occasionally caused and error regarding the lack of precision when converting between integer and double. This was addressed by "wrapping" Sect and Over with ceiling() when those numbers are first defined.

Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-IsoFiltR.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ patrick::with_parameters_test_that("IsoFiltR works",
},
mode = c("pos", "neg")
)

test_that("IsoFiltR works on recetox-aplcms output", {
raw <- read.table(file.path("test-data", "21_qc_no_dil_milliq.txt"), header=TRUE, sep="\t")
expected_path <- file.path("test-data", "21_qc_no_dil_milliq_iso.rds")

actual <- IsoFiltR(raw)

expected <- readRDS(expected_path)
expect_equal(actual, expected)
})

patrick::with_parameters_test_that("filtered_data_is_empty works", {
expect_equal(filtered_data_is_empty(test_data), expected)

},
patrick::cases(
empty = list(test_data=list(content=c()), expected=TRUE),
not_empty = list(test_data=list(content=c(1,2,3)), expected=FALSE)
)
)
Loading

0 comments on commit 79e56fc

Please sign in to comment.