From f01864199c7996da1b6d80df163fadb1032dc214 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 17:14:37 +0100 Subject: [PATCH 01/13] bump version to 2.6.4 --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3d78543..1cd3084 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: binneR Title: Spectral Processing for High Resolution Flow Infusion Mass Spectrometry -Version: 2.6.3 +Version: 2.6.4 Authors@R: person("Jasen", "Finch", email = "jsf9@aber.ac.uk", role = c("aut", "cre")) Description: A spectral binning approach for flow infusion electrospray high resolution mass spectrometry (FIE-HRMS) metabolome fingerprinting data. The methodology for this approach is outlined in Finch et al. (2022) . biocViews: MassSpectrometry, Metabolomics @@ -26,7 +26,7 @@ Imports: furrr License: GPL-3 Encoding: UTF-8 -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Collate: allGenerics.R allClasses.R binneRlyse.R binParameters.R spectralBinning-method.R show-method.R get.R calc.R readFiles.R From ed00ed95728fb0728552e931f429389e0610fa01 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 17:15:51 +0100 Subject: [PATCH 02/13] ensure detectInfusionScans() can handle duplicated file names --- R/detect.R | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/R/detect.R b/R/detect.R index b4a3c94..49a3204 100644 --- a/R/detect.R +++ b/R/detect.R @@ -16,42 +16,35 @@ detectInfusionScans <- function(files, thresh = 0.5){ + idx <- tibble( + Sample = files + ) %>% + rowid_to_column(var = 'idx') + ms <- files %>% future_map(~{ ms <- .x %>% openMSfile() file_header <- ms %>% - header() + header() %>% + as_tibble() return(file_header) }) %>% - set_names(files) + set_names(idx$idx) %>% + bind_rows(.id = 'idx') %>% + mutate( + idx = as.numeric(idx) + ) %>% + left_join(idx, + by = 'idx', + relationship = 'many-to-many') - hd <- ms %>% - bind_rows(.id = 'Sample') %>% - as_tibble() %>% - select(Sample,seqNum,acquisitionNum,polarity,totIonCurrent,filterString) %>% - split(.$polarity) %>% - map(~{ - d <- . - d %>% - split(.$Sample) %>% - map(~{ - a <- . - a %>% - split(.$filterString) %>% - map(~{ - b <- . - b %>% - mutate(acquisitionNum = seq_len(nrow(.))) - }) %>% - bind_rows() - }) %>% - bind_rows() %>% - select(Sample,acquisitionNum,polarity,totIonCurrent,filterString) - }) %>% - bind_rows() %>% + hd <- ms %>% + select(idx,seqNum,acquisitionNum,polarity,totIonCurrent,filterString) %>% + group_by(idx,polarity,filterString) %>% + mutate(acquisitionNum = seq_len(n())) %>% group_by(acquisitionNum) %>% summarise(totIonCurrent = mean(totIonCurrent)) From eb8fdf06798aa9df4d990f1e5e17722f5f57709f Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 17:23:04 +0100 Subject: [PATCH 03/13] Ensure getPeaks() returns sample index --- R/get.R | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/R/get.R b/R/get.R index 2be60f3..ffa2921 100644 --- a/R/get.R +++ b/R/get.R @@ -59,11 +59,19 @@ getFile <- function(file,scans){ getPeaks <- function(files,scans){ + idx <- tibble( + fileName = files + ) %>% + rowid_to_column(var = 'idx') + dp <- binnerDP() pks <- future_map(files,getFile,scans = scans) %>% - set_names(files) %>% - bind_rows(.id = 'fileName') %>% + set_names(idx$idx) %>% + bind_rows(.id = 'idx') %>% + mutate(idx = as.numeric(idx)) %>% + left_join(idx, + by = 'idx') %>% mutate(fileName = basename(fileName), mz = round(mz,5),bin = round(mz,dp)) return(pks) @@ -79,7 +87,7 @@ getHeaders <- function(files){ future_map(readRDS) file_headers <- file_headers %>% - set_names(files) %>% + set_names(files) %>% bind_rows(.id = 'FileName') %>% select(FileName,acquisitionNum,totIonCurrent,polarity,filterString) From 5b06581152e2def024ee15c08aaa279ad4b9cc2f Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 18:17:37 +0100 Subject: [PATCH 04/13] Add file indexes to headers in getHeaders() return --- R/get.R | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/R/get.R b/R/get.R index ffa2921..100f234 100644 --- a/R/get.R +++ b/R/get.R @@ -81,15 +81,26 @@ getPeaks <- function(files,scans){ getHeaders <- function(files){ + idx <- tibble( + FileName = files + ) %>% + rowid_to_column(var = 'idx') + available_header_temps <- availableHeaderTemps(files) file_headers <- available_header_temps %>% future_map(readRDS) file_headers <- file_headers %>% - set_names(files) %>% - bind_rows(.id = 'FileName') %>% - select(FileName,acquisitionNum,totIonCurrent,polarity,filterString) + set_names(idx$idx) %>% + bind_rows(.id = 'idx') %>% + mutate( + idx = as.numeric(idx) + ) %>% + left_join(idx, + by = 'idx') %>% + select(idx,FileName,acquisitionNum,totIonCurrent,polarity,filterString) %>% + as_tibble() return(file_headers) } From d676f4b03c24286e0cdcb3ff8c8487c807affea5 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 18:19:04 +0100 Subject: [PATCH 05/13] use file index to calculate the bin list and metrics --- R/calc.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/calc.R b/R/calc.R index 1f57790..30cf3ec 100644 --- a/R/calc.R +++ b/R/calc.R @@ -1,7 +1,7 @@ calcBinList <- function(pks){ bins <- pks %>% - group_by(fileName,polarity,scan,bin) %>% + group_by(idx,fileName,polarity,scan,bin) %>% summarise(intensity = sum(intensity), .groups = 'drop') %>% group_by(polarity,bin) %>% @@ -16,7 +16,8 @@ calcBinMeasures <- function(pks,cls){ dp <- binnerDP() binMeasures <- pks %>% - group_by_at(vars(all_of(c('fileName', + group_by_at(vars(all_of(c('idx', + 'fileName', cls, 'polarity', 'bin')))) %>% From 07fc678da4dcf48d20ced2125b4803e08187d358 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 18:19:29 +0100 Subject: [PATCH 06/13] Use file index to plot chromatograms --- R/plot.R | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/R/plot.R b/R/plot.R index 897dfaa..49ad45e 100644 --- a/R/plot.R +++ b/R/plot.R @@ -128,30 +128,14 @@ setMethod('plotChromatogram',signature = 'Binalysis', scans <- x %>% scans() chromatograms <- chromatograms %>% - dplyr::select(FileName, + select(idx, + FileName, acquisitionNum, totIonCurrent, polarity, filterString) %>% - split(.$polarity) %>% - map(~{ - f <- . - f %>% - split(.$FileName) %>% - map(~{ - a <- . - a %>% - split(.$filterString) %>% - map(~{ - b <- . - b %>% - mutate(acquisitionNum = seq_len(nrow(.))) - }) %>% - bind_rows() - }) %>% - bind_rows() - }) %>% - bind_rows() %>% + group_by(polarity,idx,filterString) %>% + mutate(acquisitionNum = seq_len(n())) %>% group_by(polarity,acquisitionNum) %>% summarise(totIonCurrent = mean(totIonCurrent)) @@ -182,19 +166,8 @@ plotChromFromFile <- function(files, scans = c()){ openMSfile(.,backend = 'pwiz') %>% header() %>% select(acquisitionNum,totIonCurrent,polarity,filterString) %>% - split(.$polarity) %>% - map(~{ - a <- . - a %>% - split(.$filterString) %>% - map(~{ - b <- . - b %>% - mutate(acquisitionNum = seq_len(nrow(.))) - }) %>% - bind_rows() - }) %>% - bind_rows() %>% + group_by(polarity,filterString) %>% + mutate(acquisitionNum = seq_len(n())) %>% group_by(polarity,acquisitionNum) %>% summarise(totIonCurrent = mean(totIonCurrent)) }) %>% From 081d133996e408b5bf079986dc897cdcd6f19b20 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 18:20:27 +0100 Subject: [PATCH 07/13] ensure the spectral binning method uses file indexes --- R/spectralBinning-method.R | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/R/spectralBinning-method.R b/R/spectralBinning-method.R index c1d9f8a..de00ffa 100644 --- a/R/spectralBinning-method.R +++ b/R/spectralBinning-method.R @@ -34,30 +34,34 @@ setMethod("spectralBinning", mutate(class = NA) } + classes <- classes %>% + rowid_to_column(var = 'idx') + n_scans <- nScans(x) if (isTRUE(verbose)) message('Averaging intensities across scans') binned_data <- pks %>% - split(.$fileName) %>% + split(.$idx) %>% future_map(~{ .x %>% - group_by(fileName,polarity,bin,scan) %>% + group_by(idx,fileName,polarity,bin,scan) %>% summarise(intensity = sum(intensity), .groups = 'drop') %>% - group_by(fileName,polarity,bin) %>% + group_by(idx,fileName,polarity,bin) %>% summarise(intensity = sum(intensity)/n_scans, .groups = 'drop') }) %>% bind_rows() pks <- pks %>% - left_join(classes,by = "fileName") %>% - split(.$fileName) %>% + left_join(classes,by = c("idx",'fileName')) %>% + split(.$idx) %>% future_map(~{ .x %>% group_by_at( vars( - all_of(c('fileName', + all_of(c('idx', + 'fileName', cls, 'polarity','mz','bin')))) %>% summarise(intensity = sum(intensity)/n_scans, @@ -71,10 +75,10 @@ setMethod("spectralBinning", if (isTRUE(verbose)) message('Calculating accurate m/z') accurate_mz <- pks %>% - group_by_at(vars(all_of(c('fileName',cls,'polarity','bin')))) %>% + group_by_at(vars(all_of(c('idx','fileName',cls,'polarity','bin')))) %>% filter(intensity == max(intensity)) %>% arrange(bin) %>% - left_join(bin_measures,by = c('fileName',cls, "polarity", "bin")) %>% + left_join(bin_measures,by = c('idx','fileName',cls, "polarity", "bin")) %>% ungroup() mz <- accurate_mz %>% @@ -94,7 +98,7 @@ setMethod("spectralBinning", future_map(~{ .x %>% spread(mz,intensity,fill = 0) %>% - select(-fileName,-polarity) + select(-idx,-fileName,-polarity) }) if (isTRUE(verbose)) message('Gathering file headers') From e0ebf061e72117657877213f2b0c927a8c9e0611 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 18:20:39 +0100 Subject: [PATCH 08/13] Update tests --- tests/testthat/test-binneRlyse.R | 2 +- tests/testthat/test-getPeaks.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-binneRlyse.R b/tests/testthat/test-binneRlyse.R index 1c8fa95..1bf942b 100644 --- a/tests/testthat/test-binneRlyse.R +++ b/tests/testthat/test-binneRlyse.R @@ -43,7 +43,7 @@ test_that('binneRlyse works',{ expect_identical(class(ad),c('tbl_df','tbl','data.frame')) expect_equal(nrow(ad),1896) - expect_equal(ncol(ad),8) + expect_equal(ncol(ad),9) }) test_that('BinParameters class show method works',{ diff --git a/tests/testthat/test-getPeaks.R b/tests/testthat/test-getPeaks.R index f2d1742..b6a1afa 100644 --- a/tests/testthat/test-getPeaks.R +++ b/tests/testthat/test-getPeaks.R @@ -14,7 +14,7 @@ test_that('getPeaks works single core',{ pks <- getPeaks(file,5:13) expect_s3_class(pks,'tbl_df') - expect_equal(ncol(pks),6) + expect_equal(ncol(pks),7) }) test_that('getHeaders works single core',{ From e0da3ffac26c13446e14c1b09f9ffc26dc606ecf Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 18:20:48 +0100 Subject: [PATCH 09/13] Check note fix --- R/binneR.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/binneR.R b/R/binneR.R index aeefb91..8064e40 100644 --- a/R/binneR.R +++ b/R/binneR.R @@ -31,5 +31,6 @@ globalVariables(c('.', 'centrality', 'Purity', 'Centrality', - 'FileName' + 'FileName', + 'idx' )) From 0133ef65113254dcbc6994dc7827fd76fc3aae61 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 18:35:31 +0100 Subject: [PATCH 10/13] Update NEWS --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index fe542bd..c20c009 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# binneR 2.6.4 + +* Ensure that duplicated files are not aggregated during spectral binning. + # binneR 2.6.3 * Fix the calculation of quartiles in [`binneR::plotTIC`](https://aberhrml.github.io/binneR/reference/plotTIC.html). From 1451f8cb75d045beac81a4de4abbab37c528c09b Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 18:53:37 +0100 Subject: [PATCH 11/13] Update github actions --- .github/workflows/R-CMD-check.yaml | 4 ++-- .github/workflows/pkgdown.yaml | 6 ++++-- .github/workflows/test-coverage.yaml | 23 +++++++++++++++++++++-- DESCRIPTION | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 304b59d..c21abc8 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} @@ -29,7 +29,7 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-pandoc@v2 diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 0b26021..ed7650c 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -19,8 +19,10 @@ jobs: group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-pandoc@v2 @@ -39,7 +41,7 @@ jobs: - name: Deploy to GitHub pages 🚀 if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@4.1.4 + uses: JamesIves/github-pages-deploy-action@v4.4.1 with: clean: false branch: gh-pages diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 4b65418..2c5bb50 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -15,7 +15,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-r@v2 with: @@ -27,5 +27,24 @@ jobs: needs: coverage - name: Test coverage - run: covr::codecov(quiet = FALSE) + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + ) shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index 1cd3084..4a3c2d7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,7 @@ Version: 2.6.4 Authors@R: person("Jasen", "Finch", email = "jsf9@aber.ac.uk", role = c("aut", "cre")) Description: A spectral binning approach for flow infusion electrospray high resolution mass spectrometry (FIE-HRMS) metabolome fingerprinting data. The methodology for this approach is outlined in Finch et al. (2022) . biocViews: MassSpectrometry, Metabolomics -URL: https://aberhrml.github.io/binneR/ +URL: https://aberhrml.github.io/binneR/, http://aberhrml.github.io/binneR/ BugReports: https://github.com/aberHRML/binneR/issues Depends: R (>= 3.5) Imports: From 1a3f03f87d4cbec1bc43d9236e5fa22a8cf6687d Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 19:04:12 +0100 Subject: [PATCH 12/13] Update mzR remote --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4a3c2d7..d9c788a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,4 +44,4 @@ Suggests: testthat, gifski VignetteBuilder: knitr -Remotes: bioc::mzR +Remotes: bioc::release/mzR From f14887eb3534be3a47eb5239ab02b817db815cc8 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Fri, 11 Aug 2023 19:06:25 +0100 Subject: [PATCH 13/13] fix Remotes field --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d9c788a..4a3c2d7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,4 +44,4 @@ Suggests: testthat, gifski VignetteBuilder: knitr -Remotes: bioc::release/mzR +Remotes: bioc::mzR