Deconvolution
JuChrom.Deconvolution.LocalMaxima
— TypeJuChrom.LocalMaxima(values::AbstractVector{<:Real};
startindex::Integer=firstindex(values), stopindex::Integer=lastindex(values))
Return an iterator that yields the index range of each local maximum until no more local maxima are found. If the maximum is a single peak, the range will have a length of 1; if a plateau maximum is found, the range will have a length greater than 1. The optional keyword arguments startindex
and stopindex
allow you to restrict the search range for the maximum. Note that startindex
and stopindex
must be at least two indices apart (e.g., startindex=1
, stopindex=3
).
See also nextlocalmaximum
.
Examples
julia> values = [4, 3, 5, 3, 6, 6, 6, 4, 7];
julia> for lm in JuChrom.LocalMaxima(values); println(lm); end
3:3
5:7
julia> for lm in JuChrom.LocalMaxima(values, startindex=3); println(lm); end
5:7
julia> for lm in JuChrom.LocalMaxima(values, stopindex=7); println(lm); end
3:3
julia> for lm in JuChrom.LocalMaxima(values, startindex=4, stopindex=8); println(lm); end
5:7
julia> for lm in JuChrom.LocalMaxima(values, startindex=4, stopindex=5); println(lm); end
ERROR: ArgumentError: stopindex not greater than startindex + 1: 4 5
[...]
julia> length(values)
9
julia> for lm in JuChrom.LocalMaxima(values, startindex=8); println(lm); end
ERROR: ArgumentError: stopindex not greater than startindex + 1: 8 9
[...]
JuChrom.Deconvolution.lsfit
— FunctionJuChrom.lsfit(xs::AbstractVector{<:Union{Real, Unitful.Quantity{<:Real}}},
ys::AbstractVector{<:Union{Real, Unitful.Quantity{<:Real}}})
Return the intercept and slope from a simple linear regression, fitting the line of best fit (in the form y = mx + b
) for the given data points xs
and ys
using the least squares method. The function expects two arguments: a vector of x-coordinates (independent variable), xs
, and a vector of y-coordinates (dependent variable), ys
. Both vectors must have the same length and contain at least two values. The function throws an ArgumentError
if the lengths of xs
and ys
differ or if either vector contains fewer than two values.
The function calculates the slope (m
) and intercept (b
) for the line of best fit using the formulas
m = Σ((xᵢ - x̄)(yᵢ - ȳ)) / Σ((xᵢ - x̄)²)
b = ȳ - m * x̄
where x̄
and ȳ
are the means of the xs
and ys
vectors, respectively.
Examples
julia> xs, ys = [1.0, 2.0, 3.0, 4.0, 5.0], [1.0, 2.0, 3.0, 4.0, 5.0];
julia> JuChrom.lsfit(xs, ys) .≈ (0.0, 1.0)
(true, true)
JuChrom.Deconvolution.nextlocalmaximum
— FunctionJuChrom.nextlocalmaximum(values::AbstractVector{<:Real};
startindex::Integer=firstindex(values), stopindex::Integer=lastindex(values))
Return the index range of the next local maximum. If the maximum is a single peak, the range will have a length of 1; if a plateau maximum is found, the range will have a length greater than 1. If no maximum is found, nothing is returned. The optional keyword arguments startindex
and startindex
allow you to restrict the search range for the maximum. Note that startindex
and startindex
must be at least two indices apart (e.g., startindex=1
, stopindex=3
).
See also LocalMaxima
.
Examples
julia> values = [4, 3, 5, 3, 6, 6, 6, 4, 7];
julia> JuChrom.nextlocalmaximum(values) # finds 5
3:3
julia> JuChrom.nextlocalmaximum(values, startindex=4) # finds pleateau maximum 6, 6, 6
5:7
julia> JuChrom.nextlocalmaximum(values, startindex=4, stopindex=7) # finds nothing
julia> length(values)
9
julia> JuChrom.nextlocalmaximum(values, startindex=8) # implicit stopindex=9
ERROR: ArgumentError: stopindex not greater than startindex + 1: 8 9
[...]
julia> JuChrom.nextlocalmaximum(values, startindex=1, stopindex=2)
ERROR: ArgumentError: stopindex not greater than startindex + 1: 1 2
[...]
JuChrom.Deconvolution.stddev
— FunctionJuChrom.stddev(chrom::AbstractChromMS; windowsize::Integer=13, threshold::Real=0,
nthreads::Integer=Threads.nthreads())::Tuple{Union{Float64, Nothing}, Int}
Return an estimate of the standard deviation (σ) in the intensity measurements of the instrument used to infer the chromatographic data by analyzing intensity fluctuations within user-defined scan windows (default: 13 scans). The function also returns the number of windows considered in the computation as a second output. This approach is based on the method described by Stein (1999) for estimating noise levels in chromatographic data, with some modifications. In brief, only windows with intensity values above the specified threshold (default: 0) are included. Additionally, the total number of transitions must exceed half the window's scan count, and no more than two consecutive intensity values can fall on the same side of the mean intensity within any given window. For windows that meet these criteria, the absolute differences between intensity values and the median intensity are used to calculate the median absolute deviation (MAD). Since intensity fluctuations are proportional to the square root of the measured intensity, the MAD is normalized by dividing it by the square root of the median intensity. The MAD is calculated for all possible non-overlapping windows across the intensity values for all ions. The median of the MAD values is then multiplied by 1.4826 to estimate σ, assuming that the intensity-normalized fluctuations follow a normal distribution. If no suitable windows are found for calculating σ, the function returns (nothing
, 0).
Reference
Stein SE (1999): An integrated method for spectrum extraction and compound identification from gas chromatography/mass spectrometry data. J. Am. Soc. Mass. Spectrom. 10: 770–781.
Examples
julia> dfolder = joinpath(JuChrom.agilent, "C7-C40_ChemStationMS.D");
julia> chrom = binions(importdata(dfolder, ChemStationMS()));
julia> JuChrom.stddev(chrom) .≈ (1.989116630064713, 9874)
(true, true)
julia> dfolder = joinpath(JuChrom.agilent, "C7-C40_MassHunterMS.D");
julia> chrom = binions(importdata(dfolder, MassHunterMS()));
julia> JuChrom.stddev(chrom) .≈ (1.951017182665152, 10979)
(true, true)