Skip to content

Commit

Permalink
Merge pull request #169 from Roestlab/patch/plot_by_qvalue
Browse files Browse the repository at this point in the history
Patch/plot by qvalue
  • Loading branch information
singjc authored Feb 24, 2025
2 parents 1f3115c + a004ae0 commit 14e5128
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion massdash/loaders/GenericChromatogramLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ def plotChromatogram(self,
# load the transitionGroup for plotting
transitionGroup = list(self.loadTransitionGroups(seq, charge, runNames=runName).values())[0]
if includeBoundaries:
transitionGroupFeatures = self.loadTransitionGroupFeaturesDf(seq, charge)
transitionGroupFeatures = self.loadTransitionGroupFeaturesDf(seq, charge, runNames=runName)
else:
transitionGroupFeatures = None

# set title automatically (as peptide and charge state) if not set by user
if not 'title' in kwargs.keys():
kwargs['title'] = f"{seq}_{charge}"

return super().plotChromatogram(transitionGroup, transitionGroupFeatures, include_ms1=include_ms1, smooth=smooth, sgolay_polynomial_order=sgolay_polynomial_order, sgolay_frame_length=sgolay_frame_length, **kwargs)
14 changes: 13 additions & 1 deletion massdash/loaders/GenericRawDataLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def plotChromatogram(self,
gaussian_window: int = 11,
gaussian_sigma: float = 2,
width=800,
allFeatures=True,
**kwargs) -> 'bokeh.plotting.figure.Figure':
'''
Plots a chromatogram for a transitionGroup and transitionGroupFeatures given peptide sequence and charge state for a given run
Expand All @@ -71,6 +72,7 @@ def plotChromatogram(self,
sgolay_polynomial_order (int, optional): Order of the polynomial to use for smoothing. Defaults to 3.
sgolay_frame_length (int, optional): Frame length to use for smoothing. Defaults to 11.
scale_intensity (bool, optional): Whether to scale the intensity of the chromatogram such that all chromatograms are individually normalized to 1. Defaults to False.
allFeatures (bool, optional): Whether to plot all features or just the top ranked feature. Defaults to True.
Returns:
bokeh.plotting.figure.Figure: Bokeh figure object
Expand All @@ -89,12 +91,23 @@ def plotChromatogram(self,
# format transitionGroupFeatures for plotting with pyopenms_viz
if transitionGroupFeatures is not None:
transitionGroupFeatures.rename(columns={'leftBoundary':'leftWidth', 'rightBoundary':'rightWidth', 'consensusApexIntensity':'apexIntensity'}, inplace=True)

# sort by qvalue
transitionGroupFeatures = transitionGroupFeatures.sort_values(by='qvalue')

# Determine the labels for the legend, this is dependent on software tool
# if multiple software tools used, label by software

labelBySoftware = transitionGroupFeatures['software'].nunique() > 1
if transitionGroupFeatures.software is not None and labelBySoftware:
transitionGroupFeatures.rename(columns={'software':'name'}, inplace=True)
transitionGroupFeatures['name'] = transitionGroupFeatures['name'] + transitionGroupFeatures['qvalue'].map(lambda x: f' (qvalue={x:.2e})')
else: # if only one software tool used, label by q value
transitionGroupFeatures['name'] = transitionGroupFeatures['sequence'] + transitionGroupFeatures['qvalue'].map(lambda x: f' (qvalue={x:.2e})')
transitionGroupFeatures.rename(columns={'annotation':'name'}, inplace=True)

if not allFeatures:
transitionGroupFeatures = transitionGroupFeatures.head(1)

def apply_smoothing(group):
if smooth == 'savgol':
Expand All @@ -107,7 +120,6 @@ def apply_smoothing(group):

return group


to_plot = to_plot.groupby('annotation').apply(apply_smoothing).reset_index(drop=True)

fig = to_plot.plot(x='rt', y='intensity', kind='chromatogram', by='annotation', backend='ms_bokeh', annotation_data=transitionGroupFeatures, width=width, show_plot=False, **kwargs)
Expand Down
4 changes: 4 additions & 0 deletions massdash/loaders/GenericSpectrumLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,8 @@ def plotChromatogram(self,
else:
transitionGroupFeatures = None

# set title automatically (as peptide and charge state) if not set by user
if not 'title' in kwargs.keys():
kwargs['title'] = f"{seq}_{charge}"

return super().plotChromatogram(transitionGroup, transitionGroupFeatures, include_ms1=include_ms1, smooth=smooth, sgolay_polynomial_order=sgolay_polynomial_order, sgolay_frame_length=sgolay_frame_length, **kwargs)

0 comments on commit 14e5128

Please sign in to comment.