Skip to content

Commit

Permalink
Merge pull request #111 from Roestlab/bug/mrmpeakpicking_none_smoother
Browse files Browse the repository at this point in the history
Bug/mrmpeakpicking none smoother
  • Loading branch information
singjc authored Jan 30, 2024
2 parents 787a33f + 7b43e5d commit ad0c55f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 626 deletions.
622 changes: 7 additions & 615 deletions docs/python_docs/Peak Picking.ipynb

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion massdash/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@
URL_TEST_PQP = "https://github.com/Roestlab/massdash/raw/dev/test/test_data/example_dia/openswath/lib/test.pqp"
URL_TEST_RAW_MZML = "https://github.com/Roestlab/massdash/raw/dev/test/test_data/example_dia/raw/test_raw_1.mzML"
URL_TEST_DREAMDIA_REPORT = "https://github.com/Roestlab/massdash/raw/dev/test/test_data/example_dia/dreamdia/test_dreamdia_report.tsv"
URL_PRETRAINED_CONFORMER = "https://github.com/Roestlab/massdash/releases/download/v0.0.1-alpha/base_cape.onnx"
URL_PRETRAINED_CONFORMER = "https://github.com/Roestlab/massdash/releases/download/v0.0.1-alpha/base_cape.onnx"

######################
## Data Handling

# Data Smoothing
SMOOTHING_DICT = {'No Smoothing': {'type': 'none'},
'Savitzky-Golay': {'type': 'sgolay', 'sgolay_polynomial_order': 3, 'sgolay_frame_length': 11},
'Gaussian': {'type': 'gauss', 'gaussian_sigma': 2.0, 'gaussian_window': 11}
}
2 changes: 1 addition & 1 deletion massdash/plotting/GenericPlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):
self.subtitle = None
self.x_axis_label = "Retention Time"
self.y_axis_label = "Intensity"
self.smoothing_dict = {'type': ['sgolay', 'gaussian'], 'sgolay_polynomial_order': 3,
self.smoothing_dict = {'type': ['sgolay', 'gauss'], 'sgolay_polynomial_order': 3,
'sgolay_frame_length': 11, 'gaussian_sigma': 2.0, 'gaussian_window': 11}

self.x_range = None
Expand Down
2 changes: 1 addition & 1 deletion massdash/plotting/InteractivePlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def process_chrom(self, p: figure, chrom: Chromatogram, label: str, color: str='
else:
raise ValueError(error_message)

elif self.smoothing_dict['type'] == 'gaussian':
elif self.smoothing_dict['type'] == 'gauss':
try:
window = gaussian(self.smoothing_dict['gaussian_window'], std=self.smoothing_dict['gaussian_sigma'])
intensity = convolve(intensity, window, mode='same') / window.sum()
Expand Down
2 changes: 1 addition & 1 deletion massdash/structs/TransitionGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def adjust_length(self, length: int) -> None:

def plot(self,
transitionGroupFeatures: Optional[List[TransitionGroupFeature]] = None,
smoothing: Optional[Literal['none', 'sgolay', 'gaussian']] = 'none',
smoothing: Optional[Literal['none', 'sgolay', 'gauss']] = 'none',
gaussian_sigma: float = 2.0,
gaussian_window: int = 11,
sgolay_polynomial_order: int = 3,
Expand Down
13 changes: 8 additions & 5 deletions massdash/ui/ChromatogramPlotUISettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import streamlit as st

# Constants
from ..constants import SMOOTHING_DICT

class ChromatogramPlotUISettings:
"""
A class for managing the settings for a chromatogram plot.
Expand Down Expand Up @@ -105,10 +108,10 @@ def create_ui(self, include_raw_data_settings: bool=False, is_ion_mobility_data:
self.set_y_range = st.checkbox("Share y-range", value=self.set_y_range, help="Share the y-range of the plots.")

# Perform Smoothing of the chromatograms
self.do_smoothing = st.selectbox("Smoothing", ['none', 'sgolay', 'gaussian'], help="The type of smoothing to apply to the chromatograms.")

self.smoothing_dict['type'] = self.do_smoothing
if self.do_smoothing == 'sgolay':
self.do_smoothing = st.selectbox("Smoothing", list(SMOOTHING_DICT.keys()), help="The type of smoothing to apply to the chromatograms.")
self.smoothing_dict = SMOOTHING_DICT[self.do_smoothing]
if self.smoothing_dict['type'] == 'sgolay':
# Create two columns for side-by-side widgets
col1, col2 = st.columns(2)

Expand All @@ -118,7 +121,7 @@ def create_ui(self, include_raw_data_settings: bool=False, is_ion_mobility_data:
# Add widget for sgolay_frame_length in the second column
self.smoothing_dict['sgolay_frame_length'] = col2.number_input("Frame Length", min_value=1, max_value=50, value=11, step=1, help="The length of the frame to use for smoothing the chromatograms.")

if self.do_smoothing == 'gaussian':
if self.smoothing_dict['type'] == 'gauss':
# Create two columns for side-by-side widgets
col1, col2 = st.columns(2)

Expand Down
8 changes: 6 additions & 2 deletions massdash/ui/MRMTransitionGroupPickerUISettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ def create_ui(self, plot_settings: ChromatogramPlotUISettings):
self.sgolay_frame_length = st.number_input("Savitzky-Golay Frame Length", value=11, step=2, min_value=1, help="Savitzky-Golay frame length.")
self.sgolay_polynomial_order = st.number_input("Savitzky-Golay Polynomial Order", value=3, min_value=1, help="Savitzky-Golay polynomial order.")
else:
self.smoother = plot_settings.do_smoothing
self.smoother = plot_settings.smoothing_dict['type']
if self.smoother == "gauss":
self.gauss_width = st.number_input("Width of the Gaussian smoothing", min_value=0.0, value=30.0, help="Width of the Gaussian smoothing.")
self.gauss_width = plot_settings.smoothing_dict['gaussian_window']
elif self.smoother == "sgolay":
self.sgolay_frame_length = plot_settings.smoothing_dict['sgolay_frame_length']
self.sgolay_polynomial_order = plot_settings.smoothing_dict['sgolay_polynomial_order']
elif self.smoother == "none":
self.smoother = "original"
else:
st.error(f"Unknown supported smoothing type for MRMTransitionGroupPicker: {self.smoother}. Needs to be one of 'Savitzky-Golay' or 'Gaussian'.")

0 comments on commit ad0c55f

Please sign in to comment.