Struct chromascope::gui::MzViewerApp
source · 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
impl MzViewerApp
sourcepub fn new(_cc: &CreationContext<'_>) -> Self
pub fn new(_cc: &CreationContext<'_>) -> Self
Creates a new instance of the MzViewerApp
struct.
§Arguments
_cc
: Theeframe::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.
sourcepub fn reset_state(&mut self)
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
.
sourcefn process_plot_data(&mut self) -> Option<Vec<[f64; 2]>>
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 theparsed_ms_data
anduser_input
fields.
§Returns
Option<Vec<[f64; 2]>>
: An optional vector of 2-element arrays off64
values, representing the processed plot data. If there was an error during the processing,None
is returned.
sourcefn plot_chromatogram(&mut self, ui: &mut Ui) -> Response
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 theuser_input
,plot_data
,state_changed
, andparsed_ms_data
fields.ui: &mut egui::Ui
: A mutable reference to the currentegui::Ui
instance, which is used to render the plot.
§Returns
egui::Response
: The response from theegui_plot::Plot
widget, which can be used to handle user interactions with the plot.
sourcefn determine_rt_clicked(
&mut self,
response: &Response,
plot_bounds: Option<PlotBounds>
) -> Option<f32>
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 theuser_input
field.response: &egui::Response
: A reference to theegui::Response
object returned by theegui_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, orNone
if the plot position or bounds are not available.
sourcefn find_closest_spectrum(&self, clicked_rt: Option<f32>) -> Option<usize>
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 theparsed_ms_data
field.clicked_rt: Option<f32>
: The retention time at which the user clicked on the plot, orNone
if no click was detected.
§Returns
Option<usize>
: The index of the mass spectrum with the closest retention time to the given value, orNone
if the retention time or index data is missing.
sourcefn plot_mass_spectrum(&mut self, ui: &mut Ui) -> Response
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 theparsed_ms_data
anduser_input
fields.ui: &mut egui::Ui
: A mutable reference to the currentegui::Ui
instance, which is used to render the plot.
§Returns
egui::Response
: The response from theegui_plot::Plot
widget, which can be used to handle user interactions with the plot.
sourcefn update_data_selection_panel(&mut self, ctx: &Context)
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 theplot_data
,parsed_ms_data
,user_input
, and other relevant fields.ctx: &Context
: A reference to theegui::Context
instance, which is used to update the UI’s visuals.
sourcefn add_display_options(&mut self, ui: &mut Ui)
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 theuser_input
andstate_changed
fields.ui: &mut Ui
: A mutable reference to theegui::Ui
instance where the display options will be added.
sourcefn add_line_color_options(&mut self, ui: &mut Ui)
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 theuser_input
field.ui: &mut Ui
: A mutable reference to theegui::Ui
instance where the line color options will be added.
sourcefn add_line_style_options(&mut self, ui: &mut Ui)
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 theuser_input
field.ui: &mut Ui
: A mutable reference to theegui::Ui
instance where the line style options will be added.
sourcefn handle_file_selection(&mut self)
fn handle_file_selection(&mut self)
Handles the selection of a file by the user.
This function is responsible for the following tasks:
- Prompts the user to select a file.
- If a file is selected, it updates the file path and the validity of the file using the
update_file_path_and_validity()
function. - If no file is selected, it sets the
invalid_file
field toFileValidity::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.
sourcefn update_file_path_and_validity(&mut self, path: &PathBuf)
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.
sourcefn update_file_information_panel(&mut self, ctx: &Context)
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 theegui::Context
object, which is used to render the user interface.
§Functionality
- If the selected file is invalid, it displays a warning message indicating the expected file format.
- If the selected file is valid, it displays the file path and provides a checkbox that allows the user to close the file.
- 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.
sourcefn update_central_panel(&mut self, ctx: &Context)
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 theegui::Context
object, which is used to render the user interface.
§Functionality
- Displays a
CentralPanel
that fills the available space in the center of the application. - Adds a
ScrollArea
to the central panel, allowing the user to scroll the content if it exceeds the available space. - 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.
- Calls the
- Adds some vertical space between the chromatogram and mass spectrum plots.
- 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.
- Calls the
§Errors
This function does not return any errors. It handles the rendering of the central panel and the associated plots within the user interface.
sourcefn add_plot_properties(&mut self, ui: &mut Ui)
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 theegui::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
.
sourcefn add_polarity_options(&mut self, ui: &mut Ui)
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 theegui::Ui
object, which is used to render the UI elements.
sourcefn add_plot_type_options(&mut self, ui: &mut Ui)
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 theegui::Ui
object, which is used to render the UI elements.
sourcefn update_xic_settings_window(&mut self, ctx: &Context)
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 theegui::Context
object, which is used to render the UI elements.
§Functionality
- Checks if the
options_window_open
field istrue
, indicating that the XIC settings window should be displayed. - If the window should be displayed, it creates a new
egui::Window
with the title “XIC settings”. - 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. - Inside the window, it adds a label that instructs the user to enter the m/z and mass tolerance values.
- 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 toStateChange::Changed
.
- If the user loses focus on the m/z input field, the function updates the
- 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 toStateChange::Changed
.
- If the user loses focus on the mass tolerance input field, the function updates the
§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
impl App for MzViewerApp
source§fn update(&mut self, ctx: &Context, _frame: &mut Frame)
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 theegui::Context
object, which is used to interact with the user interface._frame
: A mutable reference to theeframe::Frame
object, which provides access to the application’s frame and other low-level functionality. This parameter is not used in this implementation.
§Functionality
- Calls the
update_data_selection_panel()
function to update the data selection panel in the user interface. - Calls the
update_file_information_panel()
function to update the file information panel in the user interface. - Calls the
update_central_panel()
function to update the central panel in the user interface, which includes the chromatogram and mass spectrum plots. - 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)
fn save(&mut self, _storage: &mut dyn Storage)
§fn auto_save_interval(&self) -> Duration
fn auto_save_interval(&self) -> Duration
Self::save
]§fn clear_color(&self, _visuals: &Visuals) -> [f32; 4]
fn clear_color(&self, _visuals: &Visuals) -> [f32; 4]
gl.clearColor
. Read more§fn persist_egui_memory(&self) -> bool
fn persist_egui_memory(&self) -> bool
§fn raw_input_hook(&mut self, _ctx: &Context, _raw_input: &mut RawInput)
fn raw_input_hook(&mut self, _ctx: &Context, _raw_input: &mut RawInput)
Self::update
]. Read more