Skip to content

Conversation

mraves2
Copy link
Contributor

@mraves2 mraves2 commented Jul 11, 2025

The PeakFinding step in the DIMS pipeline has been refactored. Instead of averaging the intensities for technical replicates and doing PeakFinding on the averages, the new method will do PeakFinding for each technical replicate and then average the peak intensities for every biological sample. To do this, several scripts have been modified:

  • MakeInit: changed variable name 'tmp' to 'replicates_persample'
  • GenerateBreaks: breaks and trim parameters put into separate RData files
  • AssignToBins: trim parameters read in separately, 'sample_name' changed to 'techrep_name', weighted mean for half-bad TICs
  • AverageTechReplicates: averaging part removed, script renamed to EvaluateTics. Update txt file with info on samples and corresponding tech reps
  • PeakFinding: new simplified way to find peaks for every technical replicate. First step: find regions of interest (roi) with some intensity; second step: integrate intensity in each roi by fitting a Gaussian curve
    • preprocessing/peak_finding_functions: new functions for PeakFinding. Note that two functions are borrowed from other R packages which will be included in the Docker image in the future. These two functions may not adhere to our coding standards
  • AveragePeaks: averaging technical replicates after PeakFinding. Information for technical replicates from a txt file with scanmode included.
  • CollectAveraged: collect averaged peaks for all biological samples
  • PeakGrouping: input from CollectAveraged
  • tests/testthat/test_peak_finding_functions: unit tests for PeakFinding funtions. Note: no unit tests have been added for functions from external packages.

@mraves2 mraves2 marked this pull request as draft July 11, 2025 15:40
@mraves2 mraves2 marked this pull request as ready for review July 15, 2025 10:26
Copy link

@fdekievit fdekievit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Veel werk!

Ik heb hier en daar wat comments achter gelaten :)


script:
"""
Rscript ${baseDir}/CustomModules/DIMS/CollectAveraged.R

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dit Rscript wordt aangeroepen zonder argumenten, maar het R script consumed cmd_args[1] (DIMS/CollectAveraged.R regel 4) is dit correct?


# get TIC intensities for areas between trim_left and trim_right
tic_intensity_persample <- cbind(round(raw_data@scantime, 2), raw_data@tic)
tic_intensity_persample <- cbind(raw_data@scantime, raw_data@tic)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

klopt het dat er helemaal niet meer afgerond hoeft te worden?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Klopt, deze getallen worden alleen gebruikt voor het maken van een plot, dus afronden doet er niet toe.

techreps <- cmd_args[2]
scanmode <- cmd_args[3]
tech_reps <- strsplit(techreps, ";")[[1]]
print(sample_name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is dit alleen voor debugging of moet dit er in blijven staan voor de release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print statements zijn alleen voor debugging. Verwijderd.

print(scanmode)

# set ppm as fixed value, not the same ppm as in peak grouping
ppm_peak <- 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hier staan 'not the same ppm as in peak grouping' maar in peak grouping wordt deze value dynamisch ge-assigned. kan het voorkomen dat de code daar soms toch 2 gebruikt, en zo ja, is het een probleem als ze allebij t zelfde zijn en waarom?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De parameter ppm wordt op 4 verschillende plekken in de workflow gebruikt en is in te stellen bij het starten van de workflow; deze wordt voornamelijk gebruikt voor de annotatie bij een bepaalde massa plus of min een tolerantie die berekend wordt adhv ppm.
De parameter ppm_peak wordt alleen bij PeakFinding gebruikt en heeft een vaste waarde. Deze wordt gebruikt om pieken in verschillende samples bij elkaar te zoeken en een piekgroep te vormen. De waarde van 2 reflecteert de nauwkeurigheid van het MS apparaat.
Het is geen probleem als ppm en ppm_peak dezelfde waarde zouden hebben omdat ze niet in hetzelfde script gebruikt worden en een andere toepassing hebben.

# test get_fwhm function
test_that("fwhm is correctly calculated", {
# create peak info to test on:
test_mass_vector <- rep(70.00938, 5) + 1:5 * 0.00006

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zijn dit handige default waardes, of zijn deze puur gekozen omdat ze lijken op 'echte' waardes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gekozen omdat ze lijken op echte waarden. De exacte waarden maken niet uit; deze manier is compacter dan 5 losse waarden invoeren.

source("../../preprocessing/peak_finding_functions.R")

# test search_regions_of_interest function:
test_that("regions of interest are correctly found for a single peak", {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beschrijf welke functie je test (search_regions_of_interest)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De functie die getest wordt staat vernoemd in de comment erboven, in de test_that statement staat wat de functie moet doen. Dit is het format dat we afgesproken hebben.

expect_equal(nrow(search_regions_of_interest(test_ints_fullrange)), 1)
expect_equal(search_regions_of_interest(test_ints_fullrange), expected_output, tolerance = 0.000001, TRUE)
})
test_that("regions of interest are correctly found for two peaks", {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beschrijf welke functie je test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dit is de tweede test van de functie search_regions_of_interest, zoals aangegeven in regel 5. In twee aparte test_that statements wordt het geval van een enkele en van een dubbele piek getest.

})

# test integrate_peaks function:
test_that("peaks are correctly integrated", {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beschrijf welke functie je test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De functie die getest wordt staat vernoemd in de comment erboven, in de test_that statement staat wat de functie moet doen. Dit is het format dat we afgesproken hebben.

})

# test get_fwhm function
test_that("fwhm is correctly calculated", {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beschrijf welke functie je test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De functie die getest wordt staat vernoemd in de comment erboven, in de test_that statement staat wat de functie moet doen. Dit is het format dat we afgesproken hebben.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants