Skip to contents

Even after calling speaq_align(), the alignment of individual signals is not always perfect, as 'speaq' performs a segment-wise alignment i.e. groups of signals are aligned. For further improvements, partly filled neighboring columns are merged.

Usage

combine_peaks(
  shifted_mat = speaq_align(),
  range = 5,
  lower_bound = 1,
  spectrum_data = NULL,
  data_path = NULL
)

Arguments

shifted_mat

The matrix returned by speaq_align().

range

Amount of adjacent columns which are permitted to be used for improving the alignment.

lower_bound

Minimum amount of non-zero elements per column to trigger the alignment improvement.

spectrum_data

The list of deconvoluted spectra as returned by generate_lorentz_curves() that was used to generate shifted_mat. No longer required since version 1.2 of Metabodecon.

data_path

If not NULL, the returned dataframes long and short are written to data_path as "aligned_res_long.csv" and "aligned_res_short.csv".

Value

A list containing two data frames long and short. The first data frame contains one one column for each data point in the original spectrum. The second data frame contains only columns where at least one entry is non-zero.

Details

Example of what the function does:

|            | 3.56 | 3.54 | 3.51 | 3.51 | 3.50 |
|----------- |------|------|------|------|------|
| Spectrum 1 | 0.13 | 0    | 0.11 | 0    | 0    |
| Spectrum 2 | 0.13 | 0    | 0.12 | 0    | 0    |
| Spectrum 3 | 0.07 | 0    | 0    | 0    | 0    |
| Spectrum 4 | 0.08 | 0    | 0    | 0.07 | 0    |
| Spectrum 5 | 0.04 | 0    | 0.04 | 0    | 0    |

becomes

|            | 3.56 | 3.54 | 3.51 | 3.50 |
|----------- |------|------|------|------|
| Spectrum 1 | 0.13 | 0    | 0.11 | 0    |
| Spectrum 2 | 0.13 | 0    | 0.12 | 0    |
| Spectrum 3 | 0.07 | 0    | 0    | 0    |
| Spectrum 4 | 0.08 | 0    | 0.07 | 0    |
| Spectrum 5 | 0.04 | 0    | 0.04 | 0    |

I.e. column 3 and 4 get merged, because they are in range of each other and have no common non-zero entries.

Author

Initial version from Wolfram Gronwald. Refactored by Tobias Schmidt in 2024.

Examples

sim_subset <- metabodecon_file("bruker/sim_subset")
spectrum_data <- generate_lorentz_curves_sim(sim_subset)
shifted_mat <- speaq_align(spectrum_data = spectrum_data, verbose = FALSE)
range <- 5
lower_bound <- 1
obj <- combine_peaks(shifted_mat, range, lower_bound)
str(obj)
#> List of 2
#>  $ short: num [1:2, 1:35] 0.000497 0.011831 0.190204 0.186337 0.003531 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : NULL
#>   .. ..$ : chr [1:35] "3.5081" "3.50165" "3.497" "3.49475" ...
#>  $ long : num [1:2, 1:2048] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : NULL
#>   .. ..$ : chr [1:2048] "3.59" "3.58985" "3.5897" "3.58955" ...