pyms.Display

Class to Display Ion Chromatograms and TIC.

Classes:

ClickEventHandler(peak_list[, fig, ax, …])

Class to enable clicking of chromatogram to view the intensities top n most intense ions at that peak, and viewing of the mass spectrum with a right click

Display([fig, ax])

Class to display Ion Chromatograms and Total Ion Chromatograms from pyms.IonChromatogram.IonChromatogram using matplotlib.pyplot.

Functions:

invert_mass_spec(mass_spec[, inplace])

Invert the mass spectrum for display in a head2tail plot.

plot_head2tail(ax, top_mass_spec, …[, …])

Plots two mass spectra head to tail.

plot_ic(ax, ic[, minutes])

Plots an Ion Chromatogram.

plot_mass_spec(ax, mass_spec, **kwargs)

Plots a Mass Spectrum.

plot_peaks(ax, peak_list[, label, style])

Plots the locations of peaks as found by PyMassSpec.

class ClickEventHandler(peak_list, fig=None, ax=None, tolerance=0.005, n_intensities=5)[source]

Bases: object

Class to enable clicking of chromatogram to view the intensities top n most intense ions at that peak, and viewing of the mass spectrum with a right click

Methods:

get_n_largest(intensity_list)

Computes the indices of the largest n ion intensities for writing to console.

onclick(event)

Finds the n highest intensity m/z channels for the selected peak.

get_n_largest(intensity_list)[source]

Computes the indices of the largest n ion intensities for writing to console.

Parameters

intensity_list (List[float]) – List of Ion intensities

Return type

List[int]

Returns

Indices of largest n ion intensities

onclick(event)[source]

Finds the n highest intensity m/z channels for the selected peak. The peak is selected by clicking on it. If a button other than the left one is clicked, a new plot of the mass spectrum is displayed.

Parameters

event – a mouse click by the user

class Display(fig=None, ax=None)[source]

Bases: object

Class to display Ion Chromatograms and Total Ion Chromatograms from pyms.IonChromatogram.IonChromatogram using matplotlib.pyplot.

Parameters
  • fig (Figure) – figure object to use. Default None.

  • ax (Axes) – axes object to use. Default None.

If fig is not given then fig and ax default to:

>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)

If only fig is given then ax defaults to:

>>> ax = fig.add_subplot(111)
Author

Sean O’Callaghan

Author

Vladimir Likic

Author

Dominic Davis-Foster

Methods:

do_plotting([plot_label])

Plots TIC and IC(s) if they have been created by plot_tic() or plot_ic().

get_5_largest(intensity_list)

Returns the indices of the 5 largest ion intensities.

onclick(event)

Finds the 5 highest intensity m/z channels for the selected peak.

plot_ic(ic, **kwargs)

Plots an Ion Chromatogram.

plot_mass_spec(mass_spec, **kwargs)

Plots a Mass Spectrum.

plot_peaks(peak_list[, label])

Plots the locations of peaks as found by PyMassSpec.

plot_tic(tic[, minutes])

Plots a Total Ion Chromatogram.

save_chart(filepath[, filetypes])

Save the chart to the given path with the given filetypes.

show_chart()

Show the chart on screen.

do_plotting(plot_label=None)[source]

Plots TIC and IC(s) if they have been created by plot_tic() or plot_ic().

Also adds detected peaks if they have been added by plot_peaks()

Parameters

plot_label (Optional[str]) – Label for the plot to show e.g. the data origin. Default None.

static get_5_largest(intensity_list)[source]

Returns the indices of the 5 largest ion intensities.

Parameters

intensity_list (List[float]) – List of Ion intensities

Return type

List[int]

onclick(event)[source]

Finds the 5 highest intensity m/z channels for the selected peak. The peak is selected by clicking on it. If a button other than the left one is clicked, a new plot of the mass spectrum is displayed.

Parameters

event – a mouse click by the user

plot_ic(ic, **kwargs)[source]

Plots an Ion Chromatogram.

Parameters

ic (IonChromatogram) – Ion Chromatograms m/z channels for plotting

Other Parameters

matplotlib.lines.Line2D properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.

Example:

>>> plot_ic(im.get_ic_at_index(5), label='IC @ Index 5', linewidth=2)

See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs

Return type

List[Line2D]

plot_mass_spec(mass_spec, **kwargs)[source]

Plots a Mass Spectrum.

Parameters

mass_spec (MassSpectrum) – The mass spectrum at a given time/index

Other Parameters

matplotlib.lines.Line2D properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.

Example:

