pub struct MzViewerApp {
    parsed_ms_data: MzData,
    plot_data: Option<Vec<[f64; 2]>>,
    user_input: UserInput,
    invalid_file: FileValidity,
    state_changed: StateChange,
    options_window_open: bool,
    checkbox_bool: bool,
}

Fields§

§parsed_ms_data: MzData

The parsed mass spectrometry data

§plot_data: Option<Vec<[f64; 2]>>

The plot data, prepared by the process_plot_data method

§user_input: UserInput

The user input parameters

§invalid_file: FileValidity

The validity of the input file. Only MzML files can be read in.

§state_changed: StateChange

The state change of the application

§options_window_open: bool

Whether the options window/pop-up is open

§checkbox_bool: bool

A boolean value for a checkbox/file selector

Implementations§

source§

impl MzViewerApp

source

pub fn new(_cc: &CreationContext<'_>) -> Self

Creates a new instance of the MzViewerApp struct.

§Arguments
  • _cc: The eframe::CreationContext reference, which is not used in this implementation.
§Returns

A new instance of the MzViewerApp struct with the following default values:

  • user_input.line_width: 1.0
  • All other fields in user_input are set to their default values.
  • All other fields in the MzViewerApp struct are set to their default values.
source

pub fn reset_state(&mut self)

Resets the internal state of the instance.

This function clears the parsed measurement data and sets the plot data to None.

source

fn process_plot_data(&mut self) -> Option<Vec<[f64; 2]>>

Processes the plot data based on the user’s input.

This function is responsible for retrieving the appropriate plot data (TIC, BPC, or XIC) from the parsed_ms_data object, preparing the data for plotting, and optionally smoothing the data if requested by the user.

§Parameters
  • &mut self: A mutable reference to the current instance of the struct that contains the parsed_ms_data and user_input fields.
§Returns
  • Option<Vec<[f64; 2]>>: An optional vector of 2-element arrays of f64 values, representing the processed plot data. If there was an error during the processing, None is returned.
source

fn plot_chromatogram(&mut self, ui: &mut Ui) -> Response

Plots the chromatogram (TIC, BPC, or XIC) based on the user’s input.

This function is responsible for updating the plot data if the state has changed, and then rendering the plot using the egui_plot library. It also handles the user’s triple-click event on the plot, which triggers the extraction of the mass spectrum at the clicked retention time.

§Parameters
  • &mut self: A mutable reference to the current instance of the struct that contains the user_input, plot_data, state_changed, and parsed_ms_data fields.
  • ui: &mut egui::Ui: A mutable reference to the current egui::Ui instance, which is used to render the plot.
§Returns
  • egui::Response: The response from the egui_plot::Plot widget, which can be used to handle user interactions with the plot.
source

fn determine_rt_clicked( &mut self, response: &Response, plot_bounds: Option<PlotBounds> ) -> Option<f32>

Determines the retention time at the location where the user triple-clicked on the plot.

This function calculates the retention time based on the user’s click position on the plot and the plot’s bounds.

§Parameters
  • &mut self: A mutable reference to the current instance of the struct that contains the user_input field.
  • response: &egui::Response: A reference to the egui::Response object returned by the egui_plot::Plot widget.
  • plot_bounds: Option<egui_plot::PlotBounds>: An optional reference to the plot’s bounds, which are used to calculate the retention time.
§Returns
  • Option<f32>: The calculated retention time at the clicked location, or None if the plot position or bounds are not available.
source

fn find_closest_spectrum(&self, clicked_rt: Option<f32>) -> Option<usize>

Finds the index of the mass spectrum closest to the given retention time.

This function searches the retention_time array in the parsed_ms_data object to find the mass spectrum with the closest retention time to the given value. If an exact match is not found, it returns the index of the mass spectrum with the closest retention time.

§Parameters
  • &self: A reference to the current instance of the struct that contains the parsed_ms_data field.
  • clicked_rt: Option<f32>: The retention time at which the user clicked on the plot, or None if no click was detected.
§Returns
  • Option<usize>: The index of the mass spectrum with the closest retention time to the given value, or None if the retention time or index data is missing.
source

fn plot_mass_spectrum(&mut self, ui: &mut Ui) -> Response

Plots the mass spectrum based on the data available in the parsed_ms_data object.

This function creates a bar chart plot of the mass-to-charge (m/z) values and their corresponding intensities. The width of the bars is adjusted based on the zoom level of the plot to provide a better visual representation.

§Parameters
  • &mut self: A mutable reference to the current instance of the struct that contains the parsed_ms_data and user_input fields.
  • ui: &mut egui::Ui: A mutable reference to the current egui::Ui instance, which is used to render the plot.
§Returns
  • egui::Response: The response from the egui_plot::Plot widget, which can be used to handle user interactions with the plot.
source

fn update_data_selection_panel(&mut self, ctx: &Context)

Updates the data selection panel in the user interface.

This function creates a top panel in the UI that contains the following elements:

  • A “File” button that allows the user to select a file to open.
  • A “Display” menu button that allows the user to configure the display options.
  • A light/dark mode toggle button that allows the user to switch between light and dark themes.

When the “File” button is clicked, the function handles the file selection process, clears the existing plot data and parser data, and updates the user input accordingly.

When the “Display” menu button is clicked, the function calls the add_display_options function to add the display options to the menu.

When the light/dark mode toggle button is clicked, the function updates the visuals of the UI based on the user’s selection.

§Parameters
  • &mut self: A mutable reference to the current instance of the struct that contains the plot_data, parsed_ms_data, user_input, and other relevant fields.
  • ctx: &Context: A reference to the egui::Context instance, which is used to update the UI’s visuals.
source

fn add_display_options(&mut self, ui: &mut Ui)

Adds the display options to the provided egui::Ui instance.

This function creates a series of menu buttons that allow the user to adjust the following display options:

  • Smoothing level: Adjusts the level of moving average smoothing applied to the plot data.
  • Line width: Adjusts the width of the lines in the plot.
  • Line color: Allows the user to select the color of the lines in the plot.
  • Line style: Allows the user to select the style of the lines in the plot.

When the user changes any of these options, the function updates the corresponding fields in the user_input struct and sets the state_changed flag to indicate that the plot data needs to be re-processed.

§Parameters
  • &mut self: A mutable reference to the current instance of the struct that contains the user_input and state_changed fields.
  • ui: &mut Ui: A mutable reference to the egui::Ui instance where the display options will be added.
source

fn add_line_color_options(&mut self, ui: &mut Ui)

Adds the line color options to the provided egui::Ui instance.

This function creates a horizontal layout of radio buttons that allow the user to select the color of the lines in the plot. The available colors are: Red, Blue, Green, Yellow, Black, and White.

When the user selects a new color, the function updates the user_input.line_color field accordingly.

§Parameters
  • &mut self: A mutable reference to the current instance of the struct that contains the user_input field.
  • ui: &mut Ui: A mutable reference to the egui::Ui instance where the line color options will be added.
source

fn add_line_style_options(&mut self, ui: &mut Ui)

Adds the line style options to the provided egui::Ui instance.

This function creates a horizontal layout of radio buttons that allow the user to select the style of the lines in the plot. The available line styles are: Solid, Dashed, and Dotted.

When the user selects a new line style, the function updates the user_input.line_type field accordingly.

§Parameters
  • &mut self: A mutable reference to the current instance of the struct that contains the user_input field.
  • ui: &mut Ui: A mutable reference to the egui::Ui instance where the line style options will be added.
source

fn handle_file_selection(&mut self)

Handles the selection of a file by the user.

This function is responsible for the following tasks:

  1. Prompts the user to select a file.
  2. If a file is selected, it updates the file path and the validity of the file using the update_file_path_and_validity() function.
  3. If no file is selected, it sets the invalid_file field to FileValidity::Invalid.
§Errors

This function does not return any errors. If an error occurs during the file selection process, it will be handled by the rfd::FileDialog::new().pick_file() function.

source

fn update_file_path_and_validity(&mut self, path: &PathBuf)

Updates the file path and validity based on the selected file.

This function checks the file format and updates the corresponding fields in the struct. If the file format is valid, it opens the file and updates the parsed_ms_data field. If the file format is invalid, it sets the invalid_file field to FileValidity::Invalid.

§Parameters
  • path: A reference to the selected file path.
§Errors

This function may encounter errors when attempting to open the selected file. These errors will be logged as warning messages.

source

fn update_file_information_panel(&mut self, ctx: &Context)

Updates the file information panel in the user interface.

This function is responsible for displaying the status of the selected file in the left-side panel of the application. It checks the validity of the selected file and displays the appropriate information to the user.

§Parameters
  • ctx: A reference to the egui::Context object, which is used to render the user interface.
§Functionality
  1. If the selected file is invalid, it displays a warning message indicating the expected file format.
  2. If the selected file is valid, it displays the file path and provides a checkbox that allows the user to close the file.
  3. If no file is selected, it displays a message indicating that no file has been selected.
§Errors

This function does not return any errors. It handles the file validity and user interactions within the user interface.

source

fn update_central_panel(&mut self, ctx: &Context)

Updates the central panel of the user interface.

This function is responsible for rendering the main content area of the application, which includes the chromatogram and mass spectrum plots.

§Parameters
  • ctx: A reference to the egui::Context object, which is used to render the user interface.
§Functionality
  1. Displays a CentralPanel that fills the available space in the center of the application.
  2. Adds a ScrollArea to the central panel, allowing the user to scroll the content if it exceeds the available space.
  3. Renders a CollapsingHeader for the chromatogram plot, which can be expanded or collapsed by the user.
    • Calls the plot_chromatogram() function to generate the chromatogram plot.
    • Adds a context menu to the chromatogram plot, which allows the user to access the plot properties.
    • Calls the add_plot_properties() function to add the plot properties to the context menu.
  4. Adds some vertical space between the chromatogram and mass spectrum plots.
  5. Renders a CollapsingHeader for the mass spectrum plot, which can be expanded or collapsed by the user.
    • Calls the plot_mass_spectrum() function to generate the mass spectrum plot.
§Errors

This function does not return any errors. It handles the rendering of the central panel and the associated plots within the user interface.

source

fn add_plot_properties(&mut self, ui: &mut Ui)

Adds the plot properties UI elements to the provided Ui.

This function is responsible for rendering the UI elements that allow the user to customize the properties of the plots, such as the polarity and plot type.

§Parameters
  • ui: A mutable reference to the egui::Ui object, which is used to render the UI elements.
§Errors

This function does not return any errors. It handles the rendering of the plot properties UI elements within the provided Ui.

source

fn add_polarity_options(&mut self, ui: &mut Ui)

Adds the polarity options UI elements to the provided Ui.

This function renders the UI elements that allow the user to select the polarity of the mass spectrometry data. It updates the user_input.polarity and state_changed fields based on the user’s selection.

§Parameters
  • ui: A mutable reference to the egui::Ui object, which is used to render the UI elements.
source

fn add_plot_type_options(&mut self, ui: &mut Ui)

Adds the plot type options UI elements to the provided Ui.

This function renders the UI elements that allow the user to select the type of plot to display, such as TIC, Base Peak, or XIC. It updates the user_input.plot_type and related fields based on the user’s selection.

§Parameters
  • ui: A mutable reference to the egui::Ui object, which is used to render the UI elements.
source

fn update_xic_settings_window(&mut self, ctx: &Context)

Updates the XIC (Extracted Ion Chromatogram) settings window.

This function is responsible for rendering the UI elements that allow the user to configure the settings for the XIC plot, such as the m/z value and mass tolerance.

§Parameters
  • ctx: A reference to the egui::Context object, which is used to render the UI elements.
§Functionality
  1. Checks if the options_window_open field is true, indicating that the XIC settings window should be displayed.
  2. If the window should be displayed, it creates a new egui::Window with the title “XIC settings”.
  3. The window is set to be open by default, and the options_window_open field is used to control whether the window should remain open or be closed.
  4. Inside the window, it adds a label that instructs the user to enter the m/z and mass tolerance values.
  5. It adds a TextEdit widget for the user to enter the m/z value.
    • If the user loses focus on the m/z input field, the function updates the user_input.mass field with the entered value (or the default value if the input is invalid).
    • It also sets the state_changed field to StateChange::Changed.
  6. It adds a TextEdit widget for the user to enter the mass tolerance value in ppm.
    • If the user loses focus on the mass tolerance input field, the function updates the user_input.mass_tolerance field with the entered value (or the default value if the input is invalid).
    • It also sets the state_changed field to StateChange::Changed.
§Errors

This function does not return any errors. It handles the rendering of the XIC settings window and the updating of the corresponding fields in the struct.

Trait Implementations§

source§

impl App for MzViewerApp

source§

fn update(&mut self, ctx: &Context, _frame: &mut Frame)

Updates the application’s user interface.

This method is called by the eframe library to update the application’s state and render the user interface.

§Parameters
  • ctx: A reference to the egui::Context object, which is used to interact with the user interface.
  • _frame: A mutable reference to the eframe::Frame object, which provides access to the application’s frame and other low-level functionality. This parameter is not used in this implementation.
§Functionality
  1. Calls the update_data_selection_panel() function to update the data selection panel in the user interface.
  2. Calls the update_file_information_panel() function to update the file information panel in the user interface.
  3. Calls the update_central_panel() function to update the central panel in the user interface, which includes the chromatogram and mass spectrum plots.
  4. Calls the update_xic_settings_window() function to update the XIC (Extracted Ion Chromatogram) settings window in the user interface, if it is open.
§Errors

This method does not return any errors. It calls several other functions that may encounter errors, but those errors are handled within the respective functions

§

fn save(&mut self, _storage: &mut dyn Storage)

Called on shutdown, and perhaps at regular intervals. Allows you to save state. Read more
§

fn on_exit(&mut self, _gl: Option<&Context>)

Called once on shutdown, after [Self::save]. Read more
§

fn auto_save_interval(&self) -> Duration

Time between automatic calls to [Self::save]
§

fn clear_color(&self, _visuals: &Visuals) -> [f32; 4]

Background color values for the app, e.g. what is sent to gl.clearColor. Read more
§

fn persist_egui_memory(&self) -> bool

Controls whether or not the egui memory (window positions etc) will be persisted (only if the “persistence” feature is enabled).
§

fn raw_input_hook(&mut self, _ctx: &Context, _raw_input: &mut RawInput)

A hook for manipulating or filtering raw input before it is processed by [Self::update]. Read more
source§

impl Default for MzViewerApp

source§

fn default() -> MzViewerApp

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.