Pyteomics documentation v4.5dev3

pylab_aux - auxiliary functions for plotting with pylab

«  traml - targeted MS transition data in TraML format   ::   Contents   ::   xml - utilities for XML parsing  »

pylab_aux - auxiliary functions for plotting with pylab

This module serves as a collection of useful routines for data plotting with matplotlib.

Generic plotting

plot_line() - plot a line.

scatter_trend() - plot a scatter plot with a regression line.

plot_function_3d() - plot a 3D graph of a function of two variables.

plot_function_contour() - plot a contour graph of a function of two variables.

Spectrum visualization

plot_spectrum() - plot a single spectrum (m/z vs intensity).

annotate_spectrum() - plot and annotate peaks in MS/MS spectrum.

FDR control

plot_qvalue_curve() - plot the dependence of q-value on the amount of PSMs (similar to a ROC curve).

Dependencies

This module requires matplotlib. Optional dependencies: adjustText.


pyteomics.pylab_aux.annotate_spectrum(spectrum, peptide, *args, **kwargs)[source]

Plot a spectrum and annotate matching fragment peaks.

Parameters:
  • spectrum (dict) – A spectrum as returned by Pyteomics parsers. Needs to have ‘m/z array’ and ‘intensity array’ keys.
  • peptide (str) – A modX sequence.
  • backend (str, keyword only, optional) – One of {‘default’,}.
  • ion_types (Container, keyword only, optional) – Ion types to be considered for annotation. Default is (‘b’, ‘y’).
  • maxcharge (int, keyword only, optional) – Maximum charge state for fragment ions to be considered. Default is 1.
  • colors (dict, keyword only, optional) – Keys are ion types, values are colors to plot the annotated peaks with. Defaults to a red-blue scheme.
  • ftol (float, keyword only, optional) – A fixed m/z tolerance value for peak matching. Alternative to rtol.
  • rtol (float, keyword only, optional) – A relative m/z error for peak matching. Default is 10 ppm.
  • text_kw (dict, keyword only, optional) – Keyword arguments for pylab.text().
  • ion_comp (dict, keyword only, optional) – A dictionary defining ion compositions to override pyteomics.mass.std_ion_comp.
  • mass_data (dict, keyword only, optional) – A dictionary of element masses to override pyteomics.mass.nist_mass.
  • aa_mass (dict, keyword only, optional) – A dictionary of amino acid residue masses.
  • *args – Passed to the plotting backend.
  • **kwargs – Passed to the plotting backend.
  • centroided (bool, keyword only, optional) – Passed to plot_spectrum(). Only works with default backend.
  • adjust_text (bool, keyword only, optional) – Adjust the overlapping text annotations using adjustText. Only works with default backend.
  • adjust_kw (dict, keyword only, optional) – Keyword arguments for adjust_text(). Only works with default backend.
pyteomics.pylab_aux.plot_function_3d(x, y, function, **kwargs)[source]

Plot values of a function of two variables in 3D.

More on 3D plotting in pylab:

http://www.scipy.org/Cookbook/Matplotlib/mplot3D

Parameters:
  • x (array_like of float) – The plotting range on X axis.
  • y (array_like of float) – The plotting range on Y axis.
  • function (function) – The function to plot.
  • plot_type ({'surface', 'wireframe', 'scatter', 'contour', 'contourf'}, keyword only, optional) – The type of a plot, see scipy cookbook for examples. The default value is ‘surface’.
  • num_contours (int) – The number of contours to plot, 50 by default.
  • xlabel (str, keyword only, optional) – The X axis label. Empty by default.
  • ylabel (str, keyword only, optional) – The Y axis label. Empty by default.
  • zlabel (str, keyword only, optional) – The Z axis label. Empty by default.
  • title (str, keyword only, optional) – The title. Empty by default.
  • **kwargs – Passed to the respective plotting function.
pyteomics.pylab_aux.plot_function_contour(x, y, function, **kwargs)[source]

Make a contour plot of a function of two variables.

Parameters:
  • y (x,) – The positions of the nodes of a plotting grid.
  • function (function) – The function to plot.
  • filling (bool) – Fill contours if True (default).
  • num_contours (int) – The number of contours to plot, 50 by default.
  • ylabel (xlabel,) – The axes labels. Empty by default.
  • title (str, optional) – The title. Empty by default.
  • **kwargs – Passed to pylab.contour() or pylab.contourf().
