Skip to content

Commit

Permalink
Merge pull request #50 from xomicsdatascience/spectra_plotting
Browse files Browse the repository at this point in the history
added plotting functions for spectra and spectra comparison
  • Loading branch information
AlexandreHutton authored Oct 5, 2022
2 parents f0352d4 + f38533d commit b038609
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion csodiaq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.1.6'
__version__ = '1.1.7'

from csodiaq import csodiaq_gui, csodiaq, csodiaq_identification_functions, csodiaq_mgf_cleaning_functions, \
csodiaq_quantification_functions, idpicker, IdentificationSpectraMatcher, spectra_matcher_functions
Expand Down
1 change: 1 addition & 0 deletions csodiaq/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import spectra
60 changes: 60 additions & 0 deletions csodiaq/plotting/spectra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pyteomics.mzxml
from matplotlib import pyplot as plt
from csodiaq.spectrum import Spectrum


def spectrum_lineplot(spectrum: Spectrum,
positive: bool = True,
color: str = 'black',
label: str = None):
"""
Plots the input Spectrum as a line plot
Parameters
----------
spectrum : Spectrum
Spectrum object
positive : bool
Whether plot should have positive or negative intensities
color : str
Color for the line in the plot.
label : str
Label to use for the legend.
Returns
-------
None
"""
intensity = spectrum.intensity
max_intensity = max(intensity)
intensity = [i/max_intensity for i in intensity]
if not positive:
intensity = [-i for i in intensity]
plt.vlines(spectrum.mz, [0]*len(intensity), intensity, colors=color, label=label)
plt.hlines(0, min(spectrum.mz), max(spectrum.mz), colors='black')
return


def spectrum_comparison_lineplot(spectrum_positive: Spectrum,
spectrum_negative: Spectrum,
colors: list = ('dodgerblue', 'purple'),
labels: list = None):
"""
Produces a plot with input Spectrum in positive/negative y directions.
Parameters
----------
spectrum_positive : Spectrum
Spectrum to plot with positive intensity.
spectrum_negative : Spectrum
Spectrum to plot with negative intensity.
colors : list
List of colors to use for the plots.
labels : list
List of labels to use for the legends.
Returns
-------
None
"""
plt.figure()
spectrum_lineplot(spectrum_positive, positive=True, color=colors[0], label=labels[0])
spectrum_lineplot(spectrum_negative, positive=False, color=colors[1], label=labels[1])
return

0 comments on commit b038609

Please sign in to comment.