compomics / ms2pip

MS²PIP: Fast and accurate peptide spectrum prediction for multiple fragmentation methods, instruments, and labeling techniques.
https://ms2pip.readthedocs.io
Apache License 2.0
35 stars 18 forks source link

spectrum_utils: keyword grid_b is not recognized #205

Closed aretaon closed 9 months ago

aretaon commented 10 months ago

Bug summary

Python returns ValueError: keyword grid_b is not recognized; when running SinglePrediction.plot_prediction.

This is related to spectrum_utils version 0.3.5 which still utilizes the b parameter which was deprectated in matplotlib 3.5 (see https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.5.0.html#the-first-parameter-of-axes-grid-and-axis-grid-has-been-renamed-to-visible).

However, ms2pip still requires spectrum_utils 0.3.5 as indicated by upgrading spectrum_utils with pip ms2pip 3.11.0 requires spectrum-utils==0.3.5, but you have spectrum-utils 0.4.2 which is incompatible.

How to reproduce

Install ms2pip on a fresh conda environment with python==3.8 using pip install ms2pip. Run the following snippet:

from ms2pip.single_prediction import SinglePrediction
ms2pip_sp = SinglePrediction(
     modification_strings=[
         "Carbamidomethyl,57.021464,opt,C"
     ]
)

ms2pip_sp.plot_prediction("GSIGECIAEEEEFELDSESNR",  "6|Carbamidomethyl", 3)

System

OS: Win10 Python: 3.8 pip: pip 23.3

Detailed traceback

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
      1 ms2pip_sp = SinglePrediction(
      2      modification_strings=[
      3          "Carbamidomethyl,57.021464,opt,C"
      4      ]
      5 )
----> 7 ms2pip_sp.plot_prediction("GSIGECIAEEEEFELDSESNR",  "6|Carbamidomethyl", 3)

File ~\Anaconda3\envs\ms2pip\lib\site-packages\ms2pip\single_prediction.py:222, in SinglePrediction.plot_prediction(self, peptide, modifications, charge, prediction, ax, filename)
    220 if not ax:
    221     ax = plt.gca()
--> 222 sup.spectrum(spectrum, ax=ax)
    223 ax.set_title("MS²PIP prediction for " + identifier)
    224 if filename:

File ~\Anaconda3\envs\ms2pip\lib\site-packages\spectrum_utils\plot.py:141, in spectrum(spec, color_ions, annotate_ions, annot_kws, mirror_intensity, grid, ax)
    139 ax.yaxis.set_minor_locator(mticker.AutoMinorLocator())
    140 if grid in (True, 'both', 'major'):
--> 141     ax.grid(b=True, which='major', color='#9E9E9E', linewidth=0.2)
    142 if grid in (True, 'both', 'minor'):
    143     ax.grid(b=True, which='minor', color='#9E9E9E', linewidth=0.2)

File ~\Anaconda3\envs\ms2pip\lib\site-packages\matplotlib\axes\_base.py:3194, in _AxesBase.grid(self, visible, which, axis, **kwargs)
   3192 _api.check_in_list(['x', 'y', 'both'], axis=axis)
   3193 if axis in ['x', 'both']:
-> 3194     self.xaxis.grid(visible, which=which, **kwargs)
   3195 if axis in ['y', 'both']:
   3196     self.yaxis.grid(visible, which=which, **kwargs)

File ~\Anaconda3\envs\ms2pip\lib\site-packages\matplotlib\axis.py:1698, in Axis.grid(self, visible, which, **kwargs)
   1695 if which in ['major', 'both']:
   1696     gridkw['gridOn'] = (not self._major_tick_kw['gridOn']
   1697                         if visible is None else visible)
-> 1698     self.set_tick_params(which='major', **gridkw)
   1699 self.stale = True

File ~\Anaconda3\envs\ms2pip\lib\site-packages\matplotlib\axis.py:944, in Axis.set_tick_params(self, which, reset, **kwargs)
    931 """
    932 Set appearance parameters for ticks, ticklabels, and gridlines.
    933
   (...)
    941     gridlines.
    942 """
    943 _api.check_in_list(['major', 'minor', 'both'], which=which)
--> 944 kwtrans = self._translate_tick_params(kwargs)
    946 # the kwargs are stored in self._major/minor_tick_kw so that any
    947 # future new ticks will automatically get them
    948 if reset:

File ~\Anaconda3\envs\ms2pip\lib\site-packages\matplotlib\axis.py:1088, in Axis._translate_tick_params(kw, reverse)
   1086 for key in kw_:
   1087     if key not in allowed_keys:
-> 1088         raise ValueError(
   1089             "keyword %s is not recognized; valid keywords are %s"
   1090             % (key, allowed_keys))
   1091 kwtrans.update(kw_)
   1092 return kwtrans

ValueError: keyword grid_b is not recognized; valid keywords are ['size', 'width', 'color', 'tickdir', 'pad', 'labelsize', 'labelcolor', 'zorder', 'gridOn', 'tick1On', 'tick2On', 'label1On', 'label2On', 'length', 'direction', 'left', 'bottom', 'right', 'top', 'labelleft', 'labelbottom', 'labelright', 'labeltop', 'labelrotation', 'grid_agg_filter', 'grid_alpha', 'grid_animated', 'grid_antialiased', 'grid_clip_box', 'grid_clip_on', 'grid_clip_path', 'grid_color', 'grid_dash_capstyle', 'grid_dash_joinstyle', 'grid_dashes', 'grid_data', 'grid_drawstyle', 'grid_figure', 'grid_fillstyle', 'grid_gapcolor', 'grid_gid', 'grid_in_layout', 'grid_label', 'grid_linestyle', 'grid_linewidth', 'grid_marker', 'grid_markeredgecolor', 'grid_markeredgewidth', 'grid_markerfacecolor', 'grid_markerfacecoloralt', 'grid_markersize', 'grid_markevery', 'grid_mouseover', 'grid_path_effects', 'grid_picker', 'grid_pickradius', 'grid_rasterized', 'grid_sketch_params', 'grid_snap', 'grid_solid_capstyle', 'grid_solid_joinstyle', 'grid_transform', 'grid_url', 'grid_visible', 'grid_xdata', 'grid_ydata', 'grid_zorder', 'grid_aa', 'grid_c', 'grid_ds', 'grid_ls', 'grid_lw', 'grid_mec', 'grid_mew', 'grid_mfc', 'grid_mfcalt', 'grid_ms']
RalfG commented 9 months ago

Hi @aretaon,

I'm afraid you will have to downgrade matplotlib for this to work again. Alternatively, you could try the development version of MS²PIP 4.0: https://pypi.org/project/ms2pip/4.0.0.dev5/. This version uses the latest spectrum_utils, and has a much improved Python API. The prediction models are the same.

Let me know if either solutions work for you.

Best, Ralf

aretaon commented 9 months ago

Hi Ralf,

thanks for looking into this. We eventually went with rewriting the required function to work with ms2pip 0.4.2 but I will have a look into the 4.0 version. I think we can consider this closed as you have probably addressed the issue in the upcoming version.

Best Julian