diff --git a/massdash/loaders/GenericChromatogramLoader.py b/massdash/loaders/GenericChromatogramLoader.py index fe969a1..2d04eec 100644 --- a/massdash/loaders/GenericChromatogramLoader.py +++ b/massdash/loaders/GenericChromatogramLoader.py @@ -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) \ No newline at end of file diff --git a/massdash/loaders/GenericRawDataLoader.py b/massdash/loaders/GenericRawDataLoader.py index 83a9848..002ddd2 100644 --- a/massdash/loaders/GenericRawDataLoader.py +++ b/massdash/loaders/GenericRawDataLoader.py @@ -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 @@ -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 @@ -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': @@ -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) diff --git a/massdash/loaders/GenericSpectrumLoader.py b/massdash/loaders/GenericSpectrumLoader.py index de69521..9491f97 100644 --- a/massdash/loaders/GenericSpectrumLoader.py +++ b/massdash/loaders/GenericSpectrumLoader.py @@ -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) \ No newline at end of file