Fixed preprocessing module, implemented precalculations, this code gives a prediction of the values for the parameters in every step for preprocessing, added test suites for both the parameter generation and the preprocessing pipeline, included a descriptive processing that returns an image with what every parameter does in every step, added instrument metadata structure with the parser for each type of file, to retrieve several important parameters to automate precalculations and preprocessing

This commit is contained in:
Pixelguy14
2025-11-25 12:53:57 -06:00
parent 8fa92dc0e5
commit bdd9315796
15 changed files with 4167 additions and 1676 deletions
+44 -25
View File
@@ -7,7 +7,6 @@ export OpenMSIData,
GetSpectrum,
IterateSpectra,
ImportMzmlFile,
plot_slices,
plot_slice,
get_total_spectrum,
get_average_spectrum,
@@ -16,31 +15,34 @@ export OpenMSIData,
generate_colorbar_image,
process_image_pipeline,
load_and_prepare_mask,
set_global_mz_range!
set_global_mz_range!,
get_global_mz_range,
MSIData,
_iterate_spectra_fast,
validate_spectrum
# Export the public Preprocessing API
export FeatureMatrix,
run_preprocessing_pipeline,
qc_is_empty,
qc_is_regular,
transform_intensity,
smooth_spectrum,
snip_baseline,
tic_normalize,
pqn_normalize,
median_normalize,
# Export the public preprocessing & precalculations API
export run_preprocessing_analysis,
main_precalculation,
FeatureMatrix,
Calibration,
Smoothing,
BaselineCorrection,
Normalization,
PeakPicking,
PeakBinningParams,
get_masked_spectrum_indices,
detect_peaks_profile,
detect_peaks_wavelet,
detect_peaks_centroid,
align_peaks_lowess,
find_calibration_peaks,
smooth_spectrum,
apply_baseline_correction,
apply_normalization,
bin_peaks,
plot_stage_spectrum,
calculate_ppm_error,
calculate_resolution_fwhm,
analyze_mass_accuracy,
generate_qc_report,
get_common_calibration_standards
PeakSelection,
PeakAlignment,
find_calibration_peaks,
align_peaks_lowess,
MutableSpectrum
# Include all source files directly into the main module
include("BloomFilters.jl")
@@ -52,6 +54,9 @@ include("imzML.jl")
include("MzmlConverter.jl")
include("Preprocessing.jl")
include("ImageProcessing.jl")
include("Precalculations.jl")
using Setfield # For immutable struct updates
# --- Main Entry Point --- #
@@ -63,14 +68,28 @@ Opens a .mzML or .imzML file and prepares it for data access.
This is the main entry point for the new data access API.
"""
function OpenMSIData(filepath::String; cache_size=300)
function OpenMSIData(filepath::String; cache_size=300, spectrum_type_map::Union{Dict{Int, Symbol}, Nothing}=nothing)
local msi_data
if endswith(lowercase(filepath), ".mzml")
return load_mzml_lazy(filepath, cache_size=cache_size)
msi_data = load_mzml_lazy(filepath, cache_size=cache_size)
elseif endswith(lowercase(filepath), ".imzml")
return load_imzml_lazy(filepath, cache_size=cache_size)
msi_data = load_imzml_lazy(filepath, cache_size=cache_size)
else
error("Unsupported file type: $filepath. Please provide a .mzML or .imzML file.")
end
# Apply spectrum type map if provided
if spectrum_type_map !== nothing
for (idx, type_symbol) in spectrum_type_map
if 1 <= idx <= length(msi_data.spectra_metadata)
msi_data.spectra_metadata[idx] = @set msi_data.spectra_metadata[idx].type = type_symbol
else
@warn "Spectrum index $idx out of bounds for spectrum_type_map. Skipping."
end
end
end
return msi_data
end
end # module MSI_src