Skip to content

Commit

Permalink
grouping_threshold added to the remove_noise function
Browse files Browse the repository at this point in the history
  • Loading branch information
KristinaGomoryova committed Jul 9, 2024
1 parent 10e8f9f commit debf57c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
5 changes: 3 additions & 2 deletions R/remove_noise.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ load_data <- function(filename,
#' @param intensity_weighted Whether to use intensity to weight mass density estimation.
#' @param do.plot Indicates whether plot should be drawn.
#' @param cache Whether to use cache
#' @param grouping_threshold The maximum difference between two scans to be considered the same EIC. Default is Inf.
#' @return A matrix with four columns: m/z value, retention time, intensity, and group number.
#' @export
remove_noise <- function(filename,
Expand All @@ -71,7 +72,7 @@ remove_noise <- function(filename,
intensity_weighted,
do.plot,
cache,
grouping_threshold = 0) {
grouping_threshold = Inf) {
raw.data <- load_file(filename)

raw.prof <- adaptive.bin(
Expand All @@ -93,7 +94,7 @@ remove_noise <- function(filename,

newprof <- newprof[newprof[, 4] %in% run.sel, ]

if (grouping_threshold > 0) {
if (grouping_threshold < Inf) {
sorted_newprof <- newprof[order(newprof[,2]),]
new_grps <- cumsum(c(0, diff(sorted_newprof[,2])) > grouping_threshold)
sorted_newprof <- cbind(sorted_newprof, new_grps, deparse.level = 0)
Expand Down
2 changes: 1 addition & 1 deletion conda/environment-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
- icu <=70.1
- r-mass
- r-rgl
- bioconductor-mzR ==2.28.0
- bioconductor-mzR ==2.36.0
- r-splines2
- r-doparallel
- r-foreach
Expand Down
3 changes: 2 additions & 1 deletion tests/remote-files/input.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/RCX_08_shortened.mzML
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/single_eic.mzml
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/alg3.mzdata
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/test_file.mzXML
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/test_file.mzXML
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/Tribrid_201106_009-QC1_1_NEG_FISABIO_single_eic.raw.mzML
30 changes: 30 additions & 0 deletions tests/testthat/test-remove_noise.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,33 @@ patrick::with_parameters_test_that(
)
)
)

test_that("remove noise works with grouping threshold", {
testdata <- file.path("..", "testdata")
input_path <- file.path(testdata,
"input",
"Tribrid_201106_009-QC1_1_NEG_FISABIO_single_eic.raw.mzML")

expected <- tibble(group_number = c(1, 2, 3, 5, 6, 7, 8, 9),
n = c(67, 73, 3, 39, 2, 6, 3, 7))

sut <- remove_noise(
input_path,
min_pres = 0.8,
min_run = 0.2,
mz_tol = 5e-05,
baseline_correct = 0.0,
baseline_correct_noise_percentile = 0.05,
intensity_weighted = FALSE,
do.plot = FALSE,
cache = FALSE,
grouping_threshold = 4
)

actual <- sut %>%
mutate(group = factor(group_number)) %>%
group_by(group_number) %>%
summarize(n = n())

expect_equal(actual, expected)
})

0 comments on commit debf57c

Please sign in to comment.