Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions R/IsoFiltR.R
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ 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
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 +399,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
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
Loading