pyteomics.pylab_aux.plot_line(a, b, xlim=None, *args, **kwargs)[source]

Plot a line y = a * x + b.

Parameters:
  • a (float) – The slope of the line.
  • b (float) – The intercept of the line.
  • xlim (tuple, optional) – Minimal and maximal values of x. If not given, pylab.xlim() will be called.
  • *args – Passed to pylab.plot() after x and y values.
  • **kwargs – Passed to pylab.plot().
Returns:

out – The line object.

Return type:

matplotlib.lines.Line2D

pyteomics.pylab_aux.plot_qvalue_curve(qvalues, *args, **kwargs)[source]

Plot a curve with q-values on the X axis and corresponding PSM number (starting with 1) on the Y axis.

Parameters:
  • qvalues (array-like) – An array of q-values for sorted PSMs.
  • xlabel (str, keyword only, optional) – Label for the X axis. Default is “q-value”.
  • ylabel (str, keyword only, optional) – Label for the Y axis. Default is “# of PSMs”.
  • title (str, keyword only, optional) – The title. Empty by default.
  • *args – Given to pylab.plot() after x and y.
  • **kwargs – Given to pylab.plot().
Returns:

out

Return type:

matplotlib.lines.Line2D

pyteomics.pylab_aux.plot_spectrum(spectrum, centroided=True, *args, **kwargs)[source]

Plot a spectrum, assuming it is a dictionary containing “m/z array” and “intensity array”.

Parameters:
  • spectrum (dict) – A dictionary, as returned by MGF, mzML or mzXML parsers. Must contain “m/z array” and “intensity array” keys with decoded arrays.
  • centroided (bool, optional) – If True (default), peaks of the spectrum are plotted using pylab.bar(). If False, the arrays are simply plotted using pylab.plot().
  • xlabel (str, keyword only, optional) – Label for the X axis. Default is “m/z”.
  • ylabel (str, keyword only, optional) – Label for the Y axis. Default is “intensity”.
  • title (str, keyword only, optional) – The title. Empty by default.
  • *args – Given to pylab.plot() or pylab.bar() (depending on centroided).
  • **kwargs – Given to pylab.plot() or pylab.bar() (depending on centroided).
pyteomics.pylab_aux.scatter_trend(x, y=None, **kwargs)[source]

Make a scatter plot with a linear regression.

Parameters:
  • x (array_like of float) – 1-D array of floats. If y is omitted, x must be a 2-D array of shape (N, 2).
  • y (array_like of float, optional) – 1-D arrays of floats. If y is omitted or None, x must be a 2-D array of shape (N, 2).
  • plot_trend (bool, optional) – If True then plot a trendline (default).
  • plot_sigmas (bool, optional) – If True then plot confidence intervals of the linear fit. False by default.
  • show_legend (bool, optional) – If True, a legend will be shown with linear fit equation, correlation coefficient, and standard deviation from the fit. Default is True.
  • title (str, optional) – The title. Empty by default.
  • ylabel (xlabel,) – The axes labels. Empty by default.
  • alpha_legend (float, optional) – Legend box transparency. 1.0 by default
  • scatter_kwargs (dict, optional) – Keyword arguments for pylab.scatter(). Empty by default.
  • plot_kwargs (dict, optional) – Keyword arguments for plot_line(). By default, sets xlim and label.
  • legend_kwargs (dict, optional) – Keyword arguments for pylab.legend(). Default is {'loc': 'upper left'}.
  • sigma_kwargs (dict, optional) – Keyword arguments for pylab.plot() used for sigma lines. Default is {'color': 'red', 'linestyle': 'dashed'}.
  • sigma_values (iterable, optional) – Each value will be multiplied with standard error of the fit, and the line shifted by the resulting value will be plotted. Default is range(-3, 4).
  • regression (callable, optional) – Function to perform linear regression. Will be given x and y as arguments. Must return a 4-tuple: (a, b, r, stderr). Default is pyteomics.auxiliary.linear_regression().
Returns:

out – A (scatter_plot, trend_line, sigma_lines, legend) tuple.

Return type:

tuple

«  traml - targeted MS transition data in TraML format   ::   Contents   ::   xml - utilities for XML parsing  »