>>> plot_mass_spec(im.get_ms_at_index(5), linewidth=2)
>>> ax.set_title(f"Mass spec for peak at time {im.get_time_at_index(5):5.2f}")

See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs

Return type

BarContainer

plot_peaks(peak_list, label='Peaks')[source]

Plots the locations of peaks as found by PyMassSpec.

Parameters
  • peak_list (List[Peak]) – List of peaks to plot

  • label (str) – label for plot legend. Default 'Peaks'.

Return type

List[Line2D]

plot_tic(tic, minutes=False, **kwargs)[source]

Plots a Total Ion Chromatogram.

Parameters
  • tic (IonChromatogram) – Total Ion Chromatogram.

  • minutes (bool) – Whether to show the time in minutes. Default False.

Other Parameters

matplotlib.lines.Line2D properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.

Example:

>>> plot_tic(data.tic, label='TIC', linewidth=2)

See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs

Return type

List[Line2D]

save_chart(filepath, filetypes=None)[source]

Save the chart to the given path with the given filetypes.

Parameters
  • filepath (str) – Path and filename to save the chart as. Should not include extension.

  • filetypes (Optional[List[str]]) – List of filetypes to use. Default None.

Author

Dominic Davis-Foster

show_chart()[source]

Show the chart on screen.

Author

Dominic Davis-Foster

invert_mass_spec(mass_spec, inplace=False)[source]

Invert the mass spectrum for display in a head2tail plot.

Parameters
  • mass_spec (MassSpectrum) – The Mass Spectrum to normalize

  • inplace (bool) – Whether the inversion should be applied to the MassSpectrum object given, or to a copy (default behaviour). Default False.

Return type

MassSpectrum

Returns

The normalized mass spectrum

plot_head2tail(ax, top_mass_spec, bottom_mass_spec, top_spec_kwargs=None, bottom_spec_kwargs=None)[source]

Plots two mass spectra head to tail.

Parameters
  • ax (Axes) – The axes to plot the MassSpectra on

  • top_mass_spec (MassSpectrum) – The Mass Spectrum to plot on top

  • bottom_mass_spec (MassSpectrum) – The Mass Spectrum to plot on the bottom

  • top_spec_kwargs (Optional[Dict]) – A dictionary of keyword arguments for the top mass spectrum. Defaults to red with a line width of 0.5

  • bottom_spec_kwargs (Optional[Dict]) – A dictionary of keyword arguments for the bottom mass spectrum. Defaults to blue with a line width of 0.5

top_spec_kwargs and bottom_spec_kwargs are used to specify properties like a line label

(for auto legends), linewidth, antialiasing, marker face color.

See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs

Returns

A tuple of container with all the bars and optionally errorbars for the top and bottom spectra.

Return type

tuple of matplotlib.container.BarContainer

plot_ic(ax, ic, minutes=False, **kwargs)[source]

Plots an Ion Chromatogram.

Parameters
  • ax (Axes) – The axes to plot the IonChromatogram on

  • ic (IonChromatogram) – Ion Chromatograms m/z channels for plotting

  • minutes (bool) – Whether the x-axis should be plotted in minutes. Default False (plotted in seconds). Default False.

Other Parameters

matplotlib.lines.Line2D properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.

Example:

>>> plot_ic(im.get_ic_at_index(5), label='IC @ Index 5', linewidth=2)

See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs

Return type

List[Line2D]

Returns

A list of Line2D objects representing the plotted data.

plot_mass_spec(ax, mass_spec, **kwargs)[source]

Plots a Mass Spectrum.

Parameters
  • ax (Axes) – The axes to plot the MassSpectrum on

  • mass_spec (MassSpectrum) – The mass spectrum to plot

Other Parameters

matplotlib.lines.Line2D properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.

Example:

>>> plot_mass_spec(im.get_ms_at_index(5), linewidth=2)
>>> ax.set_title(f"Mass spec for peak at time {im.get_time_at_index(5):5.2f}")

See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs

Returns

Container with all the bars and optionally errorbars.

Return type

matplotlib.container.BarContainer

plot_peaks(ax, peak_list, label='Peaks', style='o')[source]

Plots the locations of peaks as found by PyMassSpec.

Parameters
  • ax (Axes) – The axes to plot the peaks on

  • peak_list (List[Peak]) – List of peaks to plot

  • label (str) – label for plot legend. Default 'Peaks'.

  • style (str) – The marker style. See https://matplotlib.org/3.1.1/api/markers_api.html for a complete list. Default 'o'.

Return type

List[Line2D]

Returns

A list of Line2D objects representing the plotted data.