author
int64
658
755k
date
stringlengths
19
19
timezone
int64
-46,800
43.2k
hash
stringlengths
40
40
message
stringlengths
5
490
mods
list
language
stringclasses
20 values
license
stringclasses
3 values
repo
stringlengths
5
68
original_message
stringlengths
12
491
377,522
16.09.2021 19:36:44
-10,800
47a72b4c450b22ac3b4c5478cf9c0acc66b92285
Add draft of new example
[ { "change_type": "ADD", "old_path": null, "new_path": "doc/source/_static/example_annotation.py", "diff": "+from pyteomics import pylab_aux as pa, usi\n+spectrum = usi.proxi('mzspec:PXD004732:01650b_BC2-TUM_first_pool_53_01_01-3xHCD-1h-R2:scan:41840', 'massive')\n+peptide = 'WNQLQAFWGTGK'\n+\n+pa.annotate_spectrum(spectrum, peptide, precursor_charge=2, backend='spectrum_utils',\n+ scaling='root', min_intensity=0.05, ion_types='aby', remove_precursor_peak=True, colors={'a': 'yellow'})\n" }, { "change_type": "MODIFY", "old_path": "doc/source/examples.rst", "new_path": "doc/source/examples.rst", "diff": "@@ -12,3 +12,4 @@ Contents:\nexamples/example_fasta\nexamples/example_msms\nexamples/example_filtering\n+ examples/example_annotation\n" }, { "change_type": "ADD", "old_path": null, "new_path": "doc/source/examples/example_annotation.rst", "diff": "+Example 4: Spectrum Annotation\n+==============================\n+\n+In this example we will retrieve a spectrum and visualize it, a lot like in `example 2 <example_msms.html>`_.\n+However, we will not read the spectrum from a file, but retrieve it directly from an online repository.\n+We will also use Pyteomics to annotate fragment ions. Let's get to it!\n+\n+We are going to need `spectrum_utils <https://github.com/bittremieux/spectrum_utils>`_, a tool for spectrum\n+processing and visualization. Pyteomics integrates with it and allows to create annotated spectrum plots easily.\n+\n+\n+.. literalinclude:: ../_static/example_annotation.py\n+ :language: python\n+\n" }, { "change_type": "MODIFY", "old_path": "doc/source/examples/example_msms.rst", "new_path": "doc/source/examples/example_msms.rst", "diff": "Example 2: Fragmentation\n========================\n+.. note::\n+ Pyteomics has come a long way since this example was written.\n+ Check `example 4 <example_annotation.html>`_ for new Pyteomics tools you should know about.\n+\nIn this example, we are going to retrieve MS/MS data from an MGF file and\ncompare it to identification info we read from a pepXML file. We are going to\ncompare the MS/MS spectrum in the file with the theoretical spectrum of a\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add draft of new example
377,522
20.09.2021 16:43:45
-10,800
448af682dac7a3fcc75c421c4dce3ceed710dbd0
Finish draft of Example 4
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "(`#35 <https://github.com/levitsky/pyteomics/pull/35>`_\nand `#38 <https://github.com/levitsky/pyteomics/pull/38>`_ by Joshua Klein)\nwith new module :py:mod:`pyteomics.mzmlb`.\n+\n- Add ProteomeExchange backend for PROXI requests and implement an aggregator for responses from all backends\n(`#36 <https://github.com/levitsky/pyteomics/pull/36>`_,\n`#45 <https://github.com/levitsky/pyteomics/pull/45>`_, and\n`#55 <https://github.com/levitsky/pyteomics/pull/55>`_ by Joshua Klein)\nin :py:mod:`pyteomics.usi`.\n+\n- Add support for `ProForma <https://www.psidev.info/proforma>`_\n(`#37 <https://github.com/levitsky/pyteomics/pull/37>`_ by Joshua Klein)\nin new module :py:mod:`pyteomics.proforma`.\n+\n- New arguments `keep_nterm_M` and `fix_aa` in :py:func:`pyteomics.fasta.shuffle`\n(`#54 <https://github.com/levitsky/pyteomics/pull/54>`_ by Vladimir Gorshkov).\n+\n- Fx for unwanted warnings in :py:func:`pyteomics.auxiliary.file_helpers._check_use_index` when\n`use_index` is explicitly passed (`#52 <https://github.com/levitsky/pyteomics/issues/52>`_).\n+\n- Update the default XML schema for featureXML and fix issues with incorrectly specified data types\n(`#53 <https://github.com/levitsky/pyteomics/pull/53>`_).\n+\n- Add a new backend for spectrum annotation and plotting. :py:func:`pyteomics.pylab_aux.plot_spectrum` and\n:py:func:`pyteomics.pylab_aux.annotate_spectrum` can now use\n`spectrum_utils <https://github.com/bittremieux/spectrum_utils>`_ under the hood\n(`#43 <https://github.com/levitsky/pyteomics/pull/43>`_).\n+\n+ See new `Example 4 <examples/example_annotation.html>`_ for demonstration.\n+\n- New function :py:func:`pyteomics.pylab_aux.mirror` for making a\n`spectrum_utils <https://github.com/bittremieux/spectrum_utils>`_ mirror plot.\n+\n- :py:func:`pyteomics.pylab_aux.plot_spectrum` and :py:func:`pyteomics.pylab_aux.annotate_spectrum` now\nalways return :py:class:`matplotlib.pyplot.Axes`.\n+\n- Add a warning when passing an existing file by name in writing functions.\nThe default mode for output files will change from `'a'` to `'w'` in a future version.\n" }, { "change_type": "ADD", "old_path": "doc/source/_static/example_annotation.png", "new_path": "doc/source/_static/example_annotation.png", "diff": "Binary files /dev/null and b/doc/source/_static/example_annotation.png differ\n" }, { "change_type": "MODIFY", "old_path": "doc/source/_static/example_annotation.py", "new_path": "doc/source/_static/example_annotation.py", "diff": "from pyteomics import pylab_aux as pa, usi\n-spectrum = usi.proxi('mzspec:PXD004732:01650b_BC2-TUM_first_pool_53_01_01-3xHCD-1h-R2:scan:41840', 'massive')\n+import matplotlib.pyplot as plt\n+spectrum = usi.proxi(\n+ 'mzspec:PXD004732:01650b_BC2-TUM_first_pool_53_01_01-3xHCD-1h-R2:scan:41840',\n+ 'massive')\npeptide = 'WNQLQAFWGTGK'\npa.annotate_spectrum(spectrum, peptide, precursor_charge=2, backend='spectrum_utils',\n- scaling='root', min_intensity=0.05, ion_types='aby', remove_precursor_peak=True, colors={'a': 'yellow'})\n+ ion_types='aby', title=peptide)\n+\n+from pyteomics import mass\n+peptide = 'DLTDYLoxMK' # oxidized methionine\n+aa_mass = mass.std_aa_mass.copy()\n+aa_mass['ox'] = 15.9949 # define the mass of the label\n+\n+usi_top = 'mzspec:MSV000079960:DY_HS_Exp7-Ad1:scan:30372'\n+usi_bottom = 'mzspec:MSV000080679:j11962_C1orf144:scan:10671'\n+\n+spectrum_top = usi.proxi(usi_top, 'massive')\n+spectrum_bottom = usi.proxi(usi_bottom, 'massive')\n+\n+fig, ax = plt.subplots(figsize=(12, 6))\n+pa.mirror(spectrum_top, spectrum_bottom, peptide=peptide, precursor_charge=2,\n+ aa_mass=aa_mass, ion_types='aby', ax=ax, title=peptide, ftol=0.5, scaling='root',\n+ remove_precursor_peak=True)\n+\n+plt.show()\n" }, { "change_type": "ADD", "old_path": "doc/source/_static/example_mirror.png", "new_path": "doc/source/_static/example_mirror.png", "diff": "Binary files /dev/null and b/doc/source/_static/example_mirror.png differ\n" }, { "change_type": "MODIFY", "old_path": "doc/source/examples/example_annotation.rst", "new_path": "doc/source/examples/example_annotation.rst", "diff": "@@ -3,12 +3,60 @@ Example 4: Spectrum Annotation\nIn this example we will retrieve a spectrum and visualize it, a lot like in `example 2 <example_msms.html>`_.\nHowever, we will not read the spectrum from a file, but retrieve it directly from an online repository.\n-We will also use Pyteomics to annotate fragment ions. Let's get to it!\n+We will also use Pyteomics to annotate fragment ions. Let's get to it! Full code can be downloaded\n+:download:`here <../_static/example_annotation.py>`.\n-We are going to need `spectrum_utils <https://github.com/bittremieux/spectrum_utils>`_, a tool for spectrum\n+We are going to need `spectrum_utils <https://github.com/bittremieux/spectrum_utils>`_, a library for spectrum\nprocessing and visualization. Pyteomics integrates with it and allows to create annotated spectrum plots easily.\n+First, we use a spectrum's `Universal Spectrum Identifier <http://www.psidev.info/usi>`_ to download it\n+directly from the `MassIVE <https://massive.ucsd.edu/>`_ repository.\n+Pyteomics provides tools for that in the :py:mod:`pyteomics.usi` module.\n.. literalinclude:: ../_static/example_annotation.py\n:language: python\n+ :lines: 1-6\n+Next, just plot the spectrum and annotate it with a single function call:\n+\n+.. literalinclude:: ../_static/example_annotation.py\n+ :language: python\n+ :lines: 8-9\n+\n+You will see a simple *spectrum_utils* annotation of the spectrum:\n+\n+.. image:: ../_static/example_annotation.png\n+\n+:py:func:`pyteomics.pylab_aux.annotate_spectrum` accepts a number of keyword parameters, allowing you to do just about\n+everything you can do with :py:mod:`spectrum_utils`.\n+\n+.. note::\n+ You can omit `backend='spectrum_utils'`, and :py:func:`annotate_spectrum` will use the default backend.\n+ The default backend supports less spectrum preprocessing features.\n+\n+Another thing *spectrum_utils* lets you do is mirror plots. Following the `spectrum_utils documentation\n+<https://spectrum-utils.readthedocs.io/en/latest/plotting.html#mirror-plot>`_, we are going to make this part more\n+complex, showing more of what you can do. This example includes modified peptides and a bit of spectrum preprocessing.\n+\n+To annotate the spectrum of a modified peptide, you can use the *spectrum_utils* notation, but you can also\n+use the *modX* notation which is standard for Pyteomics:\n+\n+.. literalinclude:: ../_static/example_annotation.py\n+ :language: python\n+ :lines: 11-14\n+\n+Next, choose two spectra:\n+\n+.. literalinclude:: ../_static/example_annotation.py\n+ :language: python\n+ :lines: 16-20\n+\n+And finally, produce the image with:\n+\n+.. literalinclude:: ../_static/example_annotation.py\n+ :language: python\n+ :lines: 22-25\n+\n+Here's the result:\n+\n+.. image:: ../_static/example_mirror.png\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Finish draft of Example 4
377,522
20.09.2021 17:37:19
-10,800
243830b024f50f4d682267de0dae1941a2167558
Fix for interactive annotation plots
[ { "change_type": "MODIFY", "old_path": "pyteomics/pylab_aux.py", "new_path": "pyteomics/pylab_aux.py", "diff": "@@ -644,7 +644,7 @@ def _spectrum_utils_annotate_iplot(spectrum, peptide, *args, **kwargs):\nimport spectrum_utils.iplot as supi\nwith SpectrumUtilsColorScheme(kwargs.pop('colors', None)):\nspectrum = _spectrum_utils_annotate_spectrum(spectrum, peptide, *args, **kwargs)\n- return supi.spectrum(spectrum, annot_kws=kwargs.pop('text_kw', None), ax=kwargs.pop('ax', None))\n+ return supi.spectrum(spectrum, annot_kws=kwargs.pop('text_kw', None))\n_annotation_backends = {\n@@ -684,13 +684,13 @@ def annotate_spectrum(spectrum, peptide, *args, **kwargs):\ntext_kw : dict, keyword only, optional\nKeyword arguments for :py:func:`pylab.text`.\nxlabel : str, keyword only, optional\n- Label for the X axis. Default is \"m/z\".\n+ Label for the X axis. Default is \"m/z\". Does not work with `spectrum_utils.iplot` backend.\nylabel : str, keyword only, optional\n- Label for the Y axis. Default is \"intensity\".\n+ Label for the Y axis. Default is \"intensity\". Does not work with `spectrum_utils.iplot` backend.\ntitle : str, keyword only, optional\n- The title. Empty by default.\n+ The title. Empty by default. Does not work with `spectrum_utils.iplot` backend.\nax : matplotlib.pyplot.Axes, keyword only, optional\n- Axes to draw the spectrum.\n+ Axes to draw the spectrum. Does not work with `spectrum_utils.iplot` backend.\n*args\nPassed to the plotting backend.\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Fix for interactive annotation plots
377,522
15.10.2021 17:10:09
-10,800
c4fd36615ebedce5ff5ced0ee7072e3e8c1ec54a
Implement `charge_carrier` and `absolute` arguments for m/z calculation
[ { "change_type": "MODIFY", "old_path": "pyteomics/auxiliary/structures.py", "new_path": "pyteomics/auxiliary/structures.py", "diff": "@@ -192,14 +192,15 @@ class BasicComposition(defaultdict, Counter):\ndef __mul__(self, other):\nif not isinstance(other, int):\n- raise PyteomicsError('Cannot multiply Composition by non-integer',\n- other)\n- return type(self)({k: v * other for k, v in self.items()})\n+ raise PyteomicsError('Cannot multiply Composition by non-integer', other)\n+ new = self.copy()\n+ for k in self:\n+ new[k] *= other\n+ return new\ndef __imul__(self, other):\nif not isinstance(other, int):\n- raise PyteomicsError('Cannot multiply Composition by non-integer',\n- other)\n+ raise PyteomicsError('Cannot multiply Composition by non-integer', other)\nfor elem in self:\nself[elem] *= other\nreturn self\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -144,7 +144,7 @@ and the sum of elemental compositions of its constituting amino acid residues.\n_isotope_string = r'^([A-Z][a-z+]*)(?:\\[(\\d+)\\])?$'\n_atom = r'([A-Z][a-z+]*)(?:\\[(\\d+)\\])?([+-]?\\d+)?'\n_formula = r'^({})*$'.format(_atom)\n-\n+PROTON = 'H+'\nclass Composition(BasicComposition):\n\"\"\"\n@@ -219,6 +219,25 @@ class Composition(BasicComposition):\n# Remove explicitly undefined isotopes (e.g. X[0]).\nself[_make_isotope_string(element_name, isotope_num)] = num_atoms\n+ def copy(self):\n+ c = Composition(self, charge_carrier=self._carrier_comp)\n+ c.charge = self.charge\n+ c.charge_carrier = self.charge_carrier\n+ return c\n+\n+ @staticmethod\n+ def _parse_carrier(carrier):\n+ try:\n+ sign = {'+': 1, '-': -1}[carrier[-1]]\n+ except KeyError:\n+ raise PyteomicsError('`charge carrier` must end with \"+\" or \"-\"')\n+\n+ if carrier != PROTON:\n+ carrier = carrier[:-1]\n+\n+ carrier_comp = Composition(formula=carrier, charge_carrier=None)\n+ return carrier_comp * sign\n+\ndef __init__(self, *args, **kwargs):\n\"\"\"\nA Composition object stores a chemical composition of a\n@@ -271,7 +290,11 @@ class Composition(BasicComposition):\nA dict with the masses of chemical elements (the default\nvalue is :py:data:`nist_mass`). It is used for formulae parsing only.\ncharge : int, optional\n- If not 0 then additional protons are added to the composition.\n+ If not 0 then additional protons (or see `charge_carrier`) are added to the composition.\n+ charge_carrier : str, optional\n+ A formula for the chemical group which carries charge. Must end with '+' or '-'.\n+ Default is :py:const:`H+` (a proton). If `charge` is specified, the composition of\n+ `charge_carrier` is added or subtracted from the composition of this object.\nion_comp : dict, optional\nA dict with the relative elemental compositions of peptide ion\nfragments (default is :py:data:`std_ion_comp`).\n@@ -325,12 +348,24 @@ class Composition(BasicComposition):\nself += ion_comp[kwargs['ion_type']]\n# Get charge\n- charge = self['H+']\n- if 'charge' in kwargs:\n- if charge:\n- raise PyteomicsError('Charge is specified both by the number of protons and `charge` in kwargs')\n- charge = kwargs['charge']\n- self['H+'] = charge\n+ self.charge_carrier = kwargs.get('charge_carrier')\n+ self.charge = kwargs.get('charge')\n+\n+ # special cases\n+ if self.charge and PROTON in self:\n+ raise PyteomicsError('Charge is specified both by the number of protons and `charge` in kwargs.')\n+\n+ if self.charge_carrier == PROTON and PROTON in self:\n+ self.charge = self[PROTON]\n+\n+ # normal case: parse carrier and add its composition\n+ if isinstance(self.charge_carrier, str):\n+ self._carrier_comp = self._parse_carrier(self.charge_carrier)\n+ if self.charge:\n+ self += self._carrier_comp * self.charge\n+ else:\n+ self._carrier_comp = None\n+\ndef mass(self, **kwargs):\n\"\"\"Calculate the mass or *m/z* of a :py:class:`Composition`.\n@@ -342,9 +377,11 @@ class Composition(BasicComposition):\nis not averaged for elements with specified isotopes. Default is\n:py:const:`False`.\ncharge : int, optional\n- If not 0 then m/z is calculated: the mass is increased\n- by the corresponding number of proton masses and divided\n- by `charge`.\n+ If not 0 then additional protons (or see `charge_carrier`) are added to the composition.\n+ charge_carrier : str, optional\n+ A formula for the chemical group which carries charge. Must end with '+' or '-'.\n+ Default is :py:const:`H+` (a proton). If `charge` is specified, the composition of\n+ `charge_carrier` is added or subtracted from the composition of this object.\nmass_data : dict, optional\nA dict with the masses of the chemical elements (the default\nvalue is :py:data:`nist_mass`).\n@@ -354,6 +391,9 @@ class Composition(BasicComposition):\nion_type : str, optional\nIf specified, then the polypeptide is considered to be in the form\nof the corresponding ion. Do not forget to specify the charge state!\n+ absolute : bool, optional\n+ If :py:const:`True`, then the returned value is always positive\n+ (even for negative charges.) Default is :py:const:`False`.\nReturns\n-------\n@@ -377,11 +417,31 @@ class Composition(BasicComposition):\nmass += (amount * mass_data[element_name][isotope_num][0])\n# Calculate m/z if required\n- charge = kwargs.get('charge', composition['H+'])\n+ charge = kwargs.get('charge', 0)\n+ carrier = kwargs.get('charge_carrier', composition.charge_carrier) or PROTON\n+ if charge and composition.charge and charge != composition.charge:\n+ raise PyteomicsError(\n+ 'Composition already has a different charge set ({}).'.format(composition.charge))\n+ if carrier != composition.charge_carrier and composition.charge_carrier is not None:\n+ raise PyteomicsError(\n+ 'Composition already has a different charge carrier set ({}).'.format(composition.charge_carrier))\n+\nif charge:\n- if not composition['H+']:\n- mass += mass_data['H+'][0][0] * charge\n+ if not composition.charge:\n+ if composition._carrier_comp:\n+ mass += composition._carrier_comp.mass(average=average, mass_data=mass_data) * charge\n+ else:\n+ if carrier == PROTON and PROTON in composition:\n+ raise PyteomicsError(\n+ 'Charge is specified both by the number of protons and `charge` in kwargs.')\n+ mass += composition._parse_carrier(carrier).mass(average=average, mass_data=mass_data) * charge\nmass /= charge\n+ elif composition.charge:\n+ mass /= composition.charge\n+ elif composition.charge_carrier is None and carrier == PROTON and PROTON in composition:\n+ mass /= composition[PROTON]\n+ if kwargs.get('absolute'):\n+ mass = abs(mass)\nreturn mass\n@@ -502,9 +562,14 @@ def calculate_mass(*args, **kwargs):\n-------\nmass : float\n\"\"\"\n- # Make a copy of `composition` keyword argument.\n- composition = (Composition(kwargs['composition']) if 'composition' in kwargs else Composition(*args, **kwargs))\n- return composition.mass(**kwargs)\n+ # Make a copy of `composition` keyword argument\n+ if 'composition' in kwargs:\n+ composition = Composition(kwargs['composition'])\n+ else:\n+ charge = kwargs.pop('charge', 0)\n+ charge_carrier = kwargs.pop('charge_carrier', None)\n+ composition = Composition(*args, **kwargs)\n+ return composition.mass(**kwargs, charge=charge, charge_carrier=charge_carrier)\ndef most_probable_isotopic_composition(*args, **kwargs):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Implement `charge_carrier` and `absolute` arguments for m/z calculation
377,522
15.10.2021 17:16:29
-10,800
ca3e1d8b8d37f6f1e3d9e6c42b152541d68d684d
Fix syntax error on Python 2.7
[ { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -569,7 +569,7 @@ def calculate_mass(*args, **kwargs):\ncharge = kwargs.pop('charge', 0)\ncharge_carrier = kwargs.pop('charge_carrier', None)\ncomposition = Composition(*args, **kwargs)\n- return composition.mass(**kwargs, charge=charge, charge_carrier=charge_carrier)\n+ return composition.mass(charge=charge, charge_carrier=charge_carrier, **kwargs)\ndef most_probable_isotopic_composition(*args, **kwargs):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Fix syntax error on Python 2.7
377,522
27.10.2021 18:46:36
-10,800
d585e930e107da00baf0c60004bfcc911f98f4e6
Fix charge state extraction from mzML
[ { "change_type": "MODIFY", "old_path": "pyteomics/_schema_defaults.py", "new_path": "pyteomics/_schema_defaults.py", "diff": "@@ -397,7 +397,8 @@ _mzml_schema_defaults = {'ints': {\n('softwareList', 'count'),\n('binaryDataArrayList', 'count'),\n('spectrumList', 'count'),\n- ('chromatogramList', 'count')},\n+ ('chromatogramList', 'count'),\n+ ('selectedIon', 'charge state')},\n'floats': {},\n'bools': {},\n'lists': {'scan', 'spectrum', 'sample', 'cv', 'dataProcessing',\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/pylab_aux.py", "new_path": "pyteomics/pylab_aux.py", "diff": "@@ -515,7 +515,7 @@ def _get_precursor_charge(spectrum):\nexcept (PyteomicsError, KeyError):\npass\ntry:\n- return spectrum['precursorList']['precursor'][0]['selectedIonList']['selectedIon'][0]['selected ion m/z']\n+ return int(spectrum['precursorList']['precursor'][0]['selectedIonList']['selectedIon'][0]['charge state'])\nexcept KeyError:\npass\nreturn None\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Fix charge state extraction from mzML
377,522
18.11.2021 17:58:20
-10,800
165ed6217423e75b36f0d651767562a66c5eecdc
Add max_length
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "+4.5.1dev1\n+---------\n+\n+ - Add `max_length` parameter in :py:func:`pyteomics.parser.cleave`.\n+ - Bugfix in :py:func:`pyteomics.parser.cleave` for `semi=True`.\n+\n+\n4.5\n---\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/parser.py", "new_path": "pyteomics/parser.py", "diff": "@@ -530,7 +530,7 @@ def amino_acid_composition(sequence, show_unmodified_termini=False, term_aa=Fals\n@memoize()\n-def cleave(sequence, rule, missed_cleavages=0, min_length=None, semi=False, exception=None):\n+def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None):\n\"\"\"Cleaves a polypeptide sequence using a given rule.\nParameters\n@@ -563,6 +563,9 @@ def cleave(sequence, rule, missed_cleavages=0, min_length=None, semi=False, exce\nyou know what you are doing and apply :py:func:`cleave` to *modX*\nsequences.\n+ max_length : int or None, optional\n+ Maximum peptide length. Defaults to :py:const:`None`. See note above.\n+\nsemi : bool, optional\nInclude products of semi-specific cleavage. Default is :py:const:`False`.\nThis effectively cuts every peptide at every position and adds results to the output.\n@@ -590,10 +593,10 @@ def cleave(sequence, rule, missed_cleavages=0, min_length=None, semi=False, exce\nTrue\n\"\"\"\n- return set(_cleave(sequence, rule, missed_cleavages, min_length, semi, exception))\n+ return set(_cleave(sequence, rule, missed_cleavages, min_length, max_length, semi, exception))\n-def _cleave(sequence, rule, missed_cleavages=0, min_length=None, semi=False, exception=None):\n+def _cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None):\n\"\"\"Like :py:func:`cleave`, but the result is a list. Refer to\n:py:func:`cleave` for explanation of parameters.\n\"\"\"\n@@ -610,11 +613,12 @@ def _cleave(sequence, rule, missed_cleavages=0, min_length=None, semi=False, exc\ncleavage_sites = deque([0], maxlen=ml)\nif min_length is None:\nmin_length = 1\n+ if max_length is None:\n+ max_length = len(sequence)\ncl = 1\nif exception is not None:\nexceptions = {x.end() for x in re.finditer(exception, sequence)}\n- for i in it.chain([x.end() for x in re.finditer(rule, sequence)],\n- [None]):\n+ for i in it.chain([x.end() for x in re.finditer(rule, sequence)], [None]):\nif exception is not None and i in exceptions:\ncontinue\ncleavage_sites.append(i)\n@@ -622,12 +626,13 @@ def _cleave(sequence, rule, missed_cleavages=0, min_length=None, semi=False, exc\ncl += 1\nfor j in trange[:cl - 1]:\nseq = sequence[cleavage_sites[j]:cleavage_sites[-1]]\n- if seq and len(seq) >= min_length:\n+ lenseq = len(seq)\n+ if seq and min_length <= lenseq <= max_length:\npeptides.append(seq)\nif semi:\n- for k in range(min_length, len(seq) - 1):\n+ for k in range(min_length, min(lenseq, max_length)):\npeptides.append(seq[:k])\n- for k in range(1, len(seq) - min_length + 1):\n+ for k in range(max(1, lenseq - max_length), lenseq - min_length + 1):\npeptides.append(seq[k:])\nreturn peptides\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5'\n+__version__ = '4.5dev1'\nfrom collections import namedtuple\nimport re\n" }, { "change_type": "MODIFY", "old_path": "tests/test_parser.py", "new_path": "tests/test_parser.py", "diff": "@@ -71,9 +71,9 @@ class ParserTest(unittest.TestCase):\ndef test_cleave_semi(self):\nself.assertEqual(parser._cleave('PEPTIDEKS', parser.expasy_rules['trypsin'], semi=True),\n- ['PEPTIDEK', 'P', 'PE', 'PEP', 'PEPT', 'PEPTI', 'PEPTID', 'EPTIDEK', 'PTIDEK', 'TIDEK', 'IDEK', 'DEK', 'EK', 'K', 'S'])\n+ ['PEPTIDEK', 'P', 'PE', 'PEP', 'PEPT', 'PEPTI', 'PEPTID', 'PEPTIDE', 'EPTIDEK', 'PTIDEK', 'TIDEK', 'IDEK', 'DEK', 'EK', 'K', 'S'])\nself.assertEqual(parser.cleave('PEPTIDEKS', parser.expasy_rules['trypsin'], semi=True),\n- {'PEPTIDEK', 'P', 'PE', 'PEP', 'PEPT', 'PEPTI', 'PEPTID', 'EPTIDEK', 'PTIDEK', 'TIDEK', 'IDEK', 'DEK', 'EK', 'K', 'S'})\n+ {'PEPTIDEK', 'P', 'PE', 'PEP', 'PEPT', 'PEPTI', 'PEPTID', 'PEPTIDE', 'EPTIDEK', 'PTIDEK', 'TIDEK', 'IDEK', 'DEK', 'EK', 'K', 'S'})\ndef test_cleave_min_length(self):\nfor seq in self.simple_sequences:\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add max_length
377,522
18.11.2021 18:11:28
-10,800
49d3ac80041ae09c1f701946c55e8516bc45a6d8
Add regex parameter in cleave and raise a warning on lowercase characters in cleavage rule
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.1dev1\n+4.5.1dev2\n---------\n- Add `max_length` parameter in :py:func:`pyteomics.parser.cleave`.\n- Bugfix in :py:func:`pyteomics.parser.cleave` for `semi=True`.\n-\n+ - Add `regex` parameter in :py:func:`pyteomics.parser.cleave` and warn for possible typos in cleavage rule names.\n4.5\n---\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/parser.py", "new_path": "pyteomics/parser.py", "diff": "@@ -101,6 +101,7 @@ Data\nimport re\nfrom collections import deque\nimport itertools as it\n+import warnings\nfrom .auxiliary import PyteomicsError, memoize, BasicComposition, cvstr, cvquery\nstd_amino_acids = ['Q', 'W', 'E', 'R', 'T', 'Y', 'I', 'P', 'A', 'S',\n@@ -530,7 +531,7 @@ def amino_acid_composition(sequence, show_unmodified_termini=False, term_aa=Fals\n@memoize()\n-def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None):\n+def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None, regex=False):\n\"\"\"Cleaves a polypeptide sequence using a given rule.\nParameters\n@@ -552,6 +553,9 @@ def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None,\nusing `lookaround assertions\n<http://www.regular-expressions.info/lookaround.html>`_.\n:py:data:`expasy_rules` contains cleavage rules for popular cleavage agents.\n+\n+ .. seealso:: The `regex` argument.\n+\nmissed_cleavages : int, optional\nMaximum number of allowed missed cleavages. Defaults to 0.\nmin_length : int or None, optional\n@@ -575,6 +579,10 @@ def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None,\nor regular expression. Cleavage sites matching `rule` will be checked against `exception` and omitted\nif they match.\n+ regex : bool, optional\n+ If :py:const:`True`, the cleavage rule is always interpreted as a regex. Otherwise, a matching value\n+ is looked up in :py:data:`expasy_rules` and :py:data:`psims_rules`.\n+\nReturns\n-------\nout : set\n@@ -593,19 +601,23 @@ def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None,\nTrue\n\"\"\"\n- return set(_cleave(sequence, rule, missed_cleavages, min_length, max_length, semi, exception))\n+ return set(_cleave(sequence, rule, missed_cleavages, min_length, max_length, semi, exception, regex))\n-def _cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None):\n+def _cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None, regex=False):\n\"\"\"Like :py:func:`cleave`, but the result is a list. Refer to\n:py:func:`cleave` for explanation of parameters.\n\"\"\"\n+ if not regex:\nif rule in expasy_rules:\nrule = expasy_rules[rule]\nelif rule in psims_rules:\nrule = psims_rules[rule]\nelif rule in _psims_index:\nrule = _psims_index[rule]\n+ elif re.search(r'[a-z]', rule):\n+ warnings.warn('Interpreting the rule as a regular expression: {}. Did you mistype the rule? '\n+ 'Specify `regex=True` to silence this warning.'.format(rule))\nexception = expasy_rules.get(exception, exception)\npeptides = []\nml = missed_cleavages + 2\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5dev1'\n+__version__ = '4.5dev2'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add regex parameter in cleave and raise a warning on lowercase characters in cleavage rule
377,522
18.11.2021 19:00:23
-10,800
fb1fb6d86152ba83fe087262199bfa86b76538ec
Return peptide indices in _cleave
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.1dev2\n+4.5.1dev3\n---------\n- Add `max_length` parameter in :py:func:`pyteomics.parser.cleave`.\n- Bugfix in :py:func:`pyteomics.parser.cleave` for `semi=True`.\n- Add `regex` parameter in :py:func:`pyteomics.parser.cleave` and warn for possible typos in cleavage rule names.\n+ - Return indices of peptides in :py:func:`parser._cleave`.\n4.5\n---\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/parser.py", "new_path": "pyteomics/parser.py", "diff": "@@ -601,7 +601,7 @@ def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None,\nTrue\n\"\"\"\n- return set(_cleave(sequence, rule, missed_cleavages, min_length, max_length, semi, exception, regex))\n+ return set(p for i, p in _cleave(sequence, rule, missed_cleavages, min_length, max_length, semi, exception, regex))\ndef _cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None, regex=False):\n@@ -630,22 +630,26 @@ def _cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None\ncl = 1\nif exception is not None:\nexceptions = {x.end() for x in re.finditer(exception, sequence)}\n- for i in it.chain([x.end() for x in re.finditer(rule, sequence)], [None]):\n- if exception is not None and i in exceptions:\n+ for end in it.chain([x.end() for x in re.finditer(rule, sequence)], [None]):\n+ if exception is not None and end in exceptions:\ncontinue\n- cleavage_sites.append(i)\n+ cleavage_sites.append(end)\nif cl < ml:\ncl += 1\nfor j in trange[:cl - 1]:\nseq = sequence[cleavage_sites[j]:cleavage_sites[-1]]\nlenseq = len(seq)\n+ if end is not None:\n+ start = end - lenseq\n+ else:\n+ start = len(sequence) - lenseq\nif seq and min_length <= lenseq <= max_length:\n- peptides.append(seq)\n+ peptides.append((start, seq))\nif semi:\nfor k in range(min_length, min(lenseq, max_length)):\n- peptides.append(seq[:k])\n+ peptides.append((start, seq[:k]))\nfor k in range(max(1, lenseq - max_length), lenseq - min_length + 1):\n- peptides.append(seq[k:])\n+ peptides.append((start + k, seq[k:]))\nreturn peptides\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5dev2'\n+__version__ = '4.5dev3'\nfrom collections import namedtuple\nimport re\n" }, { "change_type": "MODIFY", "old_path": "tests/test_parser.py", "new_path": "tests/test_parser.py", "diff": "@@ -59,9 +59,9 @@ class ParserTest(unittest.TestCase):\nself.assertEqual(sum(comp_default.values()), sum(comp.values()))\ndef test_cleave(self):\n- self.assertEqual(parser._cleave('PEPTIDEKS', parser.expasy_rules['trypsin']), ['PEPTIDEK', 'S'])\n- self.assertEqual(parser._cleave('PEPTIDEKS', 'trypsin'), ['PEPTIDEK', 'S'])\n- self.assertEqual(parser._cleave('PEPTIDEKS', 'Trypsin'), ['PEPTIDEK', 'S'])\n+ self.assertEqual(parser._cleave('PEPTIDEKS', parser.expasy_rules['trypsin']), [(0, 'PEPTIDEK'), (8, 'S')])\n+ self.assertEqual(parser._cleave('PEPTIDEKS', 'trypsin'), [(0, 'PEPTIDEK'), (8, 'S')])\n+ self.assertEqual(parser._cleave('PEPTIDEKS', 'Trypsin'), [(0, 'PEPTIDEK'), (8, 'S')])\nfor seq in self.simple_sequences:\nfor elem in parser.cleave(\nseq, 'trypsin', int(random.uniform(1, 10))):\n@@ -70,8 +70,9 @@ class ParserTest(unittest.TestCase):\nfor elem in parser.cleave(seq, parser.expasy_rules['trypsin'], len(seq))))\ndef test_cleave_semi(self):\n- self.assertEqual(parser._cleave('PEPTIDEKS', parser.expasy_rules['trypsin'], semi=True),\n- ['PEPTIDEK', 'P', 'PE', 'PEP', 'PEPT', 'PEPTI', 'PEPTID', 'PEPTIDE', 'EPTIDEK', 'PTIDEK', 'TIDEK', 'IDEK', 'DEK', 'EK', 'K', 'S'])\n+ self.assertEqual(parser._cleave('PEPTIDEKS', 'trypsin', semi=True),\n+ [(0, 'PEPTIDEK'), (0, 'P'), (0, 'PE'), (0, 'PEP'), (0, 'PEPT'), (0, 'PEPTI'), (0, 'PEPTID'), (0, 'PEPTIDE'),\n+ (1, 'EPTIDEK'), (2, 'PTIDEK'), (3, 'TIDEK'), (4, 'IDEK'), (5, 'DEK'), (6, 'EK'), (7, 'K'), (8, 'S')])\nself.assertEqual(parser.cleave('PEPTIDEKS', parser.expasy_rules['trypsin'], semi=True),\n{'PEPTIDEK', 'P', 'PE', 'PEP', 'PEPT', 'PEPTI', 'PEPTID', 'PEPTIDE', 'EPTIDEK', 'PTIDEK', 'TIDEK', 'IDEK', 'DEK', 'EK', 'K', 'S'})\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Return peptide indices in _cleave
377,522
25.11.2021 15:26:21
-10,800
fbc09df4f7f7ee1ef66bc6e07d2538794c6e4142
Specify rcond to silence warning in achrom.get_RCs
[ { "change_type": "MODIFY", "old_path": "pyteomics/achrom.py", "new_path": "pyteomics/achrom.py", "diff": "@@ -436,8 +436,7 @@ def get_RCs(sequences, RTs, lcp = -0.21,\nRTs.append(0.0)\n# Use least square linear regression.\n- RCs, res, rank, s = np.linalg.lstsq(np.array(composition_array),\n- np.array(RTs))\n+ RCs, res, rank, s = np.linalg.lstsq(np.array(composition_array), np.array(RTs), rcond=None)\n# Remove normalizing elements from the RTs vector.\nif term_aa:\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Specify rcond to silence warning in achrom.get_RCs
377,522
26.11.2021 17:41:57
-10,800
23edf600e6ead8f6ccc00f39a1e4e21202bb5c9c
Expose parser.xcleave and icleave as part of API
[ { "change_type": "MODIFY", "old_path": "doc/source/parser.rst", "new_path": "doc/source/parser.rst", "diff": "@@ -18,6 +18,9 @@ either 0 or 2 terminal groups in a *modX* sequence.\nSequence operations\n-------------------\n+Parsing\n+.......\n+\nThere are two helper functions to check if a label is in modX format or represents\na terminal modification: :py:func:`pyteomics.parser.is_modX` and\n:py:func:`pyteomics.parser.is_term_mod`:\n@@ -98,19 +101,27 @@ and returns a *dictionary* with amino acid labels as *keys* and integer numbers\n>>> parser.amino_acid_composition('PEPTIDE')\n{'I': 1.0, 'P': 2.0, 'E': 2.0, 'T': 1.0, 'D': 1.0}\n-:py:func:`pyteomics.parser.cleave` is a method to perform *in silico* cleavage.\n-The requiered arguments are the sequence, the rule for enzyme specificity and the\n+*In silico* digestion\n+.....................\n+\n+:py:func:`pyteomics.parser.cleave` performs *in silico* cleavage.\n+The required arguments are the sequence, the rule for enzyme specificity and the\nnumber of missed cleavages allowed (optional). :py:func:`cleave` returns a\n-:py:class:`set` of product peptides.\n+:py:class:`set` of product peptides; you can get original indices of peptides with :py:func:`xcleave`.\n.. code-block:: python\n>>> from pyteomics import parser\n>>> parser.cleave('AKAKBK', parser.expasy_rules['trypsin'], 0)\n{'AK', 'BK'}\n+ >>> parser.xcleave('AKAKBK', 'trypsin', 0)\n+ [(0, 'AK'), (2, 'AK'), (4, 'BK')]\n+\n+:py:data:`pyteomics.parser.expasy_rules` and :py:data:`pyteomics.parser.psims_rules` are predefined :py:class:`dicts`\n+with the clevage rules for the most common proteases. Their keys are recognized by :py:func:`cleave`.\n-:py:data:`pyteomics.parser.expasy_rules` is a predefined :py:class:`dict` with\n-the clevage rules for the most common proteases.\n+Variable modifications\n+......................\nAll possible modified sequences of a peptide can be obtained with\n:py:func:`pyteomics.parser.isoforms`:\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/parser.py", "new_path": "pyteomics/parser.py", "diff": "@@ -37,7 +37,7 @@ Operations on polypeptide sequences\n:py:func:`amino_acid_composition` - get numbers of each amino acid\nresidue in a peptide.\n- :py:func:`cleave` - cleave a polypeptide using a given rule of\n+ :py:func:`cleave`, :py:func:`icleave`, :py:func:`xcleave` - cleave a polypeptide using a given rule of\nenzymatic digestion.\n:py:func:`num_sites` - count the number of cleavage sites in a sequence.\n@@ -531,9 +531,12 @@ def amino_acid_composition(sequence, show_unmodified_termini=False, term_aa=Fals\n@memoize()\n-def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None, regex=False):\n+def cleave(*args, **kwargs):\n\"\"\"Cleaves a polypeptide sequence using a given rule.\n+ .. seealso::\n+ :func:`icleave` and :func:`xcleave`, which produce both peptides and their indices.\n+\nParameters\n----------\nsequence : str\n@@ -601,12 +604,18 @@ def cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None,\nTrue\n\"\"\"\n- return set(p for i, p in _cleave(sequence, rule, missed_cleavages, min_length, max_length, semi, exception, regex))\n+ return set(p for i, p in icleave(*args, **kwargs))\n+\n+def icleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None, regex=False):\n+ \"\"\"Like :py:func:`cleave`, but the result is an iterator and includes peptide indices.\n+ Refer to :py:func:`cleave` for explanation of parameters.\n+\n+ Returns\n+ -------\n+ out : iterator\n+ An iterator over (index, sequence) pairs.\n-def _cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None, semi=False, exception=None, regex=False):\n- \"\"\"Like :py:func:`cleave`, but the result is a list. Refer to\n- :py:func:`cleave` for explanation of parameters.\n\"\"\"\nif not regex:\nif rule in expasy_rules:\n@@ -619,7 +628,6 @@ def _cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None\nwarnings.warn('Interpreting the rule as a regular expression: {}. Did you mistype the rule? '\n'Specify `regex=True` to silence this warning.'.format(rule))\nexception = expasy_rules.get(exception, exception)\n- peptides = []\nml = missed_cleavages + 2\ntrange = range(ml)\ncleavage_sites = deque([0], maxlen=ml)\n@@ -644,13 +652,28 @@ def _cleave(sequence, rule, missed_cleavages=0, min_length=None, max_length=None\nelse:\nstart = len(sequence) - lenseq\nif seq and min_length <= lenseq <= max_length:\n- peptides.append((start, seq))\n+ yield (start, seq)\nif semi:\nfor k in range(min_length, min(lenseq, max_length)):\n- peptides.append((start, seq[:k]))\n+ yield (start, seq[:k])\nfor k in range(max(1, lenseq - max_length), lenseq - min_length + 1):\n- peptides.append((start + k, seq[k:]))\n- return peptides\n+ yield (start + k, seq[k:])\n+\n+\n+def xcleave(*args, **kwargs):\n+ \"\"\"Like :py:func:`icleave`, but returns a list.\n+\n+ Returns\n+ -------\n+ out : list\n+ A list of (index, sequence) pairs.\n+\n+ Examples\n+ --------\n+ >>> xcleave('AKAKBK', 'trypsin', 1)\n+ [(0, 'AK'), (0, 'AKAK'), (2, 'AK'), (2, 'AKBK'), (4, 'BK')]\n+ \"\"\"\n+ return list(icleave(*args, **kwargs))\ndef num_sites(sequence, rule, **kwargs):\n@@ -679,7 +702,7 @@ def num_sites(sequence, rule, **kwargs):\nout : int\nNumber of cleavage sites.\n\"\"\"\n- return len(_cleave(sequence, rule, **kwargs)) - 1\n+ return sum(1 for _ in icleave(sequence, rule, **kwargs)) - 1\nexpasy_rules = {\n" }, { "change_type": "MODIFY", "old_path": "tests/test_parser.py", "new_path": "tests/test_parser.py", "diff": "@@ -59,9 +59,9 @@ class ParserTest(unittest.TestCase):\nself.assertEqual(sum(comp_default.values()), sum(comp.values()))\ndef test_cleave(self):\n- self.assertEqual(parser._cleave('PEPTIDEKS', parser.expasy_rules['trypsin']), [(0, 'PEPTIDEK'), (8, 'S')])\n- self.assertEqual(parser._cleave('PEPTIDEKS', 'trypsin'), [(0, 'PEPTIDEK'), (8, 'S')])\n- self.assertEqual(parser._cleave('PEPTIDEKS', 'Trypsin'), [(0, 'PEPTIDEK'), (8, 'S')])\n+ self.assertEqual(parser.xcleave('PEPTIDEKS', parser.expasy_rules['trypsin']), [(0, 'PEPTIDEK'), (8, 'S')])\n+ self.assertEqual(parser.xcleave('PEPTIDEKS', 'trypsin'), [(0, 'PEPTIDEK'), (8, 'S')])\n+ self.assertEqual(parser.xcleave('PEPTIDEKS', 'Trypsin'), [(0, 'PEPTIDEK'), (8, 'S')])\nfor seq in self.simple_sequences:\nfor elem in parser.cleave(\nseq, 'trypsin', int(random.uniform(1, 10))):\n@@ -70,7 +70,7 @@ class ParserTest(unittest.TestCase):\nfor elem in parser.cleave(seq, parser.expasy_rules['trypsin'], len(seq))))\ndef test_cleave_semi(self):\n- self.assertEqual(parser._cleave('PEPTIDEKS', 'trypsin', semi=True),\n+ self.assertEqual(parser.xcleave('PEPTIDEKS', 'trypsin', semi=True),\n[(0, 'PEPTIDEK'), (0, 'P'), (0, 'PE'), (0, 'PEP'), (0, 'PEPT'), (0, 'PEPTI'), (0, 'PEPTID'), (0, 'PEPTIDE'),\n(1, 'EPTIDEK'), (2, 'PTIDEK'), (3, 'TIDEK'), (4, 'IDEK'), (5, 'DEK'), (6, 'EK'), (7, 'K'), (8, 'S')])\nself.assertEqual(parser.cleave('PEPTIDEKS', parser.expasy_rules['trypsin'], semi=True),\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Expose parser.xcleave and icleave as part of API
377,522
26.11.2021 17:47:10
-10,800
c758a7a563a394ece858c4a845cb44f52c92f9ab
Changelog and dev version bump
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.1dev3\n+4.5.1dev4\n---------\n- Add `max_length` parameter in :py:func:`pyteomics.parser.cleave`.\n- Bugfix in :py:func:`pyteomics.parser.cleave` for `semi=True`.\n- Add `regex` parameter in :py:func:`pyteomics.parser.cleave` and warn for possible typos in cleavage rule names.\n- Return indices of peptides in :py:func:`parser._cleave`.\n+ - Add functions :py:func:`parser.icleave` (generator) and :py:func:`parser.xcleave` (list) to produce\n+ peptide sequences with indices and possible repetitions.\n4.5\n---\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.1dev3'\n+__version__ = '4.5.1dev4'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Changelog and dev version bump
377,522
13.12.2021 19:05:28
-10,800
59d030f6dc16a2d1d212a1a347d6a9eecead3a23
Fix collections.abc ImportError on Python 3.10
[ { "change_type": "MODIFY", "old_path": "pyteomics/electrochem.py", "new_path": "pyteomics/electrochem.py", "diff": "@@ -114,7 +114,11 @@ References\nfrom __future__ import division\nfrom . import parser\nfrom .auxiliary import PyteomicsError\n-from collections import Iterable, Counter\n+from collections import Counter\n+try:\n+ from collections.abc import Iterable\n+except ImportError:\n+ from collections import Iterable\ndef charge(sequence, pH, **kwargs):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Fix collections.abc ImportError on Python 3.10
377,522
13.12.2021 19:08:32
-10,800
596bb3a661352874ab7e4f6524b0d25d862769de
Run GA on Python 3.10
[ { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpackage.yml", "new_path": ".github/workflows/pythonpackage.yml", "diff": "@@ -14,7 +14,7 @@ jobs:\nruns-on: ubuntu-latest\nstrategy:\nmatrix:\n- python-version: [2.7, 3.6, 3.7, 3.8, 3.9]\n+ python-version: [2.7, 3.6, 3.7, 3.8, 3.9, 3.10]\nsteps:\n- uses: actions/checkout@v2\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Run GA on Python 3.10
377,522
13.12.2021 19:10:47
-10,800
54e7d4ea605122d236065493105305218b39bbd8
Add 3.10 to helper test script
[ { "change_type": "MODIFY", "old_path": "tests/runtests.sh", "new_path": "tests/runtests.sh", "diff": "#!/bin/bash\nexport PYTHONPATH=\"..\"\nif [ $# -eq 0 ]; then\n- find . -name 'test_*.py' -exec bash -c 'declare -a versions=(2.7 3.3 3.4 3.5 3.6 3.7 3.8 3.9); for v in \"${versions[@]}\"; do command -v \"python${v}\" > /dev/null 2>&1 && { echo \"Executing python${v}\" \"$0\"; eval \"python${v}\" \"$0\"; }; done' {} \\;\n+ find . -name 'test_*.py' -exec bash -c 'declare -a versions=(2.7 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10); for v in \"${versions[@]}\"; do command -v \"python${v}\" > /dev/null 2>&1 && { echo \"Executing python${v}\" \"$0\"; eval \"python${v}\" \"$0\"; }; done' {} \\;\nelse\nfor f; do\n- for v in 2.7 3.3 3.4 3.5 3.6 3.7 3.8 3.9; do\n+ for v in 2.7 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10; do\ncommand -v \"python${v}\" >/dev/null 2>&1 && {\nif [ -f \"$f\" ]; then\nfname=\"$f\"\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add 3.10 to helper test script
377,522
13.12.2021 19:19:16
-10,800
2ac92cb30c51ee6d87da348fa3b867bede771212
Fix 3.10 -> 3.1 error in GA
[ { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpackage.yml", "new_path": ".github/workflows/pythonpackage.yml", "diff": "@@ -14,7 +14,7 @@ jobs:\nruns-on: ubuntu-latest\nstrategy:\nmatrix:\n- python-version: [2.7, 3.6, 3.7, 3.8, 3.9, 3.10]\n+ python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']\nsteps:\n- uses: actions/checkout@v2\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Fix 3.10 -> 3.1 error in GA
377,522
16.12.2021 18:57:44
-10,800
fb4991b12675d58417bdc1bd73aace493e283ff2
Bump version (Python 3.10 support)
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.2.dev1\n-----------\n+4.5.2\n+-----\n- - Fix ImportError on Python 3.10 in :py:mod:`pyteomics.electrochem`.\n+ - Support Python 3.10.\n4.5.1\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.1'\n+__version__ = '4.5.2'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Bump version (Python 3.10 support)
377,522
17.12.2021 19:33:55
-10,800
bf4feb193b79980b00814556d0a914f1374ecdfb
Update changelog, increment dev version
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "+4.5.3dev1\n+---------\n+\n+ - Fix ThreadPool shutdown and add new parameter `ephemeral_pool` in :py:class:`pyteomics.usi.PROXIAggregator`\n+ (`#67 <https://github.com/levitsky/pyteomics/pull/67>`_ by Joshua Klein).\n+\n4.5.2\n-----\n- Support Python 3.10.\n-\n4.5.1\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.2'\n+__version__ = '4.5.3dev1'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Update changelog, increment dev version
377,522
27.01.2022 20:58:53
-10,800
28405940d088087862d9e6f22cd380a005d0b6e1
Add fasta.decoy_entries
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.3dev2\n+4.5.3dev3\n---------\n- Fix ThreadPool shutdown and add new parameter `ephemeral_pool` in :py:class:`pyteomics.usi.PROXIAggregator`\n(`#67 <https://github.com/levitsky/pyteomics/pull/67>`_ by Joshua Klein).\n- Bugfix in `pyteomics.proforma.GenericModificationResolver` (`#68 <https://github.com/levitsky/pyteomics/issues/68>`_) by Joshua Klein.\n+ - New helper function :py:func:`pyteomics.fasta.decoy_entries`.\n4.5.2\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/fasta.py", "new_path": "pyteomics/fasta.py", "diff": "@@ -78,6 +78,8 @@ Decoy database generation\n:py:func:`decoy_db` - generate entries for a decoy database from a given FASTA\ndatabase.\n+ :py:func:`decoy_entries` - generate decoy entries for an iterator.\n+\n:py:func:`decoy_chain` - a version of :py:func:`decoy_db` for multiple files.\n:py:func:`decoy_chain.from_iterable` - like :py:func:`decoy_chain`, but with\n@@ -114,6 +116,7 @@ from . import auxiliary as aux\nProtein = namedtuple('Protein', ('description', 'sequence'))\n+DECOY_PREFIX = 'DECOY_'\nclass FASTABase(object):\n@@ -805,8 +808,40 @@ def decoy_sequence(sequence, mode='reverse', **kwargs):\nreturn fmode(sequence, **kwargs)\n+def decoy_entries(entries, mode='reverse', prefix=DECOY_PREFIX, decoy_only=True, **kwargs):\n+ \"\"\"Iterate over protein `entries` (tuples) and produce decoy entries.\n+ The `entries` are only iterated once.\n+\n+ Parameters\n+ ----------\n+ entries : iterable of tuples\n+ Any iterable of (description, sequence) pairs.\n+ mode : str or callable, optional\n+ Algorithm of decoy sequence generation. 'reverse' by default.\n+ See :py:func:`decoy_sequence` for more information.\n+ prefix : str, optional\n+ A prefix to the protein descriptions of decoy entries. The default\n+ value is `'DECOY_'`.\n+ decoy_only : bool, optional\n+ If set to :py:const:`True`, only the decoy entries will be written to\n+ `output`. If :py:const:`False`, each consumed entry is yielded unchanged,\n+ followed by its decoy couterpart.\n+ :py:const:`True` by default.\n+ **kwargs : given to :py:func:`decoy_sequence`.\n+\n+ Returns\n+ -------\n+ out : iterator\n+ An iterator over new entries.\n+ \"\"\"\n+ for item in entries:\n+ if not decoy_only:\n+ yield item\n+ yield Protein(prefix + item[0], decoy_sequence(item[1], mode, **kwargs))\n+\n+\n@aux._file_reader()\n-def decoy_db(source=None, mode='reverse', prefix='DECOY_', decoy_only=False,\n+def decoy_db(source=None, mode='reverse', prefix=DECOY_PREFIX, decoy_only=False,\nignore_comments=False, parser=None, **kwargs):\n\"\"\"Iterate over sequences for a decoy database out of a given ``source``.\n@@ -861,7 +896,7 @@ def decoy_db(source=None, mode='reverse', prefix='DECOY_', decoy_only=False,\n@aux._file_writer()\n-def write_decoy_db(source=None, output=None, mode='reverse', prefix='DECOY_',\n+def write_decoy_db(source=None, output=None, mode='reverse', prefix=DECOY_PREFIX,\ndecoy_only=False, **kwargs):\n\"\"\"Generate a decoy database out of a given ``source`` and write to file.\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.3dev2'\n+__version__ = '4.5.3dev3'\nfrom collections import namedtuple\nimport re\n" }, { "change_type": "MODIFY", "old_path": "tests/test_fasta.py", "new_path": "tests/test_fasta.py", "diff": "@@ -156,6 +156,16 @@ class FastaTest(unittest.TestCase):\nself.assertEqual(all_entries, self.fasta_entries_long +\n[('PREFIX_' + a, b[::-1]) for a, b in self.fasta_entries_long])\n+ def test_decoy_entries(self):\n+ with fasta.read(self.fasta_file) as f:\n+ self.assertEqual(sorted(fasta.decoy_entries(f, decoy_only=False, prefix='PREFIX_', mode='reverse')),\n+ sorted(self.fasta_entries_long + [('PREFIX_' + a, b[::-1]) for a, b in self.fasta_entries_long]))\n+\n+ def test_decoy_entries_only(self):\n+ with fasta.read(self.fasta_file) as f:\n+ self.assertEqual(list(fasta.decoy_entries(f, decoy_only=True, prefix='PREFIX_', mode='reverse')),\n+ [('PREFIX_' + a, b[::-1]) for a, b in self.fasta_entries_long])\n+\ndef test_parser_uniprotkb_decoydb(self):\nheader = ('sp|P27748|ACOX_RALEH Acetoin catabolism protein X OS=Ralstonia'\n' eutropha (strain ATCC 17699 / H16 / DSM 428 / Stanier 337)'\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add fasta.decoy_entries
377,522
29.01.2022 23:32:04
-10,800
4b05f53fb08f883b20b3aa6daf5c6fac21adf969
Do not take mass_data in Composition.__init__
[ { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -203,12 +203,10 @@ class Composition(BasicComposition):\nshow_unmodified_termini=True)\nself._from_parsed_sequence(parsed_sequence, aa_comp)\n- def _from_formula(self, formula, mass_data):\n+ def _from_formula(self, formula):\nif not re.match(_formula, formula):\nraise PyteomicsError('Invalid formula: ' + formula)\nfor elem, isotope, number in re.findall(_atom, formula):\n- if elem not in mass_data:\n- raise PyteomicsError('Unknown chemical element: ' + elem)\nself[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) if number else 1\ndef _from_composition(self, comp):\n@@ -267,9 +265,6 @@ class Composition(BasicComposition):\naa_comp : dict, optional\nA dict with the elemental composition of the amino acids (the\ndefault value is std_aa_comp).\n- mass_data : dict, optional\n- A dict with the masses of chemical elements (the default\n- value is :py:data:`nist_mass`). It is used for formulae parsing only.\ncharge : int, optional\nIf not 0 then additional protons are added to the composition.\nion_comp : dict, optional\n@@ -282,7 +277,6 @@ class Composition(BasicComposition):\ndefaultdict.__init__(self, int)\naa_comp = kwargs.get('aa_comp', std_aa_comp)\n- mass_data = kwargs.get('mass_data', nist_mass)\nkw_given = self._kw_sources.intersection(kwargs)\nif len(kw_given) > 1:\n@@ -291,8 +285,10 @@ class Composition(BasicComposition):\n', '.join(kw_given)))\nelif kw_given:\nkwa = kw_given.pop()\n- getattr(self, '_from_' + kwa)(kwargs[kwa],\n- mass_data if kwa == 'formula' else aa_comp)\n+ if kwa == 'formula':\n+ self._from_formula(kwargs['formula'])\n+ else:\n+ getattr(self, '_from_' + kwa)(kwargs[kwa], aa_comp)\n# can't build from kwargs\nelif args:\n@@ -303,7 +299,7 @@ class Composition(BasicComposition):\nself._from_sequence(args[0], aa_comp)\nexcept PyteomicsError:\ntry:\n- self._from_formula(args[0], mass_data)\n+ self._from_formula(args[0])\nexcept PyteomicsError:\nraise PyteomicsError(\n'Could not create a Composition object from '\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Do not take mass_data in Composition.__init__
377,522
01.02.2022 01:27:25
-10,800
b72e87c08f716492453fe57fc508b1fd2b9cbd46
Be more strict about charge
[ { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -93,6 +93,7 @@ except ImportError:\nfrom datetime import datetime\nimport re\nimport operator\n+import warnings\nnist_mass = _nist_mass\n\"\"\"\n@@ -265,14 +266,12 @@ class Composition(BasicComposition):\naa_comp : dict, optional\nA dict with the elemental composition of the amino acids (the\ndefault value is std_aa_comp).\n- charge : int, optional\n- If not 0 then additional protons are added to the composition.\nion_comp : dict, optional\nA dict with the relative elemental compositions of peptide ion\nfragments (default is :py:data:`std_ion_comp`).\nion_type : str, optional\nIf specified, then the polypeptide is considered to be in the form\n- of the corresponding ion. Do not forget to specify the charge state!\n+ of the corresponding ion.\n\"\"\"\ndefaultdict.__init__(self, int)\n@@ -320,13 +319,16 @@ class Composition(BasicComposition):\nif 'ion_type' in kwargs:\nself += ion_comp[kwargs['ion_type']]\n- # Get charge\n+ # Charge is not supported in kwargs\ncharge = self['H+']\nif 'charge' in kwargs:\nif charge:\nraise PyteomicsError('Charge is specified both by the number of protons and `charge` in kwargs')\n- charge = kwargs['charge']\n- self['H+'] = charge\n+ else:\n+ warnings.warn('charge and charge carrier should be specified when calling mass(). '\n+ 'Support for charge in Composition.__init__ will be removed in a future version.',\n+ FutureWarning)\n+ self['H+'] = kwargs['charge']\ndef mass(self, **kwargs):\n\"\"\"Calculate the mass or *m/z* of a :py:class:`Composition`.\n@@ -373,10 +375,15 @@ class Composition(BasicComposition):\nmass += (amount * mass_data[element_name][isotope_num][0])\n# Calculate m/z if required\n- charge = kwargs.get('charge', composition['H+'])\n- if charge:\n- if not composition['H+']:\n+ charge = kwargs.get('charge')\n+ if charge and not composition['H+']:\nmass += mass_data['H+'][0][0] * charge\n+ if charge and composition['H+']:\n+ raise PyteomicsError('Composition contains protons and charge is explicitly specified.')\n+ if charge is None and composition['H+']:\n+ warnings.warn('Charge is not specified, but the Composition contains protons. Assuming m/z calculation.')\n+ charge = composition['H+']\n+ if charge:\nmass /= charge\nreturn mass\n@@ -498,9 +505,11 @@ def calculate_mass(*args, **kwargs):\n-------\nmass : float\n\"\"\"\n+ # Charge parameters must not be passed to mass(), not __init__\n+ charge = kwargs.pop('charge', None)\n# Make a copy of `composition` keyword argument.\ncomposition = (Composition(kwargs['composition']) if 'composition' in kwargs else Composition(*args, **kwargs))\n- return composition.mass(**kwargs)\n+ return composition.mass(charge=charge, **kwargs)\ndef most_probable_isotopic_composition(*args, **kwargs):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Be more strict about charge
377,522
11.02.2022 17:24:12
-10,800
5644b56e120f1468ffbf4c8b45ccc76b9ce06a65
Add charge_carrier string spec
[ { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -104,6 +104,7 @@ abundant isotopes and a separate entry for undefined isotope with zero\nkey, mass of the most abundant isotope and 1.0 abundance.\n\"\"\"\n+PROTON = 'H+'\ndef _make_isotope_string(element_name, isotope_num):\n\"\"\"Form a string label for an isotope.\"\"\"\n@@ -158,6 +159,7 @@ class Composition(BasicComposition):\nadding and subtraction.\n\"\"\"\n_kw_sources = {'formula', 'sequence', 'parsed_sequence', 'split_sequence', 'composition'}\n+ _carrier_spec = r\"^(?P<formula>\\S+?)(?:(?P<sign>[+-])(?P<charge>\\d+)?)?$\"\ndef _from_parsed_sequence(self, parsed_sequence, aa_comp):\nself.clear()\n@@ -330,6 +332,41 @@ class Composition(BasicComposition):\nFutureWarning)\nself['H+'] = kwargs['charge']\n+ @classmethod\n+ def _parse_carrier(cls, spec):\n+ \"\"\"Parse a charge carrier spec.\n+ The spec syntax is: <formula>[+-][N]\n+ <formula> is a chemical formula as supported by :py:meth:`_from_formula`.\n+ [+-] is one of \"+\" or \"-\", N is a natural number (1 is assumed if omitted).\n+ If both the sign and the charge are missing, the charge of this group can be\n+ specified as the number of protons in `<formula>`. Otherwise, having protons\n+ in `<formula>` is an error.\n+\n+ Returns\n+ -------\n+ out : tuple\n+ Parsed :py:class:`Composition` and charge of the charge carrier.\n+ \"\"\"\n+ if spec is None:\n+ return cls({PROTON: 1}), 1\n+ try:\n+ formula, sign, charge = re.match(cls._carrier_spec, spec).groups()\n+ except AttributeError:\n+ raise PyteomicsError('Invalid charge carrier specification: ' + spec)\n+ comp = cls(formula=formula)\n+ if sign is not None and PROTON in comp:\n+ raise PyteomicsError('Carrier contains protons and also has a charge specified.')\n+ if sign is None:\n+ # only formula is given\n+ if PROTON not in comp:\n+ raise PyteomicsError('Charge of the charge carrier group not specified.')\n+ charge = comp[PROTON]\n+ elif charge is None:\n+ charge = (-1, 1)[sign == '+']\n+ else:\n+ charge = int(charge) * (-1, 1)[sign == '+']\n+ return comp, charge\n+\ndef mass(self, **kwargs):\n\"\"\"Calculate the mass or *m/z* of a :py:class:`Composition`.\n@@ -340,9 +377,16 @@ class Composition(BasicComposition):\nis not averaged for elements with specified isotopes. Default is\n:py:const:`False`.\ncharge : int, optional\n- If not 0 then m/z is calculated: the mass is increased\n- by the corresponding number of proton masses and divided\n- by `charge`.\n+ If not 0 then m/z is calculated. See also: `charge_carrier`.\n+ charge_carrier : str, optional\n+ Chemical group carrying the charge. Defaults to a proton, \"H+\".\n+ If string, must be a chemical formula, as supported by the :class:`Composition`\n+ `formula` argument, except it must end with a charge formatted as \"[+-][N]\".\n+ If N is omitted, single charge is assumed.\n+ Examples of `charge_carrier`: \"H+\", \"NH3+\" (here, 3 is part of the composition, and + is a single charge),\n+ \"Fe+2\" (\"Fe\" is the formula and \"+2\" is the charge).\n+ .. note ::\n+ The `charge` must be a multiple of `charge_carrier` charge.\nmass_data : dict, optional\nA dict with the masses of the chemical elements (the default\nvalue is :py:data:`nist_mass`).\n@@ -376,8 +420,16 @@ class Composition(BasicComposition):\n# Calculate m/z if required\ncharge = kwargs.get('charge')\n+ if charge:\n+ # get charge carrier mass and charge\n+ carrier_comp, carrier_charge = self._parse_carrier(kwargs.get('charge_carrier'))\n+ if charge % carrier_charge:\n+ raise PyteomicsError('The `charge` must be a multiple of the carrier charge. Given: {} and {}'.format(\n+ charge, carrier_charge))\n+ num = charge // carrier_charge\n+ carrier_mass = carrier_comp.mass(mass_data=mass_data, average=average)\nif charge and not composition['H+']:\n- mass += mass_data['H+'][0][0] * charge\n+ mass += carrier_mass * num\nif charge and composition['H+']:\nraise PyteomicsError('Composition contains protons and charge is explicitly specified.')\nif charge is None and composition['H+']:\n" }, { "change_type": "MODIFY", "old_path": "tests/test_mass.py", "new_path": "tests/test_mass.py", "diff": "@@ -149,6 +149,11 @@ class MassTest(unittest.TestCase):\nmass.calculate_mass(formula='ABCDE', ion_type='M', charge=charge, mass_data=self.mass_data),\nmass.calculate_mass(formula='ABCDE' + 'H+%d' % (charge,), mass_data=self.mass_data))\n+ self.assertEqual(\n+ mass.calculate_mass(formula='ABCDE', ion_type='M', charge=charge * 2, charge_carrier='AB+2', mass_data=self.mass_data),\n+ (mass.calculate_mass(formula='ABCDE', mass_data=self.mass_data) + charge * (\n+ self.mass_data['A'][0][0] + self.mass_data['B'][0][0])) / charge / 2)\n+\nself.assertEqual(\nmass.calculate_mass(formula='ABCDE', ion_type='M', charge=charge, mass_data=self.mass_data),\n(mass.calculate_mass(formula='ABCDE', mass_data=self.mass_data) + self.mass_data['H+'][0][0] * charge) / charge)\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add charge_carrier string spec
377,522
11.02.2022 18:15:58
-10,800
1d17f378d095890fe4cd731ca749e7b2c2c9cf3b
Support charge_carrier as composition, add carrier_charge, fix function-style calls
[ { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -359,7 +359,7 @@ class Composition(BasicComposition):\nif sign is None:\n# only formula is given\nif PROTON not in comp:\n- raise PyteomicsError('Charge of the charge carrier group not specified.')\n+ charge = None\ncharge = comp[PROTON]\nelif charge is None:\ncharge = (-1, 1)[sign == '+']\n@@ -373,20 +373,30 @@ class Composition(BasicComposition):\nParameters\n----------\naverage : bool, optional\n- If :py:const:`True` then the average mass is calculated. Note that mass\n- is not averaged for elements with specified isotopes. Default is\n- :py:const:`False`.\n+ If :py:const:`True` then the average mass is calculated.\n+ Note that mass is not averaged for elements with specified isotopes.\n+ Default is :py:const:`False`.\ncharge : int, optional\nIf not 0 then m/z is calculated. See also: `charge_carrier`.\n- charge_carrier : str, optional\n+ charge_carrier : str or dict, optional\nChemical group carrying the charge. Defaults to a proton, \"H+\".\n- If string, must be a chemical formula, as supported by the :class:`Composition`\n- `formula` argument, except it must end with a charge formatted as \"[+-][N]\".\n+ If string, must be a chemical formula, as supported by the\n+ :class:`Composition` `formula` argument,\n+ except it must end with a charge formatted as \"[+-][N]\".\nIf N is omitted, single charge is assumed.\n- Examples of `charge_carrier`: \"H+\", \"NH3+\" (here, 3 is part of the composition, and + is a single charge),\n+ Examples of `charge_carrier`: \"H+\", \"NH3+\"\n+ (here, 3 is part of the composition, and + is a single charge),\n\"Fe+2\" (\"Fe\" is the formula and \"+2\" is the charge).\n.. note ::\n- The `charge` must be a multiple of `charge_carrier` charge.\n+ `charge` must be a multiple of `charge_carrier` charge.\n+ If dict, it is the atomic composition of the group.\n+ In this case, the charge can be passed separately as `carrier_charge`\n+ or it will be deduced from the number of protons in `charge_carrier`.\n+ carrier_charge : int, optional\n+ Charge of the charge carrier group (if `charge_carrier` is specified\n+ as a composition dict).\n+ .. note ::\n+ `charge` must be a multiple of `charge_charge`.\nmass_data : dict, optional\nA dict with the masses of the chemical elements (the default\nvalue is :py:data:`nist_mass`).\n@@ -422,12 +432,27 @@ class Composition(BasicComposition):\ncharge = kwargs.get('charge')\nif charge:\n# get charge carrier mass and charge\n- carrier_comp, carrier_charge = self._parse_carrier(kwargs.get('charge_carrier'))\n+ charge_carrier = kwargs.get('charge_carrier')\n+ ccharge = kwargs.get('carrier_charge')\n+ if isinstance(charge_carrier, dict):\n+ carrier_comp = Composition(charge_carrier)\n+ if ccharge and PROTON in carrier_comp:\n+ raise PyteomicsError('`carrier_charge` specified but the charge carrier contains protons.')\n+ carrier_charge = ccharge or carrier_comp[PROTON]\n+ if not carrier_charge:\n+ raise PyteomicsError('Charge carrier charge not specified.')\n+ else:\n+ carrier_comp, carrier_charge = self._parse_carrier(charge_carrier)\n+ if carrier_charge and ccharge:\n+ raise PyteomicsError('Both `carrier_charge` and charge in carrier spec are given.')\n+ carrier_charge = ccharge or carrier_charge\n+ if not carrier_charge:\n+ raise PyteomicsError('Charge of the charge carrier group not specified.')\nif charge % carrier_charge:\nraise PyteomicsError('The `charge` must be a multiple of the carrier charge. Given: {} and {}'.format(\ncharge, carrier_charge))\nnum = charge // carrier_charge\n- carrier_mass = carrier_comp.mass(mass_data=mass_data, average=average)\n+ carrier_mass = carrier_comp.mass(mass_data=mass_data, average=average, charge=0)\nif charge and not composition['H+']:\nmass += carrier_mass * num\nif charge and composition['H+']:\n@@ -559,9 +584,11 @@ def calculate_mass(*args, **kwargs):\n\"\"\"\n# Charge parameters must not be passed to mass(), not __init__\ncharge = kwargs.pop('charge', None)\n+ charge_carrier = kwargs.pop('charge_carrier', None)\n+ carrier_charge = kwargs.pop('carrier_charge', None)\n# Make a copy of `composition` keyword argument.\ncomposition = (Composition(kwargs['composition']) if 'composition' in kwargs else Composition(*args, **kwargs))\n- return composition.mass(charge=charge, **kwargs)\n+ return composition.mass(charge=charge, charge_carrier=charge_carrier, carrier_charge=carrier_charge, **kwargs)\ndef most_probable_isotopic_composition(*args, **kwargs):\n" }, { "change_type": "MODIFY", "old_path": "tests/test_mass.py", "new_path": "tests/test_mass.py", "diff": "@@ -154,6 +154,12 @@ class MassTest(unittest.TestCase):\n(mass.calculate_mass(formula='ABCDE', mass_data=self.mass_data) + charge * (\nself.mass_data['A'][0][0] + self.mass_data['B'][0][0])) / charge / 2)\n+ self.assertEqual(\n+ mass.calculate_mass(formula='ABCDE', ion_type='M', charge=charge * 2, charge_carrier={'A': 1, 'B': 1},\n+ carrier_charge=2, mass_data=self.mass_data),\n+ (mass.calculate_mass(formula='ABCDE', mass_data=self.mass_data) + charge * (\n+ self.mass_data['A'][0][0] + self.mass_data['B'][0][0])) / charge / 2)\n+\nself.assertEqual(\nmass.calculate_mass(formula='ABCDE', ion_type='M', charge=charge, mass_data=self.mass_data),\n(mass.calculate_mass(formula='ABCDE', mass_data=self.mass_data) + self.mass_data['H+'][0][0] * charge) / charge)\n@@ -161,6 +167,9 @@ class MassTest(unittest.TestCase):\nself.assertRaises(auxiliary.PyteomicsError, mass.calculate_mass, **{'formula': 'ABCDEH+%d' % charge,\n'ion_type': 'M', 'charge': charge, 'mass_data': self.mass_data})\n+ self.assertRaises(auxiliary.PyteomicsError, mass.calculate_mass, **{'formula': 'ABCDE',\n+ 'ion_type': 'M', 'charge': 3, 'carrier_charge': 2, 'mass_data': self.mass_data})\n+\n# Sanity check.\nfor pep in self.random_peptides:\nself.assertEqual(\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Support charge_carrier as composition, add carrier_charge, fix function-style calls
377,522
11.02.2022 18:29:22
-10,800
c7fcb0000f7745ba90bcc9ba71610a257c0ad794
Add absolute kwarg
[ { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -406,6 +406,12 @@ class Composition(BasicComposition):\nion_type : str, optional\nIf specified, then the polypeptide is considered to be in the form\nof the corresponding ion. Do not forget to specify the charge state!\n+ absolute : bool, optional\n+ If :py:const:`True`, the m/z value returned will always be positive,\n+ even for negatively charged ions.\n+\n+ .. warning::\n+ Default is :py:const:`False` now, but will be changed in a future version.\nReturns\n-------\n@@ -417,6 +423,8 @@ class Composition(BasicComposition):\n# Calculate mass\nmass = 0.0\naverage = kwargs.get('average', False)\n+ absolute = kwargs.get('absolute')\n+\nfor isotope_string, amount in composition.items():\nelement_name, isotope_num = _parse_isotope_string(isotope_string)\n# Calculate average mass if required and the isotope number is\n@@ -462,6 +470,11 @@ class Composition(BasicComposition):\ncharge = composition['H+']\nif charge:\nmass /= charge\n+ if mass < 0 and absolute is None:\n+ warnings.warn('Returning a signed value. The default will change in the future.'\n+ ' Specify `absolute` kwarg to suppress this warning', FutureWarning)\n+ if absolute:\n+ mass = abs(mass)\nreturn mass\n@@ -582,13 +595,16 @@ def calculate_mass(*args, **kwargs):\n-------\nmass : float\n\"\"\"\n- # Charge parameters must not be passed to mass(), not __init__\n+ # These parameters must not be passed to mass(), not __init__\ncharge = kwargs.pop('charge', None)\ncharge_carrier = kwargs.pop('charge_carrier', None)\ncarrier_charge = kwargs.pop('carrier_charge', None)\n+ absolute = kwargs.pop('absolute', None)\n# Make a copy of `composition` keyword argument.\ncomposition = (Composition(kwargs['composition']) if 'composition' in kwargs else Composition(*args, **kwargs))\n- return composition.mass(charge=charge, charge_carrier=charge_carrier, carrier_charge=carrier_charge, **kwargs)\n+ return composition.mass(\n+ charge=charge, charge_carrier=charge_carrier, carrier_charge=carrier_charge,\n+ absolute=absolute, **kwargs)\ndef most_probable_isotopic_composition(*args, **kwargs):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add absolute kwarg
377,522
11.02.2022 18:30:40
-10,800
b8efe10c3aea997f0cad08b6b38ef2c476480be8
Copy the new doc to calculate_mass()
[ { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -581,6 +581,25 @@ def calculate_mass(*args, **kwargs):\nIf not 0 then m/z is calculated: the mass is increased\nby the corresponding number of proton masses and divided\nby `charge`.\n+ charge_carrier : str or dict, optional\n+ Chemical group carrying the charge. Defaults to a proton, \"H+\".\n+ If string, must be a chemical formula, as supported by the\n+ :class:`Composition` `formula` argument,\n+ except it must end with a charge formatted as \"[+-][N]\".\n+ If N is omitted, single charge is assumed.\n+ Examples of `charge_carrier`: \"H+\", \"NH3+\"\n+ (here, 3 is part of the composition, and + is a single charge),\n+ \"Fe+2\" (\"Fe\" is the formula and \"+2\" is the charge).\n+ .. note ::\n+ `charge` must be a multiple of `charge_carrier` charge.\n+ If dict, it is the atomic composition of the group.\n+ In this case, the charge can be passed separately as `carrier_charge`\n+ or it will be deduced from the number of protons in `charge_carrier`.\n+ carrier_charge : int, optional\n+ Charge of the charge carrier group (if `charge_carrier` is specified\n+ as a composition dict).\n+ .. note ::\n+ `charge` must be a multiple of `charge_charge`.\nmass_data : dict, optional\nA dict with the masses of the chemical elements (the default\nvalue is :py:data:`nist_mass`).\n@@ -590,6 +609,12 @@ def calculate_mass(*args, **kwargs):\nion_type : str, optional\nIf specified, then the polypeptide is considered to be in the form\nof the corresponding ion. Do not forget to specify the charge state!\n+ absolute : bool, optional\n+ If :py:const:`True`, the m/z value returned will always be positive,\n+ even for negatively charged ions.\n+\n+ .. warning::\n+ Default is :py:const:`False` now, but will be changed in a future version.\nReturns\n-------\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Copy the new doc to calculate_mass()
377,522
14.02.2022 13:31:11
-10,800
2ac9e6d501e4f165e72dcb0e9b1e5b24e6092cdf
Future-proof protxml test
[ { "change_type": "MODIFY", "old_path": "tests/test_protxml.py", "new_path": "tests/test_protxml.py", "diff": "@@ -62,7 +62,7 @@ class ProtXMLTest(unittest.TestCase):\ndel kw['key']\nkw['remove_decoy'] = True\ndf = protxml.DataFrame(self.path)\n- df['protein_name'] = df.protein_name.str.replace(r'DECOY_(.*)', r'\\1_SUF')\n+ df['protein_name'] = df.protein_name.str.replace(r'DECOY_(.*)', r'\\1_SUF', regex=True)\nfdf = protxml.filter_df(df, decoy_suffix='_SUF', **kw)\nself.assertEqual(fdf.shape, (1, 17))\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Future-proof protxml test
377,522
18.02.2022 15:54:58
-10,800
a889f0b48c714d7d9c9bb7115d66b7f8f780d5f1
Improve exception message in Composition._from_parsed_sequence
[ { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -164,19 +164,19 @@ class Composition(BasicComposition):\ndef _from_parsed_sequence(self, parsed_sequence, aa_comp):\nself.clear()\ncomp = defaultdict(int)\n- for aa in parsed_sequence:\n- if aa in aa_comp:\n- for elem, cnt in aa_comp[aa].items():\n+ for label in parsed_sequence:\n+ if label in aa_comp:\n+ for elem, cnt in aa_comp[label].items():\ncomp[elem] += cnt\nelse:\ntry:\n- mod, aa = parser._split_label(aa)\n+ mod, aa = parser._split_label(label)\nfor elem, cnt in chain(\naa_comp[mod].items(), aa_comp[aa].items()):\ncomp[elem] += cnt\nexcept (PyteomicsError, KeyError):\n- raise PyteomicsError('No information for %s in `aa_comp`' % aa)\n+ raise PyteomicsError('No information for %s in `aa_comp`' % label)\nself._from_composition(comp)\ndef _from_split_sequence(self, split_sequence, aa_comp):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Improve exception message in Composition._from_parsed_sequence
377,522
17.05.2022 18:58:30
-10,800
4ddd7ad2dccb401090bca34c183754370a4a62a5
Start rewriting the test runner using pyenv
[ { "change_type": "ADD", "old_path": null, "new_path": "tests/python-versions.txt", "diff": "+2.7.18\n+3.6.15\n+3.7.13\n+3.8.13\n+3.9.12\n+3.10.4\n" }, { "change_type": "MODIFY", "old_path": "tests/runtests.sh", "new_path": "tests/runtests.sh", "diff": "#!/bin/bash\n-export PYTHONPATH=\"..\"\nif [ $# -eq 0 ]; then\n- find . -name 'test_*.py' -exec bash -c 'declare -a versions=(2.7 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10); for v in \"${versions[@]}\"; do command -v \"python${v}\" > /dev/null 2>&1 && { echo \"Executing python${v}\" \"$0\"; eval \"python${v}\" \"$0\"; }; done' {} \\;\n+ echo \"Installing Python versions...\"\n+ xargs -a python-versions.txt -I{} pyenv install -s {}\n+ echo \"Creating environments...\"\n+ xargs -a python-versions.txt -I{} pyenv virtualenv {} tmp-pyteomics-{}\n+ echo \"Installing dependencies...\"\n+ while read pv; do\n+ eval \"$(pyenv root)/versions/tmp-pyteomics-${pv}/bin/pip\" install -U pip wheel\n+ eval \"$(pyenv root)/versions/tmp-pyteomics-${pv}/bin/pip\" install -r ../test-requirements.txt\n+ eval \"$(pyenv root)/versions/tmp-pyteomics-${pv}/bin/pip\" install -U ..\n+ done < python-versions.txt\n+ echo \"Running tests...\"\n+ find . -name 'test_*.py' -exec bash -c 'echo '\"$(pyenv root)\"'/versions/tmp-pyteomics-${0}/bin/python $0' {} \\;\n+ echo \"Deleting environments...\"\n+ xargs -a python-versions.txt -I{} pyenv virtualenv-delete tmp-pyteomics-{}\nelse\nfor f; do\n- for v in 2.7 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10; do\n- command -v \"python${v}\" >/dev/null 2>&1 && {\n+ while read pv; do\n+ echo \"Creating environment...\"\n+ pyenv virtualenv \"$pv\" \"tmp-pyteomics-single-${pv}\"\n+ echo \"Installing dependencies...\"\n+ eval \"$(pyenv root)/versions/tmp-pyteomics-single-${pv}/bin/pip\" install -U pip wheel\n+ eval \"$(pyenv root)/versions/tmp-pyteomics-single-${pv}/bin/pip\" install -r ../test-requirements.txt\n+ eval \"$(pyenv root)/versions/tmp-pyteomics-single-${pv}/bin/pip\" install -U ..\n+ echo \"Running test...\"\nif [ -f \"$f\" ]; then\nfname=\"$f\"\nelif [ -f \"test_${f}.py\" ]; then\nfname=\"test_${f}.py\"\nfi\n- echo \"Executing python${v}\" \"$fname\"; eval \"python${v}\" \"$fname\"\n- }\n- done\n+ echo \"Executing $(pyenv root)/versions/tmp-pyteomics-single-${pv}/bin/python ${fname}\"\n+ eval \"$(pyenv root)/versions/tmp-pyteomics-single-${pv}/bin/python\" \"${fname}\"\n+ echo \"Deleting environment...\"\n+ echo pyenv virtualenv-delete \"tmp-pyteomics-single-${pv}\"\n+ eval pyenv virtualenv-delete \"tmp-pyteomics-single-${pv}\"\n+ done < python-versions.txt\ndone\nfi\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Start rewriting the test runner using pyenv
377,522
18.05.2022 17:44:47
-10,800
de57dff70331b05df97135e4ba278b55555ba660
Save exit codes
[ { "change_type": "MODIFY", "old_path": "tests/runtests.sh", "new_path": "tests/runtests.sh", "diff": "@@ -5,6 +5,8 @@ NODEPS=0\nPREFIX_ALL=\"test_pyteomics_\"\nPREFIX_SINGLE=\"test_pyteomics_single_\"\nCLEAN=0\n+declare -A exitcodes\n+\nfor i in \"$@\" ; do\nif [[ \"$i\" == \"--all\" ]] ; then\nMODE=\"all\"\n@@ -39,6 +41,7 @@ if [[ $MODE == \"all\" ]] ; then\nwhile read pv; do\necho \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/python\" \"$f\"\neval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/python\" \"$f\"\n+ exitcodes[\"$f + py${pv}\"]=$?\ndone < python-versions.txt\ndone\nif [[ $CLEAN == 1 ]] ; then\n@@ -55,7 +58,7 @@ else\ncontinue\nfi\nwhile read pv; do\n- if [[ $CLEAN == 1 ]] || [ ! -d \"${ROOT}/versions/${PREFIX_ALL}${pv}\" ]; then\n+ if [[ $CLEAN == 1 ]] || [ ! -d \"${ROOT}/versions/${PREFIX_SINGLE}${pv}\" ]; then\necho \"Creating environment...\"\npyenv virtualenv -f \"$pv\" \"${PREFIX_SINGLE}${pv}\"\nfi\n@@ -69,6 +72,7 @@ else\necho \"Running test...\"\necho \"Executing ${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/python ${fname}\"\neval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/python\" \"${fname}\"\n+ exitcodes[\"$f + py${pv}\"]=$?\nif [[ $CLEAN == 1 ]] ; then\necho \"Deleting environment...\"\necho pyenv virtualenv-delete -f \"${PREFIX_SINGLE}${pv}\"\n@@ -77,3 +81,17 @@ else\ndone < python-versions.txt\ndone\nfi\n+\n+total=0\n+for key in \"${!exitcodes[@]}\"; do\n+ if [[ \"${exitcodes[$key]}\" != 0 ]] ; then\n+ (( total++ ))\n+ echo \"ERROR: $key => exit code ${exitcodes[$key]}\"\n+ fi\n+done\n+\n+if [[ $total == 0 ]] ; then\n+ echo \"All tests complete, there were no errors.\"\n+else\n+ echo \"All tests complete, there were ${total} errors (see above).\"\n+fi\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Save exit codes
377,522
18.05.2022 18:16:37
-10,800
c8db8982a33f9a2340a2ad2c3ac471ff3a7693ad
Do not delete envs after tests; upgrade deps
[ { "change_type": "MODIFY", "old_path": "tests/runtests.sh", "new_path": "tests/runtests.sh", "diff": "@@ -22,9 +22,15 @@ done\nif [[ $MODE == \"all\" ]] ; then\necho \"Installing Python versions...\"\nxargs -a python-versions.txt -I{} pyenv install -s {}\n- echo \"Creating environments...\"\n+ if [[ $CLEAN == 1 ]] ; then\n+ echo \"Deleting old environments...\"\n+ xargs -a python-versions.txt -I{} echo pyenv virtualenv-delete -f \"${PREFIX_ALL}\"{}\n+ fi\n+\nwhile read pv; do\nif [[ $CLEAN == 1 ]] || [ ! -d \"${ROOT}/versions/${PREFIX_ALL}${pv}\" ]; then\n+ echo \"Creating environment ${PREFIX_ALL}${pv} ...\"\n+ echo pyenv virtualenv -f \"$pv\" \"${PREFIX_ALL}${pv}\"\npyenv virtualenv -f \"$pv\" \"${PREFIX_ALL}${pv}\"\nfi\ndone < python-versions.txt\n@@ -32,7 +38,7 @@ if [[ $MODE == \"all\" ]] ; then\necho \"Installing dependencies...\"\nwhile read pv; do\neval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/pip\" install -U pip wheel\n- eval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/pip\" install -r ../test-requirements.txt\n+ eval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/pip\" install -U -r ../test-requirements.txt\neval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/pip\" install -U ..\ndone < python-versions.txt\nfi\n@@ -44,10 +50,6 @@ if [[ $MODE == \"all\" ]] ; then\nexitcodes[\"$f + py${pv}\"]=$?\ndone < python-versions.txt\ndone\n- if [[ $CLEAN == 1 ]] ; then\n- echo \"Deleting environments...\"\n- xargs -a python-versions.txt -I{} echo pyenv virtualenv-delete -f \"${PREFIX_ALL}\"{}\n- fi\nelse\nfor f; do\nif [ -f \"$f\" ]; then\n@@ -58,26 +60,28 @@ else\ncontinue\nfi\nwhile read pv; do\n+ if [[ $CLEAN == 1 ]] ; then\n+ echo \"Deleting old ${PREFIX_SINGLE}${pv} environment...\"\n+ echo pyenv virtualenv-delete -f \"${PREFIX_SINGLE}${pv}\"\n+ eval pyenv virtualenv-delete -f \"${PREFIX_SINGLE}${pv}\"\n+ fi\n+\nif [[ $CLEAN == 1 ]] || [ ! -d \"${ROOT}/versions/${PREFIX_SINGLE}${pv}\" ]; then\necho \"Creating environment...\"\n+ echo pyenv virtualenv -f \"$pv\" \"${PREFIX_SINGLE}${pv}\"\npyenv virtualenv -f \"$pv\" \"${PREFIX_SINGLE}${pv}\"\nfi\nif [[ $NODEPS == 0 ]] ; then\necho \"Installing dependencies...\"\neval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -U pip wheel\n- eval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -r ../test-requirements.txt\n+ eval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -U -r ../test-requirements.txt\neval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -U ..\nfi\necho \"Running test...\"\necho \"Executing ${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/python ${fname}\"\neval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/python\" \"${fname}\"\nexitcodes[\"$f + py${pv}\"]=$?\n- if [[ $CLEAN == 1 ]] ; then\n- echo \"Deleting environment...\"\n- echo pyenv virtualenv-delete -f \"${PREFIX_SINGLE}${pv}\"\n- eval pyenv virtualenv-delete -f \"${PREFIX_SINGLE}${pv}\"\n- fi\ndone < python-versions.txt\ndone\nfi\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Do not delete envs after tests; upgrade deps
377,522
18.05.2022 19:13:12
-10,800
224097676e6cf58e2797d7950fbf7b04fade5ec5
Add --no-run, try to fix counting for --all
[ { "change_type": "MODIFY", "old_path": "tests/runtests.sh", "new_path": "tests/runtests.sh", "diff": "@@ -10,6 +10,8 @@ declare -A exitcodes\nfor i in \"$@\" ; do\nif [[ \"$i\" == \"--all\" ]] ; then\nMODE=\"all\"\n+ elif [[ \"$i\" == \"--no-run\" ]] ; then\n+ MODE=\"no-op\"\nfi\nif [[ \"$i\" == \"--clean\" ]] ; then\nCLEAN=1\n@@ -17,6 +19,7 @@ for i in \"$@\" ; do\nif [[ \"$i\" == \"--no-deps\" ]] ; then\nNODEPS=1\nfi\n+\ndone\nif [[ $MODE == \"all\" ]] ; then\n@@ -43,22 +46,14 @@ if [[ $MODE == \"all\" ]] ; then\ndone < python-versions.txt\nfi\necho \"Running tests...\"\n- find . -name 'test_*.py' -print | while read f; do\n+ while read f; do\nwhile read pv; do\necho \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/python\" \"$f\"\neval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/python\" \"$f\"\nexitcodes[\"$f + py${pv}\"]=$?\ndone < python-versions.txt\n- done\n-else\n- for f; do\n- if [ -f \"$f\" ]; then\n- fname=\"$f\"\n- elif [ -f \"test_${f}.py\" ]; then\n- fname=\"test_${f}.py\"\n+ done < <(find . -name 'test_*.py' -print)\nelse\n- continue\n- fi\nwhile read pv; do\nif [[ $CLEAN == 1 ]] ; then\necho \"Deleting old ${PREFIX_SINGLE}${pv} environment...\"\n@@ -78,14 +73,27 @@ else\neval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -U -r ../test-requirements.txt\neval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -U ..\nfi\n- echo \"Running test...\"\n+ done < python-versions.txt\n+\n+ if [[ \"$MODE\" == \"single\" ]] ; then\n+ for f; do\n+ if [ -f \"$f\" ]; then\n+ fname=\"$f\"\n+ elif [ -f \"test_${f}.py\" ]; then\n+ fname=\"test_${f}.py\"\n+ else\n+ continue\n+ fi\n+ while read pv; do\necho \"Executing ${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/python ${fname}\"\neval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/python\" \"${fname}\"\nexitcodes[\"$f + py${pv}\"]=$?\ndone < python-versions.txt\ndone\nfi\n+fi\n+if ! [[ \"$MODE\" == \"no-op\" ]] ; then\ntotal=0\nerrors=0\nfor key in \"${!exitcodes[@]}\"; do\n@@ -101,3 +109,4 @@ if [[ $errors == 0 ]] ; then\nelse\necho \"All ${total} test runs complete, there were ${errors} errors (see above).\"\nfi\n+fi\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add --no-run, try to fix counting for --all
377,522
19.05.2022 04:23:19
-10,800
8a0e7e258497f9cdd3b2045d85df0e914b5927bd
Rewrite with GNU parallel and exceptions
[ { "change_type": "MODIFY", "old_path": "tests/runtests.sh", "new_path": "tests/runtests.sh", "diff": "#!/bin/bash\n-ROOT=\"$(pyenv root)\"\n-MODE=\"single\"\n-NODEPS=0\n-PREFIX_ALL=\"test_pyteomics_\"\n-PREFIX_SINGLE=\"test_pyteomics_single_\"\n-CLEAN=0\n+\n+export ROOT=\"$(pyenv root)\"\n+export MODE=\"single\"\n+export NODEPS=0\n+export PREFIX=\"test_pyteomics_\"\n+export CLEAN=0\n+JOBLOG=\"parallel.log\"\n+consequtive=(\"unimod\")\ndeclare -A exitcodes\n+rm -f \"$JOBLOG\"\n+\nfor i in \"$@\" ; do\nif [[ \"$i\" == \"--all\" ]] ; then\nMODE=\"all\"\n@@ -19,94 +23,117 @@ for i in \"$@\" ; do\nif [[ \"$i\" == \"--no-deps\" ]] ; then\nNODEPS=1\nfi\n-\ndone\n-if [[ $MODE == \"all\" ]] ; then\n- echo \"Installing Python versions...\"\n- xargs -a python-versions.txt -I{} pyenv install -s {}\n- if [[ $CLEAN == 1 ]] ; then\n- echo \"Deleting old environments...\"\n- xargs -a python-versions.txt -I{} echo pyenv virtualenv-delete -f \"${PREFIX_ALL}\"{}\n+create() {\n+ if [[ $CLEAN == 1 ]] || [ ! -d \"${ROOT}/versions/${PREFIX}${1}\" ]; then\n+ echo \"Creating environment ${PREFIX}${1} ...\"\n+ echo pyenv virtualenv -f \"$1\" \"${PREFIX}${1}\"\n+ pyenv virtualenv -f \"$1\" \"${PREFIX}${1}\"\nfi\n+}\n- while read pv; do\n- if [[ $CLEAN == 1 ]] || [ ! -d \"${ROOT}/versions/${PREFIX_ALL}${pv}\" ]; then\n- echo \"Creating environment ${PREFIX_ALL}${pv} ...\"\n- echo pyenv virtualenv -f \"$pv\" \"${PREFIX_ALL}${pv}\"\n- pyenv virtualenv -f \"$pv\" \"${PREFIX_ALL}${pv}\"\n- fi\n- done < python-versions.txt\n- if [[ $NODEPS == 0 ]] ; then\n- echo \"Installing dependencies...\"\n- while read pv; do\n- eval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/pip\" install -U pip wheel\n- eval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/pip\" install -U -r ../test-requirements.txt\n- eval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/pip\" install -U ..\n- done < python-versions.txt\n- fi\n- echo \"Running tests...\"\n- while read f; do\n- while read pv; do\n- echo \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/python\" \"$f\"\n- eval \"${ROOT}/versions/${PREFIX_ALL}${pv}/bin/python\" \"$f\"\n- exitcodes[\"$f + py${pv}\"]=$?\n- done < python-versions.txt\n- done < <(find . -name 'test_*.py' -print)\n+deps() {\n+ eval \"${ROOT}/versions/${PREFIX}${1}/bin/pip\" install -U pip wheel\n+ eval \"${ROOT}/versions/${PREFIX}${1}/bin/pip\" install -U -r ../test-requirements.txt\n+ eval \"${ROOT}/versions/${PREFIX}${1}/bin/pip\" install -U ..\n+}\n+\n+run() {\n+ if [ -f \"$2\" ]; then\n+ fname=\"$2\"\n+ elif [ -f \"test_${2}.py\" ]; then\n+ fname=\"test_${2}.py\"\nelse\n- while read pv; do\n- if [[ $CLEAN == 1 ]] ; then\n- echo \"Deleting old ${PREFIX_SINGLE}${pv} environment...\"\n- echo pyenv virtualenv-delete -f \"${PREFIX_SINGLE}${pv}\"\n- eval pyenv virtualenv-delete -f \"${PREFIX_SINGLE}${pv}\"\n+ return 0\nfi\n+ echo \"${ROOT}/versions/${PREFIX}${1}/bin/python\" \"$fname\"\n+ eval \"${ROOT}/versions/${PREFIX}${1}/bin/python\" \"$fname\"\n+}\n- if [[ $CLEAN == 1 ]] || [ ! -d \"${ROOT}/versions/${PREFIX_SINGLE}${pv}\" ]; then\n- echo \"Creating environment...\"\n- echo pyenv virtualenv -f \"$pv\" \"${PREFIX_SINGLE}${pv}\"\n- pyenv virtualenv -f \"$pv\" \"${PREFIX_SINGLE}${pv}\"\n+export -f create deps run\n+\n+echo \"Checking installed Python versions...\"\n+parallel pyenv install -s < python-versions.txt\n+if [[ $CLEAN == 1 ]] ; then\n+ echo \"Deleting old environments...\"\n+ xargs -a python-versions.txt -I{} echo pyenv virtualenv-delete -f \"${PREFIX}\"{}\n+ xargs -a python-versions.txt -I{} pyenv virtualenv-delete -f \"${PREFIX}\"{}\nfi\n+parallel create :::: python-versions.txt\n+\nif [[ $NODEPS == 0 ]] ; then\necho \"Installing dependencies...\"\n- eval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -U pip wheel\n- eval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -U -r ../test-requirements.txt\n- eval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/pip\" install -U ..\n+ parallel deps :::: python-versions.txt\nfi\n- done < python-versions.txt\n- if [[ \"$MODE\" == \"single\" ]] ; then\n- for f; do\n- if [ -f \"$f\" ]; then\n- fname=\"$f\"\n- elif [ -f \"test_${f}.py\" ]; then\n- fname=\"test_${f}.py\"\n- else\n+if [[ $MODE == \"all\" ]] ; then\n+ files=$(find . -name 'test_*.py' -print)\n+elif [[ \"$MODE\" == \"single\" ]] ; then\n+ files=$@\n+fi\n+\n+if [[ \"$MODE\" != \"no-op\" ]] ; then\n+ parallel_files=()\n+ consecutive_files=()\n+ for f in ${files[@]}; do\n+ if [[ \"$f\" =~ ^-- ]] ; then\ncontinue\nfi\n+ cons_flag=0\n+ for check in ${consequtive[@]}; do\n+ if [[ \"$f\" =~ \"$check\" ]] ; then\n+ cons_flag=1\n+ break\n+ fi\n+ done\n+ if [[ $cons_flag == 1 ]]; then\n+ consecutive_files+=(\"$f\")\n+ else\n+ parallel_files+=(\"$f\")\n+ fi\n+ done\n+\n+ if [[ ${#consecutive_files[@]} != 0 ]] ; then\n+ echo \"Running tests consecutively:\" ${consecutive_files[@]}\n+ for f in ${consecutive_files[@]}; do\nwhile read pv; do\n- echo \"Executing ${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/python ${fname}\"\n- eval \"${ROOT}/versions/${PREFIX_SINGLE}${pv}/bin/python\" \"${fname}\"\n- exitcodes[\"$f + py${pv}\"]=$?\n+ run \"$pv\" \"$f\"\n+ exitcodes[\"run ${pv} ${f}\"]=$?\ndone < python-versions.txt\ndone\nfi\n+\n+ if [[ ${#parallel_files[@]} != 0 ]] ; then\n+ echo \"Running tests in parallel:\" \"${parallel_files[@]}\"\n+ parallel --joblog \"$JOBLOG\" run :::: python-versions.txt ::: ${parallel_files[@]}\nfi\n-if [[ \"$MODE\" != \"no-op\" ]] ; then\n- total=0\n- errors=0\n+ total=${#exitcodes[@]}\n+ nerrors=0\n+ if [ -f \"$JOBLOG\" ] ; then\n+ total=$(( $total + $( wc -l < \"$JOBLOG\" ) - 1 ))\n+\n+ errors=$(awk -F '\\t' '\n+ NR==1 { next }\n+ $7 != 0 { sum += 1; printf \"exit code: %d; job %s\\t(parallel)\\n\", $7, $9 }' \"$JOBLOG\")\n+ echo \"$errors\"\n+ if [[ \"$errors\" != \"\" ]]; then\n+ nerrors=$(echo \"$errors\" | wc -l)\n+ fi\n+ fi\n+ conseq_errors=0\nfor key in \"${!exitcodes[@]}\"; do\n- (( total++ ))\n- if [[ \"${exitcodes[$key]}\" != 0 ]] ; then\n- (( errors++ ))\n- echo \"ERROR: $key => exit code ${exitcodes[$key]}\"\n+ if [[ ${exitcodes[\"$key\"]} != 0 ]]; then\n+ (( conseq_errors++ ))\n+ printf \"exit code: %d; job %s\\t(consequtive)\\n\" ${exitcodes[\"$key\"]} \"$key\"\nfi\ndone\n-\n- if [[ $errors == 0 ]] ; then\n+ nerrors=$(( $nerrors + $conseq_errors ))\n+ if [[ $nerrors == 0 ]] ; then\necho \"All ${total} test runs complete, there were no errors.\"\nelse\n- echo \"All ${total} test runs complete, there were ${errors} errors (see above).\"\n+ echo \"All ${total} test runs complete, there were ${nerrors} errors (see above).\"\nfi\nfi\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Rewrite with GNU parallel and exceptions
377,522
19.05.2022 04:50:13
-10,800
0a49c98316d92763b630ed371aa3e53d1ce5fec0
Install pyteomics consecutively
[ { "change_type": "MODIFY", "old_path": "tests/runtests.sh", "new_path": "tests/runtests.sh", "diff": "@@ -36,7 +36,6 @@ create() {\ndeps() {\neval \"${ROOT}/versions/${PREFIX}${1}/bin/pip\" install -U pip wheel\neval \"${ROOT}/versions/${PREFIX}${1}/bin/pip\" install -U -r ../test-requirements.txt\n- eval \"${ROOT}/versions/${PREFIX}${1}/bin/pip\" install -U ..\n}\nrun() {\n@@ -66,6 +65,10 @@ parallel create :::: python-versions.txt\nif [[ $NODEPS == 0 ]] ; then\necho \"Installing dependencies...\"\nparallel deps :::: python-versions.txt\n+ while read pv; do\n+ echo \"${ROOT}/versions/${PREFIX}${pv}/bin/pip\" install -U ..\n+ eval \"${ROOT}/versions/${PREFIX}${pv}/bin/pip\" install -U ..\n+ done < python-versions.txt\nfi\nif [[ $MODE == \"all\" ]] ; then\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Install pyteomics consecutively
377,522
07.06.2022 16:11:19
-10,800
32ad602bbd86deb910da93d90b281669277975f3
Raise PyteomicsError instead of ZeroDivisionError in aux.fdr()
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.4a1\n+4.5.4a2\n-------\n- Fix issue #74.\n+ - In :func:`pyteomics.auxiliary.fdr`, raise :exc:`PyteomicsError` instead of :exc:`ZeroDivisionError` when\n+ using formula 1 on input without any target PSMs.\n4.5.3\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/auxiliary/target_decoy.py", "new_path": "pyteomics/auxiliary/target_decoy.py", "diff": "@@ -45,6 +45,8 @@ def _calculate_qvalues(scores, isdecoy, peps=False, **kwargs):\n\"\"\"\ncorrection = kwargs.pop('correction', 0)\nratio = kwargs.pop('ratio', 1)\n+ if ratio == 0:\n+ raise PyteomicsError('Size ratio cannot be zero!')\nremove_decoy = kwargs.get('remove_decoy', False)\nformula = kwargs.pop('formula', (2, 1)[bool(remove_decoy)])\nif formula not in {1, 2}:\n@@ -73,7 +75,7 @@ def _calculate_qvalues(scores, isdecoy, peps=False, **kwargs):\ntfalse[i] = _confidence_value(\ncorrection, cumsum[i], targ[i], p)\nelif correction:\n- raise PyteomicsError('Invalid value for `correction`.')\n+ raise PyteomicsError('Invalid value for `correction`: {}.'.format(correction))\nif formula == 1:\nq = tfalse / (ind - cumsum) / ratio\n@@ -83,8 +85,7 @@ def _calculate_qvalues(scores, isdecoy, peps=False, **kwargs):\n# Make sure that q-values are equal for equal scores (conservatively)\n# and that q-values are monotonic\nfor i in range(scores.size - 1, 0, -1):\n- if (scores[i] == scores[i - 1] or\n- q[i - 1] > q[i]):\n+ if (scores[i] == scores[i - 1] or q[i - 1] > q[i]):\nq[i - 1] = q[i]\nreturn q\n@@ -918,6 +919,8 @@ def _make_fdr(is_decoy_prefix, is_decoy_suffix):\n\"\"\"\nif formula not in {1, 2}:\nraise PyteomicsError('`formula` must be either 1 or 2.')\n+ if ratio == 0:\n+ raise PyteomicsError('Size ratio cannot be zero!')\ndecoy, total = _count_psms(psms, is_decoy, pep, decoy_prefix, decoy_suffix, is_decoy_prefix, is_decoy_suffix)\nif pep is not None:\n@@ -932,6 +935,8 @@ def _make_fdr(is_decoy_prefix, is_decoy_suffix):\np = 1. / (1. + ratio)\ntfalse = _confidence_value(correction, decoy, total - decoy, p)\nif formula == 1:\n+ if total == decoy:\n+ raise PyteomicsError('Cannot compute FDR using formula 1: no target IDs found.')\nreturn float(tfalse) / (total - decoy) / ratio\nreturn (decoy + tfalse / ratio) / total\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.4a1'\n+__version__ = '4.5.4a2'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Raise PyteomicsError instead of ZeroDivisionError in aux.fdr()
377,522
15.06.2022 14:42:33
-10,800
7a20967480f211a5508bb589d0eee67a822b7932
Improve accuracy in mass.std_aa_mass
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.4a2\n+4.5.4a3\n-------\n- Fix issue #74.\n- In :func:`pyteomics.auxiliary.fdr`, raise :exc:`PyteomicsError` instead of :exc:`ZeroDivisionError` when\nusing formula 1 on input without any target PSMs.\n+ - Provide more accurate amino acid masses in :py:data:`mass.std_aa_mass`.\n4.5.3\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -843,30 +843,29 @@ def isotopologues(*args, **kwargs):\nstd_aa_mass = {\n- 'G': 57.02146,\n- 'A': 71.03711,\n- 'S': 87.03203,\n- 'P': 97.05276,\n- 'V': 99.06841,\n- 'T': 101.04768,\n- 'C': 103.00919,\n- 'L': 113.08406,\n- 'I': 113.08406,\n- 'J': 113.08406,\n- 'N': 114.04293,\n- 'D': 115.02694,\n- 'Q': 128.05858,\n- 'K': 128.09496,\n- 'E': 129.04259,\n- 'M': 131.04049,\n- 'H': 137.05891,\n- 'F': 147.06841,\n- 'U': 150.95364,\n- 'R': 156.10111,\n- 'Y': 163.06333,\n- 'W': 186.07931,\n- 'O': 237.14773,\n-}\n+ 'G': 57.02146372057,\n+ 'A': 71.03711378471,\n+ 'S': 87.03202840427001,\n+ 'P': 97.05276384885,\n+ 'V': 99.06841391299,\n+ 'T': 101.04767846841,\n+ 'C': 103.00918478471,\n+ 'L': 113.08406397713001,\n+ 'I': 113.08406397713001,\n+ 'J': 113.08406397713001,\n+ 'N': 114.04292744114001,\n+ 'D': 115.02694302383001,\n+ 'Q': 128.05857750527997,\n+ 'K': 128.09496301399997,\n+ 'E': 129.04259308796998,\n+ 'M': 131.04048491299,\n+ 'H': 137.05891185845002,\n+ 'F': 147.06841391298997,\n+ 'U': 150.95363508471,\n+ 'R': 156.10111102359997,\n+ 'Y': 163.06332853254997,\n+ 'W': 186.07931294985997,\n+ 'O': 237.14772686284996}\n\"\"\"A dictionary with monoisotopic masses of the twenty standard\namino acid residues, selenocysteine and pyrrolysine.\n\"\"\"\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.4a2'\n+__version__ = '4.5.4a3'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Improve accuracy in mass.std_aa_mass
377,522
15.06.2022 16:23:49
-10,800
6916dbe7ad9346869b01da2bbcc1af68cd0e1754
Use Github license shield
[ { "change_type": "MODIFY", "old_path": "README.rst", "new_path": "README.rst", "diff": ":target: https://pyteomics.readthedocs.io/\n:alt: Read the Docs (latest)\n-.. image:: https://img.shields.io/aur/license/python-pyteomics.svg\n+.. image:: https://img.shields.io/github/license/levitsky/pyteomics\n:target: https://www.apache.org/licenses/LICENSE-2.0\n:alt: Apache License\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Use Github license shield
377,522
17.06.2022 19:51:10
-10,800
b9fabac991d2da524b4700af871e56f6a255f924
Fix SyntaxError on Python 2.7
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.4a3\n+4.5.4a4\n-------\n- Fix issue #74.\n- In :func:`pyteomics.auxiliary.fdr`, raise :exc:`PyteomicsError` instead of :exc:`ZeroDivisionError` when\nusing formula 1 on input without any target PSMs.\n- Provide more accurate amino acid masses in :py:data:`mass.std_aa_mass`.\n+ - Fix SyntaxError in :py:mod:`pyteomics.pylab_aux` on Python 2.7.\n4.5.3\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/pylab_aux.py", "new_path": "pyteomics/pylab_aux.py", "diff": "@@ -506,7 +506,7 @@ def _default_annotate_spectrum(spectrum, peptide, *args, **kwargs):\nif adjust:\nadjust_text(texts, **adjust_kw)\nkwargs.setdefault('zorder', -1)\n- return plot_spectrum(spectrum, *args, **kwargs, centroided=centroided)\n+ return plot_spectrum(spectrum, *args, centroided=centroided, **kwargs)\ndef _get_precursor_charge(spectrum):\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.4a3'\n+__version__ = '4.5.4a4'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Fix SyntaxError on Python 2.7
377,522
18.07.2022 16:15:00
-10,800
ad80a82cdab02585a6ce17097b9c781d7522cfbd
Expand docstrings in pepxml
[ { "change_type": "MODIFY", "old_path": "pyteomics/pepxml.py", "new_path": "pyteomics/pepxml.py", "diff": "@@ -247,18 +247,18 @@ def iterfind(source, path, **kwargs):\nThe path can be absolute or \"free\". Please don't specify\nnamespaces.\n- recursive : bool, optional\n+ recursive : bool, keyword only, optional\nIf :py:const:`False`, subelements will not be processed when\nextracting info from elements. Default is :py:const:`True`.\n- iterative : bool, optional\n+ iterative : bool, keyword only, optional\nSpecifies whether iterative XML parsing should be used. Iterative\nparsing significantly reduces memory usage and may be just a little\nslower. When `retrieve_refs` is :py:const:`True`, however, it is\nhighly recommended to disable iterative parsing if possible.\nDefault value is :py:const:`True`.\n- read_schema : bool, optional\n+ read_schema : bool, keyword only, optional\nIf :py:const:`True`, attempt to extract information from the XML schema\nmentioned in the mzIdentML header. Otherwise, use default parameters.\nNot recommended without Internet connection or\n@@ -354,7 +354,7 @@ def DataFrame(*args, **kwargs):\nParameters\n----------\n*args\n- Passed to :py:func:`chain`.\n+ pepXML file names or objects. Passed to :py:func:`chain`.\n**kwargs\nPassed to :py:func:`chain`.\n@@ -365,6 +365,23 @@ def DataFrame(*args, **kwargs):\nthis delimiter. If `sep` is :py:const:`None`, they are kept as lists. Default is\n:py:const:`None`.\n+ recursive : bool, keyword only, optional\n+ If :py:const:`False`, subelements will not be processed when\n+ extracting info from elements. Default is :py:const:`True`.\n+\n+ iterative : bool, keyword only, optional\n+ Specifies whether iterative XML parsing should be used. Iterative\n+ parsing significantly reduces memory usage and may be just a little\n+ slower. When `retrieve_refs` is :py:const:`True`, however, it is\n+ highly recommended to disable iterative parsing if possible.\n+ Default value is :py:const:`True`.\n+\n+ read_schema : bool, keyword only, optional\n+ If :py:const:`True`, attempt to extract information from the XML schema\n+ mentioned in the mzIdentML header. Otherwise, use default parameters.\n+ Not recommended without Internet connection or\n+ if you don't like to get the related warnings.\n+\npd_kwargs : dict, optional\nKeyword arguments passed to the :py:class:`pandas.DataFrame` constructor.\n@@ -427,20 +444,101 @@ def DataFrame(*args, **kwargs):\ndef filter_df(*args, **kwargs):\n\"\"\"Read pepXML files or DataFrames and return a :py:class:`DataFrame` with filtered PSMs.\n- Positional arguments can be pepXML files or DataFrames.\n+ Positional arguments can be pepXML files or DataFrames. Keyword parameter `fdr` is also required.\n+ Other parameters are optional.\nRequires :py:mod:`pandas`.\nParameters\n----------\n+ positional args\n+ pepXML file names, file objects, or DataFrames. Passed to :py:func:`DataFrame`.\n+ fdr : float, keyword only, 0 <= fdr <= 1\n+ Desired FDR level.\nkey : str / iterable / callable, keyword only, optional\nPSM score. Default is 'expect'.\nis_decoy : str / iterable / callable, keyword only, optional\n- Default is to check if all strings in the \"protein\" column start with `'DECOY_'`\n- *args\n- Passed to :py:func:`auxiliary.filter` and/or :py:func:`DataFrame`.\n- **kwargs\n- Passed to :py:func:`auxiliary.filter` and/or :py:func:`DataFrame`.\n+ Default is to check if all strings in the \"protein\" column start with `'DECOY_'`.\n+ sep : str or None, keyword only, optional\n+ Some values related to PSMs (such as protein information) are variable-length\n+ lists. If `sep` is a :py:class:`str`, they will be packed into single string using\n+ this delimiter. If `sep` is :py:const:`None`, they are kept as lists. Default is\n+ :py:const:`None`.\n+ reverse : bool, keyword only, optional\n+ If :py:const:`True`, then PSMs are sorted in descending order,\n+ i.e. the value of the key function is higher for better PSMs.\n+ Default is :py:const:`False`.\n+ decoy_prefix : str, optional\n+ If the default `is_decoy` function works for you, this parameter specifies which\n+ protein name prefix to use to detect decoy matches. If you provide your own\n+ `is_decoy`, or if you specify `decoy_suffix`, this parameter has no effect.\n+ Default is `\"DECOY_\"`.\n+ decoy_suffix : str, optional\n+ If the default `is_decoy` function works for you, this parameter specifies which\n+ protein name suffix to use to detect decoy matches. If you provide your own\n+ `is_decoy`, this parameter has no effect. Mutually exclusive with `decoy_prefix`.\n+ remove_decoy : bool, keyword only, optional\n+ Defines whether decoy matches should be removed from the output.\n+ Default is :py:const:`True`.\n+\n+ .. note:: If set to :py:const:`False`, then by default the decoy\n+ PSMs will be taken into account when estimating FDR. Refer to the\n+ documentation of :py:func:`fdr` for math; basically, if\n+ `remove_decoy` is :py:const:`True`, then formula 1 is used\n+ to control output FDR, otherwise it's formula 2. This can be\n+ changed by overriding the `formula` argument.\n+\n+ formula : int, keyword only, optional\n+ Can be either 1 or 2, defines which formula should be used for FDR\n+ estimation. Default is 1 if `remove_decoy` is :py:const:`True`,\n+ else 2 (see :py:func:`fdr` for definitions).\n+ ratio : float, keyword only, optional\n+ The size ratio between the decoy and target databases. Default is\n+ 1. In theory, the \"size\" of the database is the number of\n+ theoretical peptides eligible for assignment to spectra that are\n+ produced by *in silico* cleavage of that database.\n+ correction : int or float, keyword only, optional\n+ Possible values are 0, 1 and 2, or floating point numbers between 0 and 1.\n+\n+ 0 (default): no correction;\n+\n+ 1: enable \"+1\" correction. This accounts for the probability that a false\n+ positive scores better than the first excluded decoy PSM;\n+\n+ 2: this also corrects that probability for finite size of the sample,\n+ so the correction will be slightly less than \"+1\".\n+\n+ If a floating point number\n+ is given, then instead of the expectation value for the number of false PSMs,\n+ the confidence value is used. The value of `correction` is then interpreted as\n+ desired confidence level. E.g., if correction=0.95, then the calculated q-values\n+ do not exceed the \"real\" q-values with 95% probability.\n+\n+ See `this paper <http://dx.doi.org/10.1021/acs.jproteome.6b00144>`_ for further explanation.\n+\n+ pep : callable / array-like / iterable / str, keyword only, optional\n+ If callable, a function used to determine the posterior error probability (PEP).\n+ Should accept exactly one argument (PSM) and return a float.\n+ If array-like, should contain float values for all given PSMs.\n+ If string, it is used as a field name (PSMs must be in a record array\n+ or a :py:class:`DataFrame`).\n+\n+ .. note:: If this parameter is given, then PEP values will be used to calculate\n+ q-values. Otherwise, decoy PSMs will be used instead. This option conflicts with:\n+ `is_decoy`, `remove_decoy`, `formula`, `ratio`, `correction`.\n+ `key` can still be provided. Without `key`, PSMs will be sorted by PEP.\n+\n+ q_label : str, optional\n+ Field name for q-value in the output. Default is ``'q'``.\n+\n+ score_label : str, optional\n+ Field name for score in the output. Default is ``'score'``.\n+\n+ decoy_label : str, optional\n+ Field name for the decoy flag in the output. Default is ``'is decoy'``.\n+\n+ pep_label : str, optional\n+ Field name for PEP in the output. Default is ``'PEP'``.\nReturns\n-------\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Expand docstrings in pepxml
377,522
13.10.2022 20:44:29
-14,400
ece30293cd919360b1772375112c1edc2dae4ba5
Fix fast_mass2
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "+4.5.6a1\n+-------\n+\n+ - Prevent :func:`pyteomics.mass.fast_mass2` from changing `aa_mass`.\n+\n4.5.5\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/mass/mass.py", "new_path": "pyteomics/mass/mass.py", "diff": "@@ -959,8 +959,6 @@ def fast_mass2(sequence, ion_type=None, charge=None, **kwargs):\n\"\"\"\naa_mass = kwargs.get('aa_mass', std_aa_mass)\nmass_data = kwargs.get('mass_data', nist_mass)\n- aa_mass.setdefault('H-', mass_data['H'][0][0])\n- aa_mass.setdefault('-OH', mass_data['H'][0][0] + mass_data['O'][0][0])\ntry:\ncomp = parser.amino_acid_composition(sequence,\nshow_unmodified_termini=True,\n@@ -975,6 +973,9 @@ def fast_mass2(sequence, ion_type=None, charge=None, **kwargs):\nfor aa, num in comp.items():\nif aa in aa_mass:\nmass += aa_mass[aa] * num\n+ elif parser.is_term_mod(aa):\n+ assert num == 1\n+ mass += calculate_mass(formula=aa.strip('-'), mass_data=mass_data)\nelse:\nmod, X = parser._split_label(aa)\nmass += (aa_mass[mod] + aa_mass[X]) * num\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.5'\n+__version__ = '4.5.6a1'\nfrom collections import namedtuple\nimport re\n" }, { "change_type": "MODIFY", "old_path": "tests/test_mass.py", "new_path": "tests/test_mass.py", "diff": "@@ -62,12 +62,23 @@ class MassTest(unittest.TestCase):\nmass.fast_mass(pep, aa_mass=self.test_aa_mass),\nsum(pep.count(aa) * m for aa, m in self.test_aa_mass.items()) + self.mass_H * 2.0 + self.mass_O)\n- def test_fast_mass2(self):\n+ def test_fast_mass2_no_term(self):\nfor pep in self.random_peptides:\nself.assertAlmostEqual(\nmass.fast_mass2(pep, aa_mass=self.test_aa_mass),\nsum(pep.count(aa) * m for aa, m in self.test_aa_mass.items()) + self.mass_H * 2.0 + self.mass_O)\n+ def test_fast_mass2_term(self):\n+ for pep in self.random_peptides:\n+ nterm = 'AB2C3-'\n+ cterm = '-DE2F3'\n+ self.assertAlmostEqual(\n+ mass.fast_mass2(nterm + pep + cterm, aa_mass=self.test_aa_mass, mass_data=self.mass_data),\n+ sum(pep.count(aa) * m for aa, m in self.test_aa_mass.items()) + (\n+ self.mass_data['A'][0][0] + self.mass_data['B'][0][0] * 2 + self.mass_data['C'][0][0] * 3 +\n+ self.mass_data['D'][0][0] + self.mass_data['E'][0][0] * 2 + self.mass_data['F'][0][0] * 3))\n+\n+\ndef test_Composition_dict(self):\n# Test Composition from a dict.\nself.assertEqual(mass.Composition(self.d, mass_data=self.mass_data), self.d)\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Fix fast_mass2
377,529
24.10.2022 15:33:34
-7,200
b408c0c4a89386c3b73dfb465c1605852e55f6c4
use packaging instead of distutils if available
[ { "change_type": "MODIFY", "old_path": "pyteomics/auxiliary/patch.py", "new_path": "pyteomics/auxiliary/patch.py", "diff": "-from distutils.version import LooseVersion\n+try:\n+ from packaging.version import Version\n+except ImportError:\n+ from distutils.version import LooseVersion as Version\ntry:\nimport pandas as pd\n@@ -9,5 +12,5 @@ else:\npv = pd._version.get_versions()['version']\nelse:\npv = pd.version.version\n- if LooseVersion(pv) < LooseVersion('0.17'):\n+ if Version(pv) < Version('0.17'):\npd.DataFrame.sort_values = pd.DataFrame.sort\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
use packaging instead of distutils if available
377,522
28.10.2022 14:16:10
-7,200
96849b3227541316d9681f99551cee0d5ec037b8
Use Proforma.mass in annotation
[ { "change_type": "MODIFY", "old_path": "pyteomics/pylab_aux.py", "new_path": "pyteomics/pylab_aux.py", "diff": "@@ -592,9 +592,10 @@ def _spectrum_utils_annotate_spectrum(spectrum, peptide, *args, **kwargs):\nprefix = kwargs.get('prefix')\ntry:\n- proforma.parse(peptide)\n+ parsed_proforma = proforma.Proforma.parse(peptide)\npeptide_pro = peptide\nexcept Exception:\n+ parsed_proforma = None\ntry:\npeptide_pro = parser.to_proforma(peptide, aa_mass=aa_mass, aa_comp=aa_comp, mod_names=mod_names, prefix=prefix)\nexcept Exception:\n@@ -607,8 +608,10 @@ def _spectrum_utils_annotate_spectrum(spectrum, peptide, *args, **kwargs):\ntry:\nif aa_comp:\nprecursor_mz = mass.calculate_mass(peptide, aa_comp=aa_comp, charge=precursor_charge)\n- else:\n+ elif not parsed_proforma:\nprecursor_mz = mass.fast_mass2(peptide, aa_mass=aa_mass, charge=precursor_charge)\n+ else:\n+ precursor_mz = mass.mass_charge_ratio(parsed_proforma.mass, precursor_charge)\nexcept PyteomicsError:\nraise PyteomicsError('Cannot obtain precursor m/z, please specify `precursor_mz` argument.')\n@@ -635,32 +638,6 @@ class SpectrumUtilsColorScheme:\nsup.colors = self.previous_colors\n-def _spectrum_utils_parse_sequence(sequence, aa_mass=None):\n- if isinstance(sequence, str):\n- parsed = parser.parse(sequence, show_unmodified_termini=True, labels=aa_mass, allow_unknown_modifications=True)\n- else:\n- parsed = sequence\n- mods = {}\n- aa_mass = aa_mass or mass.std_aa_mass\n- if parsed[0] != parser.std_nterm:\n- mods['N-term'] = aa_mass[parsed[0]]\n- if parsed[-1] != parser.std_cterm:\n- mods['C-term'] = aa_mass[parsed[-1]]\n- clean_sequence = []\n- for i, aa in enumerate(parsed[1:-1]):\n- if len(aa) > 1:\n- if aa[:-1] in aa_mass:\n- mods[i] = aa_mass[aa[:-1]]\n- else:\n- try:\n- mods[i] = aa_mass[aa] - aa_mass[aa[-1]]\n- except KeyError:\n- raise PyteomicsError('Unknown modification mass: {0}. {0} or {1} must be in `aa_mass`.'.format(\n- aa[:-1], aa))\n- clean_sequence.append(aa[-1])\n- return ''.join(clean_sequence), mods\n-\n-\ndef _spectrum_utils_annotate_plot(spectrum, peptide, *args, **kwargs):\nwith SpectrumUtilsColorScheme(kwargs.pop('colors', None)):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Use Proforma.mass in annotation
377,522
31.10.2022 22:20:02
-3,600
3605dc58dc05e9198759900b8419c6d8987e8986
Add spectrum_utils version check, update changelog, set version to 4.5.6
[ { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.6a3\n--------\n+4.5.6\n+-----\n- New function :py:func:`pyteomics.proforma.set_unimod_path` allowing the ProForma parsing machinery\nto work with a local Unimod copy (`#85 <https://github.com/levitsky/pyteomics/pull/85>`_ by Joshua Klein).\n+ See `documentation <https://pyteomics.readthedocs.io/en/latest/api/proforma.html#cv-disk-caching>`_ for a usage example).\n- New method :py:func:`pyteomics.proforma.Proforma.fragments` to generate m/z for an ion series\n(`#85 <https://github.com/levitsky/pyteomics/pull/85>`_ by Joshua Klein).\n- New function :py:func:`pyteomics.parser.to_proforma` helps convert *modX* sequences to ProForma.\n- Fix: prevent :func:`pyteomics.mass.fast_mass2` from changing `aa_mass`.\n- Update :py:func:`pyteomics.pylab_aux.annotate_spectrum` for compatibility with latest :py:mod:`spectrum_utils`.\n+ Pyteomics is now compatible with :py:mod:`spectrum_utils` 0.4.0 and newer.\n4.5.5\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/auxiliary/__init__.py", "new_path": "pyteomics/auxiliary/__init__.py", "diff": "@@ -3,7 +3,7 @@ try:\nexcept NameError:\nbasestring = (str, bytes)\n-from . import patch as __patch\n+from .patch import Version as _Version\nfrom .structures import (\nPyteomicsError, Charge, ChargeList,\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/pylab_aux.py", "new_path": "pyteomics/pylab_aux.py", "diff": "@@ -64,10 +64,13 @@ This module requires :py:mod:`matplotlib`. Optional dependencies: :py:mod:`adjus\nimport pylab\nimport numpy as np\n-from .auxiliary import linear_regression, PyteomicsError\n+from .auxiliary import linear_regression, PyteomicsError, _Version\nfrom . import parser, mass, mgf, proforma\ntry:\n+ import spectrum_utils\n+ if _Version(spectrum_utils.__version__) < _Version('0.4'):\n+ raise ImportError(\"Supported spectrum_utils version is 0.4.0 or newer.\")\nimport spectrum_utils.spectrum as sus\nimport spectrum_utils.plot as sup\nexcept ImportError:\n@@ -539,7 +542,7 @@ def _get_precursor_mz(spectrum):\ndef _spectrum_utils_create_spectrum(spectrum, *args, **kwargs):\nif sus is None:\n- raise PyteomicsError('This backend requires `spectrum_utils`.')\n+ raise PyteomicsError('This backend requires `spectrum_utils>=0.4`.')\n# backend-specific parameters\nmz_range = kwargs.pop('mz_range', None)\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.6a3'\n+__version__ = '4.5.6'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add spectrum_utils version check, update changelog, set version to 4.5.6
377,529
07.11.2022 20:33:48
-3,600
e45b309f1d710578402de4b27b55769e838b2b6c
link to https instead of http
[ { "change_type": "MODIFY", "old_path": "INSTALL", "new_path": "INSTALL", "diff": "@@ -8,13 +8,13 @@ Project dependencies\nPyteomics uses the following Python packages:\n- - `numpy <http://pypi.python.org/pypi/numpy>`_\n- - `matplotlib <http://sourceforge.net/projects/matplotlib/files/matplotlib/>`_\n+ - `numpy <https://pypi.python.org/pypi/numpy>`_\n+ - `matplotlib <https://sourceforge.net/projects/matplotlib/files/matplotlib/>`_\n(used by :py:mod:`pyteomics.pylab_aux`)\n- - `lxml <http://pypi.python.org/pypi/lxml>`_ (used by XML parsing modules)\n- - `pandas <http://pandas.pydata.org/>`_ (can be used with :py:mod:`pyteomics.pepxml`,\n+ - `lxml <https://pypi.python.org/pypi/lxml>`_ (used by XML parsing modules)\n+ - `pandas <https://pandas.pydata.org/>`_ (can be used with :py:mod:`pyteomics.pepxml`,\n:py:mod:`pyteomics.tandem`, :py:mod:`pyteomics.mzid`, :py:mod:`pyteomics.auxiliary`)\n- - `sqlalchemy <http://www.sqlalchemy.org/>`_ (used by :py:mod:`pyteomics.mass.unimod`)\n+ - `sqlalchemy <https://www.sqlalchemy.org/>`_ (used by :py:mod:`pyteomics.mass.unimod`)\n- `pynumpress <https://pypi.org/project/pynumpress/>`_ (adds support for Numpress compression)\nAll dependencies are optional.\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
link to https instead of http
377,529
07.11.2022 21:05:27
-3,600
f1fb0841d4f4585ddbd7b77cac5e0026626394e3
link to official matplotlib.org website
[ { "change_type": "MODIFY", "old_path": "INSTALL", "new_path": "INSTALL", "diff": "@@ -9,7 +9,7 @@ Project dependencies\nPyteomics uses the following Python packages:\n- `numpy <https://pypi.python.org/pypi/numpy>`_\n- - `matplotlib <https://sourceforge.net/projects/matplotlib/files/matplotlib/>`_\n+ - `matplotlib <https://matplotlib.org/>`_\n(used by :py:mod:`pyteomics.pylab_aux`)\n- `lxml <https://pypi.python.org/pypi/lxml>`_ (used by XML parsing modules)\n- `pandas <https://pandas.pydata.org/>`_ (can be used with :py:mod:`pyteomics.pepxml`,\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
link to official matplotlib.org website Co-authored-by: Lev Levitsky <lev.levitsky@phystech.edu>
377,529
07.11.2022 21:05:53
-3,600
4a9fe89e77041f2fd5617e7749a55abfc255569b
link to official lxml.de website
[ { "change_type": "MODIFY", "old_path": "INSTALL", "new_path": "INSTALL", "diff": "@@ -11,7 +11,7 @@ Pyteomics uses the following Python packages:\n- `numpy <https://pypi.python.org/pypi/numpy>`_\n- `matplotlib <https://matplotlib.org/>`_\n(used by :py:mod:`pyteomics.pylab_aux`)\n- - `lxml <https://pypi.python.org/pypi/lxml>`_ (used by XML parsing modules)\n+ - `lxml <https://lxml.de/>`_ (used by XML parsing modules)\n- `pandas <https://pandas.pydata.org/>`_ (can be used with :py:mod:`pyteomics.pepxml`,\n:py:mod:`pyteomics.tandem`, :py:mod:`pyteomics.mzid`, :py:mod:`pyteomics.auxiliary`)\n- `sqlalchemy <https://www.sqlalchemy.org/>`_ (used by :py:mod:`pyteomics.mass.unimod`)\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
link to official lxml.de website Co-authored-by: Lev Levitsky <lev.levitsky@phystech.edu>
377,529
07.11.2022 21:09:24
-3,600
622ed3c064796847971992175275bdf821126e47
link to official numpy.org website
[ { "change_type": "MODIFY", "old_path": "INSTALL", "new_path": "INSTALL", "diff": "@@ -8,7 +8,7 @@ Project dependencies\nPyteomics uses the following Python packages:\n- - `numpy <https://pypi.python.org/pypi/numpy>`_\n+ - `numpy <https://numpy.org/>`_\n- `matplotlib <https://matplotlib.org/>`_\n(used by :py:mod:`pyteomics.pylab_aux`)\n- `lxml <https://lxml.de/>`_ (used by XML parsing modules)\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
link to official numpy.org website Co-authored-by: Lev Levitsky <lev.levitsky@phystech.edu>
377,522
15.11.2022 13:02:15
-3,600
aa2cdb3e86356434305e862950e7de58feb29d84
Update changelog, bump Github Actions versions
[ { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpackage.yml", "new_path": ".github/workflows/pythonpackage.yml", "diff": "@@ -17,9 +17,9 @@ jobs:\npython-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']\nsteps:\n- - uses: actions/checkout@v2\n+ - uses: actions/checkout@v3\n- name: Set up Python ${{ matrix.python-version }}\n- uses: actions/setup-python@v2\n+ uses: actions/setup-python@v3\nwith:\npython-version: ${{ matrix.python-version }}\n- name: Install dependencies\n" }, { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpublish.yml", "new_path": ".github/workflows/pythonpublish.yml", "diff": "@@ -8,9 +8,9 @@ jobs:\ndeploy:\nruns-on: ubuntu-latest\nsteps:\n- - uses: actions/checkout@v2\n+ - uses: actions/checkout@v3\n- name: Set up Python\n- uses: actions/setup-python@v2\n+ uses: actions/setup-python@v3\nwith:\npython-version: '3.x'\n- name: Install dependencies\n" }, { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "+4.5.7a1\n+-------\n+\n+ - Fix issue #91 (`#92 <https://github.com/levitsky/pyteomics/pull/92>`_ by Joshua Klein).\n+\n4.5.6\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.6'\n+__version__ = '4.5.7a1'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Update changelog, bump Github Actions versions
377,522
15.11.2022 16:57:10
-3,600
db416df7704bf9706ac0a63dadfcf446adcae4ff
Try setup-python@v4
[ { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpackage.yml", "new_path": ".github/workflows/pythonpackage.yml", "diff": "@@ -19,7 +19,7 @@ jobs:\nsteps:\n- uses: actions/checkout@v3\n- name: Set up Python ${{ matrix.python-version }}\n- uses: actions/setup-python@v3\n+ uses: actions/setup-python@v4\nwith:\npython-version: ${{ matrix.python-version }}\n- name: Install dependencies\n" }, { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpublish.yml", "new_path": ".github/workflows/pythonpublish.yml", "diff": "@@ -10,7 +10,7 @@ jobs:\nsteps:\n- uses: actions/checkout@v3\n- name: Set up Python\n- uses: actions/setup-python@v3\n+ uses: actions/setup-python@v4\nwith:\npython-version: '3.x'\n- name: Install dependencies\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Try setup-python@v4
377,522
16.11.2022 22:33:02
-3,600
7cba1aa509d214e2879a80218b9f403961e709a6
Update INSTALL as proposed in
[ { "change_type": "MODIFY", "old_path": "INSTALL", "new_path": "INSTALL", "diff": "@@ -3,47 +3,59 @@ Supported Python versions\nPyteomics supports Python 2.7 and Python 3.3+.\n-Project dependencies\n---------------------\n-Pyteomics uses the following Python packages:\n+Install with pip\n+----------------\n- - `numpy <https://numpy.org/>`_\n- - `matplotlib <https://matplotlib.org/>`_\n- (used by :py:mod:`pyteomics.pylab_aux`)\n- - `lxml <https://lxml.de/>`_ (used by XML parsing modules)\n- - `pandas <https://pandas.pydata.org/>`_ (can be used with :py:mod:`pyteomics.pepxml`,\n- :py:mod:`pyteomics.tandem`, :py:mod:`pyteomics.mzid`, :py:mod:`pyteomics.auxiliary`)\n- - `sqlalchemy <https://www.sqlalchemy.org/>`_ (used by :py:mod:`pyteomics.mass.unimod`)\n- - `pynumpress <https://pypi.org/project/pynumpress/>`_ (adds support for Numpress compression)\n+The main way to obtain Pyteomics is via `pip Python package manager <https://pip.pypa.io/>`_::\n-All dependencies are optional.\n+ pip install pyteomics\n+\n+\n+Install with conda\n+------------------\n-GNU/Linux\n----------\n+You can also install Pyteomics from `Bioconda <https://bioconda.github.io/index.html>`_\n+using `conda <https://docs.conda.io/projects/conda/en/latest/index.html>`_::\n-The preferred way to obtain Pyteomics is via `pip Python package manager <https://pip.pypa.io/>`_.\n-The shell code for a freshly installed Ubuntu system::\n+ conda install -c bioconda pyteomics\n- sudo apt-get install python-setuptools python-dev build-essential\n- sudo easy_install pip\n- sudo pip install lxml numpy matplotlib pyteomics\nArch-based distros\n..................\nOn Arch Linux and related distros, you can install Pyteomics from AUR:\n+`python-pyteomics <https://aur.archlinux.org/packages/python-pyteomics/>`_\n- - `python-pyteomics <https://aur.archlinux.org/packages/python-pyteomics/>`_\n- - `python2-pyteomics <https://aur.archlinux.org/packages/python2-pyteomics/>`_\n+Project dependencies\n+--------------------\n+\n+Some functionality in Pyteomics relies on other packages:\n+ - `numpy <https://numpy.org/>`_;\n+ - `matplotlib <https://matplotlib.org/>`_ (used by :py:mod:`pyteomics.pylab_aux`);\n+ - `lxml <https://lxml.de/>`_ (used by XML parsing modules and :py:class:`pyteomics.mass.mass.Unimod`);\n+ - `pandas <https://pandas.pydata.org/>`_ (can be used with :py:mod:`pyteomics.pepxml`,\n+ :py:mod:`pyteomics.tandem`, :py:mod:`pyteomics.mzid`, :py:mod:`pyteomics.auxiliary`);\n+ - `sqlalchemy <https://www.sqlalchemy.org/>`_ (used by :py:mod:`pyteomics.mass.unimod`);\n+ - `pynumpress <https://pypi.org/project/pynumpress/>`_ (adds support for Numpress compression in mzML);\n+ - `h5py <https://www.h5py.org/>`_ and optionally `hdf5plugin <https://hdf5plugin.readthedocs.io/en/latest/>`_\n+ (used by :py:mod:`pyteomics.mzmlb`);\n+ - `psims <https://mobiusklein.github.io/psims/docs/build/html/>`_ (used py :py:mod:`pyteomics.proforma`);\n+ - `spectrum_utils <https://spectrum-utils.readthedocs.io/en/latest/>`_ (optionally used for spectrum annotation in\n+ :py:mod:`pyteomics.pylab_aux`).\n+\n+All dependencies are optional.\n-Windows\n--------\n+Installing a subset of dependencies with pip\n+............................................\n-- `Get pip <https://pip.pypa.io/en/stable/installing/>`_, if you don't have it yet.\n+You can quickly install just the dependencies you need by specifying an\n+`\"extra\" <https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#optional-dependencies>`_. For example:\n-- Install Pyteomics and its dependencies::\n+ pip install pyteomics[XML]\n- pip install lxml numpy matplotlib pyteomics\n+This will install Pyteomics, NumPy and lxml, which are needed to read XML format. Currently provided identifiers are:\n+`XML`, `TDA`, `graphics`, `DF`, Unimod`, `numpress`, `mzMLb`, `proforma`.\n+You can also use these specs as dependencies in your own packages which require specific Pyteomics functionality.\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Update INSTALL as proposed in #88
377,522
16.11.2022 22:40:50
-3,600
3bcaf4029dadb605bda33a48dfc4a906516dbc13
Add a conda badge
[ { "change_type": "MODIFY", "old_path": "README.rst", "new_path": "README.rst", "diff": ":target: https://pypi.org/project/pyteomics/\n:alt: PyPI\n+.. image:: https://img.shields.io/conda/vn/bioconda/pyteomics\n+ :target: http://bioconda.github.io/recipes/pyteomics/README.html\n+ :alt: conda\n+\n.. image:: https://img.shields.io/readthedocs/pyteomics.svg\n:target: https://pyteomics.readthedocs.io/\n:alt: Read the Docs (latest)\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add a conda badge
377,522
30.11.2022 00:00:47
-3,600
995607eb0b206c88be991a388f3ebe4c0fefc6f2
Change Uniprot header pattern to hard-code key=value keys and their order
[ { "change_type": "MODIFY", "old_path": "pyteomics/fasta.py", "new_path": "pyteomics/fasta.py", "diff": "@@ -402,16 +402,22 @@ class FlavoredMixin():\nclass UniProtMixin(FlavoredMixin):\n- header_pattern = r'^(\\w+)\\|([-\\w]+)\\|(\\w+)\\s+([^=]*\\S)((\\s+\\w+=[^=]+(?!\\w*=))+)\\s*$'\n- header_group = 2\n+ header_pattern = r'^(?P<db>\\w+)\\|(?P<id>[-\\w]+)\\|(?P<entry>\\w+)\\s+(?P<name>.*?)(\\s+OS=(?P<OS>[^=]+))?(\\s+OX=(?P<OX>\\d+))?(\\s+GN=(?P<GN>\\w+))?(\\s+PE=(?P<PE>\\d))?(\\s+SV=(?P<SV>\\d+))?\\s*$'\n+ header_group = 'id'\ndef parser(self, header):\n- db, ID, entry, name, pairs, _ = re.match(self.header_pattern, header).groups()\n- gid, taxon = entry.split('_')\n- info = {'db': db, 'id': ID, 'entry': entry,\n- 'name': name, 'gene_id': gid, 'taxon': taxon}\n- info.update(_split_pairs(pairs))\n- _intify(info, ('PE', 'SV'))\n+ # db, ID, entry, name, pairs, _ = re.match(self.header_pattern, header).groups()\n+ # gid, taxon = entry.split('_')\n+ # info = {'db': db, 'id': ID, 'entry': entry,\n+ # 'name': name, 'gene_id': gid, 'taxon': taxon}\n+ # info.update(_split_pairs(pairs))\n+\n+ info = re.match(self.header_pattern, header).groupdict()\n+ for key in ['OS', 'OX', 'GN', 'PE', 'SV']:\n+ if info[key] is None:\n+ del info[key]\n+ info['gene_id'], info['taxon'] = info['entry'].split('_')\n+ _intify(info, ('PE', 'SV', 'OX'))\nreturn info\n" }, { "change_type": "MODIFY", "old_path": "tests/test_fasta.py", "new_path": "tests/test_fasta.py", "diff": "@@ -208,7 +208,7 @@ class FastaTest(unittest.TestCase):\n'taxon': 'RALEH'}\nself.assertEqual(fasta.parse(header), parsed)\n- def test_parser_uniptokb_isoform(self):\n+ def test_parser_uniprotkb_isoform(self):\nheader = ('sp|Q4R572-2|1433B_MACFA Isoform Short of 14-3-3 protein beta'\n'/alpha OS=Macaca fascicularis GN=YWHAB')\nparsed = {'GN': 'YWHAB',\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Change Uniprot header pattern to hard-code key=value keys and their order
377,522
01.12.2022 14:24:41
-3,600
16a65eb0f9ed5ede9de4557b2e040fd0d2499682
Allow hyphen in gene names
[ { "change_type": "MODIFY", "old_path": "pyteomics/fasta.py", "new_path": "pyteomics/fasta.py", "diff": "@@ -402,7 +402,7 @@ class FlavoredMixin():\nclass UniProtMixin(FlavoredMixin):\n- header_pattern = r'^(?P<db>\\w+)\\|(?P<id>[-\\w]+)\\|(?P<entry>\\w+)\\s+(?P<name>.*?)(\\s+OS=(?P<OS>[^=]+))?(\\s+OX=(?P<OX>\\d+))?(\\s+GN=(?P<GN>\\w+))?(\\s+PE=(?P<PE>\\d))?(\\s+SV=(?P<SV>\\d+))?\\s*$'\n+ header_pattern = r'^(?P<db>\\w+)\\|(?P<id>[-\\w]+)\\|(?P<entry>\\w+)\\s+(?P<name>.*?)(\\s+OS=(?P<OS>[^=]+))?(\\s+OX=(?P<OX>\\d+))?(\\s+GN=(?P<GN>[-\\w]+))?(\\s+PE=(?P<PE>\\d))?(\\s+SV=(?P<SV>\\d+))?\\s*$'\nheader_group = 'id'\ndef parser(self, header):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Allow hyphen in gene names
377,522
02.12.2022 15:56:13
-3,600
38c3f8c318bc96367d48dcc5db28ee9c63738aea
Relax GN pattern
[ { "change_type": "MODIFY", "old_path": "pyteomics/fasta.py", "new_path": "pyteomics/fasta.py", "diff": "@@ -402,7 +402,7 @@ class FlavoredMixin():\nclass UniProtMixin(FlavoredMixin):\n- header_pattern = r'^(?P<db>\\w+)\\|(?P<id>[-\\w]+)\\|(?P<entry>\\w+)\\s+(?P<name>.*?)(\\s+OS=(?P<OS>[^=]+))?(\\s+OX=(?P<OX>\\d+))?(\\s+GN=(?P<GN>[-\\w]+))?(\\s+PE=(?P<PE>\\d))?(\\s+SV=(?P<SV>\\d+))?\\s*$'\n+ header_pattern = r'^(?P<db>\\w+)\\|(?P<id>[-\\w]+)\\|(?P<entry>\\w+)\\s+(?P<name>.*?)(\\s+OS=(?P<OS>[^=]+))?(\\s+OX=(?P<OX>\\d+))?(\\s+GN=(?P<GN>\\S+))?(\\s+PE=(?P<PE>\\d))?(\\s+SV=(?P<SV>\\d+))?\\s*$'\nheader_group = 'id'\ndef parser(self, header):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Relax GN pattern
377,522
02.12.2022 16:03:46
-3,600
df236e2907cc8f34042dcf32c774d01a26667ba2
Add get_header() for TwoLayerIndexedFASTA
[ { "change_type": "MODIFY", "old_path": "pyteomics/fasta.py", "new_path": "pyteomics/fasta.py", "diff": "@@ -386,6 +386,11 @@ class TwoLayerIndexedFASTA(IndexedFASTA):\nreturn super(TwoLayerIndexedFASTA, self).get_entry(header)\nraise KeyError(key)\n+ def get_header(self, key):\n+ if key in self._id2header:\n+ return self._id2header[key]\n+ raise KeyError(key)\n+\ndef __contains__(self, key):\nreturn super(TwoLayerIndexedFASTA, self).__contains__(key) or key in self._id2header\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Add get_header() for TwoLayerIndexedFASTA
377,522
14.12.2022 00:10:20
-3,600
5dcfe6ffdb4d847a2145637ecba92f04c364971c
Use OR-ed groups in Uniprot pattern
[ { "change_type": "MODIFY", "old_path": "pyteomics/fasta.py", "new_path": "pyteomics/fasta.py", "diff": "@@ -407,7 +407,7 @@ class FlavoredMixin():\nclass UniProtMixin(FlavoredMixin):\n- header_pattern = r'^(?P<db>\\w+)\\|(?P<id>[-\\w]+)\\|(?P<entry>\\w+)\\s+(?P<name>.*?)(\\s+OS=(?P<OS>[^=]+))?(\\s+OX=(?P<OX>\\d+))?(\\s+GN=(?P<GN>\\S+))?(\\s+PE=(?P<PE>\\d))?(\\s+SV=(?P<SV>\\d+))?\\s*$'\n+ header_pattern = r'^(?P<db>\\w+)\\|(?P<id>[-\\w]+)\\|(?P<entry>\\w+)\\s+(?P<name>.*?)(?:(\\s+OS=(?P<OS>[^=]+))|(\\s+OX=(?P<OX>\\d+))|(\\s+GN=(?P<GN>\\S+))|(\\s+PE=(?P<PE>\\d))|(\\s+SV=(?P<SV>\\d+)))*\\s*$'\nheader_group = 'id'\ndef parser(self, header):\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Use OR-ed groups in Uniprot pattern
377,522
15.12.2022 15:06:35
-3,600
dc313796dc4dfc8dd55963962e017d3033ddc590
Update changelog, test on 3.11
[ { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpackage.yml", "new_path": ".github/workflows/pythonpackage.yml", "diff": "@@ -14,7 +14,7 @@ jobs:\nruns-on: 'ubuntu-20.04'\nstrategy:\nmatrix:\n- python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']\n+ python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11']\nsteps:\n- uses: actions/checkout@v3\n" }, { "change_type": "MODIFY", "old_path": "CHANGELOG", "new_path": "CHANGELOG", "diff": "-4.5.7a2\n+4.5.7a3\n-------\n- Fix issue #91 (`#92 <https://github.com/levitsky/pyteomics/pull/92>`_ by Joshua Klein).\n- Fix issue #96.\n+ - Update the UniProt header pattern (fix rare parsing errors with\n+ :py:class:`pyteomics.fasta.UniProt` and :py:class:`pyteomics.fasta.IndexedUniProt`) in\n+ `#93 <https://github.com/levitsky/pyteomics/pull/93>`_.\n4.5.6\n-----\n" }, { "change_type": "MODIFY", "old_path": "pyteomics/version.py", "new_path": "pyteomics/version.py", "diff": "@@ -13,7 +13,7 @@ Constants\n\"\"\"\n-__version__ = '4.5.7a2'\n+__version__ = '4.5.7a3'\nfrom collections import namedtuple\nimport re\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Update changelog, test on 3.11
377,522
15.12.2022 15:29:08
-3,600
86be7c23a4bb3e7fe57d15ced12f881c1d2d99e7
Try to enable from-source install of h5py
[ { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpackage.yml", "new_path": ".github/workflows/pythonpackage.yml", "diff": "@@ -24,6 +24,8 @@ jobs:\npython-version: ${{ matrix.python-version }}\n- name: Install dependencies\nrun: |\n+ sudo apt-get update\n+ sudo apt-get install libhdf5-serial-dev\npython -m pip install --upgrade pip\npip install numpy\npip install -r test-requirements.txt\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Try to enable from-source install of h5py
377,522
15.12.2022 15:44:08
-3,600
600722712bc9e40a820fd6b4f9d16c07c30f4bed
Try to trigger tests on workflow file changes
[ { "change_type": "MODIFY", "old_path": ".github/workflows/pythonpackage.yml", "new_path": ".github/workflows/pythonpackage.yml", "diff": "@@ -4,9 +4,11 @@ on:\npush:\npaths:\n- '**.py'\n+ - '.github/workflows/pythonpackage.yml'\npull_request:\npaths:\n- '**.py'\n+ - '.github/workflows/pythonpackage.yml'\njobs:\nbuild:\n" } ]
Python
Apache License 2.0
levitsky/pyteomics
Try to trigger tests on workflow file changes