From 90239e143fc7823bd7cd84e85c12314bd2cfcada Mon Sep 17 00:00:00 2001 From: Moritz Emanuel Beber Date: Fri, 7 Feb 2014 15:15:58 +0100 Subject: [PATCH 01/15] todo file --- .coveragerc | 16 + .editorconfig | 13 + .gitattributes | 1 + .gitignore | 65 + .travis.yml | 49 + AUTHORS.rst | 5 + CHANGELOG.rst | 8 + CONTRIBUTING.rst | 90 + LICENSE | 27 + LICENSE.rst | 16 - MANIFEST.in | 12 + README.rst | 122 +- brenda/__init__.py | 23 - pyproject.toml | 5 + setup.cfg | 70 + setup.py | 14 + src/brenda_parser/__init__.py | 40 + src/brenda_parser/_version.py | 520 +++++ src/brenda_parser/api.py | 50 + src/brenda_parser/cli.py | 53 + src/brenda_parser/data/__init__.py | 33 + src/brenda_parser/data/information_fields.csv | 41 + src/brenda_parser/exceptions.py | 39 + src/brenda_parser/models/__init__.py | 44 + src/brenda_parser/models/comment.py | 54 + src/brenda_parser/models/enzyme.py | 104 + src/brenda_parser/models/field_entry.py | 76 + src/brenda_parser/models/information_field.py | 97 + src/brenda_parser/models/organism.py | 51 + src/brenda_parser/models/protein.py | 86 + src/brenda_parser/models/reference.py | 70 + .../models/special_information.py | 53 + src/brenda_parser/parsing/__init__.py | 36 + src/brenda_parser/parsing/lexer.py | 250 +++ src/brenda_parser/parsing/parser.out | 939 +++++++++ src/brenda_parser/parsing/parser.py | 384 ++++ src/brenda_parser/parsing/parsetab.py | 66 + test_requirements.txt | 5 + tests/test_brenda_parser.py | 12 + tests/test_models/conftest.py | 72 + tests/test_models/test_information_field.py | 57 + tests/test_models/test_organism.py | 60 + tests/test_models/test_protein.py | 46 + tests/test_models/test_reference.py | 67 + tests/test_parsing/data/small_section.txt | 157 ++ tests/test_parsing/test_lexer.py | 124 ++ tests/test_parsing/test_parser.py | 202 ++ tox.ini | 23 + versioneer.py | 1822 +++++++++++++++++ 49 files changed, 6186 insertions(+), 83 deletions(-) create mode 100644 .coveragerc create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 AUTHORS.rst create mode 100644 CHANGELOG.rst create mode 100644 CONTRIBUTING.rst create mode 100644 LICENSE delete mode 100644 LICENSE.rst create mode 100644 MANIFEST.in delete mode 100644 brenda/__init__.py create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 src/brenda_parser/__init__.py create mode 100644 src/brenda_parser/_version.py create mode 100644 src/brenda_parser/api.py create mode 100644 src/brenda_parser/cli.py create mode 100644 src/brenda_parser/data/__init__.py create mode 100644 src/brenda_parser/data/information_fields.csv create mode 100644 src/brenda_parser/exceptions.py create mode 100644 src/brenda_parser/models/__init__.py create mode 100644 src/brenda_parser/models/comment.py create mode 100644 src/brenda_parser/models/enzyme.py create mode 100644 src/brenda_parser/models/field_entry.py create mode 100644 src/brenda_parser/models/information_field.py create mode 100644 src/brenda_parser/models/organism.py create mode 100644 src/brenda_parser/models/protein.py create mode 100644 src/brenda_parser/models/reference.py create mode 100644 src/brenda_parser/models/special_information.py create mode 100644 src/brenda_parser/parsing/__init__.py create mode 100644 src/brenda_parser/parsing/lexer.py create mode 100644 src/brenda_parser/parsing/parser.out create mode 100644 src/brenda_parser/parsing/parser.py create mode 100644 src/brenda_parser/parsing/parsetab.py create mode 100644 test_requirements.txt create mode 100644 tests/test_brenda_parser.py create mode 100644 tests/test_models/conftest.py create mode 100644 tests/test_models/test_information_field.py create mode 100644 tests/test_models/test_organism.py create mode 100644 tests/test_models/test_protein.py create mode 100644 tests/test_models/test_reference.py create mode 100644 tests/test_parsing/data/small_section.txt create mode 100644 tests/test_parsing/test_lexer.py create mode 100644 tests/test_parsing/test_parser.py create mode 100644 tox.ini create mode 100644 versioneer.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..edcadaf --- /dev/null +++ b/.coveragerc @@ -0,0 +1,16 @@ +[paths] +source = + src/brenda_parser + */site-packages/brenda_parser + +[run] +branch = true +source = + brenda_parser + tests +parallel = true + +[report] +show_missing = true +precision = 2 +omit = *migrations* diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4000618 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# see http://editorconfig.org +root = true + +[*] +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 +charset = utf-8 + +[*.{bat,cmd,ps1}] +end_of_line = crlf diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1be5753 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +src/brenda_parser/_version.py export-subst diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7519585 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +eggs +.eggs +parts +bin +var +sdist +wheelhouse +develop-eggs +.installed.cfg +lib +lib64 +venv*/ +pyvenv*/ + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +.coverage.* +nosetests.xml +coverage.xml +htmlcov + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject +.idea +*.iml +*.komodoproject + +# Complexity +output/*.html +output/*/index.html + +# Sphinx +docs/_build + +.DS_Store +*~ +.*.sw[po] +.build +.ve +.env +.cache +.pytest +.bootstrap +.appveyor.token +*.bak +.pytest_cache/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0460603 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,49 @@ +language: python +sudo: false +cache: pip +env: + global: + - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so + - SEGFAULT_SIGNALS=all + matrix: + - TOXENV=check + - TOXENV=docs +matrix: + include: + - python: '2.7' + env: + - TOXENV=py27,report,codecov + - python: '3.3' + env: + - TOXENV=py33,report,codecov + - python: '3.4' + env: + - TOXENV=py34,report,codecov + - python: '3.5' + env: + - TOXENV=py35,report,codecov + - python: '3.6' + env: + - TOXENV=py36,report,codecov + - python: 'pypy-5.4' + env: + - TOXENV=pypy,report,codecov +before_install: + - python --version + - uname -a + - lsb_release -a +install: + - pip install tox + - virtualenv --version + - easy_install --version + - pip --version + - tox --version +script: + - tox -v +after_failure: + - more .tox/log/* | cat + - more .tox/*/log/* | cat +notifications: + email: + on_success: never + on_failure: always diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 0000000..ce814bc --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,5 @@ + +Authors +======= + +* Moritz E. Beber - https://github.com/Midnighter/BRENDA-Parser diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..16d62b6 --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,8 @@ + +Changelog +========= + +0.1.0 (2018-01-30) +------------------ + +* First release on PyPI. diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 0000000..01e2e77 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,90 @@ +============ +Contributing +============ + +Contributions are welcome, and they are greatly appreciated! Every +little bit helps, and credit will always be given. + +Bug reports +=========== + +When `reporting a bug `_ please include: + + * Your operating system name and version. + * Any details about your local setup that might be helpful in troubleshooting. + * Detailed steps to reproduce the bug. + +Documentation improvements +========================== + +BRENDA-Parser could always use more documentation, whether as part of the +official BRENDA-Parser docs, in docstrings, or even on the web in blog posts, +articles, and such. + +Feature requests and feedback +============================= + +The best way to send feedback is to file an issue at https://github.com/Midnighter/BRENDA-Parser/issues. + +If you are proposing a feature: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible, to make it easier to implement. +* Remember that this is a volunteer-driven project, and that code contributions are welcome :) + +Development +=========== + +To set up `BRENDA-Parser` for local development: + +1. Fork `BRENDA-Parser `_ + (look for the "Fork" button). +2. Clone your fork locally:: + + git clone git@github.com:your_name_here/BRENDA-Parser.git + +3. Create a branch for local development:: + + git checkout -b name-of-your-bugfix-or-feature + + Now you can make your changes locally. + +4. When you're done making changes, run all the checks, doc builder and spell checker with `tox `_ one command:: + + tox + +5. Commit your changes and push your branch to GitHub:: + + git add . + git commit -m "Your detailed description of your changes." + git push origin name-of-your-bugfix-or-feature + +6. Submit a pull request through the GitHub website. + +Pull Request Guidelines +----------------------- + +If you need some code review or feedback while you're developing the code just make the pull request. + +For merging, you should: + +1. Include passing tests (run ``tox``) [1]_. +2. Update documentation when there's new API, functionality etc. +3. Add a note to ``CHANGELOG.rst`` about the changes. +4. Add yourself to ``AUTHORS.rst``. + +.. [1] If you don't have all the necessary python versions available locally you can rely on Travis - it will + `run the tests `_ for each change you add in the pull request. + + It will be slower though ... + +Tips +---- + +To run a subset of tests:: + + tox -e envname -- py.test -k test_myfeature + +To run all the test environments in *parallel* (you need to ``pip install detox``):: + + detox diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..72adb08 --- /dev/null +++ b/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2013 Jacobs University Bremen gGmbH +Copyright (c) 2018 Moritz E. Beber + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSE.rst b/LICENSE.rst deleted file mode 100644 index 0228f25..0000000 --- a/LICENSE.rst +++ /dev/null @@ -1,16 +0,0 @@ -==================== -BSD 3-Clause License -==================== - -Copyright |c| 2013, Jacobs University Bremen gGmbH, all rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -3. Neither the name of Jacobs University Bremen gGmbH nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -.. |c| unicode:: U+A9 - diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..78ed655 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,12 @@ +graft src + +include AUTHORS.rst +include CHANGELOG.rst +include CONTRIBUTING.rst +include LICENSE +include README.rst +include versioneer.py +include src/brenda_parser/_version.py +include src/brenda_parser/data/*.csv + +global-exclude *.py[cod] __pycache__ *.so *.dylib diff --git a/README.rst b/README.rst index f31e711..94c4b6c 100644 --- a/README.rst +++ b/README.rst @@ -1,62 +1,96 @@ -============= -BRENDA Parser -============= +======== +Overview +======== + +.. start-badges + +.. list-table:: + :stub-columns: 1 + + * - docs + - |docs| + * - tests + - | |travis| |appveyor| + | |codecov| + * - package + - | |version| |wheel| |supported-versions| |supported-implementations| + | |commits-since| + +.. |docs| image:: https://readthedocs.org/projects/BRENDA-Parser/badge/?style=flat + :target: https://readthedocs.org/projects/BRENDA-Parser + :alt: Documentation Status + +.. |travis| image:: https://travis-ci.org/Midnighter/BRENDA-Parser.svg?branch=master + :alt: Travis-CI Build Status + :target: https://travis-ci.org/Midnighter/BRENDA-Parser + +.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/github/Midnighter/BRENDA-Parser?branch=master&svg=true + :alt: AppVeyor Build Status + :target: https://ci.appveyor.com/project/Midnighter/BRENDA-Parser -This Python module provides classes that encapsulate information provided by the -`BRENDA database`__ and a parser that generates relevant content from the text -file that can be downloaded for free. +.. |codecov| image:: https://codecov.io/github/Midnighter/BRENDA-Parser/coverage.svg?branch=master + :alt: Coverage Status + :target: https://codecov.io/github/Midnighter/BRENDA-Parser -.. __: http://www.brenda-enzymes.org/ +.. |version| image:: https://img.shields.io/pypi/v/brenda-parser.svg + :alt: PyPI Package latest release + :target: https://pypi.python.org/pypi/brenda-parser -Copyright ---------- +.. |commits-since| image:: https://img.shields.io/github/commits-since/Midnighter/BRENDA-Parser/v0.1.0.svg + :alt: Commits since latest release + :target: https://github.com/Midnighter/BRENDA-Parser/compare/v0.1.0...master -:Author: - Moritz Emanuel Beber -:License: - Please see the LICENSE.rst file distributed with this module. +.. |wheel| image:: https://img.shields.io/pypi/wheel/brenda-parser.svg + :alt: PyPI Wheel + :target: https://pypi.python.org/pypi/brenda-parser -Recent Changes --------------- +.. |supported-versions| image:: https://img.shields.io/pypi/pyversions/brenda-parser.svg + :alt: Supported versions + :target: https://pypi.python.org/pypi/brenda-parser -* Parser no longer hick-ups on empty lines, continued lines not starting with a - tab, and other format breaking content. -* Parser now prints progress to stdout. -* Soon, support for the SOAP interface will be added. -* If desired, a setup script could be added. +.. |supported-implementations| image:: https://img.shields.io/pypi/implementation/brenda-parser.svg + :alt: Supported implementations + :target: https://pypi.python.org/pypi/brenda-parser -Usage ------ -If you want to use this module outside its directory, you will have to add it to your -PYTHONPATH environment variable (unix). +.. end-badges + +A parser for the BRENDA flat file distribution. + +* Free software: Apache Software License 2.0 + +Installation +============ + +:: + + pip install brenda-parser + +Documentation +============= -.. code:: python +https://BRENDA-Parser.readthedocs.io/ - >>> from brenda import BRENDAParser - >>> with BRENDAParser("brenda_download.txt") as bp: - ... content = bp.parse() +Development +=========== -The method parse returns a dictionary with all enzymes that were parsed. Every -key in the dictionary is a string representing an EC number starting form the 6 -general classes down to the individual enzymes. The values in the dictionary are -always lists, as an example: +To run the all tests run:: -.. code:: python + tox - >>> len(content["1"]) - 1348 - >>> len(content["1.1.1.1"]) - 1 +Note, to combine the coverage data from all the tox environments run: -Warning -------- +.. list-table:: + :widths: 10 90 + :stub-columns: 1 -The API changed slightly. + - - Windows + - :: -Notes ------ + set PYTEST_ADDOPTS=--cov-append + tox -There is one additional key "file_encoding" which contains the argument used -for the parser when reading the file. + - - Other + - :: + PYTEST_ADDOPTS=--cov-append tox diff --git a/brenda/__init__.py b/brenda/__init__.py deleted file mode 100644 index 0391690..0000000 --- a/brenda/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- - - -""" -============================= -BRENDA Enzyme Database Access -============================= - -:Author: - Moritz Emanuel Beber -:Date: - 2013-05-16 -:Copyright: - Copyright |c| 2013, Jacobs University Bremen gGmbH, all rights reserved. -:File: - __init__.py - -.. |c| unicode:: U+A9 -""" - - -from parser import * - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c69cf5b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[build-system] +requires = [ + "setuptools>=30.3.0", + "wheel" +] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b8f857d --- /dev/null +++ b/setup.cfg @@ -0,0 +1,70 @@ +[metadata] +name = brenda-parser +url = https://github.com/Midnighter/BRENDA-Parser +download_url = https://pypi.python.org/pypi/brenda-parser +author = Moritz E. Beber +author_email = moritz.beber@gmail.com +classifiers = + Development Status :: 4 - Beta + Intended Audience :: Science/Research + Topic :: Scientific/Engineering :: Bio-Informatics + License :: OSI Approved :: BSD License + Natural Language :: English + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 +license = BSD 3-Clause License +description = A parser for the BRENDA flat file distribution. +long_description = file: README.rst +keywords = + BRENDA + parser + +[options] +zip_safe = True +install_requires = + six + future + importlib-resources + click + click-log + ply + SQLAlchemy +include_package_data = True +packages = find: +package_dir = + = src + +[options.entry_points] +console_scripts = + brenda = brenda_parser.cli:cli + +[wheel] +universal = 1 + +[bdist_wheel] +universal = 1 + +[flake8] +max-line-length = 80 +exclude = __init__.py,docs + +[pydocstyle] +match_dir = src/brenda_parser + +[tool:pytest] +testpaths = tests + +# See the docstring in versioneer.py for instructions. Note that you must +# re-run 'versioneer.py setup' after changing this section, and commit the +# resulting files. + +[versioneer] +VCS = git +style = pep440 +versionfile_source = src/brenda_parser/_version.py +versionfile_build = brenda_parser/_version.py +tag_prefix = +parentdir_prefix = brenda-parser- diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e16772c --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from __future__ import absolute_import + +import versioneer +from setuptools import setup + + +# All other arguments are defined in `setup.cfg`. +setup( + version=versioneer.get_version(), + cmdclass=versioneer.get_cmdclass() +) diff --git a/src/brenda_parser/__init__.py b/src/brenda_parser/__init__.py new file mode 100644 index 0000000..71b2ce4 --- /dev/null +++ b/src/brenda_parser/__init__.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Jacobs University Bremen gGmbH +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""BRENDA Enzyme Database Parser.""" + +from __future__ import absolute_import + +__author__ = 'Moritz E. Beber' +__email__ = 'moritz.beber@gmail.com' + +from ._version import get_versions +__version__ = get_versions()['version'] +del get_versions diff --git a/src/brenda_parser/_version.py b/src/brenda_parser/_version.py new file mode 100644 index 0000000..e88bd30 --- /dev/null +++ b/src/brenda_parser/_version.py @@ -0,0 +1,520 @@ + +# This file helps to compute a version number in source trees obtained from +# git-archive tarball (such as those provided by githubs download-from-tag +# feature). Distribution tarballs (built by setup.py sdist) and build +# directories (produced by setup.py build) will contain a much shorter file +# that just contains the computed version number. + +# This file is released into the public domain. Generated by +# versioneer-0.18 (https://github.com/warner/python-versioneer) + +"""Git implementation of _version.py.""" + +import errno +import os +import re +import subprocess +import sys + + +def get_keywords(): + """Get the keywords needed to look up the version information.""" + # these strings will be replaced by git during git-archive. + # setup.py/versioneer.py will grep for the variable names, so they must + # each be defined on a line of their own. _version.py will just call + # get_keywords(). + git_refnames = "$Format:%d$" + git_full = "$Format:%H$" + git_date = "$Format:%ci$" + keywords = {"refnames": git_refnames, "full": git_full, "date": git_date} + return keywords + + +class VersioneerConfig: + """Container for Versioneer configuration parameters.""" + + +def get_config(): + """Create, populate and return the VersioneerConfig() object.""" + # these strings are filled in when 'setup.py versioneer' creates + # _version.py + cfg = VersioneerConfig() + cfg.VCS = "git" + cfg.style = "pep440" + cfg.tag_prefix = "" + cfg.parentdir_prefix = "brenda-parser-" + cfg.versionfile_source = "src/brenda_parser/_version.py" + cfg.verbose = False + return cfg + + +class NotThisMethod(Exception): + """Exception raised if a method is not valid for the current scenario.""" + + +LONG_VERSION_PY = {} +HANDLERS = {} + + +def register_vcs_handler(vcs, method): # decorator + """Decorator to mark a method as the handler for a particular VCS.""" + def decorate(f): + """Store f in HANDLERS[vcs][method].""" + if vcs not in HANDLERS: + HANDLERS[vcs] = {} + HANDLERS[vcs][method] = f + return f + return decorate + + +def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, + env=None): + """Call the given command(s).""" + assert isinstance(commands, list) + p = None + for c in commands: + try: + dispcmd = str([c] + args) + # remember shell=False, so use git.cmd on windows, not just git + p = subprocess.Popen([c] + args, cwd=cwd, env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr + else None)) + break + except EnvironmentError: + e = sys.exc_info()[1] + if e.errno == errno.ENOENT: + continue + if verbose: + print("unable to run %s" % dispcmd) + print(e) + return None, None + else: + if verbose: + print("unable to find command, tried %s" % (commands,)) + return None, None + stdout = p.communicate()[0].strip() + if sys.version_info[0] >= 3: + stdout = stdout.decode() + if p.returncode != 0: + if verbose: + print("unable to run %s (error)" % dispcmd) + print("stdout was %s" % stdout) + return None, p.returncode + return stdout, p.returncode + + +def versions_from_parentdir(parentdir_prefix, root, verbose): + """Try to determine the version from the parent directory name. + + Source tarballs conventionally unpack into a directory that includes both + the project name and a version string. We will also support searching up + two directory levels for an appropriately named parent directory + """ + rootdirs = [] + + for i in range(3): + dirname = os.path.basename(root) + if dirname.startswith(parentdir_prefix): + return {"version": dirname[len(parentdir_prefix):], + "full-revisionid": None, + "dirty": False, "error": None, "date": None} + else: + rootdirs.append(root) + root = os.path.dirname(root) # up a level + + if verbose: + print("Tried directories %s but none started with prefix %s" % + (str(rootdirs), parentdir_prefix)) + raise NotThisMethod("rootdir doesn't start with parentdir_prefix") + + +@register_vcs_handler("git", "get_keywords") +def git_get_keywords(versionfile_abs): + """Extract version information from the given file.""" + # the code embedded in _version.py can just fetch the value of these + # keywords. When used from setup.py, we don't want to import _version.py, + # so we do it with a regexp instead. This function is not used from + # _version.py. + keywords = {} + try: + f = open(versionfile_abs, "r") + for line in f.readlines(): + if line.strip().startswith("git_refnames ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["refnames"] = mo.group(1) + if line.strip().startswith("git_full ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["full"] = mo.group(1) + if line.strip().startswith("git_date ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["date"] = mo.group(1) + f.close() + except EnvironmentError: + pass + return keywords + + +@register_vcs_handler("git", "keywords") +def git_versions_from_keywords(keywords, tag_prefix, verbose): + """Get version information from git keywords.""" + if not keywords: + raise NotThisMethod("no keywords at all, weird") + date = keywords.get("date") + if date is not None: + # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant + # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 + # -like" string, which we must then edit to make compliant), because + # it's been around since git-1.5.3, and it's too difficult to + # discover which version we're using, or to work around using an + # older one. + date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) + refnames = keywords["refnames"].strip() + if refnames.startswith("$Format"): + if verbose: + print("keywords are unexpanded, not using") + raise NotThisMethod("unexpanded keywords, not a git-archive tarball") + refs = set([r.strip() for r in refnames.strip("()").split(",")]) + # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of + # just "foo-1.0". If we see a "tag: " prefix, prefer those. + TAG = "tag: " + tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) + if not tags: + # Either we're using git < 1.8.3, or there really are no tags. We use + # a heuristic: assume all version tags have a digit. The old git %d + # expansion behaves like git log --decorate=short and strips out the + # refs/heads/ and refs/tags/ prefixes that would let us distinguish + # between branches and tags. By ignoring refnames without digits, we + # filter out many common branch names like "release" and + # "stabilization", as well as "HEAD" and "master". + tags = set([r for r in refs if re.search(r'\d', r)]) + if verbose: + print("discarding '%s', no digits" % ",".join(refs - tags)) + if verbose: + print("likely tags: %s" % ",".join(sorted(tags))) + for ref in sorted(tags): + # sorting will prefer e.g. "2.0" over "2.0rc1" + if ref.startswith(tag_prefix): + r = ref[len(tag_prefix):] + if verbose: + print("picking %s" % r) + return {"version": r, + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": None, + "date": date} + # no suitable tags, so version is "0+unknown", but full hex is still there + if verbose: + print("no suitable tags, using unknown + full revision id") + return {"version": "0+unknown", + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": "no suitable tags", "date": None} + + +@register_vcs_handler("git", "pieces_from_vcs") +def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): + """Get version from 'git describe' in the root of the source tree. + + This only gets called if the git-archive 'subst' keywords were *not* + expanded, and _version.py hasn't already been rewritten with a short + version string, meaning we're inside a checked out source tree. + """ + GITS = ["git"] + if sys.platform == "win32": + GITS = ["git.cmd", "git.exe"] + + out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, + hide_stderr=True) + if rc != 0: + if verbose: + print("Directory %s not under git control" % root) + raise NotThisMethod("'git rev-parse --git-dir' returned error") + + # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] + # if there isn't one, this yields HEX[-dirty] (no NUM) + describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", + "--always", "--long", + "--match", "%s*" % tag_prefix], + cwd=root) + # --long was added in git-1.5.5 + if describe_out is None: + raise NotThisMethod("'git describe' failed") + describe_out = describe_out.strip() + full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) + if full_out is None: + raise NotThisMethod("'git rev-parse' failed") + full_out = full_out.strip() + + pieces = {} + pieces["long"] = full_out + pieces["short"] = full_out[:7] # maybe improved later + pieces["error"] = None + + # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] + # TAG might have hyphens. + git_describe = describe_out + + # look for -dirty suffix + dirty = git_describe.endswith("-dirty") + pieces["dirty"] = dirty + if dirty: + git_describe = git_describe[:git_describe.rindex("-dirty")] + + # now we have TAG-NUM-gHEX or HEX + + if "-" in git_describe: + # TAG-NUM-gHEX + mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) + if not mo: + # unparseable. Maybe git-describe is misbehaving? + pieces["error"] = ("unable to parse git-describe output: '%s'" + % describe_out) + return pieces + + # tag + full_tag = mo.group(1) + if not full_tag.startswith(tag_prefix): + if verbose: + fmt = "tag '%s' doesn't start with prefix '%s'" + print(fmt % (full_tag, tag_prefix)) + pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" + % (full_tag, tag_prefix)) + return pieces + pieces["closest-tag"] = full_tag[len(tag_prefix):] + + # distance: number of commits since tag + pieces["distance"] = int(mo.group(2)) + + # commit: short hex revision ID + pieces["short"] = mo.group(3) + + else: + # HEX: no tags + pieces["closest-tag"] = None + count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], + cwd=root) + pieces["distance"] = int(count_out) # total number of commits + + # commit date: see ISO-8601 comment in git_versions_from_keywords() + date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], + cwd=root)[0].strip() + pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) + + return pieces + + +def plus_or_dot(pieces): + """Return a + if we don't already have one, else return a .""" + if "+" in pieces.get("closest-tag", ""): + return "." + return "+" + + +def render_pep440(pieces): + """Build up version string, with post-release "local version identifier". + + Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you + get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty + + Exceptions: + 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += plus_or_dot(pieces) + rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0+untagged.%d.g%s" % (pieces["distance"], + pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def render_pep440_pre(pieces): + """TAG[.post.devDISTANCE] -- No -dirty. + + Exceptions: + 1: no tags. 0.post.devDISTANCE + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"]: + rendered += ".post.dev%d" % pieces["distance"] + else: + # exception #1 + rendered = "0.post.dev%d" % pieces["distance"] + return rendered + + +def render_pep440_post(pieces): + """TAG[.postDISTANCE[.dev0]+gHEX] . + + The ".dev0" means dirty. Note that .dev0 sorts backwards + (a dirty tree will appear "older" than the corresponding clean one), + but you shouldn't be releasing software with -dirty anyways. + + Exceptions: + 1: no tags. 0.postDISTANCE[.dev0] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "g%s" % pieces["short"] + else: + # exception #1 + rendered = "0.post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + rendered += "+g%s" % pieces["short"] + return rendered + + +def render_pep440_old(pieces): + """TAG[.postDISTANCE[.dev0]] . + + The ".dev0" means dirty. + + Eexceptions: + 1: no tags. 0.postDISTANCE[.dev0] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + else: + # exception #1 + rendered = "0.post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + return rendered + + +def render_git_describe(pieces): + """TAG[-DISTANCE-gHEX][-dirty]. + + Like 'git describe --tags --dirty --always'. + + Exceptions: + 1: no tags. HEX[-dirty] (note: no 'g' prefix) + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"]: + rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) + else: + # exception #1 + rendered = pieces["short"] + if pieces["dirty"]: + rendered += "-dirty" + return rendered + + +def render_git_describe_long(pieces): + """TAG-DISTANCE-gHEX[-dirty]. + + Like 'git describe --tags --dirty --always -long'. + The distance/hash is unconditional. + + Exceptions: + 1: no tags. HEX[-dirty] (note: no 'g' prefix) + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) + else: + # exception #1 + rendered = pieces["short"] + if pieces["dirty"]: + rendered += "-dirty" + return rendered + + +def render(pieces, style): + """Render the given version pieces into the requested style.""" + if pieces["error"]: + return {"version": "unknown", + "full-revisionid": pieces.get("long"), + "dirty": None, + "error": pieces["error"], + "date": None} + + if not style or style == "default": + style = "pep440" # the default + + if style == "pep440": + rendered = render_pep440(pieces) + elif style == "pep440-pre": + rendered = render_pep440_pre(pieces) + elif style == "pep440-post": + rendered = render_pep440_post(pieces) + elif style == "pep440-old": + rendered = render_pep440_old(pieces) + elif style == "git-describe": + rendered = render_git_describe(pieces) + elif style == "git-describe-long": + rendered = render_git_describe_long(pieces) + else: + raise ValueError("unknown style '%s'" % style) + + return {"version": rendered, "full-revisionid": pieces["long"], + "dirty": pieces["dirty"], "error": None, + "date": pieces.get("date")} + + +def get_versions(): + """Get version information or return default if unable to do so.""" + # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have + # __file__, we can work backwards from there to the root. Some + # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which + # case we can only use expanded keywords. + + cfg = get_config() + verbose = cfg.verbose + + try: + return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, + verbose) + except NotThisMethod: + pass + + try: + root = os.path.realpath(__file__) + # versionfile_source is the relative path from the top of the source + # tree (where the .git directory might live) to this file. Invert + # this to find the root from __file__. + for i in cfg.versionfile_source.split('/'): + root = os.path.dirname(root) + except NameError: + return {"version": "0+unknown", "full-revisionid": None, + "dirty": None, + "error": "unable to find root of source tree", + "date": None} + + try: + pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) + return render(pieces, cfg.style) + except NotThisMethod: + pass + + try: + if cfg.parentdir_prefix: + return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) + except NotThisMethod: + pass + + return {"version": "0+unknown", "full-revisionid": None, + "dirty": None, + "error": "unable to compute version", "date": None} diff --git a/src/brenda_parser/api.py b/src/brenda_parser/api.py new file mode 100644 index 0000000..8679c3b --- /dev/null +++ b/src/brenda_parser/api.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Provide an API to the BRENDA parser.""" + +from __future__ import absolute_import + +import logging + +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker + +import brenda_parser.models as models + +LOGGER = logging.getLogger(__name__) +Session = sessionmaker() + + +def initialize_db(connection="sqlite:///:memory:"): + engine = create_engine(connection) + session = Session(bind=engine) + models.Base.metadata.create_all(engine, checkfirst=True) + models.InformationField.preload(session) + return engine, session diff --git a/src/brenda_parser/cli.py b/src/brenda_parser/cli.py new file mode 100644 index 0000000..a8b76b0 --- /dev/null +++ b/src/brenda_parser/cli.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Provide a command line interface for the parser.""" + +from __future__ import absolute_import + +import logging + +import click +import click_log + +from brenda_parser import __version__ + +LOGGER = logging.getLogger(__name__.split(".", 1)[0]) +click_log.basic_config(LOGGER) + + +@click.group() +@click.help_option("--help", "-h") +@click.version_option(__version__, "--version", "-V") +@click_log.simple_verbosity_option( + LOGGER, default="INFO", show_default=True, + type=click.Choice(["CRITICAL", "ERROR", "WARN", "INFO", "DEBUG"])) +def cli(): + """Parse the BRENDA Enzyme flat file distribution to a local database.""" + pass diff --git a/src/brenda_parser/data/__init__.py b/src/brenda_parser/data/__init__.py new file mode 100644 index 0000000..a85f09c --- /dev/null +++ b/src/brenda_parser/data/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Jacobs University Bremen gGmbH +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Provide data resources.""" + +from __future__ import absolute_import diff --git a/src/brenda_parser/data/information_fields.csv b/src/brenda_parser/data/information_fields.csv new file mode 100644 index 0000000..c65b83b --- /dev/null +++ b/src/brenda_parser/data/information_fields.csv @@ -0,0 +1,41 @@ +"acronym","name" +"PR","protein" +"RN","recommended name (IUPAC)" +"SN","systematic name" +"SY","synonym" +"RE","catalyzed reaction" +"RT","reaction type" +"ST","source/tissue" +"LO","localization" +"NSP","natural substrate product" +"SP","substrate/product" +"TN","turnover number" +"KM","KM value" +"PHO","pH optimum" +"PHR","pH range" +"SA","specific activity" +"TO","temperature optimum" +"TR","temperature range" +"CF","co-factor" +"AC","activating compound" +"IN","inhibitor" +"KI","Ki value" +"ME","metal/ion" +"MW","molecular weight" +"PM","post-translational modification" +"SU","subunit" +"PI","isoelectric point" +"AP","application" +"EN","engineering" +"CL","cloned" +"CR","crystallization" +"PU","purification" +"REN","renatured" +"GS","general stability" +"OSS","organic solvent stability" +"OS","oxidation stability" +"PHS","pH stability" +"SS","storage stability" +"TS","temperature stability" +"RF","reference" +"IC50","IC-50 value" diff --git a/src/brenda_parser/exceptions.py b/src/brenda_parser/exceptions.py new file mode 100644 index 0000000..e44c440 --- /dev/null +++ b/src/brenda_parser/exceptions.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Jacobs University Bremen gGmbH +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Provide custom exceptions.""" + +from __future__ import absolute_import + + +class ValidationError(AssertionError): + pass + + diff --git a/src/brenda_parser/models/__init__.py b/src/brenda_parser/models/__init__.py new file mode 100644 index 0000000..6350ed4 --- /dev/null +++ b/src/brenda_parser/models/__init__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Jacobs University Bremen gGmbH +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Provide data models for storing BRENDA EC-number information.""" + +from __future__ import absolute_import + +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() + +from brenda_parser.models.information_field import * +from brenda_parser.models.organism import * +from brenda_parser.models.reference import * +from brenda_parser.models.protein import * +from brenda_parser.models.field_entry import * +from brenda_parser.models.enzyme import * diff --git a/src/brenda_parser/models/comment.py b/src/brenda_parser/models/comment.py new file mode 100644 index 0000000..92d7f7e --- /dev/null +++ b/src/brenda_parser/models/comment.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Provide a data model for a comment.""" + +from __future__ import absolute_import + +import logging + +from sqlalchemy import Column, Text +from sqlalchemy.orm import relationship + +from brenda_parser.models import Base + +__all__ = ("Comment",) + +LOGGER = logging.getLogger(__name__) + + +class Comment(Base): + + __tablename__ = "comment" + + proteins = relationship("Protein") + commentary = Column(Text()) + citations = relationship("Reference") + diff --git a/src/brenda_parser/models/enzyme.py b/src/brenda_parser/models/enzyme.py new file mode 100644 index 0000000..9a02beb --- /dev/null +++ b/src/brenda_parser/models/enzyme.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Provide a data model for an information field entry.""" + +from __future__ import absolute_import + +import logging +import re + +from sqlalchemy import Column, Integer, String, ForeignKey +from sqlalchemy.orm import validates, relationship + +from brenda_parser.exceptions import ValidationError +from brenda_parser.models import Base + +__all__ = ("Enzyme",) + +LOGGER = logging.getLogger(__name__) + + +class Enzyme(Base): + """Represent a complete enzyme classification (EC) number section.""" + + __tablename__ = "enzyme" + + id = Column(Integer, primary_key=True) + ec_number = Column(String(19)) + # # TODO: The following relationships should be established by joins on + # # 'field' selecting specific acronyms. + # proteins = relationship("PR") + # recommended_names = relationship("RN") + # systematic_names = relationship("SN") + # synonyms = relationship("SY") + # reactions = relationship("RE") + # reaction_types = relationship("RT") + # source_tissues = relationship("ST") + # localization = relationship("LO") + # natural_substrates_products = relationship("NSP") + # substrates_products = relationship("SP") + # turnover_numbers = relationship("TN") + # km_values = relationship("KM") + # ph_optima = relationship("PHO") + # ph_ranges = relationship("PHR") + # specific_activities = relationship("SA") + # temperature_optima = relationship("TO") + # temperature_ranges = relationship("TR") + # cofactors = relationship("CF") + # activating_compounds = relationship("AC") + # inhibitors = relationship("IN") + # ki_values = relationship("KI") + # metals_ions = relationship("ME") + # molecular_weights = relationship("MW") + # posttranslational_modifications = relationship("PM") + # subunits = relationship("SU") + # pi_values = relationship("PI") + # applications = relationship("AP") + # engineering = relationship("EN") + # clones = relationship("CL") + # crystallizations = relationship("CR") + # purifications = relationship("PU") + # renatured = relationship("REN") + # general_stabilities = relationship("GS") + # organic_solvent_stabilities = relationship("OSS") + # oxidation_stabilities = relationship("OS") + # ph_stabilities = relationship("PHS") + # storage_stabilities = relationship("SS") + # temperature_stabilities = relationship("TS") + # references = relationship("RF") + # ic50_values = relationship("IC50") + + def __init__(self, **kwargs): + super(Enzyme, self).__init__(**kwargs) + self.entries = list() + self.proteins = list() + self.references = list() + self.comments = list() diff --git a/src/brenda_parser/models/field_entry.py b/src/brenda_parser/models/field_entry.py new file mode 100644 index 0000000..3100a5f --- /dev/null +++ b/src/brenda_parser/models/field_entry.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Provide a data model for an information field entry.""" + +from __future__ import absolute_import + +import logging +import re + +from sqlalchemy import Column, Integer, String, ForeignKey +from sqlalchemy.orm import validates, relationship + +from brenda_parser.exceptions import ValidationError +from brenda_parser.models import Base + +__all__ = ("FieldEntry",) + +LOGGER = logging.getLogger(__name__) + + +class FieldEntry(Base): + + __tablename__ = "fieldentry" + + id = Column(Integer, primary_key=True) + field_id = Column(Integer, ForeignKey("informationfield.id")) + field = relationship("InformationField") + # The `body` might have to be Text. + body = Column(String(255), nullable=False) + # enzyme_id = Column(Integer, ForeignKey("enzyme.id")) + # enzyme = relationship("Enzyme") + # proteins = relationship("Protein") + # citations = relationship("Reference") + # comments = relationship("Comment") + # special_information = relationship("SpecialInformation") + + def __init__(self, **kwargs): + """ + Instantiate an entry with extra attributes. + + The attributes are used to hold the integer references to proteins + and citations. These are later replaced with actual relationships + when an entire enzyme section is completed. + """ + super(FieldEntry, self).__init__(**kwargs) + self.protein_references = list() + self.citation_references = list() + self.comment_references = list() diff --git a/src/brenda_parser/models/information_field.py b/src/brenda_parser/models/information_field.py new file mode 100644 index 0000000..e867166 --- /dev/null +++ b/src/brenda_parser/models/information_field.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Provide a data model for an information field.""" + +from __future__ import absolute_import + +import csv +import logging +import re + +from importlib_resources import open_text +from sqlalchemy import Column, Integer, String +from sqlalchemy.orm import validates +from sqlalchemy.exc import IntegrityError + +import brenda_parser.data +from brenda_parser.exceptions import ValidationError +from brenda_parser.models import Base + +__all__ = ("InformationField",) + +LOGGER = logging.getLogger(__name__) + + +class InformationField(Base): + + __tablename__ = "informationfield" + + id = Column(Integer, primary_key=True) + acronym = Column(String(4), nullable=False, unique=True, index=True) + name = Column(String(100), nullable=True) + + ACRONYM_PATTERN = re.compile(r"^[A-Z0-9]{2,4}$") + + @validates("acronym") + def validate_acronym(self, key, value): + if self.ACRONYM_PATTERN.match(value) is None: + raise ValidationError( + "'{}' does not match the required pattern '{}'." + "".format(value, self.ACRONYM_PATTERN)) + return value + + @classmethod + def preload(cls, session): + """ + Pre-load information fields from the packaged list. + + Parameters + ---------- + session : sqlalchemy.Session + A valid SQLAlchemy database session. + + """ + with open_text(brenda_parser.data, "information_fields.csv") as handle: + rows = list(csv.DictReader(handle)) + table = cls.__table__ + try: + session.execute(table.insert().values(rows)) + LOGGER.debug("Successfully loaded information fields.") + except IntegrityError: + session.rollback() + for row in rows: + # This query will ignore or fail on non-existent + # `row["acronym"]`. + session.query(InformationField) \ + .filter_by(acronym=row["acronym"]) \ + .update(row) + LOGGER.debug("Updated field '%s'.", row["acronym"]) + session.commit() diff --git a/src/brenda_parser/models/organism.py b/src/brenda_parser/models/organism.py new file mode 100644 index 0000000..2296b6f --- /dev/null +++ b/src/brenda_parser/models/organism.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Provide a data model for an organism.""" + +from __future__ import absolute_import + +import logging + +from sqlalchemy import Column, Integer, String + +from brenda_parser.models import Base + +__all__ = ("Organism",) + +LOGGER = logging.getLogger(__name__) + + +class Organism(Base): + + __tablename__ = "organism" + + id = Column(Integer, primary_key=True) + name = Column(String(255), nullable=False, unique=True, index=True) diff --git a/src/brenda_parser/models/protein.py b/src/brenda_parser/models/protein.py new file mode 100644 index 0000000..2e7cb58 --- /dev/null +++ b/src/brenda_parser/models/protein.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Provide a data model for a protein.""" + +from __future__ import absolute_import + +import logging +import re + +from sqlalchemy import Column, Integer, String, ForeignKey +from sqlalchemy.orm import validates, relationship + +from brenda_parser.exceptions import ValidationError +from brenda_parser.models import Base + +__all__ = ("Protein",) + +LOGGER = logging.getLogger(__name__) + + +class Protein(Base): + + __tablename__ = "protein" + + # Taken from identifiers.org + UNIPROT_PATTERN = re.compile( + r"([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9]" + r"[A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\.\d+)?") + + id = Column(Integer, primary_key=True) + field_id = Column(Integer, ForeignKey("informationfield.id")) + field = relationship("InformationField") + organism_id = Column(Integer, ForeignKey("organism.id")) + organism = relationship("Organism") + accession = Column(String(255), nullable=True, unique=True) + database = Column(String(255), nullable=True) + # citations = relationship("Reference") + + def __init__(self, **kwargs): + super(Protein, self).__init__(**kwargs) + self.organism_name = "" + self.citation_references = list() + + @validates("accession") + def validate_accession(self, key, value): + if value is None: + return value + if self.UNIPROT_PATTERN.match(value) is None: + raise ValidationError( + "'{}' does not match the required pattern '{}'." + "".format(value, self.UNIPROT_PATTERN)) + return value + + @validates("field") + def validate_field(self, key, value): + if value.acronym != "PR": + raise ValidationError("Wrong field for a protein description!") + return value diff --git a/src/brenda_parser/models/reference.py b/src/brenda_parser/models/reference.py new file mode 100644 index 0000000..15304f0 --- /dev/null +++ b/src/brenda_parser/models/reference.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Provide a data model for a reference.""" + +from __future__ import absolute_import + +import logging +import re + +from sqlalchemy import Column, Integer, String, ForeignKey +from sqlalchemy.orm import relationship, validates + +from brenda_parser.exceptions import ValidationError +from brenda_parser.models import Base + +__all__ = ("Reference",) + +LOGGER = logging.getLogger(__name__) + + +class Reference(Base): + + __tablename__ = "reference" + + id = Column(Integer, primary_key=True) + field_id = Column(Integer, ForeignKey("informationfield.id")) + field = relationship("InformationField") + pubmed = Column(String(14), nullable=True, unique=True, index=True) + # The `body` might have to be Text. + body = Column(String(255), nullable=False) + + PUBMED_PATTERN = re.compile(r"^Pubmed:\d{7}$") + + @validates("pubmed") + def validate_pubmed(self, key, value): + if value is None: + return value + if self.PUBMED_PATTERN.match(value) is None: + raise ValidationError( + "'{}' does not match the required pattern '{}'." + "".format(value, self.PUBMED_PATTERN)) + return value diff --git a/src/brenda_parser/models/special_information.py b/src/brenda_parser/models/special_information.py new file mode 100644 index 0000000..55d59a7 --- /dev/null +++ b/src/brenda_parser/models/special_information.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Provide a data model for additional information.""" + +from __future__ import absolute_import + +import logging + +from sqlalchemy import Column, Text +from sqlalchemy.orm import relationship + +from brenda_parser.models import Base + +__all__ = ("SpecialInformation",) + +LOGGER = logging.getLogger(__name__) + + +class SpecialInformation(Base): + + __tablename__ = "special" + + proteins = relationship("Protein") + commentary = Column(Text()) + citations = relationship("Reference") diff --git a/src/brenda_parser/parsing/__init__.py b/src/brenda_parser/parsing/__init__.py new file mode 100644 index 0000000..acc07ba --- /dev/null +++ b/src/brenda_parser/parsing/__init__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Jacobs University Bremen gGmbH +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Provide the BRENDA flat file parsing capabilities.""" + +from __future__ import absolute_import + +from brenda_parser.parsing.lexer import * +from brenda_parser.parsing.parser import * diff --git a/src/brenda_parser/parsing/lexer.py b/src/brenda_parser/parsing/lexer.py new file mode 100644 index 0000000..d5bee6c --- /dev/null +++ b/src/brenda_parser/parsing/lexer.py @@ -0,0 +1,250 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Tokenize the BRENDA flat file.""" + +from __future__ import absolute_import + +import logging + +from ply.lex import lex + +__all__ = ("BRENDALexer",) + +LOGGER = logging.getLogger(__name__) + + +class BRENDALexer(object): + """ + + We use functions for most tokens in order to fully control pattern + matching order. Tokens (methods) defined first are matched first. + """ + + states = ( + ("citation", "exclusive"), + ("protein", "exclusive"), + ("special", "exclusive"), + ("comment", "exclusive"), + ("protentry", "inclusive"), + ) + # List of token names. This is always required. + tokens = ( + "PROTEIN", + "CITATION", + "ENTRY", + "PROTEIN_ENTRY", + "REFERENCE_ENTRY", + "POUND", + "LPARENS", + "RPARENS", + "LANGLE", + "RANGLE", + "LCURLY", + "RCURLY", + "EC_NUMBER", + "END", + "CONTENT", + "SPECIAL", + "COMMENT", + "ACCESSION" + ) + + # A string containing ignored characters interpreted literally not as regex. + t_ignore = " \t\r\f\v" # all whitespace + t_citation_protein_ignore = " ," + t_special_comment_ignore = " \t\r\f\v" + # Regular expression rules for simple tokens are parsed after all patterns + # defined in methods. + t_CONTENT = "[^\{\}\(\)\<\>\#\n]+" + + def __init__(self, **kw_args): + """ + Instantiate a BRENDA flat file specific lexer. + + An instance can then be used to tokenize a string by using + >>> lexer = BRENDALexer() + >>> lexer.input("What will happen?") + >>> [token.type for token in lexer] + ['CONTENT', 'CONTENT', 'CONTENT'] + + Parameters + ---------- + kw_args : + Keyword arguments are passed to the ply.lex.lex call. + """ + super(BRENDALexer, self).__init__() + self.lexer = lex(module=self, errorlog=LOGGER, **kw_args) + self.parens_level = 0 + self.last_lparens = 0 + self.last_rparens = 0 + + def __getattr__(self, attr): + return getattr(self.lexer, attr) + + def __iter__(self): + return (tok for tok in iter(self.lexer.token, None)) + + def input(self, data): + """Add a new string to the lexer. + This is the setup step necessary before you can iterate over the tokens. + Parameters + ---------- + data : str + Any string. + """ + self.lexer.push_state("INITIAL") + self.parens_level = 0 + self.lexer.input(data) + + def t_ANY_error(self, t): + LOGGER.error("Invalid token '%s' at line %d.", t.value[0], t.lineno) + t.lexer.skip(1) + + def t_ANY_newline(self, t): + r'\n+' + t.lexer.lineno += len(t.value) + + def t_brenda_comment(self, t): + r"\*.+\n" + t.lexer.lineno += 1 + pass + + def t_POUND(self, t): + r"[#]" + self.lexer.push_state("protein") + return t + + def t_protein_PROTEIN(self, t): + r"\d+" + t.value = int(t.value) + return t + + def t_protein_POUND(self, t): + r"[#]" + self.lexer.pop_state() + return t + + def t_LANGLE(self, t): + r"<" + t.lexer.push_state("citation") + return t + + def t_citation_CITATION(self, t): + r"\d+" + t.value = int(t.value) + return t + + def t_citation_RANGLE(self, t): + r">" + t.lexer.pop_state() + return t + + def t_LCURLY(self, t): + r"{" + t.lexer.push_state("special") + return t + + def t_special_SPECIAL(self, t): + r"[^\{\}\s]+" + return t + + def t_special_RCURLY(self, t): + r"}" + t.lexer.pop_state() + return t + + def t_LPARENS(self, t): + r"\(" + t.lexer.push_state("comment") + self.parens_level += 1 + return t + + def t_comment_COMMENT(self, t): + r"[^\(\)\s]+" + # TODO: In future properly parse proteins and citations inside comments. + # r"[^\s\{\}\(\)\<\>\#]+" + return t + + def t_comment_LPARENS(self, t): + r"\(" + self.parens_level += 1 + t.type = "COMMENT" + return t + + def t_comment_RPARENS(self, t): + r"\)" + self.parens_level -= 1 + if self.parens_level == 0: + t.lexer.pop_state() + else: + t.type = "COMMENT" + return t + + def t_EC_NUMBER(self, t): + r"(\d+)\.(\d+)\.(\d+)\.(\d+)" + return t + + def t_END(self, t): + r"[/]{3}\s" + return t + + def t_protentry_ENTRY(self, t): + r"[A-Z0-9]{2,4}\t" + t.value = t.value.strip() + if t.value != "PR": + t.lexer.pop_state() + return t + + def t_PROTEIN_ENTRY(self, t): + r"PR\t" + t.value = t.value.strip() + if t.lexer.current_state() != "protentry": + t.lexer.push_state("protentry") + return t + + def t_REFERENCE_ENTRY(self, t): + r"RF\t" + t.value = t.value.strip() + return t + + def t_ENTRY(self, t): + r"[A-Z0-9]{2,4}\t" + t.value = t.value.strip() + return t + + def t_brenda_header(self, t): + r"[A-Z0-9]{4,}\n" + t.lexer.lineno += 1 + pass + + def t_protentry_ACCESSION(self, t): + r"([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\.\d+)?" + # Regular expression from identifiers.org for UniProt. + return t diff --git a/src/brenda_parser/parsing/parser.out b/src/brenda_parser/parsing/parser.out new file mode 100644 index 0000000..6eabc02 --- /dev/null +++ b/src/brenda_parser/parsing/parser.out @@ -0,0 +1,939 @@ +Created by PLY version 3.10 (http://www.dabeaz.com/ply) + +Grammar + +Rule 0 S' -> enzyme +Rule 1 enzyme -> ENTRY EC_NUMBER new_enzyme +Rule 2 new_enzyme -> +Rule 3 enzyme -> enzyme comment +Rule 4 enzyme -> enzyme protein_entry +Rule 5 enzyme -> enzyme reference_entry +Rule 6 enzyme -> enzyme entry +Rule 7 enzyme -> enzyme END +Rule 8 entry -> ENTRY new_entry +Rule 9 new_entry -> +Rule 10 entry -> entry CONTENT +Rule 11 entry -> entry comment +Rule 12 reference_entry -> REFERENCE_ENTRY new_reference citations +Rule 13 new_reference -> +Rule 14 reference_entry -> reference_entry CONTENT +Rule 15 reference_entry -> reference_entry comment +Rule 16 reference_entry -> reference_entry special +Rule 17 protein_entry -> PROTEIN_ENTRY new_protein proteins +Rule 18 new_protein -> +Rule 19 protein_entry -> protein_entry CONTENT +Rule 20 protein_entry -> protein_entry ACCESSION CONTENT +Rule 21 protein_entry -> protein_entry citations +Rule 22 special -> LCURLY special RCURLY +Rule 23 special -> LCURLY RCURLY +Rule 24 special -> special SPECIAL +Rule 25 special -> SPECIAL +Rule 26 proteins -> POUND proteins POUND +Rule 27 proteins -> POUND POUND +Rule 28 proteins -> proteins PROTEIN +Rule 29 proteins -> PROTEIN +Rule 30 citations -> LANGLE citations RANGLE +Rule 31 citations -> LANGLE RANGLE +Rule 32 citations -> citations CITATION +Rule 33 citations -> CITATION +Rule 34 comment -> LPARENS comment RPARENS +Rule 35 comment -> LPARENS RPARENS +Rule 36 comment -> comment COMMENT +Rule 37 comment -> COMMENT + +Terminals, with rules where they appear + +ACCESSION : 20 +CITATION : 32 33 +COMMENT : 36 37 +CONTENT : 10 14 19 20 +EC_NUMBER : 1 +END : 7 +ENTRY : 1 8 +LANGLE : 30 31 +LCURLY : 22 23 +LPARENS : 34 35 +POUND : 26 26 27 27 +PROTEIN : 28 29 +PROTEIN_ENTRY : 17 +RANGLE : 30 31 +RCURLY : 22 23 +REFERENCE_ENTRY : 12 +RPARENS : 34 35 +SPECIAL : 24 25 +error : + +Nonterminals, with rules where they appear + +citations : 12 21 30 32 +comment : 3 11 15 34 36 +entry : 6 10 11 +enzyme : 3 4 5 6 7 0 +new_entry : 8 +new_enzyme : 1 +new_protein : 17 +new_reference : 12 +protein_entry : 4 19 20 21 +proteins : 17 26 28 +reference_entry : 5 14 15 16 +special : 16 22 24 + +Parsing method: LALR + +state 0 + + (0) S' -> . enzyme + (1) enzyme -> . ENTRY EC_NUMBER new_enzyme + (3) enzyme -> . enzyme comment + (4) enzyme -> . enzyme protein_entry + (5) enzyme -> . enzyme reference_entry + (6) enzyme -> . enzyme entry + (7) enzyme -> . enzyme END + + ENTRY shift and go to state 2 + + enzyme shift and go to state 1 + +state 1 + + (0) S' -> enzyme . + (3) enzyme -> enzyme . comment + (4) enzyme -> enzyme . protein_entry + (5) enzyme -> enzyme . reference_entry + (6) enzyme -> enzyme . entry + (7) enzyme -> enzyme . END + (34) comment -> . LPARENS comment RPARENS + (35) comment -> . LPARENS RPARENS + (36) comment -> . comment COMMENT + (37) comment -> . COMMENT + (17) protein_entry -> . PROTEIN_ENTRY new_protein proteins + (19) protein_entry -> . protein_entry CONTENT + (20) protein_entry -> . protein_entry ACCESSION CONTENT + (21) protein_entry -> . protein_entry citations + (12) reference_entry -> . REFERENCE_ENTRY new_reference citations + (14) reference_entry -> . reference_entry CONTENT + (15) reference_entry -> . reference_entry comment + (16) reference_entry -> . reference_entry special + (8) entry -> . ENTRY new_entry + (10) entry -> . entry CONTENT + (11) entry -> . entry comment + + END shift and go to state 7 + LPARENS shift and go to state 8 + COMMENT shift and go to state 9 + PROTEIN_ENTRY shift and go to state 10 + REFERENCE_ENTRY shift and go to state 11 + ENTRY shift and go to state 12 + + comment shift and go to state 3 + protein_entry shift and go to state 4 + reference_entry shift and go to state 5 + entry shift and go to state 6 + +state 2 + + (1) enzyme -> ENTRY . EC_NUMBER new_enzyme + + EC_NUMBER shift and go to state 13 + + +state 3 + + (3) enzyme -> enzyme comment . + (36) comment -> comment . COMMENT + + END reduce using rule 3 (enzyme -> enzyme comment .) + LPARENS reduce using rule 3 (enzyme -> enzyme comment .) + COMMENT reduce using rule 3 (enzyme -> enzyme comment .) + PROTEIN_ENTRY reduce using rule 3 (enzyme -> enzyme comment .) + REFERENCE_ENTRY reduce using rule 3 (enzyme -> enzyme comment .) + ENTRY reduce using rule 3 (enzyme -> enzyme comment .) + $end reduce using rule 3 (enzyme -> enzyme comment .) + + ! COMMENT [ shift and go to state 14 ] + + +state 4 + + (4) enzyme -> enzyme protein_entry . + (19) protein_entry -> protein_entry . CONTENT + (20) protein_entry -> protein_entry . ACCESSION CONTENT + (21) protein_entry -> protein_entry . citations + (30) citations -> . LANGLE citations RANGLE + (31) citations -> . LANGLE RANGLE + (32) citations -> . citations CITATION + (33) citations -> . CITATION + + END reduce using rule 4 (enzyme -> enzyme protein_entry .) + LPARENS reduce using rule 4 (enzyme -> enzyme protein_entry .) + COMMENT reduce using rule 4 (enzyme -> enzyme protein_entry .) + PROTEIN_ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) + REFERENCE_ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) + ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) + $end reduce using rule 4 (enzyme -> enzyme protein_entry .) + CONTENT shift and go to state 15 + ACCESSION shift and go to state 16 + LANGLE shift and go to state 18 + CITATION shift and go to state 19 + + citations shift and go to state 17 + +state 5 + + (5) enzyme -> enzyme reference_entry . + (14) reference_entry -> reference_entry . CONTENT + (15) reference_entry -> reference_entry . comment + (16) reference_entry -> reference_entry . special + (34) comment -> . LPARENS comment RPARENS + (35) comment -> . LPARENS RPARENS + (36) comment -> . comment COMMENT + (37) comment -> . COMMENT + (22) special -> . LCURLY special RCURLY + (23) special -> . LCURLY RCURLY + (24) special -> . special SPECIAL + (25) special -> . SPECIAL + + END reduce using rule 5 (enzyme -> enzyme reference_entry .) + LPARENS reduce using rule 5 (enzyme -> enzyme reference_entry .) + COMMENT reduce using rule 5 (enzyme -> enzyme reference_entry .) + PROTEIN_ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) + REFERENCE_ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) + ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) + $end reduce using rule 5 (enzyme -> enzyme reference_entry .) + CONTENT shift and go to state 20 + LCURLY shift and go to state 23 + SPECIAL shift and go to state 24 + + ! LPARENS [ shift and go to state 8 ] + ! COMMENT [ shift and go to state 9 ] + + comment shift and go to state 21 + special shift and go to state 22 + +state 6 + + (6) enzyme -> enzyme entry . + (10) entry -> entry . CONTENT + (11) entry -> entry . comment + (34) comment -> . LPARENS comment RPARENS + (35) comment -> . LPARENS RPARENS + (36) comment -> . comment COMMENT + (37) comment -> . COMMENT + + END reduce using rule 6 (enzyme -> enzyme entry .) + LPARENS reduce using rule 6 (enzyme -> enzyme entry .) + COMMENT reduce using rule 6 (enzyme -> enzyme entry .) + PROTEIN_ENTRY reduce using rule 6 (enzyme -> enzyme entry .) + REFERENCE_ENTRY reduce using rule 6 (enzyme -> enzyme entry .) + ENTRY reduce using rule 6 (enzyme -> enzyme entry .) + $end reduce using rule 6 (enzyme -> enzyme entry .) + CONTENT shift and go to state 25 + + ! LPARENS [ shift and go to state 8 ] + ! COMMENT [ shift and go to state 9 ] + + comment shift and go to state 26 + +state 7 + + (7) enzyme -> enzyme END . + + END reduce using rule 7 (enzyme -> enzyme END .) + LPARENS reduce using rule 7 (enzyme -> enzyme END .) + COMMENT reduce using rule 7 (enzyme -> enzyme END .) + PROTEIN_ENTRY reduce using rule 7 (enzyme -> enzyme END .) + REFERENCE_ENTRY reduce using rule 7 (enzyme -> enzyme END .) + ENTRY reduce using rule 7 (enzyme -> enzyme END .) + $end reduce using rule 7 (enzyme -> enzyme END .) + + +state 8 + + (34) comment -> LPARENS . comment RPARENS + (35) comment -> LPARENS . RPARENS + (34) comment -> . LPARENS comment RPARENS + (35) comment -> . LPARENS RPARENS + (36) comment -> . comment COMMENT + (37) comment -> . COMMENT + + RPARENS shift and go to state 28 + LPARENS shift and go to state 8 + COMMENT shift and go to state 9 + + comment shift and go to state 27 + +state 9 + + (37) comment -> COMMENT . + + COMMENT reduce using rule 37 (comment -> COMMENT .) + END reduce using rule 37 (comment -> COMMENT .) + LPARENS reduce using rule 37 (comment -> COMMENT .) + PROTEIN_ENTRY reduce using rule 37 (comment -> COMMENT .) + REFERENCE_ENTRY reduce using rule 37 (comment -> COMMENT .) + ENTRY reduce using rule 37 (comment -> COMMENT .) + $end reduce using rule 37 (comment -> COMMENT .) + CONTENT reduce using rule 37 (comment -> COMMENT .) + LCURLY reduce using rule 37 (comment -> COMMENT .) + SPECIAL reduce using rule 37 (comment -> COMMENT .) + RPARENS reduce using rule 37 (comment -> COMMENT .) + + +state 10 + + (17) protein_entry -> PROTEIN_ENTRY . new_protein proteins + (18) new_protein -> . + + POUND reduce using rule 18 (new_protein -> .) + PROTEIN reduce using rule 18 (new_protein -> .) + + new_protein shift and go to state 29 + +state 11 + + (12) reference_entry -> REFERENCE_ENTRY . new_reference citations + (13) new_reference -> . + + LANGLE reduce using rule 13 (new_reference -> .) + CITATION reduce using rule 13 (new_reference -> .) + + new_reference shift and go to state 30 + +state 12 + + (8) entry -> ENTRY . new_entry + (9) new_entry -> . + + CONTENT reduce using rule 9 (new_entry -> .) + LPARENS reduce using rule 9 (new_entry -> .) + COMMENT reduce using rule 9 (new_entry -> .) + END reduce using rule 9 (new_entry -> .) + PROTEIN_ENTRY reduce using rule 9 (new_entry -> .) + REFERENCE_ENTRY reduce using rule 9 (new_entry -> .) + ENTRY reduce using rule 9 (new_entry -> .) + $end reduce using rule 9 (new_entry -> .) + + new_entry shift and go to state 31 + +state 13 + + (1) enzyme -> ENTRY EC_NUMBER . new_enzyme + (2) new_enzyme -> . + + END reduce using rule 2 (new_enzyme -> .) + LPARENS reduce using rule 2 (new_enzyme -> .) + COMMENT reduce using rule 2 (new_enzyme -> .) + PROTEIN_ENTRY reduce using rule 2 (new_enzyme -> .) + REFERENCE_ENTRY reduce using rule 2 (new_enzyme -> .) + ENTRY reduce using rule 2 (new_enzyme -> .) + $end reduce using rule 2 (new_enzyme -> .) + + new_enzyme shift and go to state 32 + +state 14 + + (36) comment -> comment COMMENT . + + COMMENT reduce using rule 36 (comment -> comment COMMENT .) + END reduce using rule 36 (comment -> comment COMMENT .) + LPARENS reduce using rule 36 (comment -> comment COMMENT .) + PROTEIN_ENTRY reduce using rule 36 (comment -> comment COMMENT .) + REFERENCE_ENTRY reduce using rule 36 (comment -> comment COMMENT .) + ENTRY reduce using rule 36 (comment -> comment COMMENT .) + $end reduce using rule 36 (comment -> comment COMMENT .) + CONTENT reduce using rule 36 (comment -> comment COMMENT .) + LCURLY reduce using rule 36 (comment -> comment COMMENT .) + SPECIAL reduce using rule 36 (comment -> comment COMMENT .) + RPARENS reduce using rule 36 (comment -> comment COMMENT .) + + +state 15 + + (19) protein_entry -> protein_entry CONTENT . + + CONTENT reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + ACCESSION reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + LANGLE reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + CITATION reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + END reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + LPARENS reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + COMMENT reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + PROTEIN_ENTRY reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + REFERENCE_ENTRY reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + ENTRY reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + $end reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + + +state 16 + + (20) protein_entry -> protein_entry ACCESSION . CONTENT + + CONTENT shift and go to state 33 + + +state 17 + + (21) protein_entry -> protein_entry citations . + (32) citations -> citations . CITATION + + CONTENT reduce using rule 21 (protein_entry -> protein_entry citations .) + ACCESSION reduce using rule 21 (protein_entry -> protein_entry citations .) + LANGLE reduce using rule 21 (protein_entry -> protein_entry citations .) + CITATION reduce using rule 21 (protein_entry -> protein_entry citations .) + END reduce using rule 21 (protein_entry -> protein_entry citations .) + LPARENS reduce using rule 21 (protein_entry -> protein_entry citations .) + COMMENT reduce using rule 21 (protein_entry -> protein_entry citations .) + PROTEIN_ENTRY reduce using rule 21 (protein_entry -> protein_entry citations .) + REFERENCE_ENTRY reduce using rule 21 (protein_entry -> protein_entry citations .) + ENTRY reduce using rule 21 (protein_entry -> protein_entry citations .) + $end reduce using rule 21 (protein_entry -> protein_entry citations .) + + ! CITATION [ shift and go to state 34 ] + + +state 18 + + (30) citations -> LANGLE . citations RANGLE + (31) citations -> LANGLE . RANGLE + (30) citations -> . LANGLE citations RANGLE + (31) citations -> . LANGLE RANGLE + (32) citations -> . citations CITATION + (33) citations -> . CITATION + + RANGLE shift and go to state 36 + LANGLE shift and go to state 18 + CITATION shift and go to state 19 + + citations shift and go to state 35 + +state 19 + + (33) citations -> CITATION . + + CITATION reduce using rule 33 (citations -> CITATION .) + CONTENT reduce using rule 33 (citations -> CITATION .) + ACCESSION reduce using rule 33 (citations -> CITATION .) + LANGLE reduce using rule 33 (citations -> CITATION .) + END reduce using rule 33 (citations -> CITATION .) + LPARENS reduce using rule 33 (citations -> CITATION .) + COMMENT reduce using rule 33 (citations -> CITATION .) + PROTEIN_ENTRY reduce using rule 33 (citations -> CITATION .) + REFERENCE_ENTRY reduce using rule 33 (citations -> CITATION .) + ENTRY reduce using rule 33 (citations -> CITATION .) + $end reduce using rule 33 (citations -> CITATION .) + RANGLE reduce using rule 33 (citations -> CITATION .) + LCURLY reduce using rule 33 (citations -> CITATION .) + SPECIAL reduce using rule 33 (citations -> CITATION .) + + +state 20 + + (14) reference_entry -> reference_entry CONTENT . + + CONTENT reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + LPARENS reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + COMMENT reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + LCURLY reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + SPECIAL reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + END reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + PROTEIN_ENTRY reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + REFERENCE_ENTRY reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + ENTRY reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + $end reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + + +state 21 + + (15) reference_entry -> reference_entry comment . + (36) comment -> comment . COMMENT + + CONTENT reduce using rule 15 (reference_entry -> reference_entry comment .) + LPARENS reduce using rule 15 (reference_entry -> reference_entry comment .) + COMMENT reduce using rule 15 (reference_entry -> reference_entry comment .) + LCURLY reduce using rule 15 (reference_entry -> reference_entry comment .) + SPECIAL reduce using rule 15 (reference_entry -> reference_entry comment .) + END reduce using rule 15 (reference_entry -> reference_entry comment .) + PROTEIN_ENTRY reduce using rule 15 (reference_entry -> reference_entry comment .) + REFERENCE_ENTRY reduce using rule 15 (reference_entry -> reference_entry comment .) + ENTRY reduce using rule 15 (reference_entry -> reference_entry comment .) + $end reduce using rule 15 (reference_entry -> reference_entry comment .) + + ! COMMENT [ shift and go to state 14 ] + + +state 22 + + (16) reference_entry -> reference_entry special . + (24) special -> special . SPECIAL + + CONTENT reduce using rule 16 (reference_entry -> reference_entry special .) + LPARENS reduce using rule 16 (reference_entry -> reference_entry special .) + COMMENT reduce using rule 16 (reference_entry -> reference_entry special .) + LCURLY reduce using rule 16 (reference_entry -> reference_entry special .) + SPECIAL reduce using rule 16 (reference_entry -> reference_entry special .) + END reduce using rule 16 (reference_entry -> reference_entry special .) + PROTEIN_ENTRY reduce using rule 16 (reference_entry -> reference_entry special .) + REFERENCE_ENTRY reduce using rule 16 (reference_entry -> reference_entry special .) + ENTRY reduce using rule 16 (reference_entry -> reference_entry special .) + $end reduce using rule 16 (reference_entry -> reference_entry special .) + + ! SPECIAL [ shift and go to state 37 ] + + +state 23 + + (22) special -> LCURLY . special RCURLY + (23) special -> LCURLY . RCURLY + (22) special -> . LCURLY special RCURLY + (23) special -> . LCURLY RCURLY + (24) special -> . special SPECIAL + (25) special -> . SPECIAL + + RCURLY shift and go to state 39 + LCURLY shift and go to state 23 + SPECIAL shift and go to state 24 + + special shift and go to state 38 + +state 24 + + (25) special -> SPECIAL . + + SPECIAL reduce using rule 25 (special -> SPECIAL .) + CONTENT reduce using rule 25 (special -> SPECIAL .) + LPARENS reduce using rule 25 (special -> SPECIAL .) + COMMENT reduce using rule 25 (special -> SPECIAL .) + LCURLY reduce using rule 25 (special -> SPECIAL .) + END reduce using rule 25 (special -> SPECIAL .) + PROTEIN_ENTRY reduce using rule 25 (special -> SPECIAL .) + REFERENCE_ENTRY reduce using rule 25 (special -> SPECIAL .) + ENTRY reduce using rule 25 (special -> SPECIAL .) + $end reduce using rule 25 (special -> SPECIAL .) + RCURLY reduce using rule 25 (special -> SPECIAL .) + + +state 25 + + (10) entry -> entry CONTENT . + + CONTENT reduce using rule 10 (entry -> entry CONTENT .) + LPARENS reduce using rule 10 (entry -> entry CONTENT .) + COMMENT reduce using rule 10 (entry -> entry CONTENT .) + END reduce using rule 10 (entry -> entry CONTENT .) + PROTEIN_ENTRY reduce using rule 10 (entry -> entry CONTENT .) + REFERENCE_ENTRY reduce using rule 10 (entry -> entry CONTENT .) + ENTRY reduce using rule 10 (entry -> entry CONTENT .) + $end reduce using rule 10 (entry -> entry CONTENT .) + + +state 26 + + (11) entry -> entry comment . + (36) comment -> comment . COMMENT + + CONTENT reduce using rule 11 (entry -> entry comment .) + LPARENS reduce using rule 11 (entry -> entry comment .) + COMMENT reduce using rule 11 (entry -> entry comment .) + END reduce using rule 11 (entry -> entry comment .) + PROTEIN_ENTRY reduce using rule 11 (entry -> entry comment .) + REFERENCE_ENTRY reduce using rule 11 (entry -> entry comment .) + ENTRY reduce using rule 11 (entry -> entry comment .) + $end reduce using rule 11 (entry -> entry comment .) + + ! COMMENT [ shift and go to state 14 ] + + +state 27 + + (34) comment -> LPARENS comment . RPARENS + (36) comment -> comment . COMMENT + + RPARENS shift and go to state 40 + COMMENT shift and go to state 14 + + +state 28 + + (35) comment -> LPARENS RPARENS . + + COMMENT reduce using rule 35 (comment -> LPARENS RPARENS .) + END reduce using rule 35 (comment -> LPARENS RPARENS .) + LPARENS reduce using rule 35 (comment -> LPARENS RPARENS .) + PROTEIN_ENTRY reduce using rule 35 (comment -> LPARENS RPARENS .) + REFERENCE_ENTRY reduce using rule 35 (comment -> LPARENS RPARENS .) + ENTRY reduce using rule 35 (comment -> LPARENS RPARENS .) + $end reduce using rule 35 (comment -> LPARENS RPARENS .) + CONTENT reduce using rule 35 (comment -> LPARENS RPARENS .) + LCURLY reduce using rule 35 (comment -> LPARENS RPARENS .) + SPECIAL reduce using rule 35 (comment -> LPARENS RPARENS .) + RPARENS reduce using rule 35 (comment -> LPARENS RPARENS .) + + +state 29 + + (17) protein_entry -> PROTEIN_ENTRY new_protein . proteins + (26) proteins -> . POUND proteins POUND + (27) proteins -> . POUND POUND + (28) proteins -> . proteins PROTEIN + (29) proteins -> . PROTEIN + + POUND shift and go to state 42 + PROTEIN shift and go to state 43 + + proteins shift and go to state 41 + +state 30 + + (12) reference_entry -> REFERENCE_ENTRY new_reference . citations + (30) citations -> . LANGLE citations RANGLE + (31) citations -> . LANGLE RANGLE + (32) citations -> . citations CITATION + (33) citations -> . CITATION + + LANGLE shift and go to state 18 + CITATION shift and go to state 19 + + citations shift and go to state 44 + +state 31 + + (8) entry -> ENTRY new_entry . + + CONTENT reduce using rule 8 (entry -> ENTRY new_entry .) + LPARENS reduce using rule 8 (entry -> ENTRY new_entry .) + COMMENT reduce using rule 8 (entry -> ENTRY new_entry .) + END reduce using rule 8 (entry -> ENTRY new_entry .) + PROTEIN_ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) + REFERENCE_ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) + ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) + $end reduce using rule 8 (entry -> ENTRY new_entry .) + + +state 32 + + (1) enzyme -> ENTRY EC_NUMBER new_enzyme . + + END reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) + LPARENS reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) + COMMENT reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) + PROTEIN_ENTRY reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) + REFERENCE_ENTRY reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) + ENTRY reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) + $end reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) + + +state 33 + + (20) protein_entry -> protein_entry ACCESSION CONTENT . + + CONTENT reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + ACCESSION reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + LANGLE reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + CITATION reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + END reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + LPARENS reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + COMMENT reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + PROTEIN_ENTRY reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + REFERENCE_ENTRY reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + ENTRY reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + $end reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + + +state 34 + + (32) citations -> citations CITATION . + + CITATION reduce using rule 32 (citations -> citations CITATION .) + CONTENT reduce using rule 32 (citations -> citations CITATION .) + ACCESSION reduce using rule 32 (citations -> citations CITATION .) + LANGLE reduce using rule 32 (citations -> citations CITATION .) + END reduce using rule 32 (citations -> citations CITATION .) + LPARENS reduce using rule 32 (citations -> citations CITATION .) + COMMENT reduce using rule 32 (citations -> citations CITATION .) + PROTEIN_ENTRY reduce using rule 32 (citations -> citations CITATION .) + REFERENCE_ENTRY reduce using rule 32 (citations -> citations CITATION .) + ENTRY reduce using rule 32 (citations -> citations CITATION .) + $end reduce using rule 32 (citations -> citations CITATION .) + RANGLE reduce using rule 32 (citations -> citations CITATION .) + LCURLY reduce using rule 32 (citations -> citations CITATION .) + SPECIAL reduce using rule 32 (citations -> citations CITATION .) + + +state 35 + + (30) citations -> LANGLE citations . RANGLE + (32) citations -> citations . CITATION + + RANGLE shift and go to state 45 + CITATION shift and go to state 34 + + +state 36 + + (31) citations -> LANGLE RANGLE . + + CITATION reduce using rule 31 (citations -> LANGLE RANGLE .) + CONTENT reduce using rule 31 (citations -> LANGLE RANGLE .) + ACCESSION reduce using rule 31 (citations -> LANGLE RANGLE .) + LANGLE reduce using rule 31 (citations -> LANGLE RANGLE .) + END reduce using rule 31 (citations -> LANGLE RANGLE .) + LPARENS reduce using rule 31 (citations -> LANGLE RANGLE .) + COMMENT reduce using rule 31 (citations -> LANGLE RANGLE .) + PROTEIN_ENTRY reduce using rule 31 (citations -> LANGLE RANGLE .) + REFERENCE_ENTRY reduce using rule 31 (citations -> LANGLE RANGLE .) + ENTRY reduce using rule 31 (citations -> LANGLE RANGLE .) + $end reduce using rule 31 (citations -> LANGLE RANGLE .) + RANGLE reduce using rule 31 (citations -> LANGLE RANGLE .) + LCURLY reduce using rule 31 (citations -> LANGLE RANGLE .) + SPECIAL reduce using rule 31 (citations -> LANGLE RANGLE .) + + +state 37 + + (24) special -> special SPECIAL . + + SPECIAL reduce using rule 24 (special -> special SPECIAL .) + CONTENT reduce using rule 24 (special -> special SPECIAL .) + LPARENS reduce using rule 24 (special -> special SPECIAL .) + COMMENT reduce using rule 24 (special -> special SPECIAL .) + LCURLY reduce using rule 24 (special -> special SPECIAL .) + END reduce using rule 24 (special -> special SPECIAL .) + PROTEIN_ENTRY reduce using rule 24 (special -> special SPECIAL .) + REFERENCE_ENTRY reduce using rule 24 (special -> special SPECIAL .) + ENTRY reduce using rule 24 (special -> special SPECIAL .) + $end reduce using rule 24 (special -> special SPECIAL .) + RCURLY reduce using rule 24 (special -> special SPECIAL .) + + +state 38 + + (22) special -> LCURLY special . RCURLY + (24) special -> special . SPECIAL + + RCURLY shift and go to state 46 + SPECIAL shift and go to state 37 + + +state 39 + + (23) special -> LCURLY RCURLY . + + SPECIAL reduce using rule 23 (special -> LCURLY RCURLY .) + CONTENT reduce using rule 23 (special -> LCURLY RCURLY .) + LPARENS reduce using rule 23 (special -> LCURLY RCURLY .) + COMMENT reduce using rule 23 (special -> LCURLY RCURLY .) + LCURLY reduce using rule 23 (special -> LCURLY RCURLY .) + END reduce using rule 23 (special -> LCURLY RCURLY .) + PROTEIN_ENTRY reduce using rule 23 (special -> LCURLY RCURLY .) + REFERENCE_ENTRY reduce using rule 23 (special -> LCURLY RCURLY .) + ENTRY reduce using rule 23 (special -> LCURLY RCURLY .) + $end reduce using rule 23 (special -> LCURLY RCURLY .) + RCURLY reduce using rule 23 (special -> LCURLY RCURLY .) + + +state 40 + + (34) comment -> LPARENS comment RPARENS . + + COMMENT reduce using rule 34 (comment -> LPARENS comment RPARENS .) + END reduce using rule 34 (comment -> LPARENS comment RPARENS .) + LPARENS reduce using rule 34 (comment -> LPARENS comment RPARENS .) + PROTEIN_ENTRY reduce using rule 34 (comment -> LPARENS comment RPARENS .) + REFERENCE_ENTRY reduce using rule 34 (comment -> LPARENS comment RPARENS .) + ENTRY reduce using rule 34 (comment -> LPARENS comment RPARENS .) + $end reduce using rule 34 (comment -> LPARENS comment RPARENS .) + CONTENT reduce using rule 34 (comment -> LPARENS comment RPARENS .) + LCURLY reduce using rule 34 (comment -> LPARENS comment RPARENS .) + SPECIAL reduce using rule 34 (comment -> LPARENS comment RPARENS .) + RPARENS reduce using rule 34 (comment -> LPARENS comment RPARENS .) + + +state 41 + + (17) protein_entry -> PROTEIN_ENTRY new_protein proteins . + (28) proteins -> proteins . PROTEIN + + CONTENT reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + ACCESSION reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + LANGLE reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + CITATION reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + END reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + LPARENS reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + COMMENT reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + PROTEIN_ENTRY reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + REFERENCE_ENTRY reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + ENTRY reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + $end reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + PROTEIN shift and go to state 47 + + +state 42 + + (26) proteins -> POUND . proteins POUND + (27) proteins -> POUND . POUND + (26) proteins -> . POUND proteins POUND + (27) proteins -> . POUND POUND + (28) proteins -> . proteins PROTEIN + (29) proteins -> . PROTEIN + + POUND shift and go to state 48 + PROTEIN shift and go to state 43 + + proteins shift and go to state 49 + +state 43 + + (29) proteins -> PROTEIN . + + PROTEIN reduce using rule 29 (proteins -> PROTEIN .) + CONTENT reduce using rule 29 (proteins -> PROTEIN .) + ACCESSION reduce using rule 29 (proteins -> PROTEIN .) + LANGLE reduce using rule 29 (proteins -> PROTEIN .) + CITATION reduce using rule 29 (proteins -> PROTEIN .) + END reduce using rule 29 (proteins -> PROTEIN .) + LPARENS reduce using rule 29 (proteins -> PROTEIN .) + COMMENT reduce using rule 29 (proteins -> PROTEIN .) + PROTEIN_ENTRY reduce using rule 29 (proteins -> PROTEIN .) + REFERENCE_ENTRY reduce using rule 29 (proteins -> PROTEIN .) + ENTRY reduce using rule 29 (proteins -> PROTEIN .) + $end reduce using rule 29 (proteins -> PROTEIN .) + POUND reduce using rule 29 (proteins -> PROTEIN .) + + +state 44 + + (12) reference_entry -> REFERENCE_ENTRY new_reference citations . + (32) citations -> citations . CITATION + + CONTENT reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + LPARENS reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + COMMENT reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + LCURLY reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + SPECIAL reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + END reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + PROTEIN_ENTRY reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + REFERENCE_ENTRY reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + ENTRY reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + $end reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + CITATION shift and go to state 34 + + +state 45 + + (30) citations -> LANGLE citations RANGLE . + + CITATION reduce using rule 30 (citations -> LANGLE citations RANGLE .) + CONTENT reduce using rule 30 (citations -> LANGLE citations RANGLE .) + ACCESSION reduce using rule 30 (citations -> LANGLE citations RANGLE .) + LANGLE reduce using rule 30 (citations -> LANGLE citations RANGLE .) + END reduce using rule 30 (citations -> LANGLE citations RANGLE .) + LPARENS reduce using rule 30 (citations -> LANGLE citations RANGLE .) + COMMENT reduce using rule 30 (citations -> LANGLE citations RANGLE .) + PROTEIN_ENTRY reduce using rule 30 (citations -> LANGLE citations RANGLE .) + REFERENCE_ENTRY reduce using rule 30 (citations -> LANGLE citations RANGLE .) + ENTRY reduce using rule 30 (citations -> LANGLE citations RANGLE .) + $end reduce using rule 30 (citations -> LANGLE citations RANGLE .) + RANGLE reduce using rule 30 (citations -> LANGLE citations RANGLE .) + LCURLY reduce using rule 30 (citations -> LANGLE citations RANGLE .) + SPECIAL reduce using rule 30 (citations -> LANGLE citations RANGLE .) + + +state 46 + + (22) special -> LCURLY special RCURLY . + + SPECIAL reduce using rule 22 (special -> LCURLY special RCURLY .) + CONTENT reduce using rule 22 (special -> LCURLY special RCURLY .) + LPARENS reduce using rule 22 (special -> LCURLY special RCURLY .) + COMMENT reduce using rule 22 (special -> LCURLY special RCURLY .) + LCURLY reduce using rule 22 (special -> LCURLY special RCURLY .) + END reduce using rule 22 (special -> LCURLY special RCURLY .) + PROTEIN_ENTRY reduce using rule 22 (special -> LCURLY special RCURLY .) + REFERENCE_ENTRY reduce using rule 22 (special -> LCURLY special RCURLY .) + ENTRY reduce using rule 22 (special -> LCURLY special RCURLY .) + $end reduce using rule 22 (special -> LCURLY special RCURLY .) + RCURLY reduce using rule 22 (special -> LCURLY special RCURLY .) + + +state 47 + + (28) proteins -> proteins PROTEIN . + + PROTEIN reduce using rule 28 (proteins -> proteins PROTEIN .) + CONTENT reduce using rule 28 (proteins -> proteins PROTEIN .) + ACCESSION reduce using rule 28 (proteins -> proteins PROTEIN .) + LANGLE reduce using rule 28 (proteins -> proteins PROTEIN .) + CITATION reduce using rule 28 (proteins -> proteins PROTEIN .) + END reduce using rule 28 (proteins -> proteins PROTEIN .) + LPARENS reduce using rule 28 (proteins -> proteins PROTEIN .) + COMMENT reduce using rule 28 (proteins -> proteins PROTEIN .) + PROTEIN_ENTRY reduce using rule 28 (proteins -> proteins PROTEIN .) + REFERENCE_ENTRY reduce using rule 28 (proteins -> proteins PROTEIN .) + ENTRY reduce using rule 28 (proteins -> proteins PROTEIN .) + $end reduce using rule 28 (proteins -> proteins PROTEIN .) + POUND reduce using rule 28 (proteins -> proteins PROTEIN .) + + +state 48 + + (27) proteins -> POUND POUND . + (26) proteins -> POUND . proteins POUND + (27) proteins -> POUND . POUND + (26) proteins -> . POUND proteins POUND + (27) proteins -> . POUND POUND + (28) proteins -> . proteins PROTEIN + (29) proteins -> . PROTEIN + + ! shift/reduce conflict for POUND resolved as shift + ! shift/reduce conflict for PROTEIN resolved as shift + CONTENT reduce using rule 27 (proteins -> POUND POUND .) + ACCESSION reduce using rule 27 (proteins -> POUND POUND .) + LANGLE reduce using rule 27 (proteins -> POUND POUND .) + CITATION reduce using rule 27 (proteins -> POUND POUND .) + END reduce using rule 27 (proteins -> POUND POUND .) + LPARENS reduce using rule 27 (proteins -> POUND POUND .) + COMMENT reduce using rule 27 (proteins -> POUND POUND .) + PROTEIN_ENTRY reduce using rule 27 (proteins -> POUND POUND .) + REFERENCE_ENTRY reduce using rule 27 (proteins -> POUND POUND .) + ENTRY reduce using rule 27 (proteins -> POUND POUND .) + $end reduce using rule 27 (proteins -> POUND POUND .) + POUND shift and go to state 48 + PROTEIN shift and go to state 43 + + ! PROTEIN [ reduce using rule 27 (proteins -> POUND POUND .) ] + ! POUND [ reduce using rule 27 (proteins -> POUND POUND .) ] + + proteins shift and go to state 49 + +state 49 + + (26) proteins -> POUND proteins . POUND + (28) proteins -> proteins . PROTEIN + + POUND shift and go to state 50 + PROTEIN shift and go to state 47 + + +state 50 + + (26) proteins -> POUND proteins POUND . + + PROTEIN reduce using rule 26 (proteins -> POUND proteins POUND .) + CONTENT reduce using rule 26 (proteins -> POUND proteins POUND .) + ACCESSION reduce using rule 26 (proteins -> POUND proteins POUND .) + LANGLE reduce using rule 26 (proteins -> POUND proteins POUND .) + CITATION reduce using rule 26 (proteins -> POUND proteins POUND .) + END reduce using rule 26 (proteins -> POUND proteins POUND .) + LPARENS reduce using rule 26 (proteins -> POUND proteins POUND .) + COMMENT reduce using rule 26 (proteins -> POUND proteins POUND .) + PROTEIN_ENTRY reduce using rule 26 (proteins -> POUND proteins POUND .) + REFERENCE_ENTRY reduce using rule 26 (proteins -> POUND proteins POUND .) + ENTRY reduce using rule 26 (proteins -> POUND proteins POUND .) + $end reduce using rule 26 (proteins -> POUND proteins POUND .) + POUND reduce using rule 26 (proteins -> POUND proteins POUND .) + +WARNING: +WARNING: Conflicts: +WARNING: +WARNING: shift/reduce conflict for POUND in state 48 resolved as shift +WARNING: shift/reduce conflict for PROTEIN in state 48 resolved as shift diff --git a/src/brenda_parser/parsing/parser.py b/src/brenda_parser/parsing/parser.py new file mode 100644 index 0000000..4bc1349 --- /dev/null +++ b/src/brenda_parser/parsing/parser.py @@ -0,0 +1,384 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2011 Jacobs University Bremen gGmbH +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Parse BRENDA tokens using the provided grammar.""" + +from __future__ import absolute_import + +import logging + +from ply.yacc import yacc + +import brenda_parser.models as models +from brenda_parser.exceptions import ValidationError +from brenda_parser.parsing.lexer import BRENDALexer + +__all__ = ("BRENDAParser",) + +LOGGER = logging.getLogger(__name__) + + +class BRENDAParser(object): + """ + Parse the BRENDA flat file into database models. + + Implement the following rules using the tokens generated by an + appropriate lexer. + :: + enzyme : ID EC_NUMBER comment + | END + + entry : ENTRY protein TEXT comment citation special + | ENTRY protein TEXT comment + | ENTRY protein TEXT + + protein_entry : PROTEIN_ENTRY new_protein protein_entry + | protein_entry protein_entry + | protein_entry ACCESSION CONTENT + | proteins + + comment : LPARENS comment RPARENS + | LPARENS RPARENS + | comment comment + | CONTENT + + special : LCURLY special RCURLY + | LCURLY RCURLY + | special special + | CONTENT + + proteins : POUND proteins POUND + | POUND POUND + | proteins proteins + | PROTEIN + + citations : LANGLE citations RANGLE + | LANGLE RANGLE + | citations citations + | CITATION + + """ + + precedence = ( + ("left", "ENZYME"), + ("left", "ASSEMBLE"), + ("left", "REDUCE"), + ("left", "COMBINE") + ) + + def __init__(self, lexer=None, **kw_args): + """ + Instantiate a BRENDA parser. + + Parameters + ---------- + lexer : ply.lex (optional) + Any ply.lex lexer instance that generates the tokens listed in the + rules. The default uses a BRENDALexer instance. + kw_args : + Keyword arguments are passed to the ply.yacc.yacc call. + """ + super(BRENDAParser, self).__init__() + self._lexer = BRENDALexer() if lexer is None else lexer + self.tokens = self._lexer.tokens + self.parser = yacc(module=self, errorlog=LOGGER, **kw_args) + self._session = None + self.proteins = dict() + self.citations = dict() + self._current_entry = None + + def parse(self, section, session, **kw_args): + """ + Parse an entire enzyme section according to the rules. + + The parser fills a database ``Enzyme`` model with information and + returns it. + + Parameters + ---------- + section : str + A BRENDA enzyme section starting from 'ID x.x.x.x' until '///'. + session : sqlalchemy.Session + A running session for querying database connections. + kw_args : + Keyword arguments are passed on to the ply.yacc.yacc.parse call. + + """ + self._session = session + self.proteins.clear() + self.citations.clear() + self._current_entry = None + return self.parser.parse(section, lexer=self._lexer, **kw_args) + + def p_enzyme(self, p): + """enzyme : ENTRY EC_NUMBER new_enzyme""" + LOGGER.debug("%s: %s", self.p_enzyme.__doc__, p[3].ec_number) + p[0] = p[3] + + def p_new_enzyme(self, p): + """new_enzyme :""" + LOGGER.debug("%s: %s", self.p_new_enzyme.__doc__, p[-1]) + assert p[-2] == "ID" + p[0] = models.Enzyme(ec_number=p[-1]) + + def p_enzyme_comment(self, p): + """enzyme : enzyme comment %prec ENZYME""" + LOGGER.debug("%s: %s", self.p_enzyme_comment.__doc__, p[1].ec_number) + if p[2] is not None: + p[1].comments.append(p[2]) + p[0] = p[1] + + def p_enzyme_protein(self, p): + """enzyme : enzyme protein_entry %prec ENZYME""" + LOGGER.debug("%s: %s", self.p_enzyme_protein.__doc__, p[1].ec_number) + p[1].proteins.append(p[2]) + p[0] = p[1] + + def p_enzyme_reference(self, p): + """enzyme : enzyme reference_entry %prec ENZYME""" + LOGGER.debug("%s: %s", self.p_enzyme_reference.__doc__, p[1].ec_number) + p[1].references.append(p[2]) + p[0] = p[1] + + def p_enzyme_entry(self, p): + """enzyme : enzyme entry %prec ENZYME""" + LOGGER.debug("%s: %s", self.p_enzyme_entry.__doc__, p[1].ec_number) + # TODO: In future, add to specific children based on acronym. + p[1].entries.append(p[2]) + p[0] = p[1] + + def p_enzyme_end(self, p): + """enzyme : enzyme END""" + LOGGER.debug("%s: %s", self.p_enzyme_end.__doc__, p[1].ec_number) + # TODO: Finalize protein and citation references. + p[0] = p[1] + + def p_entry(self, p): + """entry : ENTRY new_entry""" + LOGGER.debug("%s: %s", self.p_entry.__doc__, p[1]) + assert p[1] == p[2].field.acronym + p[0] = p[2] + + def p_new_entry(self, p): + """new_entry :""" + LOGGER.debug("%s: %s", self.p_new_entry.__doc__, p[-1]) + field = self._session.query(models.InformationField) \ + .filter_by(acronym=p[-1]) \ + .one() + p[0] = models.FieldEntry(field=field, body="") + + def p_entry_content(self, p): + """entry : entry CONTENT""" + LOGGER.debug("%s: %s", self.p_entry_content.__doc__, p[1].field.acronym) + assert len(p[2]) > 0 + p[1].body += " {}".format(p[2]) + p[0] = p[1] + + def p_entry_comment(self, p): + """entry : entry comment %prec ASSEMBLE""" + LOGGER.debug("%s: %s", self.p_entry_comment.__doc__, p[1].field.acronym) + if p[2] is not None: + p[1].comment_references.append(p[2]) + p[0] = p[1] + + def p_reference_entry(self, p): + """reference_entry : REFERENCE_ENTRY new_reference citations""" + LOGGER.debug("%s: %s", self.p_reference_entry.__doc__, + p[2].field.acronym) + assert len(p[3]) == 1 # Reference entry only has its own number. + self.citations[p[3][0]] = p[2] + p[0] = p[2] + + def p_new_reference(self, p): + """new_reference :""" + LOGGER.debug("%s: %s", self.p_new_reference.__doc__, p[-1]) + assert p[-1] == "RF" + field = self._session.query(models.InformationField) \ + .filter_by(acronym=p[-1]) \ + .one() + p[0] = models.Reference(field=field, body="") + + def p_reference_content(self, p): + """reference_entry : reference_entry CONTENT""" + LOGGER.debug("%s: %s", self.p_reference_content.__doc__, + p[1].field.acronym) + assert len(p[2]) > 0 + p[1].body += " {}".format(p[2]) + p[0] = p[1] + + def p_reference_year(self, p): + """reference_entry : reference_entry comment %prec ASSEMBLE""" + LOGGER.debug("%s: %s", self.p_reference_year.__doc__, + p[1].field.acronym) + if p[2] is not None: + p[1].body += " ({})".format(p[2]) + p[0] = p[1] + + def p_reference_pubmed(self, p): + """reference_entry : reference_entry special %prec ASSEMBLE""" + LOGGER.debug("%s: %s", self.p_reference_pubmed.__doc__, + p[1].field.acronym) + try: + p[1].pubmed = p[2] + except ValidationError: + pass + p[0] = p[1] + + def p_protein_entry(self, p): + """protein_entry : PROTEIN_ENTRY new_protein proteins""" + LOGGER.debug("%s: %s", self.p_protein_entry.__doc__, p[1]) + assert len(p[3]) == 1 # Protein entry only has its own number. + self.proteins[p[3][0]] = p[2] + p[0] = p[2] + + def p_new_protein(self, p): + """new_protein :""" + LOGGER.debug("%s: %s", self.p_new_protein.__doc__, p[-1]) + assert p[-1] == "PR" + field = self._session.query(models.InformationField) \ + .filter_by(acronym=p[-1]) \ + .one() + p[0] = models.Protein(field=field) + + def p_protein_organism(self, p): + """protein_entry : protein_entry CONTENT""" + LOGGER.debug("%s: %s", self.p_protein_organism.__doc__, + p[1].field.acronym) + assert len(p[2]) > 0 + # TODO: Find or create the organism. + p[1].organism_name += p[2] + p[0] = p[1] + + def p_protein_accession(self, p): + """protein_entry : protein_entry ACCESSION CONTENT""" + LOGGER.debug("%s: %s", self.p_protein_accession.__doc__, + p[1].field.acronym) + # Might have to be split into its own rule if ACCESSION occurs without + # database (CONTENT). + p[1].accession = p[2] + p[1].database = p[3] + p[0] = p[1] + + def p_protein_citations(self, p): + """protein_entry : protein_entry citations %prec ASSEMBLE""" + LOGGER.debug("%s: %s", self.p_protein_citations.__doc__, + p[1].field.acronym) + if p[2] is not None: + p[1].citation_references.extend(p[2]) + p[0] = p[1] + + def p_special(self, p): + """special : LCURLY special RCURLY""" + LOGGER.debug("%s", self.p_special.__doc__) + p[0] = p[2] + + def p_special_empty(self, p): + """special : LCURLY RCURLY""" + LOGGER.debug("%s", self.p_special_empty.__doc__) + pass + + def p_special_combine(self, p): + """special : special SPECIAL %prec COMBINE""" + LOGGER.debug("%s", self.p_special_combine.__doc__) + p[0] = "{0} {1}".format(p[1], p[2]) + + def p_special_end(self, p): + """special : SPECIAL %prec REDUCE""" + LOGGER.debug("%s", self.p_special_end.__doc__) + p[0] = p[1].strip() + + def p_proteins(self, p): + """proteins : POUND proteins POUND""" + LOGGER.debug("%s", self.p_proteins.__doc__) + p[0] = p[2] + + def p_proteins_empty(self, p): + """proteins : POUND POUND """ + LOGGER.debug("%s", self.p_proteins_empty.__doc__) + pass + + def p_proteins_combine(self, p): + """proteins : proteins PROTEIN %prec COMBINE""" + LOGGER.debug("%s", self.p_proteins_combine.__doc__) + p[1].append(p[2]) + p[0] = p[1] + + def p_proteins_end(self, p): + """proteins : PROTEIN %prec REDUCE""" + LOGGER.debug("%s", self.p_proteins_end.__doc__) + p[0] = [p[1]] + + def p_citations(self, p): + """citations : LANGLE citations RANGLE""" + LOGGER.debug("%s", self.p_citations.__doc__) + p[0] = p[2] + + def p_citations_empty(self, p): + """citations : LANGLE RANGLE """ + LOGGER.debug("%s", self.p_citations_empty.__doc__) + pass + + def p_citations_combine(self, p): + """citations : citations CITATION %prec COMBINE""" + LOGGER.debug("%s", self.p_citations_combine.__doc__) + p[1].append(p[2]) + p[0] = p[1] + + def p_citations_end(self, p): + """citations : CITATION %prec REDUCE""" + LOGGER.debug("%s", self.p_citations_end.__doc__) + p[0] = [p[1]] + + def p_comment(self, p): + """comment : LPARENS comment RPARENS""" + LOGGER.debug("%s", self.p_comment.__doc__) + p[0] = p[2] + + def p_comment_empty(self, p): + """comment : LPARENS RPARENS""" + LOGGER.debug("%s", self.p_comment_empty.__doc__) + pass + + def p_comment_combine(self, p): + """comment : comment COMMENT %prec COMBINE""" + LOGGER.debug("%s", self.p_comment_combine.__doc__) + p[0] = "{0} {1}".format(p[1], p[2]) + + def p_comment_end(self, p): + """comment : COMMENT %prec REDUCE""" + LOGGER.debug("%s", self.p_comment_end.__doc__) + p[0] = p[1] + + def p_error(self, p): + LOGGER.debug("error: %s", str(p)) + # TODO: If `p` is None (we allow some empty rules) it's only an error + # if any parentheses or similar are unbalanced. + if False: + raise SyntaxError(str(p)) diff --git a/src/brenda_parser/parsing/parsetab.py b/src/brenda_parser/parsing/parsetab.py new file mode 100644 index 0000000..fa23024 --- /dev/null +++ b/src/brenda_parser/parsing/parsetab.py @@ -0,0 +1,66 @@ + +# parsetab.py +# This file is automatically generated. Do not edit. +_tabversion = '3.10' + +_lr_method = 'LALR' + +_lr_signature = 'leftENZYMEleftASSEMBLEleftREDUCEleftCOMBINEPROTEIN CITATION ENTRY PROTEIN_ENTRY REFERENCE_ENTRY POUND LPARENS RPARENS LANGLE RANGLE LCURLY RCURLY EC_NUMBER END CONTENT SPECIAL COMMENT ACCESSIONenzyme : ENTRY EC_NUMBER new_enzymenew_enzyme :enzyme : enzyme comment %prec ENZYMEenzyme : enzyme protein_entry %prec ENZYMEenzyme : enzyme reference_entry %prec ENZYMEenzyme : enzyme entry %prec ENZYMEenzyme : enzyme ENDentry : ENTRY new_entrynew_entry :entry : entry CONTENTentry : entry comment %prec ASSEMBLEreference_entry : REFERENCE_ENTRY new_reference citationsnew_reference :reference_entry : reference_entry CONTENTreference_entry : reference_entry comment %prec ASSEMBLEreference_entry : reference_entry special %prec ASSEMBLEprotein_entry : PROTEIN_ENTRY new_protein proteinsnew_protein :protein_entry : protein_entry CONTENTprotein_entry : protein_entry ACCESSION CONTENTprotein_entry : protein_entry citations %prec ASSEMBLEspecial : LCURLY special RCURLYspecial : LCURLY RCURLYspecial : special SPECIAL %prec COMBINEspecial : SPECIAL %prec REDUCEproteins : POUND proteins POUNDproteins : POUND POUND proteins : proteins PROTEIN %prec COMBINEproteins : PROTEIN %prec REDUCEcitations : LANGLE citations RANGLEcitations : LANGLE RANGLE citations : citations CITATION %prec COMBINEcitations : CITATION %prec REDUCEcomment : LPARENS comment RPARENS %prec REDUCEcomment : LPARENS RPARENS %prec REDUCEcomment : comment COMMENT %prec COMBINEcomment : COMMENT %prec REDUCE' + +_lr_action_items = {'ENTRY':([0,1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[2,12,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'$end':([1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[0,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'END':([1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[7,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'LPARENS':([1,3,4,5,6,7,8,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[8,-3,-4,-5,-6,-7,8,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'COMMENT':([1,3,4,5,6,7,8,9,12,13,14,15,17,19,20,21,22,24,25,26,27,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[9,-3,-4,-5,-6,-7,9,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,14,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'PROTEIN_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[10,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'REFERENCE_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[11,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'EC_NUMBER':([2,],[13,]),'CONTENT':([4,5,6,9,12,14,15,16,17,19,20,21,22,24,25,26,28,31,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[15,20,25,-37,-9,-36,-19,33,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'ACCESSION':([4,15,17,19,33,34,36,41,43,45,47,48,50,],[16,-19,-21,-33,-20,-32,-31,-17,-29,-30,-28,-27,-26,]),'LANGLE':([4,11,15,17,18,19,30,33,34,36,41,43,45,47,48,50,],[18,-13,-19,-21,18,-33,18,-20,-32,-31,-17,-29,-30,-28,-27,-26,]),'CITATION':([4,11,15,17,18,19,30,33,34,35,36,41,43,44,45,47,48,50,],[19,-13,-19,-21,19,-33,19,-20,-32,34,-31,-17,-29,34,-30,-28,-27,-26,]),'LCURLY':([5,9,14,19,20,21,22,23,24,28,34,36,37,39,40,44,45,46,],[23,-37,-36,-33,-14,-15,-16,23,-25,-35,-32,-31,-24,-23,-34,-12,-30,-22,]),'SPECIAL':([5,9,14,19,20,21,22,23,24,28,34,36,37,38,39,40,44,45,46,],[24,-37,-36,-33,-14,-15,-16,24,-25,-35,-32,-31,-24,37,-23,-34,-12,-30,-22,]),'RPARENS':([8,9,14,27,28,40,],[28,-37,-36,40,-35,-34,]),'POUND':([10,29,42,43,47,48,49,50,],[-18,42,48,-29,-28,48,50,-26,]),'PROTEIN':([10,29,41,42,43,47,48,49,50,],[-18,43,47,43,-29,-28,43,47,-26,]),'RANGLE':([18,19,34,35,36,45,],[36,-33,-32,45,-31,-30,]),'RCURLY':([23,24,37,38,39,46,],[39,-25,-24,46,-23,-22,]),} + +_lr_action = {} +for _k, _v in _lr_action_items.items(): + for _x,_y in zip(_v[0],_v[1]): + if not _x in _lr_action: _lr_action[_x] = {} + _lr_action[_x][_k] = _y +del _lr_action_items + +_lr_goto_items = {'enzyme':([0,],[1,]),'comment':([1,5,6,8,],[3,21,26,27,]),'protein_entry':([1,],[4,]),'reference_entry':([1,],[5,]),'entry':([1,],[6,]),'citations':([4,18,30,],[17,35,44,]),'special':([5,23,],[22,38,]),'new_protein':([10,],[29,]),'new_reference':([11,],[30,]),'new_entry':([12,],[31,]),'new_enzyme':([13,],[32,]),'proteins':([29,42,48,],[41,49,49,]),} + +_lr_goto = {} +for _k, _v in _lr_goto_items.items(): + for _x, _y in zip(_v[0], _v[1]): + if not _x in _lr_goto: _lr_goto[_x] = {} + _lr_goto[_x][_k] = _y +del _lr_goto_items +_lr_productions = [ + ("S' -> enzyme","S'",1,None,None,None), + ('enzyme -> ENTRY EC_NUMBER new_enzyme','enzyme',3,'p_enzyme','parser.py',141), + ('new_enzyme -> ','new_enzyme',0,'p_new_enzyme','parser.py',146), + ('enzyme -> enzyme comment','enzyme',2,'p_enzyme_comment','parser.py',152), + ('enzyme -> enzyme protein_entry','enzyme',2,'p_enzyme_protein','parser.py',159), + ('enzyme -> enzyme reference_entry','enzyme',2,'p_enzyme_reference','parser.py',165), + ('enzyme -> enzyme entry','enzyme',2,'p_enzyme_entry','parser.py',171), + ('enzyme -> enzyme END','enzyme',2,'p_enzyme_end','parser.py',178), + ('entry -> ENTRY new_entry','entry',2,'p_entry','parser.py',184), + ('new_entry -> ','new_entry',0,'p_new_entry','parser.py',190), + ('entry -> entry CONTENT','entry',2,'p_entry_content','parser.py',198), + ('entry -> entry comment','entry',2,'p_entry_comment','parser.py',205), + ('reference_entry -> REFERENCE_ENTRY new_reference citations','reference_entry',3,'p_reference_entry','parser.py',212), + ('new_reference -> ','new_reference',0,'p_new_reference','parser.py',220), + ('reference_entry -> reference_entry CONTENT','reference_entry',2,'p_reference_content','parser.py',229), + ('reference_entry -> reference_entry comment','reference_entry',2,'p_reference_year','parser.py',237), + ('reference_entry -> reference_entry special','reference_entry',2,'p_reference_pubmed','parser.py',245), + ('protein_entry -> PROTEIN_ENTRY new_protein proteins','protein_entry',3,'p_protein_entry','parser.py',255), + ('new_protein -> ','new_protein',0,'p_new_protein','parser.py',262), + ('protein_entry -> protein_entry CONTENT','protein_entry',2,'p_protein_organism','parser.py',271), + ('protein_entry -> protein_entry ACCESSION CONTENT','protein_entry',3,'p_protein_accession','parser.py',280), + ('protein_entry -> protein_entry citations','protein_entry',2,'p_protein_citations','parser.py',290), + ('special -> LCURLY special RCURLY','special',3,'p_special','parser.py',298), + ('special -> LCURLY RCURLY','special',2,'p_special_empty','parser.py',303), + ('special -> special SPECIAL','special',2,'p_special_combine','parser.py',308), + ('special -> SPECIAL','special',1,'p_special_end','parser.py',313), + ('proteins -> POUND proteins POUND','proteins',3,'p_proteins','parser.py',318), + ('proteins -> POUND POUND','proteins',2,'p_proteins_empty','parser.py',323), + ('proteins -> proteins PROTEIN','proteins',2,'p_proteins_combine','parser.py',328), + ('proteins -> PROTEIN','proteins',1,'p_proteins_end','parser.py',334), + ('citations -> LANGLE citations RANGLE','citations',3,'p_citations','parser.py',339), + ('citations -> LANGLE RANGLE','citations',2,'p_citations_empty','parser.py',344), + ('citations -> citations CITATION','citations',2,'p_citations_combine','parser.py',349), + ('citations -> CITATION','citations',1,'p_citations_end','parser.py',355), + ('comment -> LPARENS comment RPARENS','comment',3,'p_comment','parser.py',360), + ('comment -> LPARENS RPARENS','comment',2,'p_comment_empty','parser.py',365), + ('comment -> comment COMMENT','comment',2,'p_comment_combine','parser.py',370), + ('comment -> COMMENT','comment',1,'p_comment_end','parser.py',375), +] diff --git a/test_requirements.txt b/test_requirements.txt new file mode 100644 index 0000000..c86521f --- /dev/null +++ b/test_requirements.txt @@ -0,0 +1,5 @@ +pytest>=3.1 +pytest-mock +pytest-raises +pytest-cov +codecov diff --git a/tests/test_brenda_parser.py b/tests/test_brenda_parser.py new file mode 100644 index 0000000..961fce7 --- /dev/null +++ b/tests/test_brenda_parser.py @@ -0,0 +1,12 @@ + +# from click.testing import CliRunner + +# from brenda_parser.cli import main + + +# def test_main(): +# runner = CliRunner() +# result = runner.invoke(main, []) + + # assert result.output == '()\n' + # assert result.exit_code == 0 diff --git a/tests/test_models/conftest.py b/tests/test_models/conftest.py new file mode 100644 index 0000000..8b0b773 --- /dev/null +++ b/tests/test_models/conftest.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + +import pytest +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker + +from brenda_parser.models import Base + +Session = sessionmaker() + + +@pytest.fixture(scope="session") +def connection(): + """ + Use a connection such transactions can be used. + + Notes + ----- + Follows a transaction pattern described in the following: + http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#session-begin-nested + """ + engine = create_engine("sqlite:///:memory:") + Base.metadata.create_all(engine) + connection = engine.connect() + yield connection + connection.close() + + +@pytest.fixture(scope="function") +def session(connection): + """ + Create a transaction and session per test unit. + + Rolling back a transaction removes even committed rows + (``session.commit``) from the database. + """ + transaction = connection.begin() + session = Session(bind=connection) + yield session + session.close() + transaction.rollback() + + diff --git a/tests/test_models/test_information_field.py b/tests/test_models/test_information_field.py new file mode 100644 index 0000000..9c44107 --- /dev/null +++ b/tests/test_models/test_information_field.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + +import pytest +from six import iteritems +from sqlalchemy.exc import IntegrityError + +from brenda_parser.exceptions import ValidationError +from brenda_parser.models import InformationField + + +@pytest.mark.parametrize("attributes", [ + pytest.mark.raises({"acronym": ""}, exception=ValidationError), + pytest.mark.raises({"acronym": "I"}, exception=ValidationError), + pytest.mark.raises({"acronym": "on"}, exception=ValidationError), + {"acronym": "RN"}, + {"acronym": "REF"}, + {"acronym": "IC50"}, + pytest.mark.raises({"acronym": "too long"}, exception=ValidationError), + {"acronym": "SM", "name": "Super Man"}, + # pytest.mark.raises({"acronym": "SM", "name": "an" * 51}, + # exception=IntegrityError) +]) +def test_create_information_field(session, attributes): + obj = InformationField(**attributes) + session.add(obj) + session.commit() + for attr, value in iteritems(attributes): + assert getattr(obj, attr) == value diff --git a/tests/test_models/test_organism.py b/tests/test_models/test_organism.py new file mode 100644 index 0000000..64bf9bf --- /dev/null +++ b/tests/test_models/test_organism.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + +import pytest +from six import iteritems +from sqlalchemy.exc import IntegrityError + +from brenda_parser.models import Organism + + +@pytest.mark.parametrize("attributes", [ + pytest.mark.raises({"name": None}, exception=IntegrityError), + {"name": ""}, + {"name": "Homo sapiens"} +]) +def test_create_organism(session, attributes): + obj = Organism(**attributes) + session.add(obj) + session.commit() + for attr, value in iteritems(attributes): + assert getattr(obj, attr) == value + + +@pytest.mark.parametrize("name_a, name_b", [ + pytest.mark.raises(("same", "same"), exception=IntegrityError), + ("way", "different") +]) +def test_unique_name(session, name_a, name_b): + obj_a = Organism(name=name_a) + obj_b = Organism(name=name_b) + session.add_all([obj_a, obj_b]) + session.commit() diff --git a/tests/test_models/test_protein.py b/tests/test_models/test_protein.py new file mode 100644 index 0000000..45e5064 --- /dev/null +++ b/tests/test_models/test_protein.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + +import pytest +from six import iteritems +from sqlalchemy.exc import IntegrityError + +from brenda_parser.exceptions import ValidationError +import brenda_parser.models as models + + +def test_create_protein(session): + org = models.Organism(name="S. glucosis") + # ref = models.Reference(citation="Starchman et al.") + field = models.InformationField(acronym="PR") + obj = models.Protein(field=field, organism=org) + session.add(obj) + session.commit() diff --git a/tests/test_models/test_reference.py b/tests/test_models/test_reference.py new file mode 100644 index 0000000..bbf0bce --- /dev/null +++ b/tests/test_models/test_reference.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + +import pytest +from six import iteritems +from sqlalchemy.exc import IntegrityError + +from brenda_parser.exceptions import ValidationError +from brenda_parser.models import Reference + + +@pytest.mark.parametrize("attributes", [ + pytest.mark.raises({"body": None}, exception=IntegrityError), + {"body": "Cunning et al."}, + pytest.mark.raises({"body": "Evil Inc.", "pubmed": "fail"}, + exception=ValidationError), + {"body": "Vitello et al.", "pubmed": "Pubmed:1234567"} +]) +def test_create_reference(session, attributes): + obj = Reference(**attributes) + session.add(obj) + session.commit() + for attr, value in iteritems(attributes): + assert getattr(obj, attr) == value + + +@pytest.mark.parametrize("ref_a, ref_b", [ + pytest.mark.raises( + ({"body": "Vitello et al.", "pubmed": "Pubmed:1234567"}, + {"body": "The Others", "pubmed": "Pubmed:1234567"}), + exception=IntegrityError), + ({"body": "Batman", "pubmed": "Pubmed:1111111"}, + {"body": "Robin", "pubmed": "Pubmed:2222222"}) +]) +def test_unique_name(session, ref_a, ref_b): + obj_a = Reference(**ref_a) + obj_b = Reference(**ref_b) + session.add_all([obj_a, obj_b]) + session.commit() diff --git a/tests/test_parsing/data/small_section.txt b/tests/test_parsing/data/small_section.txt new file mode 100644 index 0000000..16e3352 --- /dev/null +++ b/tests/test_parsing/data/small_section.txt @@ -0,0 +1,157 @@ +ID 6.6.1.2 +******************************************************************************** +* * +* Copyrighted by Dietmar Schomburg, Techn. University Braunschweig, GERMANY * +* Distributed under the License as stated at http:/www.brenda-enzymes.org * +* * +******************************************************************************** + +PROTEIN +PR #1# Pseudomonas denitrificans (nomen rejiciendum) <1> +PR #2# Salmonella enterica <4> +PR #3# Desulfovibrio vulgaris <4> +PR #4# Brucella melitensis <3> +PR #5# Pseudomonas denitrificans (nomen rejiciendum) P29933 AND P29934 AND + Q9HZQ3 AND P29929 + <2> + +RECOMMENDED_NAME +RN cobaltochelatase + + +SYSTEMATIC_NAME +SN hydrogenobyrinic-acid-a,c-diamide:cobalt cobalt-ligase (ADP-forming) + + +SYNONYMS +SY CobN–CobST +SY #2,3# CbiK <4> +SY #4,5# cobaltochelatase <2,3> +SY #5# hydrogenobyrinic acid a,c-diamide cobaltochelatase <2> +SY #5# CobNST <2> +SY #5# cobalt chelatase <2> +SY #5# CobN-CobST <2> +SY #5# gene cobN/gene cobS cobaltochelatase <2> +SY #5# holocobalamin synthase <2> + +REACTION +RE ATP + hydrogenobyrinic acid a,c-diamide + Co2+ + H2O = ADP + phosphate + + cob(II)yrinic acid a,c-diamide + H+ + +LOCALIZATION +LO #2,3# periplasm <4> + +NATURAL_SUBSTRATE_PRODUCT +NSP #1,4# ATP + hydrogenobyrinic acid a,c-diamide + Co2+ = ADP + phosphate + + cob(II)yrinic acid a,c-diamide + H+ <1,3> +NSP #1,4# ATP + hydrogenobyrinic acid a,c-diamide + Co2+ = ADP + phosphate + + cob(II)yrinic acid a,c-diamide + H+ {ir} <1,3> +NSP #5# hydrogenobyrinic acid a,c-diamide + ATP + Co2+ = ADP + phosphate + + cob(II)yrinic acid a,c-diamide + H+ <2> + +SUBSTRATE_PRODUCT +SP #1,4,5# ATP + hydrogenobyrinic acid a,c-diamide + Co2+ = ADP + + phosphate + cob(II)yrinic acid a,c-diamide + H+ <1,2,3> +SP #1,4,5# ATP + hydrogenobyrinic acid a,c-diamide + Co2+ = ADP + + phosphate + cob(II)yrinic acid a,c-diamide + H+ {ir} <1,2,3> +SP #3# more = ? (#3# the protein binds cobalt via residues His154, Glu184, + and His216 <4>) {} <4> +SP #5# dATP + hydrogenobyrinic acid a,c-diamide + Co2+ = dADP + phosphate + + cob(II)yrinic acid a,c-diamide + H+ (#5# 65% of activity with respect + to ATP <2>) <2> +SP #5# CTP + hydrogenobyrinic acid a,c-diamide + Co2+ = CDP + phosphate + + cob(II)yrinic acid a,c-diamide + H+ (#5# 45% of activity with respect + to ATP <2>) <2> +SP #5# ITP + hydrogenobyrinic acid a,c-diamide + Co2+ = IDP + phosphate + + cob(II)yrinic acid a,c-diamide + H+ (#5# 5% of activity with respect to + ATP <2>) <2> +SP #5# hydrogenobyrinic acid a,c-diamide + ATP + Co2+ = ADP + phosphate + + cob(II)yrinic acid a,c-diamide + H+ <2> + +KM_VALUE +KM #5# 0.22 {ATP} (#5# pH 8.0, 30°C <2>) <2> +KM #5# 0.0042 {Co2+} (#5# pH 8.0, 30°C <2>) <2> +KM #5# 0.000085 {hydrogenobyrinic acid a,c-diamide} (#5# pH 8.0, 30°C + <2>) <2> + +SPECIFIC_ACTIVITY +SA #5# -999.0 (#5# 0.0057 units for CobST subunit, 1 unit of CobN is + defined as the amount of CobST necessary to reconstruct 1 unit of the + entire complex. 0.006 for CobN subunit, 1 unit of CobN is defined as + the amount of CobN necessary to reconstruct 1 unit of the entire + complex <2>) <2> + +COFACTOR +CF #2,3# heme b <4> + +INHIBITORS +IN #5# diphosphate (#5# 50% inhibition at 5 mM <2>) <2> +IN #5# adenylyl (beta,gamma-methylene)-diphosphonate (#5# 50% inhibition + at 5 mM <2>) <2> +IN #5# Fe2+ (#5# 50% inhibition at 0.05 mM <2>) <2> +IN #5# N-ethylmaleimide (#5# 50% inhibition at 0.005 mM <2>) <2> +IN #5# adenylyl-imidodiphosphate (#5# 50% inhibition at 2 mM <2>) <2> +IN #5# Ni2+ (#5# 50% inhibition at 0.003 mM <2>) <2> +IN #5# Cu2+ (#5# 50% inhibition at 0.002 mM <2>) <2> +IN #5# AMP (#5# 15% inhibition at 10 mM <2>) <2> +IN #5# ADP (#5# 50% inhibition at 8 mM <2>) <2> +IN #5# Zn2+ (#5# 50% inhibition at 0.0005 mM <2>) <2> + +METALS_IONS +ME #5# Mg2+ (#5# ATP binding cation <2>) <2> + +MOLECULAR_WEIGHT +MW #5# 80000 (#5# 1 * 140000, CobN + 1 * 38000, namely CobS + 1 * 80000, + namely CobT, gel filtration, SDS-PAGE <2>) <2> +MW #5# 38000 (#5# 1 * 140000, CobN + 1 * 38000, namely CobS + 1 * 80000, + namely CobT, gel filtration, SDS-PAGE <2>) <2> +MW #5# 140000 (#5# 1 * 140000, CobN + 1 * 38000, namely CobS + 1 * 80000, + namely CobT, gel filtration, SDS-PAGE <2>) <2> +MW #5# 258000 (#5# gel filtration <2>) <2> + +SUBUNITS +SU #2,3# tetramer <4> +SU #5# trimer (#5# 1 * 140000, CobN + 1 * 38000, namely CobS + 1 * 80000, + namely CobT, gel filtration, SDS-PAGE <2>) <2> + +CLONED +CL #2# <4> +CL #3# <4> +CL #4# (subunits separately overexpressed in Escherichia coli BL21star + (DE3)pLysS) <3> + +CRYSTALLIZATION +CR #2# (hanging drop vapor diffusion method, using 100 mM Tris-HCl. pH + 8.5, containing 2.0 M ammonium sulfate) <4> +CR #3# (hanging drop vapor diffusion method, using 100 mM Tris-HCl. pH + 8.5, containing 2.0 M ammonium sulfate) <4> + +PURIFICATION +PU #2# <4> +PU #3# <4> +PU #5# (purification includes: Mono Q HR 10/10, Penyl-Superose and Mono Q + HR 5/5 chromatographies for CobN subunit, Mono Q HR 10/10, + Phenyl-Superose and AGATP for CobST subunit) <2> + +REFERENCE +RF <1> Debussche, L.; Thibaut, D.; Cameron, B.; Crouzet, J.; Blanche, F.: + Biosynthesis of the corrin macrocycle of coenzyme B12 in Pseudomonas + denitrificans. J. Bacteriol. (1993) 175, 7430-7440. {Pubmed:8226690} (c) +RF <2> Debussche, L.; Couder, M.; Thibaut, D.; Cameron, B.; Crouzet, J.; + Blanche, F.: Assay, purification, and characterization of + cobaltochelatase, a unique complex enzyme catalyzing cobalt insertion + in hydrogenobyrinic acid a,c-diamide during coenzime B12 biosynthesis + in Pseudomonas denitrificans. J. Bacteriol. (1992) 174, 7445-7451. + {Pubmed:1429466} +RF <3> Lundqvist, J.; Elmlund, D.; Heldt, D.; Deery, E.; Soederberg, C.A.; + Hansson, M.; Warren, M.; Al-Karadaghi, S.: The AAA(+) motor complex of + subunits CobS and CobT of cobaltochelatase visualized by single + particle electron microscopy. J. Struct. Biol. (2009) 167, 227-234. + {Pubmed:19545636} +RF <4> Romao, C.V.; Ladakis, D.; Lobo, S.A.; Carrondo, M.A.; Brindley, + A.A.; Deery, E.; Matias, P.M.; Pickersgill, R.W.; Saraiva, L.M.; + Warren, M.J.: Evolution in a family of chelatases facilitated by the + introduction of active site asymmetry and protein oligomerization. + Proc. Natl. Acad. Sci. USA (2011) 108, 97-102. {Pubmed:21173279} + +/// diff --git a/tests/test_parsing/test_lexer.py b/tests/test_parsing/test_lexer.py new file mode 100644 index 0000000..8b8fffb --- /dev/null +++ b/tests/test_parsing/test_lexer.py @@ -0,0 +1,124 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + +import pytest + +from brenda_parser.parsing.lexer import BRENDALexer + + +@pytest.fixture(scope="module") +def lexer(): + return BRENDALexer() + + +@pytest.fixture(scope="function") +def tokenizer(lexer, request): + lexer.input(request.param) + return lexer + + +@pytest.mark.parametrize("tokenizer, expected", [ + ("KM\tRF\tKI\t", ["INITIAL", "INITIAL", "INITIAL"]), + ("KM\tPR\tKI\t", ["INITIAL", "protentry", "INITIAL"]), + ("KM\tPR\tPR\tKI\t", ["INITIAL", "protentry", "protentry", "INITIAL"]), + ("KM\tPR\tRF\t", ["INITIAL", "protentry", "INITIAL"]) +], indirect=["tokenizer"]) +def test_inclusive_entry_states(tokenizer, expected): + states = [t.lexer.current_state() for t in tokenizer] + assert states == expected + + +@pytest.mark.parametrize("tokenizer, expected", [ + ("<13>", ["citation", "citation", "INITIAL"]), + ("#13#", ["protein", "protein", "INITIAL"]), + ("#13##", ["protein", "protein", "INITIAL", "protein"]), + ("{13}", ["special", "special", "INITIAL"]), + ("(13)", ["comment", "comment", "INITIAL"]), +], indirect=["tokenizer"]) +def test_exclusive_states(tokenizer, expected): + states = [t.lexer.current_state() for t in tokenizer] + assert states == expected + + +@pytest.mark.parametrize("tokenizer, expected", [ + ("# ,,#", ["POUND", "POUND"]), + ("#12#", ["POUND", "PROTEIN", "POUND"]), + ("# 12,423,23#", ["POUND", "PROTEIN", "PROTEIN", "PROTEIN", "POUND"]), + ("# # 13 #", ["POUND", "POUND", "CONTENT", "POUND"]), +], indirect=["tokenizer"]) +def test_protein_tokens(tokenizer, expected): + tokens = [t.type for t in tokenizer] + assert tokens == expected + + +@pytest.mark.parametrize("tokenizer, expected", [ + ("< ,,>", ["LANGLE", "RANGLE"]), + ("<12>", ["LANGLE", "CITATION", "RANGLE"]), + ("< 12,423,23>", ["LANGLE", "CITATION", "CITATION", "CITATION", "RANGLE"]), + ("<12> 13 <", ["LANGLE", "CITATION", "RANGLE", "CONTENT", "LANGLE"]), +], indirect=["tokenizer"]) +def test_citation_tokens(tokenizer, expected): + tokens = [t.type for t in tokenizer] + assert tokens == expected + + +@pytest.mark.parametrize("tokenizer, expected", [ + ("{ }", ["LCURLY", "RCURLY"]), + ("{12}", ["LCURLY", "SPECIAL", "RCURLY"]), + ("{ 12,423,23}", ["LCURLY", "SPECIAL", "RCURLY"]), + ("{12} 13 {", ["LCURLY", "SPECIAL", "RCURLY", "CONTENT", "LCURLY"]), +], indirect=["tokenizer"]) +def test_special_tokens(tokenizer, expected): + tokens = [t.type for t in tokenizer] + assert tokens == expected + + +@pytest.mark.parametrize("tokenizer, expected", [ + ("( )", ["LPARENS", "RPARENS"]), + ("(12)", ["LPARENS", "COMMENT", "RPARENS"]), + ("( 12,423,23)", ["LPARENS", "COMMENT", "RPARENS"]), + ("(12) 13 (", ["LPARENS", "COMMENT", "RPARENS", "CONTENT", "LPARENS"]), +], indirect=["tokenizer"]) +def test_special_tokens(tokenizer, expected): + tokens = [t.type for t in tokenizer] + assert tokens == expected + + +@pytest.mark.parametrize("tokenizer, expected", [ + ("KM\t#13# Q4AE87 SwissProt\n", + ["ENTRY", "POUND", "PROTEIN", "POUND", "CONTENT", "CONTENT"]), + ("PR\t#41# Pseudomonas sp. Q4AE87 SwissProt\nPI\t", + ["PROTEIN_ENTRY", "POUND", "PROTEIN", "POUND", "CONTENT", "CONTENT", + "ACCESSION", "CONTENT", "ENTRY"]), +], indirect=["tokenizer"]) +def test_protein_entry_state(tokenizer, expected): + tokens = [t.type for t in tokenizer] + assert tokens == expected diff --git a/tests/test_parsing/test_parser.py b/tests/test_parsing/test_parser.py new file mode 100644 index 0000000..d2c16be --- /dev/null +++ b/tests/test_parsing/test_parser.py @@ -0,0 +1,202 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + +from builtins import open +from os.path import dirname, join + +import pytest +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker + +from brenda_parser.models import Base, InformationField +from brenda_parser.parsing.parser import BRENDAParser + +Session = sessionmaker() + + +@pytest.fixture(scope="module") +def connection(): + """ + Use a connection such transactions can be used. + + Notes + ----- + Follows a transaction pattern described in the following: + http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#session-begin-nested + """ + engine = create_engine("sqlite:///:memory:") + Base.metadata.create_all(engine) + session = Session(bind=engine) + InformationField.preload(session) + session.close() + del session + connection = engine.connect() + yield connection + connection.close() + + +@pytest.fixture(scope="function") +def session(connection): + """ + Create a transaction and session per test unit. + + Rolling back a transaction removes even committed rows + (``session.commit``) from the database. + """ + transaction = connection.begin() + session = Session(bind=connection) + yield session + session.close() + transaction.rollback() + + +@pytest.fixture(scope="module") +def proteins_parser(): + return BRENDAParser(start="proteins") + + +@pytest.mark.parametrize("text, expected", [ + (" #, #", None), + (" #13, 334,23 #", [13, 334, 23]), +]) +def test_proteins(proteins_parser, text, expected): + assert proteins_parser.parse(text, None) == expected + + +@pytest.fixture(scope="module") +def citations_parser(): + return BRENDAParser(start="citations") + + +@pytest.mark.parametrize("text, expected", [ + (" <, >", None), + (" <13, 334,23 >", [13, 334, 23]), +]) +def test_citations(citations_parser, text, expected): + assert citations_parser.parse(text, None) == expected + + +@pytest.fixture(scope="module") +def special_parser(): + return BRENDAParser(start="special") + + +@pytest.mark.parametrize("text, expected", [ + (" { }", None), + (" { I am important content. }", "I am important content.") +]) +def test_special(special_parser, text, expected): + assert special_parser.parse(text, None) == expected + + +@pytest.fixture(scope="module") +def comment_parser(): + return BRENDAParser(start="comment") + + +@pytest.mark.parametrize("text, expected", [ + (" ( )", None), + (" ( I am important content. )", "I am important content.") +]) +def test_comment(comment_parser, text, expected): + assert comment_parser.parse(text, None) == expected + + +@pytest.fixture(scope="module") +def protein_entry_parser(): + return BRENDAParser(start="protein_entry") + + +@pytest.mark.parametrize("text, expected", [ + ("PR\t#2#", "PR"), + ("PR\t#2# alpha omega", "PR"), + ("PR\t#2# <12, 14>", "PR"), + ("PR\t#2# Q4AE87 SwissProt", "PR"), +]) +def test_protein_entry(session, protein_entry_parser, text, expected): + protein = protein_entry_parser.parse(text, session) + assert protein.field.acronym == expected + assert protein_entry_parser.proteins[2] is protein + + +@pytest.fixture(scope="module") +def reference_entry_parser(): + return BRENDAParser(start="reference_entry") + + +@pytest.mark.parametrize("text, expected", [ + ("RF\t<2>", "RF"), + ("RF\t<2> Dogbert & Co", "RF"), + ("RF\t<2> Dogbert & Co (1748) Cool", "RF"), + ("RF\t<2> Dogbert & Co {Pubmed:1234567}", "RF"), +]) +def test_reference_entry(session, reference_entry_parser, text, expected): + reference = reference_entry_parser.parse(text, session) + assert reference.field.acronym == expected + assert reference_entry_parser.citations[2] is reference + + +@pytest.fixture(scope="module") +def entry_parser(): + return BRENDAParser(start="entry") + + +@pytest.mark.parametrize("text, expected", [ + ("PI\thigh point", "PI"), + ("KI\t(high point)", "KI"), + ("KM\thigh point (this is a comment)", "KM"), +]) +def test_entry(session, entry_parser, text, expected): + entry = entry_parser.parse(text, session) + assert entry.field.acronym == expected + + +@pytest.fixture(scope="module") +def enzyme_parser(): + return BRENDAParser(start="enzyme") + + +@pytest.mark.parametrize("text, expected", [ + ("ID\t1.1.1.1", "1.1.1.1"), + ("ID\t1.1.2.1\n///\n", "1.1.2.1"), + ("ID\t1.1.2.3 (mighty comment)\n///\n", "1.1.2.3"), +]) +def test_enzyme(session, enzyme_parser, text, expected): + enzyme = enzyme_parser.parse(text, session) + assert enzyme.ec_number == expected + + +def test_section(session): + parser = BRENDAParser() + with open(join( + dirname(__file__), "data", "small_section.txt")) as file_handle: + enzyme = parser.parse(file_handle.read(), session) + print(enzyme.__dict__) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..8d66a4a --- /dev/null +++ b/tox.ini @@ -0,0 +1,23 @@ +[tox] +envlist = flake8, py{27,35,36} + +[testenv] +setenv = + PYTHONUNBUFFERED=yes +passenv = + CI + TRAVIS + TRAVIS_* +usedevelop = true +deps = + -r{toxinidir}/test_requirements.txt +commands = + {posargs:pytest --cov-append=brenda_parser} + +[testenv:flake8] +skip_install = True +deps= + flake8 + flake8-docstrings +commands= + flake8 src/brenda_parser diff --git a/versioneer.py b/versioneer.py new file mode 100644 index 0000000..64fea1c --- /dev/null +++ b/versioneer.py @@ -0,0 +1,1822 @@ + +# Version: 0.18 + +"""The Versioneer - like a rocketeer, but for versions. + +The Versioneer +============== + +* like a rocketeer, but for versions! +* https://github.com/warner/python-versioneer +* Brian Warner +* License: Public Domain +* Compatible With: python2.6, 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, and pypy +* [![Latest Version] +(https://pypip.in/version/versioneer/badge.svg?style=flat) +](https://pypi.python.org/pypi/versioneer/) +* [![Build Status] +(https://travis-ci.org/warner/python-versioneer.png?branch=master) +](https://travis-ci.org/warner/python-versioneer) + +This is a tool for managing a recorded version number in distutils-based +python projects. The goal is to remove the tedious and error-prone "update +the embedded version string" step from your release process. Making a new +release should be as easy as recording a new tag in your version-control +system, and maybe making new tarballs. + + +## Quick Install + +* `pip install versioneer` to somewhere to your $PATH +* add a `[versioneer]` section to your setup.cfg (see below) +* run `versioneer install` in your source tree, commit the results + +## Version Identifiers + +Source trees come from a variety of places: + +* a version-control system checkout (mostly used by developers) +* a nightly tarball, produced by build automation +* a snapshot tarball, produced by a web-based VCS browser, like github's + "tarball from tag" feature +* a release tarball, produced by "setup.py sdist", distributed through PyPI + +Within each source tree, the version identifier (either a string or a number, +this tool is format-agnostic) can come from a variety of places: + +* ask the VCS tool itself, e.g. "git describe" (for checkouts), which knows + about recent "tags" and an absolute revision-id +* the name of the directory into which the tarball was unpacked +* an expanded VCS keyword ($Id$, etc) +* a `_version.py` created by some earlier build step + +For released software, the version identifier is closely related to a VCS +tag. Some projects use tag names that include more than just the version +string (e.g. "myproject-1.2" instead of just "1.2"), in which case the tool +needs to strip the tag prefix to extract the version identifier. For +unreleased software (between tags), the version identifier should provide +enough information to help developers recreate the same tree, while also +giving them an idea of roughly how old the tree is (after version 1.2, before +version 1.3). Many VCS systems can report a description that captures this, +for example `git describe --tags --dirty --always` reports things like +"0.7-1-g574ab98-dirty" to indicate that the checkout is one revision past the +0.7 tag, has a unique revision id of "574ab98", and is "dirty" (it has +uncommitted changes. + +The version identifier is used for multiple purposes: + +* to allow the module to self-identify its version: `myproject.__version__` +* to choose a name and prefix for a 'setup.py sdist' tarball + +## Theory of Operation + +Versioneer works by adding a special `_version.py` file into your source +tree, where your `__init__.py` can import it. This `_version.py` knows how to +dynamically ask the VCS tool for version information at import time. + +`_version.py` also contains `$Revision$` markers, and the installation +process marks `_version.py` to have this marker rewritten with a tag name +during the `git archive` command. As a result, generated tarballs will +contain enough information to get the proper version. + +To allow `setup.py` to compute a version too, a `versioneer.py` is added to +the top level of your source tree, next to `setup.py` and the `setup.cfg` +that configures it. This overrides several distutils/setuptools commands to +compute the version when invoked, and changes `setup.py build` and `setup.py +sdist` to replace `_version.py` with a small static file that contains just +the generated version data. + +## Installation + +See [INSTALL.md](./INSTALL.md) for detailed installation instructions. + +## Version-String Flavors + +Code which uses Versioneer can learn about its version string at runtime by +importing `_version` from your main `__init__.py` file and running the +`get_versions()` function. From the "outside" (e.g. in `setup.py`), you can +import the top-level `versioneer.py` and run `get_versions()`. + +Both functions return a dictionary with different flavors of version +information: + +* `['version']`: A condensed version string, rendered using the selected + style. This is the most commonly used value for the project's version + string. The default "pep440" style yields strings like `0.11`, + `0.11+2.g1076c97`, or `0.11+2.g1076c97.dirty`. See the "Styles" section + below for alternative styles. + +* `['full-revisionid']`: detailed revision identifier. For Git, this is the + full SHA1 commit id, e.g. "1076c978a8d3cfc70f408fe5974aa6c092c949ac". + +* `['date']`: Date and time of the latest `HEAD` commit. For Git, it is the + commit date in ISO 8601 format. This will be None if the date is not + available. + +* `['dirty']`: a boolean, True if the tree has uncommitted changes. Note that + this is only accurate if run in a VCS checkout, otherwise it is likely to + be False or None + +* `['error']`: if the version string could not be computed, this will be set + to a string describing the problem, otherwise it will be None. It may be + useful to throw an exception in setup.py if this is set, to avoid e.g. + creating tarballs with a version string of "unknown". + +Some variants are more useful than others. Including `full-revisionid` in a +bug report should allow developers to reconstruct the exact code being tested +(or indicate the presence of local changes that should be shared with the +developers). `version` is suitable for display in an "about" box or a CLI +`--version` output: it can be easily compared against release notes and lists +of bugs fixed in various releases. + +The installer adds the following text to your `__init__.py` to place a basic +version in `YOURPROJECT.__version__`: + + from ._version import get_versions + __version__ = get_versions()['version'] + del get_versions + +## Styles + +The setup.cfg `style=` configuration controls how the VCS information is +rendered into a version string. + +The default style, "pep440", produces a PEP440-compliant string, equal to the +un-prefixed tag name for actual releases, and containing an additional "local +version" section with more detail for in-between builds. For Git, this is +TAG[+DISTANCE.gHEX[.dirty]] , using information from `git describe --tags +--dirty --always`. For example "0.11+2.g1076c97.dirty" indicates that the +tree is like the "1076c97" commit but has uncommitted changes (".dirty"), and +that this commit is two revisions ("+2") beyond the "0.11" tag. For released +software (exactly equal to a known tag), the identifier will only contain the +stripped tag, e.g. "0.11". + +Other styles are available. See [details.md](details.md) in the Versioneer +source tree for descriptions. + +## Debugging + +Versioneer tries to avoid fatal errors: if something goes wrong, it will tend +to return a version of "0+unknown". To investigate the problem, run `setup.py +version`, which will run the version-lookup code in a verbose mode, and will +display the full contents of `get_versions()` (including the `error` string, +which may help identify what went wrong). + +## Known Limitations + +Some situations are known to cause problems for Versioneer. This details the +most significant ones. More can be found on Github +[issues page](https://github.com/warner/python-versioneer/issues). + +### Subprojects + +Versioneer has limited support for source trees in which `setup.py` is not in +the root directory (e.g. `setup.py` and `.git/` are *not* siblings). The are +two common reasons why `setup.py` might not be in the root: + +* Source trees which contain multiple subprojects, such as + [Buildbot](https://github.com/buildbot/buildbot), which contains both + "master" and "slave" subprojects, each with their own `setup.py`, + `setup.cfg`, and `tox.ini`. Projects like these produce multiple PyPI + distributions (and upload multiple independently-installable tarballs). +* Source trees whose main purpose is to contain a C library, but which also + provide bindings to Python (and perhaps other langauges) in subdirectories. + +Versioneer will look for `.git` in parent directories, and most operations +should get the right version string. However `pip` and `setuptools` have bugs +and implementation details which frequently cause `pip install .` from a +subproject directory to fail to find a correct version string (so it usually +defaults to `0+unknown`). + +`pip install --editable .` should work correctly. `setup.py install` might +work too. + +Pip-8.1.1 is known to have this problem, but hopefully it will get fixed in +some later version. + +[Bug #38](https://github.com/warner/python-versioneer/issues/38) is tracking +this issue. The discussion in +[PR #61](https://github.com/warner/python-versioneer/pull/61) describes the +issue from the Versioneer side in more detail. +[pip PR#3176](https://github.com/pypa/pip/pull/3176) and +[pip PR#3615](https://github.com/pypa/pip/pull/3615) contain work to improve +pip to let Versioneer work correctly. + +Versioneer-0.16 and earlier only looked for a `.git` directory next to the +`setup.cfg`, so subprojects were completely unsupported with those releases. + +### Editable installs with setuptools <= 18.5 + +`setup.py develop` and `pip install --editable .` allow you to install a +project into a virtualenv once, then continue editing the source code (and +test) without re-installing after every change. + +"Entry-point scripts" (`setup(entry_points={"console_scripts": ..})`) are a +convenient way to specify executable scripts that should be installed along +with the python package. + +These both work as expected when using modern setuptools. When using +setuptools-18.5 or earlier, however, certain operations will cause +`pkg_resources.DistributionNotFound` errors when running the entrypoint +script, which must be resolved by re-installing the package. This happens +when the install happens with one version, then the egg_info data is +regenerated while a different version is checked out. Many setup.py commands +cause egg_info to be rebuilt (including `sdist`, `wheel`, and installing into +a different virtualenv), so this can be surprising. + +[Bug #83](https://github.com/warner/python-versioneer/issues/83) describes +this one, but upgrading to a newer version of setuptools should probably +resolve it. + +### Unicode version strings + +While Versioneer works (and is continually tested) with both Python 2 and +Python 3, it is not entirely consistent with bytes-vs-unicode distinctions. +Newer releases probably generate unicode version strings on py2. It's not +clear that this is wrong, but it may be surprising for applications when then +write these strings to a network connection or include them in bytes-oriented +APIs like cryptographic checksums. + +[Bug #71](https://github.com/warner/python-versioneer/issues/71) investigates +this question. + + +## Updating Versioneer + +To upgrade your project to a new release of Versioneer, do the following: + +* install the new Versioneer (`pip install -U versioneer` or equivalent) +* edit `setup.cfg`, if necessary, to include any new configuration settings + indicated by the release notes. See [UPGRADING](./UPGRADING.md) for details. +* re-run `versioneer install` in your source tree, to replace + `SRC/_version.py` +* commit any changed files + +## Future Directions + +This tool is designed to make it easily extended to other version-control +systems: all VCS-specific components are in separate directories like +src/git/ . The top-level `versioneer.py` script is assembled from these +components by running make-versioneer.py . In the future, make-versioneer.py +will take a VCS name as an argument, and will construct a version of +`versioneer.py` that is specific to the given VCS. It might also take the +configuration arguments that are currently provided manually during +installation by editing setup.py . Alternatively, it might go the other +direction and include code from all supported VCS systems, reducing the +number of intermediate scripts. + + +## License + +To make Versioneer easier to embed, all its code is dedicated to the public +domain. The `_version.py` that it creates is also in the public domain. +Specifically, both are released under the Creative Commons "Public Domain +Dedication" license (CC0-1.0), as described in +https://creativecommons.org/publicdomain/zero/1.0/ . + +""" + +from __future__ import print_function +try: + import configparser +except ImportError: + import ConfigParser as configparser +import errno +import json +import os +import re +import subprocess +import sys + + +class VersioneerConfig: + """Container for Versioneer configuration parameters.""" + + +def get_root(): + """Get the project root directory. + + We require that all commands are run from the project root, i.e. the + directory that contains setup.py, setup.cfg, and versioneer.py . + """ + root = os.path.realpath(os.path.abspath(os.getcwd())) + setup_py = os.path.join(root, "setup.py") + versioneer_py = os.path.join(root, "versioneer.py") + if not (os.path.exists(setup_py) or os.path.exists(versioneer_py)): + # allow 'python path/to/setup.py COMMAND' + root = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))) + setup_py = os.path.join(root, "setup.py") + versioneer_py = os.path.join(root, "versioneer.py") + if not (os.path.exists(setup_py) or os.path.exists(versioneer_py)): + err = ("Versioneer was unable to run the project root directory. " + "Versioneer requires setup.py to be executed from " + "its immediate directory (like 'python setup.py COMMAND'), " + "or in a way that lets it use sys.argv[0] to find the root " + "(like 'python path/to/setup.py COMMAND').") + raise VersioneerBadRootError(err) + try: + # Certain runtime workflows (setup.py install/develop in a setuptools + # tree) execute all dependencies in a single python process, so + # "versioneer" may be imported multiple times, and python's shared + # module-import table will cache the first one. So we can't use + # os.path.dirname(__file__), as that will find whichever + # versioneer.py was first imported, even in later projects. + me = os.path.realpath(os.path.abspath(__file__)) + me_dir = os.path.normcase(os.path.splitext(me)[0]) + vsr_dir = os.path.normcase(os.path.splitext(versioneer_py)[0]) + if me_dir != vsr_dir: + print("Warning: build in %s is using versioneer.py from %s" + % (os.path.dirname(me), versioneer_py)) + except NameError: + pass + return root + + +def get_config_from_root(root): + """Read the project setup.cfg file to determine Versioneer config.""" + # This might raise EnvironmentError (if setup.cfg is missing), or + # configparser.NoSectionError (if it lacks a [versioneer] section), or + # configparser.NoOptionError (if it lacks "VCS="). See the docstring at + # the top of versioneer.py for instructions on writing your setup.cfg . + setup_cfg = os.path.join(root, "setup.cfg") + parser = configparser.SafeConfigParser() + with open(setup_cfg, "r") as f: + parser.readfp(f) + VCS = parser.get("versioneer", "VCS") # mandatory + + def get(parser, name): + if parser.has_option("versioneer", name): + return parser.get("versioneer", name) + return None + cfg = VersioneerConfig() + cfg.VCS = VCS + cfg.style = get(parser, "style") or "" + cfg.versionfile_source = get(parser, "versionfile_source") + cfg.versionfile_build = get(parser, "versionfile_build") + cfg.tag_prefix = get(parser, "tag_prefix") + if cfg.tag_prefix in ("''", '""'): + cfg.tag_prefix = "" + cfg.parentdir_prefix = get(parser, "parentdir_prefix") + cfg.verbose = get(parser, "verbose") + return cfg + + +class NotThisMethod(Exception): + """Exception raised if a method is not valid for the current scenario.""" + + +# these dictionaries contain VCS-specific tools +LONG_VERSION_PY = {} +HANDLERS = {} + + +def register_vcs_handler(vcs, method): # decorator + """Decorator to mark a method as the handler for a particular VCS.""" + def decorate(f): + """Store f in HANDLERS[vcs][method].""" + if vcs not in HANDLERS: + HANDLERS[vcs] = {} + HANDLERS[vcs][method] = f + return f + return decorate + + +def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, + env=None): + """Call the given command(s).""" + assert isinstance(commands, list) + p = None + for c in commands: + try: + dispcmd = str([c] + args) + # remember shell=False, so use git.cmd on windows, not just git + p = subprocess.Popen([c] + args, cwd=cwd, env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr + else None)) + break + except EnvironmentError: + e = sys.exc_info()[1] + if e.errno == errno.ENOENT: + continue + if verbose: + print("unable to run %s" % dispcmd) + print(e) + return None, None + else: + if verbose: + print("unable to find command, tried %s" % (commands,)) + return None, None + stdout = p.communicate()[0].strip() + if sys.version_info[0] >= 3: + stdout = stdout.decode() + if p.returncode != 0: + if verbose: + print("unable to run %s (error)" % dispcmd) + print("stdout was %s" % stdout) + return None, p.returncode + return stdout, p.returncode + + +LONG_VERSION_PY['git'] = ''' +# This file helps to compute a version number in source trees obtained from +# git-archive tarball (such as those provided by githubs download-from-tag +# feature). Distribution tarballs (built by setup.py sdist) and build +# directories (produced by setup.py build) will contain a much shorter file +# that just contains the computed version number. + +# This file is released into the public domain. Generated by +# versioneer-0.18 (https://github.com/warner/python-versioneer) + +"""Git implementation of _version.py.""" + +import errno +import os +import re +import subprocess +import sys + + +def get_keywords(): + """Get the keywords needed to look up the version information.""" + # these strings will be replaced by git during git-archive. + # setup.py/versioneer.py will grep for the variable names, so they must + # each be defined on a line of their own. _version.py will just call + # get_keywords(). + git_refnames = "%(DOLLAR)sFormat:%%d%(DOLLAR)s" + git_full = "%(DOLLAR)sFormat:%%H%(DOLLAR)s" + git_date = "%(DOLLAR)sFormat:%%ci%(DOLLAR)s" + keywords = {"refnames": git_refnames, "full": git_full, "date": git_date} + return keywords + + +class VersioneerConfig: + """Container for Versioneer configuration parameters.""" + + +def get_config(): + """Create, populate and return the VersioneerConfig() object.""" + # these strings are filled in when 'setup.py versioneer' creates + # _version.py + cfg = VersioneerConfig() + cfg.VCS = "git" + cfg.style = "%(STYLE)s" + cfg.tag_prefix = "%(TAG_PREFIX)s" + cfg.parentdir_prefix = "%(PARENTDIR_PREFIX)s" + cfg.versionfile_source = "%(VERSIONFILE_SOURCE)s" + cfg.verbose = False + return cfg + + +class NotThisMethod(Exception): + """Exception raised if a method is not valid for the current scenario.""" + + +LONG_VERSION_PY = {} +HANDLERS = {} + + +def register_vcs_handler(vcs, method): # decorator + """Decorator to mark a method as the handler for a particular VCS.""" + def decorate(f): + """Store f in HANDLERS[vcs][method].""" + if vcs not in HANDLERS: + HANDLERS[vcs] = {} + HANDLERS[vcs][method] = f + return f + return decorate + + +def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, + env=None): + """Call the given command(s).""" + assert isinstance(commands, list) + p = None + for c in commands: + try: + dispcmd = str([c] + args) + # remember shell=False, so use git.cmd on windows, not just git + p = subprocess.Popen([c] + args, cwd=cwd, env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr + else None)) + break + except EnvironmentError: + e = sys.exc_info()[1] + if e.errno == errno.ENOENT: + continue + if verbose: + print("unable to run %%s" %% dispcmd) + print(e) + return None, None + else: + if verbose: + print("unable to find command, tried %%s" %% (commands,)) + return None, None + stdout = p.communicate()[0].strip() + if sys.version_info[0] >= 3: + stdout = stdout.decode() + if p.returncode != 0: + if verbose: + print("unable to run %%s (error)" %% dispcmd) + print("stdout was %%s" %% stdout) + return None, p.returncode + return stdout, p.returncode + + +def versions_from_parentdir(parentdir_prefix, root, verbose): + """Try to determine the version from the parent directory name. + + Source tarballs conventionally unpack into a directory that includes both + the project name and a version string. We will also support searching up + two directory levels for an appropriately named parent directory + """ + rootdirs = [] + + for i in range(3): + dirname = os.path.basename(root) + if dirname.startswith(parentdir_prefix): + return {"version": dirname[len(parentdir_prefix):], + "full-revisionid": None, + "dirty": False, "error": None, "date": None} + else: + rootdirs.append(root) + root = os.path.dirname(root) # up a level + + if verbose: + print("Tried directories %%s but none started with prefix %%s" %% + (str(rootdirs), parentdir_prefix)) + raise NotThisMethod("rootdir doesn't start with parentdir_prefix") + + +@register_vcs_handler("git", "get_keywords") +def git_get_keywords(versionfile_abs): + """Extract version information from the given file.""" + # the code embedded in _version.py can just fetch the value of these + # keywords. When used from setup.py, we don't want to import _version.py, + # so we do it with a regexp instead. This function is not used from + # _version.py. + keywords = {} + try: + f = open(versionfile_abs, "r") + for line in f.readlines(): + if line.strip().startswith("git_refnames ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["refnames"] = mo.group(1) + if line.strip().startswith("git_full ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["full"] = mo.group(1) + if line.strip().startswith("git_date ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["date"] = mo.group(1) + f.close() + except EnvironmentError: + pass + return keywords + + +@register_vcs_handler("git", "keywords") +def git_versions_from_keywords(keywords, tag_prefix, verbose): + """Get version information from git keywords.""" + if not keywords: + raise NotThisMethod("no keywords at all, weird") + date = keywords.get("date") + if date is not None: + # git-2.2.0 added "%%cI", which expands to an ISO-8601 -compliant + # datestamp. However we prefer "%%ci" (which expands to an "ISO-8601 + # -like" string, which we must then edit to make compliant), because + # it's been around since git-1.5.3, and it's too difficult to + # discover which version we're using, or to work around using an + # older one. + date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) + refnames = keywords["refnames"].strip() + if refnames.startswith("$Format"): + if verbose: + print("keywords are unexpanded, not using") + raise NotThisMethod("unexpanded keywords, not a git-archive tarball") + refs = set([r.strip() for r in refnames.strip("()").split(",")]) + # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of + # just "foo-1.0". If we see a "tag: " prefix, prefer those. + TAG = "tag: " + tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) + if not tags: + # Either we're using git < 1.8.3, or there really are no tags. We use + # a heuristic: assume all version tags have a digit. The old git %%d + # expansion behaves like git log --decorate=short and strips out the + # refs/heads/ and refs/tags/ prefixes that would let us distinguish + # between branches and tags. By ignoring refnames without digits, we + # filter out many common branch names like "release" and + # "stabilization", as well as "HEAD" and "master". + tags = set([r for r in refs if re.search(r'\d', r)]) + if verbose: + print("discarding '%%s', no digits" %% ",".join(refs - tags)) + if verbose: + print("likely tags: %%s" %% ",".join(sorted(tags))) + for ref in sorted(tags): + # sorting will prefer e.g. "2.0" over "2.0rc1" + if ref.startswith(tag_prefix): + r = ref[len(tag_prefix):] + if verbose: + print("picking %%s" %% r) + return {"version": r, + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": None, + "date": date} + # no suitable tags, so version is "0+unknown", but full hex is still there + if verbose: + print("no suitable tags, using unknown + full revision id") + return {"version": "0+unknown", + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": "no suitable tags", "date": None} + + +@register_vcs_handler("git", "pieces_from_vcs") +def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): + """Get version from 'git describe' in the root of the source tree. + + This only gets called if the git-archive 'subst' keywords were *not* + expanded, and _version.py hasn't already been rewritten with a short + version string, meaning we're inside a checked out source tree. + """ + GITS = ["git"] + if sys.platform == "win32": + GITS = ["git.cmd", "git.exe"] + + out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, + hide_stderr=True) + if rc != 0: + if verbose: + print("Directory %%s not under git control" %% root) + raise NotThisMethod("'git rev-parse --git-dir' returned error") + + # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] + # if there isn't one, this yields HEX[-dirty] (no NUM) + describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", + "--always", "--long", + "--match", "%%s*" %% tag_prefix], + cwd=root) + # --long was added in git-1.5.5 + if describe_out is None: + raise NotThisMethod("'git describe' failed") + describe_out = describe_out.strip() + full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) + if full_out is None: + raise NotThisMethod("'git rev-parse' failed") + full_out = full_out.strip() + + pieces = {} + pieces["long"] = full_out + pieces["short"] = full_out[:7] # maybe improved later + pieces["error"] = None + + # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] + # TAG might have hyphens. + git_describe = describe_out + + # look for -dirty suffix + dirty = git_describe.endswith("-dirty") + pieces["dirty"] = dirty + if dirty: + git_describe = git_describe[:git_describe.rindex("-dirty")] + + # now we have TAG-NUM-gHEX or HEX + + if "-" in git_describe: + # TAG-NUM-gHEX + mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) + if not mo: + # unparseable. Maybe git-describe is misbehaving? + pieces["error"] = ("unable to parse git-describe output: '%%s'" + %% describe_out) + return pieces + + # tag + full_tag = mo.group(1) + if not full_tag.startswith(tag_prefix): + if verbose: + fmt = "tag '%%s' doesn't start with prefix '%%s'" + print(fmt %% (full_tag, tag_prefix)) + pieces["error"] = ("tag '%%s' doesn't start with prefix '%%s'" + %% (full_tag, tag_prefix)) + return pieces + pieces["closest-tag"] = full_tag[len(tag_prefix):] + + # distance: number of commits since tag + pieces["distance"] = int(mo.group(2)) + + # commit: short hex revision ID + pieces["short"] = mo.group(3) + + else: + # HEX: no tags + pieces["closest-tag"] = None + count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], + cwd=root) + pieces["distance"] = int(count_out) # total number of commits + + # commit date: see ISO-8601 comment in git_versions_from_keywords() + date = run_command(GITS, ["show", "-s", "--format=%%ci", "HEAD"], + cwd=root)[0].strip() + pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) + + return pieces + + +def plus_or_dot(pieces): + """Return a + if we don't already have one, else return a .""" + if "+" in pieces.get("closest-tag", ""): + return "." + return "+" + + +def render_pep440(pieces): + """Build up version string, with post-release "local version identifier". + + Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you + get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty + + Exceptions: + 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += plus_or_dot(pieces) + rendered += "%%d.g%%s" %% (pieces["distance"], pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0+untagged.%%d.g%%s" %% (pieces["distance"], + pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def render_pep440_pre(pieces): + """TAG[.post.devDISTANCE] -- No -dirty. + + Exceptions: + 1: no tags. 0.post.devDISTANCE + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"]: + rendered += ".post.dev%%d" %% pieces["distance"] + else: + # exception #1 + rendered = "0.post.dev%%d" %% pieces["distance"] + return rendered + + +def render_pep440_post(pieces): + """TAG[.postDISTANCE[.dev0]+gHEX] . + + The ".dev0" means dirty. Note that .dev0 sorts backwards + (a dirty tree will appear "older" than the corresponding clean one), + but you shouldn't be releasing software with -dirty anyways. + + Exceptions: + 1: no tags. 0.postDISTANCE[.dev0] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%%d" %% pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "g%%s" %% pieces["short"] + else: + # exception #1 + rendered = "0.post%%d" %% pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + rendered += "+g%%s" %% pieces["short"] + return rendered + + +def render_pep440_old(pieces): + """TAG[.postDISTANCE[.dev0]] . + + The ".dev0" means dirty. + + Eexceptions: + 1: no tags. 0.postDISTANCE[.dev0] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%%d" %% pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + else: + # exception #1 + rendered = "0.post%%d" %% pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + return rendered + + +def render_git_describe(pieces): + """TAG[-DISTANCE-gHEX][-dirty]. + + Like 'git describe --tags --dirty --always'. + + Exceptions: + 1: no tags. HEX[-dirty] (note: no 'g' prefix) + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"]: + rendered += "-%%d-g%%s" %% (pieces["distance"], pieces["short"]) + else: + # exception #1 + rendered = pieces["short"] + if pieces["dirty"]: + rendered += "-dirty" + return rendered + + +def render_git_describe_long(pieces): + """TAG-DISTANCE-gHEX[-dirty]. + + Like 'git describe --tags --dirty --always -long'. + The distance/hash is unconditional. + + Exceptions: + 1: no tags. HEX[-dirty] (note: no 'g' prefix) + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + rendered += "-%%d-g%%s" %% (pieces["distance"], pieces["short"]) + else: + # exception #1 + rendered = pieces["short"] + if pieces["dirty"]: + rendered += "-dirty" + return rendered + + +def render(pieces, style): + """Render the given version pieces into the requested style.""" + if pieces["error"]: + return {"version": "unknown", + "full-revisionid": pieces.get("long"), + "dirty": None, + "error": pieces["error"], + "date": None} + + if not style or style == "default": + style = "pep440" # the default + + if style == "pep440": + rendered = render_pep440(pieces) + elif style == "pep440-pre": + rendered = render_pep440_pre(pieces) + elif style == "pep440-post": + rendered = render_pep440_post(pieces) + elif style == "pep440-old": + rendered = render_pep440_old(pieces) + elif style == "git-describe": + rendered = render_git_describe(pieces) + elif style == "git-describe-long": + rendered = render_git_describe_long(pieces) + else: + raise ValueError("unknown style '%%s'" %% style) + + return {"version": rendered, "full-revisionid": pieces["long"], + "dirty": pieces["dirty"], "error": None, + "date": pieces.get("date")} + + +def get_versions(): + """Get version information or return default if unable to do so.""" + # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have + # __file__, we can work backwards from there to the root. Some + # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which + # case we can only use expanded keywords. + + cfg = get_config() + verbose = cfg.verbose + + try: + return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, + verbose) + except NotThisMethod: + pass + + try: + root = os.path.realpath(__file__) + # versionfile_source is the relative path from the top of the source + # tree (where the .git directory might live) to this file. Invert + # this to find the root from __file__. + for i in cfg.versionfile_source.split('/'): + root = os.path.dirname(root) + except NameError: + return {"version": "0+unknown", "full-revisionid": None, + "dirty": None, + "error": "unable to find root of source tree", + "date": None} + + try: + pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) + return render(pieces, cfg.style) + except NotThisMethod: + pass + + try: + if cfg.parentdir_prefix: + return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) + except NotThisMethod: + pass + + return {"version": "0+unknown", "full-revisionid": None, + "dirty": None, + "error": "unable to compute version", "date": None} +''' + + +@register_vcs_handler("git", "get_keywords") +def git_get_keywords(versionfile_abs): + """Extract version information from the given file.""" + # the code embedded in _version.py can just fetch the value of these + # keywords. When used from setup.py, we don't want to import _version.py, + # so we do it with a regexp instead. This function is not used from + # _version.py. + keywords = {} + try: + f = open(versionfile_abs, "r") + for line in f.readlines(): + if line.strip().startswith("git_refnames ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["refnames"] = mo.group(1) + if line.strip().startswith("git_full ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["full"] = mo.group(1) + if line.strip().startswith("git_date ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["date"] = mo.group(1) + f.close() + except EnvironmentError: + pass + return keywords + + +@register_vcs_handler("git", "keywords") +def git_versions_from_keywords(keywords, tag_prefix, verbose): + """Get version information from git keywords.""" + if not keywords: + raise NotThisMethod("no keywords at all, weird") + date = keywords.get("date") + if date is not None: + # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant + # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 + # -like" string, which we must then edit to make compliant), because + # it's been around since git-1.5.3, and it's too difficult to + # discover which version we're using, or to work around using an + # older one. + date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) + refnames = keywords["refnames"].strip() + if refnames.startswith("$Format"): + if verbose: + print("keywords are unexpanded, not using") + raise NotThisMethod("unexpanded keywords, not a git-archive tarball") + refs = set([r.strip() for r in refnames.strip("()").split(",")]) + # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of + # just "foo-1.0". If we see a "tag: " prefix, prefer those. + TAG = "tag: " + tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) + if not tags: + # Either we're using git < 1.8.3, or there really are no tags. We use + # a heuristic: assume all version tags have a digit. The old git %d + # expansion behaves like git log --decorate=short and strips out the + # refs/heads/ and refs/tags/ prefixes that would let us distinguish + # between branches and tags. By ignoring refnames without digits, we + # filter out many common branch names like "release" and + # "stabilization", as well as "HEAD" and "master". + tags = set([r for r in refs if re.search(r'\d', r)]) + if verbose: + print("discarding '%s', no digits" % ",".join(refs - tags)) + if verbose: + print("likely tags: %s" % ",".join(sorted(tags))) + for ref in sorted(tags): + # sorting will prefer e.g. "2.0" over "2.0rc1" + if ref.startswith(tag_prefix): + r = ref[len(tag_prefix):] + if verbose: + print("picking %s" % r) + return {"version": r, + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": None, + "date": date} + # no suitable tags, so version is "0+unknown", but full hex is still there + if verbose: + print("no suitable tags, using unknown + full revision id") + return {"version": "0+unknown", + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": "no suitable tags", "date": None} + + +@register_vcs_handler("git", "pieces_from_vcs") +def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): + """Get version from 'git describe' in the root of the source tree. + + This only gets called if the git-archive 'subst' keywords were *not* + expanded, and _version.py hasn't already been rewritten with a short + version string, meaning we're inside a checked out source tree. + """ + GITS = ["git"] + if sys.platform == "win32": + GITS = ["git.cmd", "git.exe"] + + out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, + hide_stderr=True) + if rc != 0: + if verbose: + print("Directory %s not under git control" % root) + raise NotThisMethod("'git rev-parse --git-dir' returned error") + + # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] + # if there isn't one, this yields HEX[-dirty] (no NUM) + describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", + "--always", "--long", + "--match", "%s*" % tag_prefix], + cwd=root) + # --long was added in git-1.5.5 + if describe_out is None: + raise NotThisMethod("'git describe' failed") + describe_out = describe_out.strip() + full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) + if full_out is None: + raise NotThisMethod("'git rev-parse' failed") + full_out = full_out.strip() + + pieces = {} + pieces["long"] = full_out + pieces["short"] = full_out[:7] # maybe improved later + pieces["error"] = None + + # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] + # TAG might have hyphens. + git_describe = describe_out + + # look for -dirty suffix + dirty = git_describe.endswith("-dirty") + pieces["dirty"] = dirty + if dirty: + git_describe = git_describe[:git_describe.rindex("-dirty")] + + # now we have TAG-NUM-gHEX or HEX + + if "-" in git_describe: + # TAG-NUM-gHEX + mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) + if not mo: + # unparseable. Maybe git-describe is misbehaving? + pieces["error"] = ("unable to parse git-describe output: '%s'" + % describe_out) + return pieces + + # tag + full_tag = mo.group(1) + if not full_tag.startswith(tag_prefix): + if verbose: + fmt = "tag '%s' doesn't start with prefix '%s'" + print(fmt % (full_tag, tag_prefix)) + pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" + % (full_tag, tag_prefix)) + return pieces + pieces["closest-tag"] = full_tag[len(tag_prefix):] + + # distance: number of commits since tag + pieces["distance"] = int(mo.group(2)) + + # commit: short hex revision ID + pieces["short"] = mo.group(3) + + else: + # HEX: no tags + pieces["closest-tag"] = None + count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], + cwd=root) + pieces["distance"] = int(count_out) # total number of commits + + # commit date: see ISO-8601 comment in git_versions_from_keywords() + date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], + cwd=root)[0].strip() + pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) + + return pieces + + +def do_vcs_install(manifest_in, versionfile_source, ipy): + """Git-specific installation logic for Versioneer. + + For Git, this means creating/changing .gitattributes to mark _version.py + for export-subst keyword substitution. + """ + GITS = ["git"] + if sys.platform == "win32": + GITS = ["git.cmd", "git.exe"] + files = [manifest_in, versionfile_source] + if ipy: + files.append(ipy) + try: + me = __file__ + if me.endswith(".pyc") or me.endswith(".pyo"): + me = os.path.splitext(me)[0] + ".py" + versioneer_file = os.path.relpath(me) + except NameError: + versioneer_file = "versioneer.py" + files.append(versioneer_file) + present = False + try: + f = open(".gitattributes", "r") + for line in f.readlines(): + if line.strip().startswith(versionfile_source): + if "export-subst" in line.strip().split()[1:]: + present = True + f.close() + except EnvironmentError: + pass + if not present: + f = open(".gitattributes", "a+") + f.write("%s export-subst\n" % versionfile_source) + f.close() + files.append(".gitattributes") + run_command(GITS, ["add", "--"] + files) + + +def versions_from_parentdir(parentdir_prefix, root, verbose): + """Try to determine the version from the parent directory name. + + Source tarballs conventionally unpack into a directory that includes both + the project name and a version string. We will also support searching up + two directory levels for an appropriately named parent directory + """ + rootdirs = [] + + for i in range(3): + dirname = os.path.basename(root) + if dirname.startswith(parentdir_prefix): + return {"version": dirname[len(parentdir_prefix):], + "full-revisionid": None, + "dirty": False, "error": None, "date": None} + else: + rootdirs.append(root) + root = os.path.dirname(root) # up a level + + if verbose: + print("Tried directories %s but none started with prefix %s" % + (str(rootdirs), parentdir_prefix)) + raise NotThisMethod("rootdir doesn't start with parentdir_prefix") + + +SHORT_VERSION_PY = """ +# This file was generated by 'versioneer.py' (0.18) from +# revision-control system data, or from the parent directory name of an +# unpacked source archive. Distribution tarballs contain a pre-generated copy +# of this file. + +import json + +version_json = ''' +%s +''' # END VERSION_JSON + + +def get_versions(): + return json.loads(version_json) +""" + + +def versions_from_file(filename): + """Try to determine the version from _version.py if present.""" + try: + with open(filename) as f: + contents = f.read() + except EnvironmentError: + raise NotThisMethod("unable to read _version.py") + mo = re.search(r"version_json = '''\n(.*)''' # END VERSION_JSON", + contents, re.M | re.S) + if not mo: + mo = re.search(r"version_json = '''\r\n(.*)''' # END VERSION_JSON", + contents, re.M | re.S) + if not mo: + raise NotThisMethod("no version_json in _version.py") + return json.loads(mo.group(1)) + + +def write_to_version_file(filename, versions): + """Write the given version number to the given _version.py file.""" + os.unlink(filename) + contents = json.dumps(versions, sort_keys=True, + indent=1, separators=(",", ": ")) + with open(filename, "w") as f: + f.write(SHORT_VERSION_PY % contents) + + print("set %s to '%s'" % (filename, versions["version"])) + + +def plus_or_dot(pieces): + """Return a + if we don't already have one, else return a .""" + if "+" in pieces.get("closest-tag", ""): + return "." + return "+" + + +def render_pep440(pieces): + """Build up version string, with post-release "local version identifier". + + Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you + get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty + + Exceptions: + 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += plus_or_dot(pieces) + rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0+untagged.%d.g%s" % (pieces["distance"], + pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def render_pep440_pre(pieces): + """TAG[.post.devDISTANCE] -- No -dirty. + + Exceptions: + 1: no tags. 0.post.devDISTANCE + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"]: + rendered += ".post.dev%d" % pieces["distance"] + else: + # exception #1 + rendered = "0.post.dev%d" % pieces["distance"] + return rendered + + +def render_pep440_post(pieces): + """TAG[.postDISTANCE[.dev0]+gHEX] . + + The ".dev0" means dirty. Note that .dev0 sorts backwards + (a dirty tree will appear "older" than the corresponding clean one), + but you shouldn't be releasing software with -dirty anyways. + + Exceptions: + 1: no tags. 0.postDISTANCE[.dev0] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "g%s" % pieces["short"] + else: + # exception #1 + rendered = "0.post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + rendered += "+g%s" % pieces["short"] + return rendered + + +def render_pep440_old(pieces): + """TAG[.postDISTANCE[.dev0]] . + + The ".dev0" means dirty. + + Eexceptions: + 1: no tags. 0.postDISTANCE[.dev0] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + else: + # exception #1 + rendered = "0.post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + return rendered + + +def render_git_describe(pieces): + """TAG[-DISTANCE-gHEX][-dirty]. + + Like 'git describe --tags --dirty --always'. + + Exceptions: + 1: no tags. HEX[-dirty] (note: no 'g' prefix) + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"]: + rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) + else: + # exception #1 + rendered = pieces["short"] + if pieces["dirty"]: + rendered += "-dirty" + return rendered + + +def render_git_describe_long(pieces): + """TAG-DISTANCE-gHEX[-dirty]. + + Like 'git describe --tags --dirty --always -long'. + The distance/hash is unconditional. + + Exceptions: + 1: no tags. HEX[-dirty] (note: no 'g' prefix) + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) + else: + # exception #1 + rendered = pieces["short"] + if pieces["dirty"]: + rendered += "-dirty" + return rendered + + +def render(pieces, style): + """Render the given version pieces into the requested style.""" + if pieces["error"]: + return {"version": "unknown", + "full-revisionid": pieces.get("long"), + "dirty": None, + "error": pieces["error"], + "date": None} + + if not style or style == "default": + style = "pep440" # the default + + if style == "pep440": + rendered = render_pep440(pieces) + elif style == "pep440-pre": + rendered = render_pep440_pre(pieces) + elif style == "pep440-post": + rendered = render_pep440_post(pieces) + elif style == "pep440-old": + rendered = render_pep440_old(pieces) + elif style == "git-describe": + rendered = render_git_describe(pieces) + elif style == "git-describe-long": + rendered = render_git_describe_long(pieces) + else: + raise ValueError("unknown style '%s'" % style) + + return {"version": rendered, "full-revisionid": pieces["long"], + "dirty": pieces["dirty"], "error": None, + "date": pieces.get("date")} + + +class VersioneerBadRootError(Exception): + """The project root directory is unknown or missing key files.""" + + +def get_versions(verbose=False): + """Get the project version from whatever source is available. + + Returns dict with two keys: 'version' and 'full'. + """ + if "versioneer" in sys.modules: + # see the discussion in cmdclass.py:get_cmdclass() + del sys.modules["versioneer"] + + root = get_root() + cfg = get_config_from_root(root) + + assert cfg.VCS is not None, "please set [versioneer]VCS= in setup.cfg" + handlers = HANDLERS.get(cfg.VCS) + assert handlers, "unrecognized VCS '%s'" % cfg.VCS + verbose = verbose or cfg.verbose + assert cfg.versionfile_source is not None, \ + "please set versioneer.versionfile_source" + assert cfg.tag_prefix is not None, "please set versioneer.tag_prefix" + + versionfile_abs = os.path.join(root, cfg.versionfile_source) + + # extract version from first of: _version.py, VCS command (e.g. 'git + # describe'), parentdir. This is meant to work for developers using a + # source checkout, for users of a tarball created by 'setup.py sdist', + # and for users of a tarball/zipball created by 'git archive' or github's + # download-from-tag feature or the equivalent in other VCSes. + + get_keywords_f = handlers.get("get_keywords") + from_keywords_f = handlers.get("keywords") + if get_keywords_f and from_keywords_f: + try: + keywords = get_keywords_f(versionfile_abs) + ver = from_keywords_f(keywords, cfg.tag_prefix, verbose) + if verbose: + print("got version from expanded keyword %s" % ver) + return ver + except NotThisMethod: + pass + + try: + ver = versions_from_file(versionfile_abs) + if verbose: + print("got version from file %s %s" % (versionfile_abs, ver)) + return ver + except NotThisMethod: + pass + + from_vcs_f = handlers.get("pieces_from_vcs") + if from_vcs_f: + try: + pieces = from_vcs_f(cfg.tag_prefix, root, verbose) + ver = render(pieces, cfg.style) + if verbose: + print("got version from VCS %s" % ver) + return ver + except NotThisMethod: + pass + + try: + if cfg.parentdir_prefix: + ver = versions_from_parentdir(cfg.parentdir_prefix, root, verbose) + if verbose: + print("got version from parentdir %s" % ver) + return ver + except NotThisMethod: + pass + + if verbose: + print("unable to compute version") + + return {"version": "0+unknown", "full-revisionid": None, + "dirty": None, "error": "unable to compute version", + "date": None} + + +def get_version(): + """Get the short version string for this project.""" + return get_versions()["version"] + + +def get_cmdclass(): + """Get the custom setuptools/distutils subclasses used by Versioneer.""" + if "versioneer" in sys.modules: + del sys.modules["versioneer"] + # this fixes the "python setup.py develop" case (also 'install' and + # 'easy_install .'), in which subdependencies of the main project are + # built (using setup.py bdist_egg) in the same python process. Assume + # a main project A and a dependency B, which use different versions + # of Versioneer. A's setup.py imports A's Versioneer, leaving it in + # sys.modules by the time B's setup.py is executed, causing B to run + # with the wrong versioneer. Setuptools wraps the sub-dep builds in a + # sandbox that restores sys.modules to it's pre-build state, so the + # parent is protected against the child's "import versioneer". By + # removing ourselves from sys.modules here, before the child build + # happens, we protect the child from the parent's versioneer too. + # Also see https://github.com/warner/python-versioneer/issues/52 + + cmds = {} + + # we add "version" to both distutils and setuptools + from distutils.core import Command + + class cmd_version(Command): + description = "report generated version string" + user_options = [] + boolean_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + vers = get_versions(verbose=True) + print("Version: %s" % vers["version"]) + print(" full-revisionid: %s" % vers.get("full-revisionid")) + print(" dirty: %s" % vers.get("dirty")) + print(" date: %s" % vers.get("date")) + if vers["error"]: + print(" error: %s" % vers["error"]) + cmds["version"] = cmd_version + + # we override "build_py" in both distutils and setuptools + # + # most invocation pathways end up running build_py: + # distutils/build -> build_py + # distutils/install -> distutils/build ->.. + # setuptools/bdist_wheel -> distutils/install ->.. + # setuptools/bdist_egg -> distutils/install_lib -> build_py + # setuptools/install -> bdist_egg ->.. + # setuptools/develop -> ? + # pip install: + # copies source tree to a tempdir before running egg_info/etc + # if .git isn't copied too, 'git describe' will fail + # then does setup.py bdist_wheel, or sometimes setup.py install + # setup.py egg_info -> ? + + # we override different "build_py" commands for both environments + if "setuptools" in sys.modules: + from setuptools.command.build_py import build_py as _build_py + else: + from distutils.command.build_py import build_py as _build_py + + class cmd_build_py(_build_py): + def run(self): + root = get_root() + cfg = get_config_from_root(root) + versions = get_versions() + _build_py.run(self) + # now locate _version.py in the new build/ directory and replace + # it with an updated value + if cfg.versionfile_build: + target_versionfile = os.path.join(self.build_lib, + cfg.versionfile_build) + print("UPDATING %s" % target_versionfile) + write_to_version_file(target_versionfile, versions) + cmds["build_py"] = cmd_build_py + + if "cx_Freeze" in sys.modules: # cx_freeze enabled? + from cx_Freeze.dist import build_exe as _build_exe + # nczeczulin reports that py2exe won't like the pep440-style string + # as FILEVERSION, but it can be used for PRODUCTVERSION, e.g. + # setup(console=[{ + # "version": versioneer.get_version().split("+", 1)[0], # FILEVERSION + # "product_version": versioneer.get_version(), + # ... + + class cmd_build_exe(_build_exe): + def run(self): + root = get_root() + cfg = get_config_from_root(root) + versions = get_versions() + target_versionfile = cfg.versionfile_source + print("UPDATING %s" % target_versionfile) + write_to_version_file(target_versionfile, versions) + + _build_exe.run(self) + os.unlink(target_versionfile) + with open(cfg.versionfile_source, "w") as f: + LONG = LONG_VERSION_PY[cfg.VCS] + f.write(LONG % + {"DOLLAR": "$", + "STYLE": cfg.style, + "TAG_PREFIX": cfg.tag_prefix, + "PARENTDIR_PREFIX": cfg.parentdir_prefix, + "VERSIONFILE_SOURCE": cfg.versionfile_source, + }) + cmds["build_exe"] = cmd_build_exe + del cmds["build_py"] + + if 'py2exe' in sys.modules: # py2exe enabled? + try: + from py2exe.distutils_buildexe import py2exe as _py2exe # py3 + except ImportError: + from py2exe.build_exe import py2exe as _py2exe # py2 + + class cmd_py2exe(_py2exe): + def run(self): + root = get_root() + cfg = get_config_from_root(root) + versions = get_versions() + target_versionfile = cfg.versionfile_source + print("UPDATING %s" % target_versionfile) + write_to_version_file(target_versionfile, versions) + + _py2exe.run(self) + os.unlink(target_versionfile) + with open(cfg.versionfile_source, "w") as f: + LONG = LONG_VERSION_PY[cfg.VCS] + f.write(LONG % + {"DOLLAR": "$", + "STYLE": cfg.style, + "TAG_PREFIX": cfg.tag_prefix, + "PARENTDIR_PREFIX": cfg.parentdir_prefix, + "VERSIONFILE_SOURCE": cfg.versionfile_source, + }) + cmds["py2exe"] = cmd_py2exe + + # we override different "sdist" commands for both environments + if "setuptools" in sys.modules: + from setuptools.command.sdist import sdist as _sdist + else: + from distutils.command.sdist import sdist as _sdist + + class cmd_sdist(_sdist): + def run(self): + versions = get_versions() + self._versioneer_generated_versions = versions + # unless we update this, the command will keep using the old + # version + self.distribution.metadata.version = versions["version"] + return _sdist.run(self) + + def make_release_tree(self, base_dir, files): + root = get_root() + cfg = get_config_from_root(root) + _sdist.make_release_tree(self, base_dir, files) + # now locate _version.py in the new base_dir directory + # (remembering that it may be a hardlink) and replace it with an + # updated value + target_versionfile = os.path.join(base_dir, cfg.versionfile_source) + print("UPDATING %s" % target_versionfile) + write_to_version_file(target_versionfile, + self._versioneer_generated_versions) + cmds["sdist"] = cmd_sdist + + return cmds + + +CONFIG_ERROR = """ +setup.cfg is missing the necessary Versioneer configuration. You need +a section like: + + [versioneer] + VCS = git + style = pep440 + versionfile_source = src/myproject/_version.py + versionfile_build = myproject/_version.py + tag_prefix = + parentdir_prefix = myproject- + +You will also need to edit your setup.py to use the results: + + import versioneer + setup(version=versioneer.get_version(), + cmdclass=versioneer.get_cmdclass(), ...) + +Please read the docstring in ./versioneer.py for configuration instructions, +edit setup.cfg, and re-run the installer or 'python versioneer.py setup'. +""" + +SAMPLE_CONFIG = """ +# See the docstring in versioneer.py for instructions. Note that you must +# re-run 'versioneer.py setup' after changing this section, and commit the +# resulting files. + +[versioneer] +#VCS = git +#style = pep440 +#versionfile_source = +#versionfile_build = +#tag_prefix = +#parentdir_prefix = + +""" + +INIT_PY_SNIPPET = """ +from ._version import get_versions +__version__ = get_versions()['version'] +del get_versions +""" + + +def do_setup(): + """Main VCS-independent setup function for installing Versioneer.""" + root = get_root() + try: + cfg = get_config_from_root(root) + except (EnvironmentError, configparser.NoSectionError, + configparser.NoOptionError) as e: + if isinstance(e, (EnvironmentError, configparser.NoSectionError)): + print("Adding sample versioneer config to setup.cfg", + file=sys.stderr) + with open(os.path.join(root, "setup.cfg"), "a") as f: + f.write(SAMPLE_CONFIG) + print(CONFIG_ERROR, file=sys.stderr) + return 1 + + print(" creating %s" % cfg.versionfile_source) + with open(cfg.versionfile_source, "w") as f: + LONG = LONG_VERSION_PY[cfg.VCS] + f.write(LONG % {"DOLLAR": "$", + "STYLE": cfg.style, + "TAG_PREFIX": cfg.tag_prefix, + "PARENTDIR_PREFIX": cfg.parentdir_prefix, + "VERSIONFILE_SOURCE": cfg.versionfile_source, + }) + + ipy = os.path.join(os.path.dirname(cfg.versionfile_source), + "__init__.py") + if os.path.exists(ipy): + try: + with open(ipy, "r") as f: + old = f.read() + except EnvironmentError: + old = "" + if INIT_PY_SNIPPET not in old: + print(" appending to %s" % ipy) + with open(ipy, "a") as f: + f.write(INIT_PY_SNIPPET) + else: + print(" %s unmodified" % ipy) + else: + print(" %s doesn't exist, ok" % ipy) + ipy = None + + # Make sure both the top-level "versioneer.py" and versionfile_source + # (PKG/_version.py, used by runtime code) are in MANIFEST.in, so + # they'll be copied into source distributions. Pip won't be able to + # install the package without this. + manifest_in = os.path.join(root, "MANIFEST.in") + simple_includes = set() + try: + with open(manifest_in, "r") as f: + for line in f: + if line.startswith("include "): + for include in line.split()[1:]: + simple_includes.add(include) + except EnvironmentError: + pass + # That doesn't cover everything MANIFEST.in can do + # (http://docs.python.org/2/distutils/sourcedist.html#commands), so + # it might give some false negatives. Appending redundant 'include' + # lines is safe, though. + if "versioneer.py" not in simple_includes: + print(" appending 'versioneer.py' to MANIFEST.in") + with open(manifest_in, "a") as f: + f.write("include versioneer.py\n") + else: + print(" 'versioneer.py' already in MANIFEST.in") + if cfg.versionfile_source not in simple_includes: + print(" appending versionfile_source ('%s') to MANIFEST.in" % + cfg.versionfile_source) + with open(manifest_in, "a") as f: + f.write("include %s\n" % cfg.versionfile_source) + else: + print(" versionfile_source already in MANIFEST.in") + + # Make VCS-specific changes. For git, this means creating/changing + # .gitattributes to mark _version.py for export-subst keyword + # substitution. + do_vcs_install(manifest_in, cfg.versionfile_source, ipy) + return 0 + + +def scan_setup_py(): + """Validate the contents of setup.py against Versioneer's expectations.""" + found = set() + setters = False + errors = 0 + with open("setup.py", "r") as f: + for line in f.readlines(): + if "import versioneer" in line: + found.add("import") + if "versioneer.get_cmdclass()" in line: + found.add("cmdclass") + if "versioneer.get_version()" in line: + found.add("get_version") + if "versioneer.VCS" in line: + setters = True + if "versioneer.versionfile_source" in line: + setters = True + if len(found) != 3: + print("") + print("Your setup.py appears to be missing some important items") + print("(but I might be wrong). Please make sure it has something") + print("roughly like the following:") + print("") + print(" import versioneer") + print(" setup( version=versioneer.get_version(),") + print(" cmdclass=versioneer.get_cmdclass(), ...)") + print("") + errors += 1 + if setters: + print("You should remove lines like 'versioneer.VCS = ' and") + print("'versioneer.versionfile_source = ' . This configuration") + print("now lives in setup.cfg, and should be removed from setup.py") + print("") + errors += 1 + return errors + + +if __name__ == "__main__": + cmd = sys.argv[1] + if cmd == "setup": + errors = do_setup() + errors += scan_setup_py() + if errors: + sys.exit(1) From 2b28f8c1151d8cab34e9b47f656949872cb2a81a Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sat, 17 Feb 2018 22:58:23 +0100 Subject: [PATCH 02/15] feat: implement a prototype of a new parser --- .coveragerc | 9 +- AUTHORS.rst | 2 +- setup.cfg | 1 + src/brenda_parser/__init__.py | 5 + src/brenda_parser/api.py | 111 +- src/brenda_parser/cli.py | 30 + src/brenda_parser/exceptions.py | 2 + src/brenda_parser/models/__init__.py | 2 + .../{special_information.py => accession.py} | 34 +- src/brenda_parser/models/comment.py | 27 +- src/brenda_parser/models/enzyme.py | 40 +- src/brenda_parser/models/field_entry.py | 50 +- src/brenda_parser/models/protein.py | 43 +- src/brenda_parser/parsing/lexer.py | 52 +- src/brenda_parser/parsing/lextab.py | 10 + src/brenda_parser/parsing/parser.out | 1459 ++++++++++------- src/brenda_parser/parsing/parser.py | 147 +- src/brenda_parser/parsing/parsetab.py | 85 +- tests/test_parsing/data/long_comments.txt | 155 ++ tests/test_parsing/test_comments.py | 95 ++ tests/test_parsing/test_lexer.py | 2 +- tests/test_parsing/test_parser.py | 5 +- tox.ini | 3 +- 23 files changed, 1587 insertions(+), 782 deletions(-) rename src/brenda_parser/models/{special_information.py => accession.py} (62%) create mode 100644 src/brenda_parser/parsing/lextab.py create mode 100644 tests/test_parsing/data/long_comments.txt create mode 100644 tests/test_parsing/test_comments.py diff --git a/.coveragerc b/.coveragerc index edcadaf..f052d25 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,14 +1,17 @@ [paths] source = - src/brenda_parser - */site-packages/brenda_parser + src/brenda_parser + */site-packages/brenda_parser [run] branch = true source = brenda_parser - tests parallel = true +omit = + */_version.py + */lextab.py + */parsetab.py [report] show_missing = true diff --git a/AUTHORS.rst b/AUTHORS.rst index ce814bc..84a17ad 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -2,4 +2,4 @@ Authors ======= -* Moritz E. Beber - https://github.com/Midnighter/BRENDA-Parser +* `Moritz E. Beber `_ diff --git a/setup.cfg b/setup.cfg index b8f857d..c889b31 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,7 @@ install_requires = click-log ply SQLAlchemy + tqdm include_package_data = True packages = find: package_dir = diff --git a/src/brenda_parser/__init__.py b/src/brenda_parser/__init__.py index 71b2ce4..88b74d3 100644 --- a/src/brenda_parser/__init__.py +++ b/src/brenda_parser/__init__.py @@ -38,3 +38,8 @@ from ._version import get_versions __version__ = get_versions()['version'] del get_versions + + +from brenda_parser.exceptions import * +from brenda_parser.models import * +from brenda_parser.api import * diff --git a/src/brenda_parser/api.py b/src/brenda_parser/api.py index 8679c3b..8f8c107 100644 --- a/src/brenda_parser/api.py +++ b/src/brenda_parser/api.py @@ -29,22 +29,129 @@ """Provide an API to the BRENDA parser.""" -from __future__ import absolute_import +from __future__ import absolute_import, division import logging +import multiprocessing +import re +from warnings import warn from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker +from tqdm import tqdm import brenda_parser.models as models +from brenda_parser.parsing import BRENDAParser, BRENDALexer + +__all__ = ("initialize", "parse") LOGGER = logging.getLogger(__name__) +EC_PATTERN = re.compile(r"ID\t((\d+)\.(\d+)\.(\d+)\.(\d+))") + Session = sessionmaker() -def initialize_db(connection="sqlite:///:memory:"): +def init_worker(engine): + global lexer + global parser + global session + lexer = BRENDALexer(optimize=1) + parser = BRENDAParser(lexer=lexer, optimize=1) + session = Session(bind=engine) + + +def worker(section): + global parser + global session + enzyme = parser.parse(section, session) + if enzyme is None: + match = EC_PATTERN.match(section) + return False, match.group(1) + else: + return True, enzyme + + +def initialize(connection="sqlite:///:memory:"): engine = create_engine(connection) session = Session(bind=engine) models.Base.metadata.create_all(engine, checkfirst=True) models.InformationField.preload(session) return engine, session + + +def parse(lines, connection="sqlite:///:memory:", processes=1): + """ + Parse each section of the BRENDA flat file into an enzyme model. + + Parameters + ---------- + lines : list + The BRENDA flat file download as a list of strings. + connection : str, optional + An rfc1738 compatible database connection string. + processes : int, optional + The number of processes to use. + + Returns + ------- + Session + A database session that can be queried using the various data models. + + """ + engine, session = initialize(connection) + start = 1 + sections = list() + for i in range(len(lines)): + if lines[i].startswith("ID"): + start = i + continue + if lines[i].startswith("///"): + sections.append("".join(lines[start:i + 1])) + processes = min(processes, len(sections)) + if processes > 1: + multi_parse(sections, engine, processes=processes) + else: + init_worker(engine) + single_parse(sections) + return session + + +def single_parse(sections): + """ + + Parameters + ---------- + sections + + Returns + ------- + + """ + global parser + global session + for section in tqdm(sections): + enzyme = parser.parse(section, session) + if enzyme is None: + match = EC_PATTERN.match(section) + LOGGER.error("Problem with enzyme '%s'.", match.group(1)) + LOGGER.debug("%s", section) + else: + session.add(enzyme) + session.commit() + + +def multi_parse(sections, engine, processes=2): + pool = multiprocessing.Pool( + processes=processes, initializer=init_worker, initargs=(engine,)) + result_iter = pool.imap_unordered( + worker, sections, chunksize=len(sections) // processes) + with tqdm(total=len(sections)) as pbar: + for success, enzyme in result_iter: + if success: + session.add(enzyme) + session.commit() + else: + LOGGER.error("Problem with enzyme '%s'.", enzyme) + pbar.update() + pool.close() + pool.join() diff --git a/src/brenda_parser/cli.py b/src/brenda_parser/cli.py index a8b76b0..053d830 100644 --- a/src/brenda_parser/cli.py +++ b/src/brenda_parser/cli.py @@ -32,15 +32,25 @@ from __future__ import absolute_import import logging +from multiprocessing import cpu_count +from warnings import warn import click import click_log +import brenda_parser.api as api from brenda_parser import __version__ LOGGER = logging.getLogger(__name__.split(".", 1)[0]) click_log.basic_config(LOGGER) +try: + PROCESSES = cpu_count() +except NotImplementedError: + warn("Could not detect the number of CPUs - assuming 1.", + UserWarning) + PROCESSES = 1 + @click.group() @click.help_option("--help", "-h") @@ -51,3 +61,23 @@ def cli(): """Parse the BRENDA Enzyme flat file distribution to a local database.""" pass + + +@cli.command() +@click.help_option("--help", "-h") +@click.option("--filename", type=click.Path(exists=False, writable=True), + default="brenda.db", show_default=True, + help="Path to where the SQLite3 database is stored.") +@click.option("--connection", default=None, show_default=True, metavar="URL", + help="An rfc1738 compatible database URL. Overrides the " + "filename option.") +@click.option("--processes", type=int, default=PROCESSES, show_default=True, + help="The number of parallel processes to use during parsing.") +@click.argument("flat_file", type=click.Path(exists=True, dir_okay=False), + envvar="FILENAME") +def parse(flat_file, filename, connection, processes): + if connection is None: + connection = "sqlite:///{}".format(filename) + with open(flat_file) as file_handle: + lines = file_handle.readlines() + api.parse(lines, connection, processes=processes) diff --git a/src/brenda_parser/exceptions.py b/src/brenda_parser/exceptions.py index e44c440..5124d58 100644 --- a/src/brenda_parser/exceptions.py +++ b/src/brenda_parser/exceptions.py @@ -32,6 +32,8 @@ from __future__ import absolute_import +__all__ = ("ValidationError",) + class ValidationError(AssertionError): pass diff --git a/src/brenda_parser/models/__init__.py b/src/brenda_parser/models/__init__.py index 6350ed4..c34dce0 100644 --- a/src/brenda_parser/models/__init__.py +++ b/src/brenda_parser/models/__init__.py @@ -37,8 +37,10 @@ Base = declarative_base() from brenda_parser.models.information_field import * +from brenda_parser.models.accession import * from brenda_parser.models.organism import * from brenda_parser.models.reference import * from brenda_parser.models.protein import * +from brenda_parser.models.comment import * from brenda_parser.models.field_entry import * from brenda_parser.models.enzyme import * diff --git a/src/brenda_parser/models/special_information.py b/src/brenda_parser/models/accession.py similarity index 62% rename from src/brenda_parser/models/special_information.py rename to src/brenda_parser/models/accession.py index 55d59a7..7763565 100644 --- a/src/brenda_parser/models/special_information.py +++ b/src/brenda_parser/models/accession.py @@ -28,26 +28,44 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -"""Provide a data model for additional information.""" +"""Provide a data model for a protein database cross reference.""" from __future__ import absolute_import import logging +import re -from sqlalchemy import Column, Text -from sqlalchemy.orm import relationship +from sqlalchemy import Column, Integer, String +from sqlalchemy.orm import relationship, validates from brenda_parser.models import Base +from brenda_parser.exceptions import ValidationError -__all__ = ("SpecialInformation",) +__all__ = ("Accession",) LOGGER = logging.getLogger(__name__) -class SpecialInformation(Base): +class Accession(Base): - __tablename__ = "special" + __tablename__ = "accession" + # http://identifiers.org/uniprot/ + UNIPROT_PATTERN = re.compile( + r"([A-NR-Z][0-9]([A-Z][A-Z0-9][A-Z0-9][0-9]){1,2})|" + r"([OPQ][0-9][A-Z0-9][A-Z0-9][A-Z0-9][0-9])(\.\d+)?") + + id = Column(Integer, primary_key=True) + accession = Column(String(255), nullable=False, unique=True, index=True) + database = Column(String(255), nullable=True) proteins = relationship("Protein") - commentary = Column(Text()) - citations = relationship("Reference") + + @validates("accession") + def validate_accession(self, key, value): + if value is None: + return value + if self.UNIPROT_PATTERN.match(value) is None: + raise ValidationError( + "'{}' does not match the required pattern '{}'." + "".format(value, self.UNIPROT_PATTERN)) + return value diff --git a/src/brenda_parser/models/comment.py b/src/brenda_parser/models/comment.py index 92d7f7e..8fad56d 100644 --- a/src/brenda_parser/models/comment.py +++ b/src/brenda_parser/models/comment.py @@ -34,7 +34,7 @@ import logging -from sqlalchemy import Column, Text +from sqlalchemy import Table, Column, String, Integer, ForeignKey from sqlalchemy.orm import relationship from brenda_parser.models import Base @@ -44,11 +44,30 @@ LOGGER = logging.getLogger(__name__) +comment_protein_association = Table( + "comment_protein_association", + Base.metadata, + Column('comment_id', Integer, ForeignKey('comment.id')), + Column('protein_id', Integer, ForeignKey('protein.id')) +) + + +comment_citation_association = Table( + "comment_citation_association", + Base.metadata, + Column('comment_id', Integer, ForeignKey('comment.id')), + Column('reference_id', Integer, ForeignKey('reference.id')) +) + + class Comment(Base): __tablename__ = "comment" - proteins = relationship("Protein") - commentary = Column(Text()) - citations = relationship("Reference") + id = Column(Integer, primary_key=True) + body = Column(String(255)) + proteins = relationship("Protein", + secondary=comment_protein_association) + citations = relationship("Reference", + secondary=comment_citation_association) diff --git a/src/brenda_parser/models/enzyme.py b/src/brenda_parser/models/enzyme.py index 9a02beb..25a4b9d 100644 --- a/src/brenda_parser/models/enzyme.py +++ b/src/brenda_parser/models/enzyme.py @@ -33,12 +33,10 @@ from __future__ import absolute_import import logging -import re -from sqlalchemy import Column, Integer, String, ForeignKey -from sqlalchemy.orm import validates, relationship +from sqlalchemy import Table, Column, Integer, String, ForeignKey +from sqlalchemy.orm import relationship -from brenda_parser.exceptions import ValidationError from brenda_parser.models import Base __all__ = ("Enzyme",) @@ -46,17 +44,39 @@ LOGGER = logging.getLogger(__name__) +enzyme_entry_association = Table( + "enzyme_entry_association", + Base.metadata, + Column('enzyme_id', Integer, ForeignKey('enzyme.id')), + Column('fieldentry_id', Integer, ForeignKey('fieldentry.id')) +) + + +enzyme_comment_association = Table( + "enzyme_comment_association", + Base.metadata, + Column('enzyme_id', Integer, ForeignKey('enzyme.id')), + Column('comment_id', Integer, ForeignKey('comment.id')) +) + + class Enzyme(Base): """Represent a complete enzyme classification (EC) number section.""" __tablename__ = "enzyme" id = Column(Integer, primary_key=True) - ec_number = Column(String(19)) + ec_number = Column(String(19), nullable=False) + entries = relationship("FieldEntry", secondary=enzyme_entry_association) + comments = relationship("Comment", secondary=enzyme_comment_association) + # proteins = relationship("PR") # # TODO: The following relationships should be established by joins on # # 'field' selecting specific acronyms. - # proteins = relationship("PR") - # recommended_names = relationship("RN") + # recommended_names = relationship( + # "FieldEntry", + # secondary=enzyme_entry_association, + # secondaryjoin="FieldEntry.field.acronym == 'RN'" + # ) # systematic_names = relationship("SN") # synonyms = relationship("SY") # reactions = relationship("RE") @@ -98,7 +118,5 @@ class Enzyme(Base): def __init__(self, **kwargs): super(Enzyme, self).__init__(**kwargs) - self.entries = list() - self.proteins = list() - self.references = list() - self.comments = list() + self.protein_references = list() + self.citation_references = list() diff --git a/src/brenda_parser/models/field_entry.py b/src/brenda_parser/models/field_entry.py index 3100a5f..c2bb7b2 100644 --- a/src/brenda_parser/models/field_entry.py +++ b/src/brenda_parser/models/field_entry.py @@ -33,12 +33,10 @@ from __future__ import absolute_import import logging -import re -from sqlalchemy import Column, Integer, String, ForeignKey -from sqlalchemy.orm import validates, relationship +from sqlalchemy import Table, Column, Integer, String, ForeignKey +from sqlalchemy.orm import relationship -from brenda_parser.exceptions import ValidationError from brenda_parser.models import Base __all__ = ("FieldEntry",) @@ -46,6 +44,30 @@ LOGGER = logging.getLogger(__name__) +fieldentry_protein_association = Table( + "fieldentry_protein_association", + Base.metadata, + Column('fieldentry_id', Integer, ForeignKey('fieldentry.id')), + Column('protein_id', Integer, ForeignKey('protein.id')) +) + + +fieldentry_citation_association = Table( + "fieldentry_citation_association", + Base.metadata, + Column('fieldentry_id', Integer, ForeignKey('fieldentry.id')), + Column('reference_id', Integer, ForeignKey('reference.id')) +) + + +fieldentry_comment_association = Table( + "fieldentry_comment_association", + Base.metadata, + Column('fieldentry_id', Integer, ForeignKey('fieldentry.id')), + Column('comment_id', Integer, ForeignKey('comment.id')) +) + + class FieldEntry(Base): __tablename__ = "fieldentry" @@ -55,22 +77,24 @@ class FieldEntry(Base): field = relationship("InformationField") # The `body` might have to be Text. body = Column(String(255), nullable=False) - # enzyme_id = Column(Integer, ForeignKey("enzyme.id")) - # enzyme = relationship("Enzyme") - # proteins = relationship("Protein") - # citations = relationship("Reference") - # comments = relationship("Comment") - # special_information = relationship("SpecialInformation") + special = Column(String(255), nullable=True) + enzyme_id = Column(Integer, ForeignKey("enzyme.id")) + enzyme = relationship("Enzyme") + proteins = relationship("Protein", + secondary=fieldentry_protein_association) + citations = relationship("Reference", + secondary=fieldentry_citation_association) + comments = relationship("Comment", + secondary=fieldentry_comment_association) def __init__(self, **kwargs): """ Instantiate an entry with extra attributes. The attributes are used to hold the integer references to proteins - and citations. These are later replaced with actual relationships - when an entire enzyme section is completed. + and citations. These are later replaced with actual relationships. + """ super(FieldEntry, self).__init__(**kwargs) self.protein_references = list() self.citation_references = list() - self.comment_references = list() diff --git a/src/brenda_parser/models/protein.py b/src/brenda_parser/models/protein.py index 2e7cb58..1d2246c 100644 --- a/src/brenda_parser/models/protein.py +++ b/src/brenda_parser/models/protein.py @@ -33,9 +33,8 @@ from __future__ import absolute_import import logging -import re -from sqlalchemy import Column, Integer, String, ForeignKey +from sqlalchemy import Table, Column, Integer, ForeignKey from sqlalchemy.orm import validates, relationship from brenda_parser.exceptions import ValidationError @@ -46,39 +45,43 @@ LOGGER = logging.getLogger(__name__) +protein_citation_association = Table( + "protein_citation_association", + Base.metadata, + Column('protein_id', Integer, ForeignKey('protein.id')), + Column('reference_id', Integer, ForeignKey('reference.id')) +) + + +protein_comment_association = Table( + "protein_comment_association", + Base.metadata, + Column('protein_id', Integer, ForeignKey('protein.id')), + Column('comment_id', Integer, ForeignKey('comment.id')) +) + + class Protein(Base): __tablename__ = "protein" - # Taken from identifiers.org - UNIPROT_PATTERN = re.compile( - r"([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9]" - r"[A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\.\d+)?") - id = Column(Integer, primary_key=True) field_id = Column(Integer, ForeignKey("informationfield.id")) field = relationship("InformationField") organism_id = Column(Integer, ForeignKey("organism.id")) organism = relationship("Organism") - accession = Column(String(255), nullable=True, unique=True) - database = Column(String(255), nullable=True) - # citations = relationship("Reference") + accession_id = Column(Integer, ForeignKey("accession.id")) + accession = relationship("Accession") + citations = relationship("Reference", + secondary=protein_citation_association) + comments = relationship("Comment", + secondary=protein_comment_association) def __init__(self, **kwargs): super(Protein, self).__init__(**kwargs) self.organism_name = "" self.citation_references = list() - @validates("accession") - def validate_accession(self, key, value): - if value is None: - return value - if self.UNIPROT_PATTERN.match(value) is None: - raise ValidationError( - "'{}' does not match the required pattern '{}'." - "".format(value, self.UNIPROT_PATTERN)) - return value - @validates("field") def validate_field(self, key, value): if value.acronym != "PR": diff --git a/src/brenda_parser/parsing/lexer.py b/src/brenda_parser/parsing/lexer.py index d5bee6c..84204dc 100644 --- a/src/brenda_parser/parsing/lexer.py +++ b/src/brenda_parser/parsing/lexer.py @@ -52,10 +52,12 @@ class BRENDALexer(object): ("protein", "exclusive"), ("special", "exclusive"), ("comment", "exclusive"), + ("enzyme", "exclusive"), ("protentry", "inclusive"), ) # List of token names. This is always required. tokens = ( + "ENZYME_ENTRY", "PROTEIN", "CITATION", "ENTRY", @@ -73,18 +75,19 @@ class BRENDALexer(object): "CONTENT", "SPECIAL", "COMMENT", + "AND", "ACCESSION" ) # A string containing ignored characters interpreted literally not as regex. - t_ignore = " \t\r\f\v" # all whitespace - t_citation_protein_ignore = " ," - t_special_comment_ignore = " \t\r\f\v" + t_ignore = " \t\r\f\v" # all whitespace minus newlines + t_citation_protein_ignore = " ,\t" + t_special_comment_enzyme_ignore = " \t\r\f\v" # Regular expression rules for simple tokens are parsed after all patterns # defined in methods. - t_CONTENT = "[^\{\}\(\)\<\>\#\n]+" + t_CONTENT = "[^\{\}\(\)\<\>\# \t\r\f\v\n]+" - def __init__(self, **kw_args): + def __init__(self, **kwargs): """ Instantiate a BRENDA flat file specific lexer. @@ -100,7 +103,7 @@ def __init__(self, **kw_args): Keyword arguments are passed to the ply.lex.lex call. """ super(BRENDALexer, self).__init__() - self.lexer = lex(module=self, errorlog=LOGGER, **kw_args) + self.lexer = lex(module=self, errorlog=LOGGER, **kwargs) self.parens_level = 0 self.last_lparens = 0 self.last_rparens = 0 @@ -112,8 +115,11 @@ def __iter__(self): return (tok for tok in iter(self.lexer.token, None)) def input(self, data): - """Add a new string to the lexer. + """ + Add a new string to the lexer. + This is the setup step necessary before you can iterate over the tokens. + Parameters ---------- data : str @@ -129,12 +135,13 @@ def t_ANY_error(self, t): def t_ANY_newline(self, t): r'\n+' + LOGGER.debug("lineno %d +%d", t.lineno, len(t.value)) t.lexer.lineno += len(t.value) def t_brenda_comment(self, t): r"\*.+\n" + LOGGER.debug("lineno %d: Skipping comment line.", t.lineno) t.lexer.lineno += 1 - pass def t_POUND(self, t): r"[#]" @@ -207,12 +214,26 @@ def t_comment_RPARENS(self, t): t.type = "COMMENT" return t - def t_EC_NUMBER(self, t): + def t_END(self, t): + r"[/]{3}\s" + t.lexer.push_state("INITIAL") + t.value = t.value.strip() + return t + + def t_ENZYME_ENTRY(self, t): + r"ID\t" + t.lexer.push_state("enzyme") + t.value = t.value.strip() + return t + + def t_enzyme_EC_NUMBER(self, t): r"(\d+)\.(\d+)\.(\d+)\.(\d+)" + t.lexer.pop_state() return t - def t_END(self, t): - r"[/]{3}\s" + def t_protentry_PROTEIN_ENTRY(self, t): + r"PR\t" + t.value = t.value.strip() return t def t_protentry_ENTRY(self, t): @@ -240,9 +261,14 @@ def t_ENTRY(self, t): return t def t_brenda_header(self, t): - r"[A-Z0-9]{4,}\n" + r"[A-Z0-9_]{4,}\n" + LOGGER.debug("lineno %d: Section header '%s'.", t.lineno, + t.value.strip()) t.lexer.lineno += 1 - pass + + def t_protentry_AND(self, t): + r"AND" + return t def t_protentry_ACCESSION(self, t): r"([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\.\d+)?" diff --git a/src/brenda_parser/parsing/lextab.py b/src/brenda_parser/parsing/lextab.py new file mode 100644 index 0000000..ead6c92 --- /dev/null +++ b/src/brenda_parser/parsing/lextab.py @@ -0,0 +1,10 @@ +# lextab.py. This file automatically created by PLY (version 3.10). Don't edit! +_tabversion = '3.10' +_lextokens = set(('COMMENT', 'RCURLY', 'REFERENCE_ENTRY', 'EC_NUMBER', 'CONTENT', 'ENTRY', 'RANGLE', 'LPARENS', 'RPARENS', 'LCURLY', 'ENZYME_ENTRY', 'PROTEIN', 'END', 'LANGLE', 'SPECIAL', 'AND', 'PROTEIN_ENTRY', 'CITATION', 'POUND', 'ACCESSION')) +_lexreflags = 64 +_lexliterals = '' +_lexstateinfo = {'INITIAL': 'inclusive', 'citation': 'exclusive', 'protein': 'exclusive', 'special': 'exclusive', 'comment': 'exclusive', 'enzyme': 'exclusive', 'protentry': 'inclusive'} +_lexstatere = {'INITIAL': [('(?P\\n+)|(?P\\*.+\\n)|(?P[#])|(?P<)|(?P{)|(?P\\()|(?P[/]{3}\\s)|(?PID\\t)|(?PPR\\t)|(?PRF\\t)|(?P[A-Z0-9]{2,4}\\t)|(?P[A-Z0-9_]{4,}\\n)|(?P[^\\{\\}\\(\\)\\<\\>\\# \t\r\x0c\x0b\n]+)', [None, ('t_ANY_newline', 'newline'), ('t_brenda_comment', 'brenda_comment'), ('t_POUND', 'POUND'), ('t_LANGLE', 'LANGLE'), ('t_LCURLY', 'LCURLY'), ('t_LPARENS', 'LPARENS'), ('t_END', 'END'), ('t_ENZYME_ENTRY', 'ENZYME_ENTRY'), ('t_PROTEIN_ENTRY', 'PROTEIN_ENTRY'), ('t_REFERENCE_ENTRY', 'REFERENCE_ENTRY'), ('t_ENTRY', 'ENTRY'), ('t_brenda_header', 'brenda_header'), (None, 'CONTENT')])], 'citation': [('(?P\\n+)|(?P\\d+)|(?P>)', [None, ('t_ANY_newline', 'newline'), ('t_citation_CITATION', 'CITATION'), ('t_citation_RANGLE', 'RANGLE')])], 'protein': [('(?P\\n+)|(?P\\d+)|(?P[#])', [None, ('t_ANY_newline', 'newline'), ('t_protein_PROTEIN', 'PROTEIN'), ('t_protein_POUND', 'POUND')])], 'special': [('(?P\\n+)|(?P[^\\{\\}\\s]+)|(?P})', [None, ('t_ANY_newline', 'newline'), ('t_special_SPECIAL', 'SPECIAL'), ('t_special_RCURLY', 'RCURLY')])], 'comment': [('(?P\\n+)|(?P[^\\(\\)\\s]+)|(?P\\()|(?P\\))', [None, ('t_ANY_newline', 'newline'), ('t_comment_COMMENT', 'COMMENT'), ('t_comment_LPARENS', 'LPARENS'), ('t_comment_RPARENS', 'RPARENS')])], 'enzyme': [('(?P\\n+)|(?P(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+))', [None, ('t_ANY_newline', 'newline'), ('t_enzyme_EC_NUMBER', 'EC_NUMBER')])], 'protentry': [('(?P\\n+)|(?PPR\\t)|(?P[A-Z0-9]{2,4}\\t)|(?PAND)|(?P([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?)', [None, ('t_ANY_newline', 'newline'), ('t_protentry_PROTEIN_ENTRY', 'PROTEIN_ENTRY'), ('t_protentry_ENTRY', 'ENTRY'), ('t_protentry_AND', 'AND'), ('t_protentry_ACCESSION', 'ACCESSION')]), ('(?P\\n+)|(?P\\*.+\\n)|(?P[#])|(?P<)|(?P{)|(?P\\()|(?P[/]{3}\\s)|(?PID\\t)|(?PPR\\t)|(?PRF\\t)|(?P[A-Z0-9]{2,4}\\t)|(?P[A-Z0-9_]{4,}\\n)|(?P[^\\{\\}\\(\\)\\<\\>\\# \t\r\x0c\x0b\n]+)', [None, ('t_ANY_newline', 'newline'), ('t_brenda_comment', 'brenda_comment'), ('t_POUND', 'POUND'), ('t_LANGLE', 'LANGLE'), ('t_LCURLY', 'LCURLY'), ('t_LPARENS', 'LPARENS'), ('t_END', 'END'), ('t_ENZYME_ENTRY', 'ENZYME_ENTRY'), ('t_PROTEIN_ENTRY', 'PROTEIN_ENTRY'), ('t_REFERENCE_ENTRY', 'REFERENCE_ENTRY'), ('t_ENTRY', 'ENTRY'), ('t_brenda_header', 'brenda_header'), (None, 'CONTENT')])]} +_lexstateignore = {'citation': ' ,\t', 'protein': ' ,\t', 'INITIAL': ' \t\r\x0c\x0b', 'special': ' \t\r\x0c\x0b', 'comment': ' \t\r\x0c\x0b', 'enzyme': ' \t\r\x0c\x0b', 'protentry': ' \t\r\x0c\x0b'} +_lexstateerrorf = {'INITIAL': 't_ANY_error', 'citation': 't_ANY_error', 'protein': 't_ANY_error', 'special': 't_ANY_error', 'comment': 't_ANY_error', 'enzyme': 't_ANY_error', 'protentry': 't_ANY_error'} +_lexstateeoff = {} diff --git a/src/brenda_parser/parsing/parser.out b/src/brenda_parser/parsing/parser.out index 6eabc02..9058129 100644 --- a/src/brenda_parser/parsing/parser.out +++ b/src/brenda_parser/parsing/parser.out @@ -3,7 +3,7 @@ Created by PLY version 3.10 (http://www.dabeaz.com/ply) Grammar Rule 0 S' -> enzyme -Rule 1 enzyme -> ENTRY EC_NUMBER new_enzyme +Rule 1 enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme Rule 2 new_enzyme -> Rule 3 enzyme -> enzyme comment Rule 4 enzyme -> enzyme protein_entry @@ -13,84 +13,94 @@ Rule 7 enzyme -> enzyme END Rule 8 entry -> ENTRY new_entry Rule 9 new_entry -> Rule 10 entry -> entry CONTENT -Rule 11 entry -> entry comment -Rule 12 reference_entry -> REFERENCE_ENTRY new_reference citations -Rule 13 new_reference -> -Rule 14 reference_entry -> reference_entry CONTENT -Rule 15 reference_entry -> reference_entry comment -Rule 16 reference_entry -> reference_entry special -Rule 17 protein_entry -> PROTEIN_ENTRY new_protein proteins -Rule 18 new_protein -> -Rule 19 protein_entry -> protein_entry CONTENT -Rule 20 protein_entry -> protein_entry ACCESSION CONTENT -Rule 21 protein_entry -> protein_entry citations -Rule 22 special -> LCURLY special RCURLY -Rule 23 special -> LCURLY RCURLY -Rule 24 special -> special SPECIAL -Rule 25 special -> SPECIAL -Rule 26 proteins -> POUND proteins POUND -Rule 27 proteins -> POUND POUND -Rule 28 proteins -> proteins PROTEIN -Rule 29 proteins -> PROTEIN -Rule 30 citations -> LANGLE citations RANGLE -Rule 31 citations -> LANGLE RANGLE -Rule 32 citations -> citations CITATION -Rule 33 citations -> CITATION -Rule 34 comment -> LPARENS comment RPARENS -Rule 35 comment -> LPARENS RPARENS -Rule 36 comment -> comment COMMENT -Rule 37 comment -> COMMENT +Rule 11 entry -> entry proteins +Rule 12 entry -> entry comment +Rule 13 entry -> entry special +Rule 14 entry -> entry citations +Rule 15 reference_entry -> REFERENCE_ENTRY new_reference citations +Rule 16 new_reference -> +Rule 17 reference_entry -> reference_entry CONTENT +Rule 18 reference_entry -> reference_entry comment +Rule 19 reference_entry -> reference_entry special +Rule 20 protein_entry -> PROTEIN_ENTRY new_protein proteins +Rule 21 new_protein -> +Rule 22 protein_entry -> protein_entry CONTENT +Rule 23 protein_entry -> protein_entry accession +Rule 24 protein_entry -> protein_entry comment +Rule 25 protein_entry -> protein_entry citations +Rule 26 accession -> accession AND ACCESSION +Rule 27 accession -> accession CONTENT +Rule 28 accession -> ACCESSION +Rule 29 special -> LCURLY special RCURLY +Rule 30 special -> LCURLY RCURLY +Rule 31 special -> special SPECIAL +Rule 32 special -> SPECIAL +Rule 33 proteins -> POUND proteins POUND +Rule 34 proteins -> POUND POUND +Rule 35 proteins -> proteins PROTEIN +Rule 36 proteins -> PROTEIN +Rule 37 citations -> LANGLE citations RANGLE +Rule 38 citations -> LANGLE RANGLE +Rule 39 citations -> citations CITATION +Rule 40 citations -> CITATION +Rule 41 comment -> LPARENS comment RPARENS +Rule 42 comment -> LPARENS RPARENS +Rule 43 comment -> comment COMMENT +Rule 44 comment -> COMMENT Terminals, with rules where they appear -ACCESSION : 20 -CITATION : 32 33 -COMMENT : 36 37 -CONTENT : 10 14 19 20 +ACCESSION : 26 28 +AND : 26 +CITATION : 39 40 +COMMENT : 43 44 +CONTENT : 10 17 22 27 EC_NUMBER : 1 END : 7 -ENTRY : 1 8 -LANGLE : 30 31 -LCURLY : 22 23 -LPARENS : 34 35 -POUND : 26 26 27 27 -PROTEIN : 28 29 -PROTEIN_ENTRY : 17 -RANGLE : 30 31 -RCURLY : 22 23 -REFERENCE_ENTRY : 12 -RPARENS : 34 35 -SPECIAL : 24 25 +ENTRY : 8 +ENZYME_ENTRY : 1 +LANGLE : 37 38 +LCURLY : 29 30 +LPARENS : 41 42 +POUND : 33 33 34 34 +PROTEIN : 35 36 +PROTEIN_ENTRY : 20 +RANGLE : 37 38 +RCURLY : 29 30 +REFERENCE_ENTRY : 15 +RPARENS : 41 42 +SPECIAL : 31 32 error : Nonterminals, with rules where they appear -citations : 12 21 30 32 -comment : 3 11 15 34 36 -entry : 6 10 11 +accession : 23 26 27 +citations : 14 15 25 37 39 +comment : 3 12 18 24 41 43 +entry : 6 10 11 12 13 14 enzyme : 3 4 5 6 7 0 new_entry : 8 new_enzyme : 1 -new_protein : 17 -new_reference : 12 -protein_entry : 4 19 20 21 -proteins : 17 26 28 -reference_entry : 5 14 15 16 -special : 16 22 24 +new_protein : 20 +new_reference : 15 +protein_entry : 4 22 23 24 25 +proteins : 11 20 33 35 +reference_entry : 5 17 18 19 +special : 13 19 29 31 Parsing method: LALR state 0 (0) S' -> . enzyme - (1) enzyme -> . ENTRY EC_NUMBER new_enzyme + (1) enzyme -> . ENZYME_ENTRY EC_NUMBER new_enzyme (3) enzyme -> . enzyme comment (4) enzyme -> . enzyme protein_entry (5) enzyme -> . enzyme reference_entry (6) enzyme -> . enzyme entry (7) enzyme -> . enzyme END - ENTRY shift and go to state 2 + ENZYME_ENTRY shift and go to state 2 enzyme shift and go to state 1 @@ -102,21 +112,25 @@ state 1 (5) enzyme -> enzyme . reference_entry (6) enzyme -> enzyme . entry (7) enzyme -> enzyme . END - (34) comment -> . LPARENS comment RPARENS - (35) comment -> . LPARENS RPARENS - (36) comment -> . comment COMMENT - (37) comment -> . COMMENT - (17) protein_entry -> . PROTEIN_ENTRY new_protein proteins - (19) protein_entry -> . protein_entry CONTENT - (20) protein_entry -> . protein_entry ACCESSION CONTENT - (21) protein_entry -> . protein_entry citations - (12) reference_entry -> . REFERENCE_ENTRY new_reference citations - (14) reference_entry -> . reference_entry CONTENT - (15) reference_entry -> . reference_entry comment - (16) reference_entry -> . reference_entry special + (41) comment -> . LPARENS comment RPARENS + (42) comment -> . LPARENS RPARENS + (43) comment -> . comment COMMENT + (44) comment -> . COMMENT + (20) protein_entry -> . PROTEIN_ENTRY new_protein proteins + (22) protein_entry -> . protein_entry CONTENT + (23) protein_entry -> . protein_entry accession + (24) protein_entry -> . protein_entry comment + (25) protein_entry -> . protein_entry citations + (15) reference_entry -> . REFERENCE_ENTRY new_reference citations + (17) reference_entry -> . reference_entry CONTENT + (18) reference_entry -> . reference_entry comment + (19) reference_entry -> . reference_entry special (8) entry -> . ENTRY new_entry (10) entry -> . entry CONTENT - (11) entry -> . entry comment + (11) entry -> . entry proteins + (12) entry -> . entry comment + (13) entry -> . entry special + (14) entry -> . entry citations END shift and go to state 7 LPARENS shift and go to state 8 @@ -132,7 +146,7 @@ state 1 state 2 - (1) enzyme -> ENTRY . EC_NUMBER new_enzyme + (1) enzyme -> ENZYME_ENTRY . EC_NUMBER new_enzyme EC_NUMBER shift and go to state 13 @@ -140,99 +154,143 @@ state 2 state 3 (3) enzyme -> enzyme comment . - (36) comment -> comment . COMMENT + (43) comment -> comment . COMMENT + ! shift/reduce conflict for COMMENT resolved as shift END reduce using rule 3 (enzyme -> enzyme comment .) LPARENS reduce using rule 3 (enzyme -> enzyme comment .) - COMMENT reduce using rule 3 (enzyme -> enzyme comment .) PROTEIN_ENTRY reduce using rule 3 (enzyme -> enzyme comment .) REFERENCE_ENTRY reduce using rule 3 (enzyme -> enzyme comment .) ENTRY reduce using rule 3 (enzyme -> enzyme comment .) $end reduce using rule 3 (enzyme -> enzyme comment .) + COMMENT shift and go to state 14 - ! COMMENT [ shift and go to state 14 ] + ! COMMENT [ reduce using rule 3 (enzyme -> enzyme comment .) ] state 4 (4) enzyme -> enzyme protein_entry . - (19) protein_entry -> protein_entry . CONTENT - (20) protein_entry -> protein_entry . ACCESSION CONTENT - (21) protein_entry -> protein_entry . citations - (30) citations -> . LANGLE citations RANGLE - (31) citations -> . LANGLE RANGLE - (32) citations -> . citations CITATION - (33) citations -> . CITATION - + (22) protein_entry -> protein_entry . CONTENT + (23) protein_entry -> protein_entry . accession + (24) protein_entry -> protein_entry . comment + (25) protein_entry -> protein_entry . citations + (26) accession -> . accession AND ACCESSION + (27) accession -> . accession CONTENT + (28) accession -> . ACCESSION + (41) comment -> . LPARENS comment RPARENS + (42) comment -> . LPARENS RPARENS + (43) comment -> . comment COMMENT + (44) comment -> . COMMENT + (37) citations -> . LANGLE citations RANGLE + (38) citations -> . LANGLE RANGLE + (39) citations -> . citations CITATION + (40) citations -> . CITATION + + ! shift/reduce conflict for LPARENS resolved as shift + ! shift/reduce conflict for COMMENT resolved as shift END reduce using rule 4 (enzyme -> enzyme protein_entry .) - LPARENS reduce using rule 4 (enzyme -> enzyme protein_entry .) - COMMENT reduce using rule 4 (enzyme -> enzyme protein_entry .) PROTEIN_ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) REFERENCE_ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) $end reduce using rule 4 (enzyme -> enzyme protein_entry .) CONTENT shift and go to state 15 - ACCESSION shift and go to state 16 - LANGLE shift and go to state 18 - CITATION shift and go to state 19 + ACCESSION shift and go to state 19 + LPARENS shift and go to state 8 + COMMENT shift and go to state 9 + LANGLE shift and go to state 20 + CITATION shift and go to state 21 - citations shift and go to state 17 + ! LPARENS [ reduce using rule 4 (enzyme -> enzyme protein_entry .) ] + ! COMMENT [ reduce using rule 4 (enzyme -> enzyme protein_entry .) ] + + accession shift and go to state 16 + comment shift and go to state 17 + citations shift and go to state 18 state 5 (5) enzyme -> enzyme reference_entry . - (14) reference_entry -> reference_entry . CONTENT - (15) reference_entry -> reference_entry . comment - (16) reference_entry -> reference_entry . special - (34) comment -> . LPARENS comment RPARENS - (35) comment -> . LPARENS RPARENS - (36) comment -> . comment COMMENT - (37) comment -> . COMMENT - (22) special -> . LCURLY special RCURLY - (23) special -> . LCURLY RCURLY - (24) special -> . special SPECIAL - (25) special -> . SPECIAL - + (17) reference_entry -> reference_entry . CONTENT + (18) reference_entry -> reference_entry . comment + (19) reference_entry -> reference_entry . special + (41) comment -> . LPARENS comment RPARENS + (42) comment -> . LPARENS RPARENS + (43) comment -> . comment COMMENT + (44) comment -> . COMMENT + (29) special -> . LCURLY special RCURLY + (30) special -> . LCURLY RCURLY + (31) special -> . special SPECIAL + (32) special -> . SPECIAL + + ! shift/reduce conflict for LPARENS resolved as shift + ! shift/reduce conflict for COMMENT resolved as shift END reduce using rule 5 (enzyme -> enzyme reference_entry .) - LPARENS reduce using rule 5 (enzyme -> enzyme reference_entry .) - COMMENT reduce using rule 5 (enzyme -> enzyme reference_entry .) PROTEIN_ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) REFERENCE_ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) $end reduce using rule 5 (enzyme -> enzyme reference_entry .) - CONTENT shift and go to state 20 - LCURLY shift and go to state 23 - SPECIAL shift and go to state 24 + CONTENT shift and go to state 22 + LPARENS shift and go to state 8 + COMMENT shift and go to state 9 + LCURLY shift and go to state 25 + SPECIAL shift and go to state 26 - ! LPARENS [ shift and go to state 8 ] - ! COMMENT [ shift and go to state 9 ] + ! LPARENS [ reduce using rule 5 (enzyme -> enzyme reference_entry .) ] + ! COMMENT [ reduce using rule 5 (enzyme -> enzyme reference_entry .) ] - comment shift and go to state 21 - special shift and go to state 22 + comment shift and go to state 23 + special shift and go to state 24 state 6 (6) enzyme -> enzyme entry . (10) entry -> entry . CONTENT - (11) entry -> entry . comment - (34) comment -> . LPARENS comment RPARENS - (35) comment -> . LPARENS RPARENS - (36) comment -> . comment COMMENT - (37) comment -> . COMMENT - + (11) entry -> entry . proteins + (12) entry -> entry . comment + (13) entry -> entry . special + (14) entry -> entry . citations + (33) proteins -> . POUND proteins POUND + (34) proteins -> . POUND POUND + (35) proteins -> . proteins PROTEIN + (36) proteins -> . PROTEIN + (41) comment -> . LPARENS comment RPARENS + (42) comment -> . LPARENS RPARENS + (43) comment -> . comment COMMENT + (44) comment -> . COMMENT + (29) special -> . LCURLY special RCURLY + (30) special -> . LCURLY RCURLY + (31) special -> . special SPECIAL + (32) special -> . SPECIAL + (37) citations -> . LANGLE citations RANGLE + (38) citations -> . LANGLE RANGLE + (39) citations -> . citations CITATION + (40) citations -> . CITATION + + ! shift/reduce conflict for LPARENS resolved as shift + ! shift/reduce conflict for COMMENT resolved as shift END reduce using rule 6 (enzyme -> enzyme entry .) - LPARENS reduce using rule 6 (enzyme -> enzyme entry .) - COMMENT reduce using rule 6 (enzyme -> enzyme entry .) PROTEIN_ENTRY reduce using rule 6 (enzyme -> enzyme entry .) REFERENCE_ENTRY reduce using rule 6 (enzyme -> enzyme entry .) ENTRY reduce using rule 6 (enzyme -> enzyme entry .) $end reduce using rule 6 (enzyme -> enzyme entry .) - CONTENT shift and go to state 25 + CONTENT shift and go to state 27 + POUND shift and go to state 32 + PROTEIN shift and go to state 33 + LPARENS shift and go to state 8 + COMMENT shift and go to state 9 + LCURLY shift and go to state 25 + SPECIAL shift and go to state 26 + LANGLE shift and go to state 20 + CITATION shift and go to state 21 - ! LPARENS [ shift and go to state 8 ] - ! COMMENT [ shift and go to state 9 ] + ! LPARENS [ reduce using rule 6 (enzyme -> enzyme entry .) ] + ! COMMENT [ reduce using rule 6 (enzyme -> enzyme entry .) ] - comment shift and go to state 26 + proteins shift and go to state 28 + comment shift and go to state 29 + special shift and go to state 30 + citations shift and go to state 31 state 7 @@ -249,55 +307,60 @@ state 7 state 8 - (34) comment -> LPARENS . comment RPARENS - (35) comment -> LPARENS . RPARENS - (34) comment -> . LPARENS comment RPARENS - (35) comment -> . LPARENS RPARENS - (36) comment -> . comment COMMENT - (37) comment -> . COMMENT + (41) comment -> LPARENS . comment RPARENS + (42) comment -> LPARENS . RPARENS + (41) comment -> . LPARENS comment RPARENS + (42) comment -> . LPARENS RPARENS + (43) comment -> . comment COMMENT + (44) comment -> . COMMENT - RPARENS shift and go to state 28 + RPARENS shift and go to state 35 LPARENS shift and go to state 8 COMMENT shift and go to state 9 - comment shift and go to state 27 + comment shift and go to state 34 state 9 - (37) comment -> COMMENT . - - COMMENT reduce using rule 37 (comment -> COMMENT .) - END reduce using rule 37 (comment -> COMMENT .) - LPARENS reduce using rule 37 (comment -> COMMENT .) - PROTEIN_ENTRY reduce using rule 37 (comment -> COMMENT .) - REFERENCE_ENTRY reduce using rule 37 (comment -> COMMENT .) - ENTRY reduce using rule 37 (comment -> COMMENT .) - $end reduce using rule 37 (comment -> COMMENT .) - CONTENT reduce using rule 37 (comment -> COMMENT .) - LCURLY reduce using rule 37 (comment -> COMMENT .) - SPECIAL reduce using rule 37 (comment -> COMMENT .) - RPARENS reduce using rule 37 (comment -> COMMENT .) + (44) comment -> COMMENT . + + COMMENT reduce using rule 44 (comment -> COMMENT .) + END reduce using rule 44 (comment -> COMMENT .) + LPARENS reduce using rule 44 (comment -> COMMENT .) + PROTEIN_ENTRY reduce using rule 44 (comment -> COMMENT .) + REFERENCE_ENTRY reduce using rule 44 (comment -> COMMENT .) + ENTRY reduce using rule 44 (comment -> COMMENT .) + $end reduce using rule 44 (comment -> COMMENT .) + CONTENT reduce using rule 44 (comment -> COMMENT .) + ACCESSION reduce using rule 44 (comment -> COMMENT .) + LANGLE reduce using rule 44 (comment -> COMMENT .) + CITATION reduce using rule 44 (comment -> COMMENT .) + LCURLY reduce using rule 44 (comment -> COMMENT .) + SPECIAL reduce using rule 44 (comment -> COMMENT .) + POUND reduce using rule 44 (comment -> COMMENT .) + PROTEIN reduce using rule 44 (comment -> COMMENT .) + RPARENS reduce using rule 44 (comment -> COMMENT .) state 10 - (17) protein_entry -> PROTEIN_ENTRY . new_protein proteins - (18) new_protein -> . + (20) protein_entry -> PROTEIN_ENTRY . new_protein proteins + (21) new_protein -> . - POUND reduce using rule 18 (new_protein -> .) - PROTEIN reduce using rule 18 (new_protein -> .) + POUND reduce using rule 21 (new_protein -> .) + PROTEIN reduce using rule 21 (new_protein -> .) - new_protein shift and go to state 29 + new_protein shift and go to state 36 state 11 - (12) reference_entry -> REFERENCE_ENTRY . new_reference citations - (13) new_reference -> . + (15) reference_entry -> REFERENCE_ENTRY . new_reference citations + (16) new_reference -> . - LANGLE reduce using rule 13 (new_reference -> .) - CITATION reduce using rule 13 (new_reference -> .) + LANGLE reduce using rule 16 (new_reference -> .) + CITATION reduce using rule 16 (new_reference -> .) - new_reference shift and go to state 30 + new_reference shift and go to state 37 state 12 @@ -305,19 +368,25 @@ state 12 (9) new_entry -> . CONTENT reduce using rule 9 (new_entry -> .) + POUND reduce using rule 9 (new_entry -> .) + PROTEIN reduce using rule 9 (new_entry -> .) LPARENS reduce using rule 9 (new_entry -> .) COMMENT reduce using rule 9 (new_entry -> .) + LCURLY reduce using rule 9 (new_entry -> .) + SPECIAL reduce using rule 9 (new_entry -> .) + LANGLE reduce using rule 9 (new_entry -> .) + CITATION reduce using rule 9 (new_entry -> .) END reduce using rule 9 (new_entry -> .) PROTEIN_ENTRY reduce using rule 9 (new_entry -> .) REFERENCE_ENTRY reduce using rule 9 (new_entry -> .) ENTRY reduce using rule 9 (new_entry -> .) $end reduce using rule 9 (new_entry -> .) - new_entry shift and go to state 31 + new_entry shift and go to state 38 state 13 - (1) enzyme -> ENTRY EC_NUMBER . new_enzyme + (1) enzyme -> ENZYME_ENTRY EC_NUMBER . new_enzyme (2) new_enzyme -> . END reduce using rule 2 (new_enzyme -> .) @@ -328,612 +397,828 @@ state 13 ENTRY reduce using rule 2 (new_enzyme -> .) $end reduce using rule 2 (new_enzyme -> .) - new_enzyme shift and go to state 32 + new_enzyme shift and go to state 39 state 14 - (36) comment -> comment COMMENT . - - COMMENT reduce using rule 36 (comment -> comment COMMENT .) - END reduce using rule 36 (comment -> comment COMMENT .) - LPARENS reduce using rule 36 (comment -> comment COMMENT .) - PROTEIN_ENTRY reduce using rule 36 (comment -> comment COMMENT .) - REFERENCE_ENTRY reduce using rule 36 (comment -> comment COMMENT .) - ENTRY reduce using rule 36 (comment -> comment COMMENT .) - $end reduce using rule 36 (comment -> comment COMMENT .) - CONTENT reduce using rule 36 (comment -> comment COMMENT .) - LCURLY reduce using rule 36 (comment -> comment COMMENT .) - SPECIAL reduce using rule 36 (comment -> comment COMMENT .) - RPARENS reduce using rule 36 (comment -> comment COMMENT .) + (43) comment -> comment COMMENT . + + COMMENT reduce using rule 43 (comment -> comment COMMENT .) + END reduce using rule 43 (comment -> comment COMMENT .) + LPARENS reduce using rule 43 (comment -> comment COMMENT .) + PROTEIN_ENTRY reduce using rule 43 (comment -> comment COMMENT .) + REFERENCE_ENTRY reduce using rule 43 (comment -> comment COMMENT .) + ENTRY reduce using rule 43 (comment -> comment COMMENT .) + $end reduce using rule 43 (comment -> comment COMMENT .) + CONTENT reduce using rule 43 (comment -> comment COMMENT .) + ACCESSION reduce using rule 43 (comment -> comment COMMENT .) + LANGLE reduce using rule 43 (comment -> comment COMMENT .) + CITATION reduce using rule 43 (comment -> comment COMMENT .) + LCURLY reduce using rule 43 (comment -> comment COMMENT .) + SPECIAL reduce using rule 43 (comment -> comment COMMENT .) + POUND reduce using rule 43 (comment -> comment COMMENT .) + PROTEIN reduce using rule 43 (comment -> comment COMMENT .) + RPARENS reduce using rule 43 (comment -> comment COMMENT .) state 15 - (19) protein_entry -> protein_entry CONTENT . + (22) protein_entry -> protein_entry CONTENT . - CONTENT reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - ACCESSION reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - LANGLE reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - CITATION reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - END reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - LPARENS reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - COMMENT reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - PROTEIN_ENTRY reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - REFERENCE_ENTRY reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - ENTRY reduce using rule 19 (protein_entry -> protein_entry CONTENT .) - $end reduce using rule 19 (protein_entry -> protein_entry CONTENT .) + CONTENT reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + ACCESSION reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + LPARENS reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + COMMENT reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + LANGLE reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + CITATION reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + END reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + PROTEIN_ENTRY reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + REFERENCE_ENTRY reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + ENTRY reduce using rule 22 (protein_entry -> protein_entry CONTENT .) + $end reduce using rule 22 (protein_entry -> protein_entry CONTENT .) state 16 - (20) protein_entry -> protein_entry ACCESSION . CONTENT + (23) protein_entry -> protein_entry accession . + (26) accession -> accession . AND ACCESSION + (27) accession -> accession . CONTENT - CONTENT shift and go to state 33 + CONTENT reduce using rule 23 (protein_entry -> protein_entry accession .) + ACCESSION reduce using rule 23 (protein_entry -> protein_entry accession .) + LPARENS reduce using rule 23 (protein_entry -> protein_entry accession .) + COMMENT reduce using rule 23 (protein_entry -> protein_entry accession .) + LANGLE reduce using rule 23 (protein_entry -> protein_entry accession .) + CITATION reduce using rule 23 (protein_entry -> protein_entry accession .) + END reduce using rule 23 (protein_entry -> protein_entry accession .) + PROTEIN_ENTRY reduce using rule 23 (protein_entry -> protein_entry accession .) + REFERENCE_ENTRY reduce using rule 23 (protein_entry -> protein_entry accession .) + ENTRY reduce using rule 23 (protein_entry -> protein_entry accession .) + $end reduce using rule 23 (protein_entry -> protein_entry accession .) + AND shift and go to state 40 + ! CONTENT [ shift and go to state 41 ] -state 17 - (21) protein_entry -> protein_entry citations . - (32) citations -> citations . CITATION +state 17 - CONTENT reduce using rule 21 (protein_entry -> protein_entry citations .) - ACCESSION reduce using rule 21 (protein_entry -> protein_entry citations .) - LANGLE reduce using rule 21 (protein_entry -> protein_entry citations .) - CITATION reduce using rule 21 (protein_entry -> protein_entry citations .) - END reduce using rule 21 (protein_entry -> protein_entry citations .) - LPARENS reduce using rule 21 (protein_entry -> protein_entry citations .) - COMMENT reduce using rule 21 (protein_entry -> protein_entry citations .) - PROTEIN_ENTRY reduce using rule 21 (protein_entry -> protein_entry citations .) - REFERENCE_ENTRY reduce using rule 21 (protein_entry -> protein_entry citations .) - ENTRY reduce using rule 21 (protein_entry -> protein_entry citations .) - $end reduce using rule 21 (protein_entry -> protein_entry citations .) + (24) protein_entry -> protein_entry comment . + (43) comment -> comment . COMMENT + + CONTENT reduce using rule 24 (protein_entry -> protein_entry comment .) + ACCESSION reduce using rule 24 (protein_entry -> protein_entry comment .) + LPARENS reduce using rule 24 (protein_entry -> protein_entry comment .) + COMMENT reduce using rule 24 (protein_entry -> protein_entry comment .) + LANGLE reduce using rule 24 (protein_entry -> protein_entry comment .) + CITATION reduce using rule 24 (protein_entry -> protein_entry comment .) + END reduce using rule 24 (protein_entry -> protein_entry comment .) + PROTEIN_ENTRY reduce using rule 24 (protein_entry -> protein_entry comment .) + REFERENCE_ENTRY reduce using rule 24 (protein_entry -> protein_entry comment .) + ENTRY reduce using rule 24 (protein_entry -> protein_entry comment .) + $end reduce using rule 24 (protein_entry -> protein_entry comment .) - ! CITATION [ shift and go to state 34 ] + ! COMMENT [ shift and go to state 14 ] state 18 - (30) citations -> LANGLE . citations RANGLE - (31) citations -> LANGLE . RANGLE - (30) citations -> . LANGLE citations RANGLE - (31) citations -> . LANGLE RANGLE - (32) citations -> . citations CITATION - (33) citations -> . CITATION + (25) protein_entry -> protein_entry citations . + (39) citations -> citations . CITATION + + CONTENT reduce using rule 25 (protein_entry -> protein_entry citations .) + ACCESSION reduce using rule 25 (protein_entry -> protein_entry citations .) + LPARENS reduce using rule 25 (protein_entry -> protein_entry citations .) + COMMENT reduce using rule 25 (protein_entry -> protein_entry citations .) + LANGLE reduce using rule 25 (protein_entry -> protein_entry citations .) + CITATION reduce using rule 25 (protein_entry -> protein_entry citations .) + END reduce using rule 25 (protein_entry -> protein_entry citations .) + PROTEIN_ENTRY reduce using rule 25 (protein_entry -> protein_entry citations .) + REFERENCE_ENTRY reduce using rule 25 (protein_entry -> protein_entry citations .) + ENTRY reduce using rule 25 (protein_entry -> protein_entry citations .) + $end reduce using rule 25 (protein_entry -> protein_entry citations .) - RANGLE shift and go to state 36 - LANGLE shift and go to state 18 - CITATION shift and go to state 19 + ! CITATION [ shift and go to state 42 ] - citations shift and go to state 35 state 19 - (33) citations -> CITATION . + (28) accession -> ACCESSION . - CITATION reduce using rule 33 (citations -> CITATION .) - CONTENT reduce using rule 33 (citations -> CITATION .) - ACCESSION reduce using rule 33 (citations -> CITATION .) - LANGLE reduce using rule 33 (citations -> CITATION .) - END reduce using rule 33 (citations -> CITATION .) - LPARENS reduce using rule 33 (citations -> CITATION .) - COMMENT reduce using rule 33 (citations -> CITATION .) - PROTEIN_ENTRY reduce using rule 33 (citations -> CITATION .) - REFERENCE_ENTRY reduce using rule 33 (citations -> CITATION .) - ENTRY reduce using rule 33 (citations -> CITATION .) - $end reduce using rule 33 (citations -> CITATION .) - RANGLE reduce using rule 33 (citations -> CITATION .) - LCURLY reduce using rule 33 (citations -> CITATION .) - SPECIAL reduce using rule 33 (citations -> CITATION .) + AND reduce using rule 28 (accession -> ACCESSION .) + CONTENT reduce using rule 28 (accession -> ACCESSION .) + ACCESSION reduce using rule 28 (accession -> ACCESSION .) + LPARENS reduce using rule 28 (accession -> ACCESSION .) + COMMENT reduce using rule 28 (accession -> ACCESSION .) + LANGLE reduce using rule 28 (accession -> ACCESSION .) + CITATION reduce using rule 28 (accession -> ACCESSION .) + END reduce using rule 28 (accession -> ACCESSION .) + PROTEIN_ENTRY reduce using rule 28 (accession -> ACCESSION .) + REFERENCE_ENTRY reduce using rule 28 (accession -> ACCESSION .) + ENTRY reduce using rule 28 (accession -> ACCESSION .) + $end reduce using rule 28 (accession -> ACCESSION .) state 20 - (14) reference_entry -> reference_entry CONTENT . + (37) citations -> LANGLE . citations RANGLE + (38) citations -> LANGLE . RANGLE + (37) citations -> . LANGLE citations RANGLE + (38) citations -> . LANGLE RANGLE + (39) citations -> . citations CITATION + (40) citations -> . CITATION - CONTENT reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - LPARENS reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - COMMENT reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - LCURLY reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - SPECIAL reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - END reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - PROTEIN_ENTRY reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - REFERENCE_ENTRY reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - ENTRY reduce using rule 14 (reference_entry -> reference_entry CONTENT .) - $end reduce using rule 14 (reference_entry -> reference_entry CONTENT .) + RANGLE shift and go to state 44 + LANGLE shift and go to state 20 + CITATION shift and go to state 21 + citations shift and go to state 43 state 21 - (15) reference_entry -> reference_entry comment . - (36) comment -> comment . COMMENT - - CONTENT reduce using rule 15 (reference_entry -> reference_entry comment .) - LPARENS reduce using rule 15 (reference_entry -> reference_entry comment .) - COMMENT reduce using rule 15 (reference_entry -> reference_entry comment .) - LCURLY reduce using rule 15 (reference_entry -> reference_entry comment .) - SPECIAL reduce using rule 15 (reference_entry -> reference_entry comment .) - END reduce using rule 15 (reference_entry -> reference_entry comment .) - PROTEIN_ENTRY reduce using rule 15 (reference_entry -> reference_entry comment .) - REFERENCE_ENTRY reduce using rule 15 (reference_entry -> reference_entry comment .) - ENTRY reduce using rule 15 (reference_entry -> reference_entry comment .) - $end reduce using rule 15 (reference_entry -> reference_entry comment .) - - ! COMMENT [ shift and go to state 14 ] + (40) citations -> CITATION . + + CITATION reduce using rule 40 (citations -> CITATION .) + CONTENT reduce using rule 40 (citations -> CITATION .) + ACCESSION reduce using rule 40 (citations -> CITATION .) + LPARENS reduce using rule 40 (citations -> CITATION .) + COMMENT reduce using rule 40 (citations -> CITATION .) + LANGLE reduce using rule 40 (citations -> CITATION .) + END reduce using rule 40 (citations -> CITATION .) + PROTEIN_ENTRY reduce using rule 40 (citations -> CITATION .) + REFERENCE_ENTRY reduce using rule 40 (citations -> CITATION .) + ENTRY reduce using rule 40 (citations -> CITATION .) + $end reduce using rule 40 (citations -> CITATION .) + POUND reduce using rule 40 (citations -> CITATION .) + PROTEIN reduce using rule 40 (citations -> CITATION .) + LCURLY reduce using rule 40 (citations -> CITATION .) + SPECIAL reduce using rule 40 (citations -> CITATION .) + RANGLE reduce using rule 40 (citations -> CITATION .) state 22 - (16) reference_entry -> reference_entry special . - (24) special -> special . SPECIAL - - CONTENT reduce using rule 16 (reference_entry -> reference_entry special .) - LPARENS reduce using rule 16 (reference_entry -> reference_entry special .) - COMMENT reduce using rule 16 (reference_entry -> reference_entry special .) - LCURLY reduce using rule 16 (reference_entry -> reference_entry special .) - SPECIAL reduce using rule 16 (reference_entry -> reference_entry special .) - END reduce using rule 16 (reference_entry -> reference_entry special .) - PROTEIN_ENTRY reduce using rule 16 (reference_entry -> reference_entry special .) - REFERENCE_ENTRY reduce using rule 16 (reference_entry -> reference_entry special .) - ENTRY reduce using rule 16 (reference_entry -> reference_entry special .) - $end reduce using rule 16 (reference_entry -> reference_entry special .) + (17) reference_entry -> reference_entry CONTENT . - ! SPECIAL [ shift and go to state 37 ] + CONTENT reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + LPARENS reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + COMMENT reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + LCURLY reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + SPECIAL reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + END reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + PROTEIN_ENTRY reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + REFERENCE_ENTRY reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + ENTRY reduce using rule 17 (reference_entry -> reference_entry CONTENT .) + $end reduce using rule 17 (reference_entry -> reference_entry CONTENT .) state 23 - (22) special -> LCURLY . special RCURLY - (23) special -> LCURLY . RCURLY - (22) special -> . LCURLY special RCURLY - (23) special -> . LCURLY RCURLY - (24) special -> . special SPECIAL - (25) special -> . SPECIAL + (18) reference_entry -> reference_entry comment . + (43) comment -> comment . COMMENT - RCURLY shift and go to state 39 - LCURLY shift and go to state 23 - SPECIAL shift and go to state 24 + CONTENT reduce using rule 18 (reference_entry -> reference_entry comment .) + LPARENS reduce using rule 18 (reference_entry -> reference_entry comment .) + COMMENT reduce using rule 18 (reference_entry -> reference_entry comment .) + LCURLY reduce using rule 18 (reference_entry -> reference_entry comment .) + SPECIAL reduce using rule 18 (reference_entry -> reference_entry comment .) + END reduce using rule 18 (reference_entry -> reference_entry comment .) + PROTEIN_ENTRY reduce using rule 18 (reference_entry -> reference_entry comment .) + REFERENCE_ENTRY reduce using rule 18 (reference_entry -> reference_entry comment .) + ENTRY reduce using rule 18 (reference_entry -> reference_entry comment .) + $end reduce using rule 18 (reference_entry -> reference_entry comment .) + + ! COMMENT [ shift and go to state 14 ] - special shift and go to state 38 state 24 - (25) special -> SPECIAL . + (19) reference_entry -> reference_entry special . + (31) special -> special . SPECIAL + + CONTENT reduce using rule 19 (reference_entry -> reference_entry special .) + LPARENS reduce using rule 19 (reference_entry -> reference_entry special .) + COMMENT reduce using rule 19 (reference_entry -> reference_entry special .) + LCURLY reduce using rule 19 (reference_entry -> reference_entry special .) + SPECIAL reduce using rule 19 (reference_entry -> reference_entry special .) + END reduce using rule 19 (reference_entry -> reference_entry special .) + PROTEIN_ENTRY reduce using rule 19 (reference_entry -> reference_entry special .) + REFERENCE_ENTRY reduce using rule 19 (reference_entry -> reference_entry special .) + ENTRY reduce using rule 19 (reference_entry -> reference_entry special .) + $end reduce using rule 19 (reference_entry -> reference_entry special .) - SPECIAL reduce using rule 25 (special -> SPECIAL .) - CONTENT reduce using rule 25 (special -> SPECIAL .) - LPARENS reduce using rule 25 (special -> SPECIAL .) - COMMENT reduce using rule 25 (special -> SPECIAL .) - LCURLY reduce using rule 25 (special -> SPECIAL .) - END reduce using rule 25 (special -> SPECIAL .) - PROTEIN_ENTRY reduce using rule 25 (special -> SPECIAL .) - REFERENCE_ENTRY reduce using rule 25 (special -> SPECIAL .) - ENTRY reduce using rule 25 (special -> SPECIAL .) - $end reduce using rule 25 (special -> SPECIAL .) - RCURLY reduce using rule 25 (special -> SPECIAL .) + ! SPECIAL [ shift and go to state 45 ] state 25 - (10) entry -> entry CONTENT . + (29) special -> LCURLY . special RCURLY + (30) special -> LCURLY . RCURLY + (29) special -> . LCURLY special RCURLY + (30) special -> . LCURLY RCURLY + (31) special -> . special SPECIAL + (32) special -> . SPECIAL - CONTENT reduce using rule 10 (entry -> entry CONTENT .) - LPARENS reduce using rule 10 (entry -> entry CONTENT .) - COMMENT reduce using rule 10 (entry -> entry CONTENT .) - END reduce using rule 10 (entry -> entry CONTENT .) - PROTEIN_ENTRY reduce using rule 10 (entry -> entry CONTENT .) - REFERENCE_ENTRY reduce using rule 10 (entry -> entry CONTENT .) - ENTRY reduce using rule 10 (entry -> entry CONTENT .) - $end reduce using rule 10 (entry -> entry CONTENT .) + RCURLY shift and go to state 47 + LCURLY shift and go to state 25 + SPECIAL shift and go to state 26 + special shift and go to state 46 state 26 - (11) entry -> entry comment . - (36) comment -> comment . COMMENT - - CONTENT reduce using rule 11 (entry -> entry comment .) - LPARENS reduce using rule 11 (entry -> entry comment .) - COMMENT reduce using rule 11 (entry -> entry comment .) - END reduce using rule 11 (entry -> entry comment .) - PROTEIN_ENTRY reduce using rule 11 (entry -> entry comment .) - REFERENCE_ENTRY reduce using rule 11 (entry -> entry comment .) - ENTRY reduce using rule 11 (entry -> entry comment .) - $end reduce using rule 11 (entry -> entry comment .) - - ! COMMENT [ shift and go to state 14 ] + (32) special -> SPECIAL . + + SPECIAL reduce using rule 32 (special -> SPECIAL .) + CONTENT reduce using rule 32 (special -> SPECIAL .) + LPARENS reduce using rule 32 (special -> SPECIAL .) + COMMENT reduce using rule 32 (special -> SPECIAL .) + LCURLY reduce using rule 32 (special -> SPECIAL .) + END reduce using rule 32 (special -> SPECIAL .) + PROTEIN_ENTRY reduce using rule 32 (special -> SPECIAL .) + REFERENCE_ENTRY reduce using rule 32 (special -> SPECIAL .) + ENTRY reduce using rule 32 (special -> SPECIAL .) + $end reduce using rule 32 (special -> SPECIAL .) + POUND reduce using rule 32 (special -> SPECIAL .) + PROTEIN reduce using rule 32 (special -> SPECIAL .) + LANGLE reduce using rule 32 (special -> SPECIAL .) + CITATION reduce using rule 32 (special -> SPECIAL .) + RCURLY reduce using rule 32 (special -> SPECIAL .) state 27 - (34) comment -> LPARENS comment . RPARENS - (36) comment -> comment . COMMENT + (10) entry -> entry CONTENT . - RPARENS shift and go to state 40 - COMMENT shift and go to state 14 + CONTENT reduce using rule 10 (entry -> entry CONTENT .) + POUND reduce using rule 10 (entry -> entry CONTENT .) + PROTEIN reduce using rule 10 (entry -> entry CONTENT .) + LPARENS reduce using rule 10 (entry -> entry CONTENT .) + COMMENT reduce using rule 10 (entry -> entry CONTENT .) + LCURLY reduce using rule 10 (entry -> entry CONTENT .) + SPECIAL reduce using rule 10 (entry -> entry CONTENT .) + LANGLE reduce using rule 10 (entry -> entry CONTENT .) + CITATION reduce using rule 10 (entry -> entry CONTENT .) + END reduce using rule 10 (entry -> entry CONTENT .) + PROTEIN_ENTRY reduce using rule 10 (entry -> entry CONTENT .) + REFERENCE_ENTRY reduce using rule 10 (entry -> entry CONTENT .) + ENTRY reduce using rule 10 (entry -> entry CONTENT .) + $end reduce using rule 10 (entry -> entry CONTENT .) state 28 - (35) comment -> LPARENS RPARENS . + (11) entry -> entry proteins . + (35) proteins -> proteins . PROTEIN + + CONTENT reduce using rule 11 (entry -> entry proteins .) + POUND reduce using rule 11 (entry -> entry proteins .) + PROTEIN reduce using rule 11 (entry -> entry proteins .) + LPARENS reduce using rule 11 (entry -> entry proteins .) + COMMENT reduce using rule 11 (entry -> entry proteins .) + LCURLY reduce using rule 11 (entry -> entry proteins .) + SPECIAL reduce using rule 11 (entry -> entry proteins .) + LANGLE reduce using rule 11 (entry -> entry proteins .) + CITATION reduce using rule 11 (entry -> entry proteins .) + END reduce using rule 11 (entry -> entry proteins .) + PROTEIN_ENTRY reduce using rule 11 (entry -> entry proteins .) + REFERENCE_ENTRY reduce using rule 11 (entry -> entry proteins .) + ENTRY reduce using rule 11 (entry -> entry proteins .) + $end reduce using rule 11 (entry -> entry proteins .) - COMMENT reduce using rule 35 (comment -> LPARENS RPARENS .) - END reduce using rule 35 (comment -> LPARENS RPARENS .) - LPARENS reduce using rule 35 (comment -> LPARENS RPARENS .) - PROTEIN_ENTRY reduce using rule 35 (comment -> LPARENS RPARENS .) - REFERENCE_ENTRY reduce using rule 35 (comment -> LPARENS RPARENS .) - ENTRY reduce using rule 35 (comment -> LPARENS RPARENS .) - $end reduce using rule 35 (comment -> LPARENS RPARENS .) - CONTENT reduce using rule 35 (comment -> LPARENS RPARENS .) - LCURLY reduce using rule 35 (comment -> LPARENS RPARENS .) - SPECIAL reduce using rule 35 (comment -> LPARENS RPARENS .) - RPARENS reduce using rule 35 (comment -> LPARENS RPARENS .) + ! PROTEIN [ shift and go to state 48 ] state 29 - (17) protein_entry -> PROTEIN_ENTRY new_protein . proteins - (26) proteins -> . POUND proteins POUND - (27) proteins -> . POUND POUND - (28) proteins -> . proteins PROTEIN - (29) proteins -> . PROTEIN + (12) entry -> entry comment . + (43) comment -> comment . COMMENT + + CONTENT reduce using rule 12 (entry -> entry comment .) + POUND reduce using rule 12 (entry -> entry comment .) + PROTEIN reduce using rule 12 (entry -> entry comment .) + LPARENS reduce using rule 12 (entry -> entry comment .) + COMMENT reduce using rule 12 (entry -> entry comment .) + LCURLY reduce using rule 12 (entry -> entry comment .) + SPECIAL reduce using rule 12 (entry -> entry comment .) + LANGLE reduce using rule 12 (entry -> entry comment .) + CITATION reduce using rule 12 (entry -> entry comment .) + END reduce using rule 12 (entry -> entry comment .) + PROTEIN_ENTRY reduce using rule 12 (entry -> entry comment .) + REFERENCE_ENTRY reduce using rule 12 (entry -> entry comment .) + ENTRY reduce using rule 12 (entry -> entry comment .) + $end reduce using rule 12 (entry -> entry comment .) - POUND shift and go to state 42 - PROTEIN shift and go to state 43 + ! COMMENT [ shift and go to state 14 ] - proteins shift and go to state 41 state 30 - (12) reference_entry -> REFERENCE_ENTRY new_reference . citations - (30) citations -> . LANGLE citations RANGLE - (31) citations -> . LANGLE RANGLE - (32) citations -> . citations CITATION - (33) citations -> . CITATION + (13) entry -> entry special . + (31) special -> special . SPECIAL + + CONTENT reduce using rule 13 (entry -> entry special .) + POUND reduce using rule 13 (entry -> entry special .) + PROTEIN reduce using rule 13 (entry -> entry special .) + LPARENS reduce using rule 13 (entry -> entry special .) + COMMENT reduce using rule 13 (entry -> entry special .) + LCURLY reduce using rule 13 (entry -> entry special .) + SPECIAL reduce using rule 13 (entry -> entry special .) + LANGLE reduce using rule 13 (entry -> entry special .) + CITATION reduce using rule 13 (entry -> entry special .) + END reduce using rule 13 (entry -> entry special .) + PROTEIN_ENTRY reduce using rule 13 (entry -> entry special .) + REFERENCE_ENTRY reduce using rule 13 (entry -> entry special .) + ENTRY reduce using rule 13 (entry -> entry special .) + $end reduce using rule 13 (entry -> entry special .) - LANGLE shift and go to state 18 - CITATION shift and go to state 19 + ! SPECIAL [ shift and go to state 45 ] - citations shift and go to state 44 state 31 - (8) entry -> ENTRY new_entry . + (14) entry -> entry citations . + (39) citations -> citations . CITATION - CONTENT reduce using rule 8 (entry -> ENTRY new_entry .) - LPARENS reduce using rule 8 (entry -> ENTRY new_entry .) - COMMENT reduce using rule 8 (entry -> ENTRY new_entry .) - END reduce using rule 8 (entry -> ENTRY new_entry .) - PROTEIN_ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) - REFERENCE_ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) - ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) - $end reduce using rule 8 (entry -> ENTRY new_entry .) + CONTENT reduce using rule 14 (entry -> entry citations .) + POUND reduce using rule 14 (entry -> entry citations .) + PROTEIN reduce using rule 14 (entry -> entry citations .) + LPARENS reduce using rule 14 (entry -> entry citations .) + COMMENT reduce using rule 14 (entry -> entry citations .) + LCURLY reduce using rule 14 (entry -> entry citations .) + SPECIAL reduce using rule 14 (entry -> entry citations .) + LANGLE reduce using rule 14 (entry -> entry citations .) + CITATION reduce using rule 14 (entry -> entry citations .) + END reduce using rule 14 (entry -> entry citations .) + PROTEIN_ENTRY reduce using rule 14 (entry -> entry citations .) + REFERENCE_ENTRY reduce using rule 14 (entry -> entry citations .) + ENTRY reduce using rule 14 (entry -> entry citations .) + $end reduce using rule 14 (entry -> entry citations .) + + ! CITATION [ shift and go to state 42 ] state 32 - (1) enzyme -> ENTRY EC_NUMBER new_enzyme . + (33) proteins -> POUND . proteins POUND + (34) proteins -> POUND . POUND + (33) proteins -> . POUND proteins POUND + (34) proteins -> . POUND POUND + (35) proteins -> . proteins PROTEIN + (36) proteins -> . PROTEIN - END reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) - LPARENS reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) - COMMENT reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) - PROTEIN_ENTRY reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) - REFERENCE_ENTRY reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) - ENTRY reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) - $end reduce using rule 1 (enzyme -> ENTRY EC_NUMBER new_enzyme .) + POUND shift and go to state 49 + PROTEIN shift and go to state 33 + proteins shift and go to state 50 state 33 - (20) protein_entry -> protein_entry ACCESSION CONTENT . - - CONTENT reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - ACCESSION reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - LANGLE reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - CITATION reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - END reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - LPARENS reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - COMMENT reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - PROTEIN_ENTRY reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - REFERENCE_ENTRY reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - ENTRY reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) - $end reduce using rule 20 (protein_entry -> protein_entry ACCESSION CONTENT .) + (36) proteins -> PROTEIN . + + PROTEIN reduce using rule 36 (proteins -> PROTEIN .) + CONTENT reduce using rule 36 (proteins -> PROTEIN .) + POUND reduce using rule 36 (proteins -> PROTEIN .) + LPARENS reduce using rule 36 (proteins -> PROTEIN .) + COMMENT reduce using rule 36 (proteins -> PROTEIN .) + LCURLY reduce using rule 36 (proteins -> PROTEIN .) + SPECIAL reduce using rule 36 (proteins -> PROTEIN .) + LANGLE reduce using rule 36 (proteins -> PROTEIN .) + CITATION reduce using rule 36 (proteins -> PROTEIN .) + END reduce using rule 36 (proteins -> PROTEIN .) + PROTEIN_ENTRY reduce using rule 36 (proteins -> PROTEIN .) + REFERENCE_ENTRY reduce using rule 36 (proteins -> PROTEIN .) + ENTRY reduce using rule 36 (proteins -> PROTEIN .) + $end reduce using rule 36 (proteins -> PROTEIN .) + ACCESSION reduce using rule 36 (proteins -> PROTEIN .) state 34 - (32) citations -> citations CITATION . + (41) comment -> LPARENS comment . RPARENS + (43) comment -> comment . COMMENT - CITATION reduce using rule 32 (citations -> citations CITATION .) - CONTENT reduce using rule 32 (citations -> citations CITATION .) - ACCESSION reduce using rule 32 (citations -> citations CITATION .) - LANGLE reduce using rule 32 (citations -> citations CITATION .) - END reduce using rule 32 (citations -> citations CITATION .) - LPARENS reduce using rule 32 (citations -> citations CITATION .) - COMMENT reduce using rule 32 (citations -> citations CITATION .) - PROTEIN_ENTRY reduce using rule 32 (citations -> citations CITATION .) - REFERENCE_ENTRY reduce using rule 32 (citations -> citations CITATION .) - ENTRY reduce using rule 32 (citations -> citations CITATION .) - $end reduce using rule 32 (citations -> citations CITATION .) - RANGLE reduce using rule 32 (citations -> citations CITATION .) - LCURLY reduce using rule 32 (citations -> citations CITATION .) - SPECIAL reduce using rule 32 (citations -> citations CITATION .) + RPARENS shift and go to state 51 + COMMENT shift and go to state 14 state 35 - (30) citations -> LANGLE citations . RANGLE - (32) citations -> citations . CITATION - - RANGLE shift and go to state 45 - CITATION shift and go to state 34 + (42) comment -> LPARENS RPARENS . + + COMMENT reduce using rule 42 (comment -> LPARENS RPARENS .) + END reduce using rule 42 (comment -> LPARENS RPARENS .) + LPARENS reduce using rule 42 (comment -> LPARENS RPARENS .) + PROTEIN_ENTRY reduce using rule 42 (comment -> LPARENS RPARENS .) + REFERENCE_ENTRY reduce using rule 42 (comment -> LPARENS RPARENS .) + ENTRY reduce using rule 42 (comment -> LPARENS RPARENS .) + $end reduce using rule 42 (comment -> LPARENS RPARENS .) + CONTENT reduce using rule 42 (comment -> LPARENS RPARENS .) + ACCESSION reduce using rule 42 (comment -> LPARENS RPARENS .) + LANGLE reduce using rule 42 (comment -> LPARENS RPARENS .) + CITATION reduce using rule 42 (comment -> LPARENS RPARENS .) + LCURLY reduce using rule 42 (comment -> LPARENS RPARENS .) + SPECIAL reduce using rule 42 (comment -> LPARENS RPARENS .) + POUND reduce using rule 42 (comment -> LPARENS RPARENS .) + PROTEIN reduce using rule 42 (comment -> LPARENS RPARENS .) + RPARENS reduce using rule 42 (comment -> LPARENS RPARENS .) state 36 - (31) citations -> LANGLE RANGLE . + (20) protein_entry -> PROTEIN_ENTRY new_protein . proteins + (33) proteins -> . POUND proteins POUND + (34) proteins -> . POUND POUND + (35) proteins -> . proteins PROTEIN + (36) proteins -> . PROTEIN - CITATION reduce using rule 31 (citations -> LANGLE RANGLE .) - CONTENT reduce using rule 31 (citations -> LANGLE RANGLE .) - ACCESSION reduce using rule 31 (citations -> LANGLE RANGLE .) - LANGLE reduce using rule 31 (citations -> LANGLE RANGLE .) - END reduce using rule 31 (citations -> LANGLE RANGLE .) - LPARENS reduce using rule 31 (citations -> LANGLE RANGLE .) - COMMENT reduce using rule 31 (citations -> LANGLE RANGLE .) - PROTEIN_ENTRY reduce using rule 31 (citations -> LANGLE RANGLE .) - REFERENCE_ENTRY reduce using rule 31 (citations -> LANGLE RANGLE .) - ENTRY reduce using rule 31 (citations -> LANGLE RANGLE .) - $end reduce using rule 31 (citations -> LANGLE RANGLE .) - RANGLE reduce using rule 31 (citations -> LANGLE RANGLE .) - LCURLY reduce using rule 31 (citations -> LANGLE RANGLE .) - SPECIAL reduce using rule 31 (citations -> LANGLE RANGLE .) + POUND shift and go to state 32 + PROTEIN shift and go to state 33 + proteins shift and go to state 52 state 37 - (24) special -> special SPECIAL . + (15) reference_entry -> REFERENCE_ENTRY new_reference . citations + (37) citations -> . LANGLE citations RANGLE + (38) citations -> . LANGLE RANGLE + (39) citations -> . citations CITATION + (40) citations -> . CITATION - SPECIAL reduce using rule 24 (special -> special SPECIAL .) - CONTENT reduce using rule 24 (special -> special SPECIAL .) - LPARENS reduce using rule 24 (special -> special SPECIAL .) - COMMENT reduce using rule 24 (special -> special SPECIAL .) - LCURLY reduce using rule 24 (special -> special SPECIAL .) - END reduce using rule 24 (special -> special SPECIAL .) - PROTEIN_ENTRY reduce using rule 24 (special -> special SPECIAL .) - REFERENCE_ENTRY reduce using rule 24 (special -> special SPECIAL .) - ENTRY reduce using rule 24 (special -> special SPECIAL .) - $end reduce using rule 24 (special -> special SPECIAL .) - RCURLY reduce using rule 24 (special -> special SPECIAL .) + LANGLE shift and go to state 20 + CITATION shift and go to state 21 + citations shift and go to state 53 state 38 - (22) special -> LCURLY special . RCURLY - (24) special -> special . SPECIAL + (8) entry -> ENTRY new_entry . - RCURLY shift and go to state 46 - SPECIAL shift and go to state 37 + CONTENT reduce using rule 8 (entry -> ENTRY new_entry .) + POUND reduce using rule 8 (entry -> ENTRY new_entry .) + PROTEIN reduce using rule 8 (entry -> ENTRY new_entry .) + LPARENS reduce using rule 8 (entry -> ENTRY new_entry .) + COMMENT reduce using rule 8 (entry -> ENTRY new_entry .) + LCURLY reduce using rule 8 (entry -> ENTRY new_entry .) + SPECIAL reduce using rule 8 (entry -> ENTRY new_entry .) + LANGLE reduce using rule 8 (entry -> ENTRY new_entry .) + CITATION reduce using rule 8 (entry -> ENTRY new_entry .) + END reduce using rule 8 (entry -> ENTRY new_entry .) + PROTEIN_ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) + REFERENCE_ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) + ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) + $end reduce using rule 8 (entry -> ENTRY new_entry .) state 39 - (23) special -> LCURLY RCURLY . + (1) enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme . - SPECIAL reduce using rule 23 (special -> LCURLY RCURLY .) - CONTENT reduce using rule 23 (special -> LCURLY RCURLY .) - LPARENS reduce using rule 23 (special -> LCURLY RCURLY .) - COMMENT reduce using rule 23 (special -> LCURLY RCURLY .) - LCURLY reduce using rule 23 (special -> LCURLY RCURLY .) - END reduce using rule 23 (special -> LCURLY RCURLY .) - PROTEIN_ENTRY reduce using rule 23 (special -> LCURLY RCURLY .) - REFERENCE_ENTRY reduce using rule 23 (special -> LCURLY RCURLY .) - ENTRY reduce using rule 23 (special -> LCURLY RCURLY .) - $end reduce using rule 23 (special -> LCURLY RCURLY .) - RCURLY reduce using rule 23 (special -> LCURLY RCURLY .) + END reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) + LPARENS reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) + COMMENT reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) + PROTEIN_ENTRY reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) + REFERENCE_ENTRY reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) + ENTRY reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) + $end reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) state 40 - (34) comment -> LPARENS comment RPARENS . + (26) accession -> accession AND . ACCESSION - COMMENT reduce using rule 34 (comment -> LPARENS comment RPARENS .) - END reduce using rule 34 (comment -> LPARENS comment RPARENS .) - LPARENS reduce using rule 34 (comment -> LPARENS comment RPARENS .) - PROTEIN_ENTRY reduce using rule 34 (comment -> LPARENS comment RPARENS .) - REFERENCE_ENTRY reduce using rule 34 (comment -> LPARENS comment RPARENS .) - ENTRY reduce using rule 34 (comment -> LPARENS comment RPARENS .) - $end reduce using rule 34 (comment -> LPARENS comment RPARENS .) - CONTENT reduce using rule 34 (comment -> LPARENS comment RPARENS .) - LCURLY reduce using rule 34 (comment -> LPARENS comment RPARENS .) - SPECIAL reduce using rule 34 (comment -> LPARENS comment RPARENS .) - RPARENS reduce using rule 34 (comment -> LPARENS comment RPARENS .) + ACCESSION shift and go to state 54 state 41 - (17) protein_entry -> PROTEIN_ENTRY new_protein proteins . - (28) proteins -> proteins . PROTEIN + (27) accession -> accession CONTENT . - CONTENT reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - ACCESSION reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - LANGLE reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - CITATION reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - END reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - LPARENS reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - COMMENT reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - PROTEIN_ENTRY reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - REFERENCE_ENTRY reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - ENTRY reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - $end reduce using rule 17 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - PROTEIN shift and go to state 47 + AND reduce using rule 27 (accession -> accession CONTENT .) + CONTENT reduce using rule 27 (accession -> accession CONTENT .) + ACCESSION reduce using rule 27 (accession -> accession CONTENT .) + LPARENS reduce using rule 27 (accession -> accession CONTENT .) + COMMENT reduce using rule 27 (accession -> accession CONTENT .) + LANGLE reduce using rule 27 (accession -> accession CONTENT .) + CITATION reduce using rule 27 (accession -> accession CONTENT .) + END reduce using rule 27 (accession -> accession CONTENT .) + PROTEIN_ENTRY reduce using rule 27 (accession -> accession CONTENT .) + REFERENCE_ENTRY reduce using rule 27 (accession -> accession CONTENT .) + ENTRY reduce using rule 27 (accession -> accession CONTENT .) + $end reduce using rule 27 (accession -> accession CONTENT .) state 42 - (26) proteins -> POUND . proteins POUND - (27) proteins -> POUND . POUND - (26) proteins -> . POUND proteins POUND - (27) proteins -> . POUND POUND - (28) proteins -> . proteins PROTEIN - (29) proteins -> . PROTEIN - - POUND shift and go to state 48 - PROTEIN shift and go to state 43 + (39) citations -> citations CITATION . + + CITATION reduce using rule 39 (citations -> citations CITATION .) + CONTENT reduce using rule 39 (citations -> citations CITATION .) + ACCESSION reduce using rule 39 (citations -> citations CITATION .) + LPARENS reduce using rule 39 (citations -> citations CITATION .) + COMMENT reduce using rule 39 (citations -> citations CITATION .) + LANGLE reduce using rule 39 (citations -> citations CITATION .) + END reduce using rule 39 (citations -> citations CITATION .) + PROTEIN_ENTRY reduce using rule 39 (citations -> citations CITATION .) + REFERENCE_ENTRY reduce using rule 39 (citations -> citations CITATION .) + ENTRY reduce using rule 39 (citations -> citations CITATION .) + $end reduce using rule 39 (citations -> citations CITATION .) + POUND reduce using rule 39 (citations -> citations CITATION .) + PROTEIN reduce using rule 39 (citations -> citations CITATION .) + LCURLY reduce using rule 39 (citations -> citations CITATION .) + SPECIAL reduce using rule 39 (citations -> citations CITATION .) + RANGLE reduce using rule 39 (citations -> citations CITATION .) - proteins shift and go to state 49 state 43 - (29) proteins -> PROTEIN . + (37) citations -> LANGLE citations . RANGLE + (39) citations -> citations . CITATION - PROTEIN reduce using rule 29 (proteins -> PROTEIN .) - CONTENT reduce using rule 29 (proteins -> PROTEIN .) - ACCESSION reduce using rule 29 (proteins -> PROTEIN .) - LANGLE reduce using rule 29 (proteins -> PROTEIN .) - CITATION reduce using rule 29 (proteins -> PROTEIN .) - END reduce using rule 29 (proteins -> PROTEIN .) - LPARENS reduce using rule 29 (proteins -> PROTEIN .) - COMMENT reduce using rule 29 (proteins -> PROTEIN .) - PROTEIN_ENTRY reduce using rule 29 (proteins -> PROTEIN .) - REFERENCE_ENTRY reduce using rule 29 (proteins -> PROTEIN .) - ENTRY reduce using rule 29 (proteins -> PROTEIN .) - $end reduce using rule 29 (proteins -> PROTEIN .) - POUND reduce using rule 29 (proteins -> PROTEIN .) + RANGLE shift and go to state 55 + CITATION shift and go to state 42 state 44 - (12) reference_entry -> REFERENCE_ENTRY new_reference citations . - (32) citations -> citations . CITATION - - CONTENT reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - LPARENS reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - COMMENT reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - LCURLY reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - SPECIAL reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - END reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - PROTEIN_ENTRY reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - REFERENCE_ENTRY reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - ENTRY reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - $end reduce using rule 12 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - CITATION shift and go to state 34 + (38) citations -> LANGLE RANGLE . + + CITATION reduce using rule 38 (citations -> LANGLE RANGLE .) + CONTENT reduce using rule 38 (citations -> LANGLE RANGLE .) + ACCESSION reduce using rule 38 (citations -> LANGLE RANGLE .) + LPARENS reduce using rule 38 (citations -> LANGLE RANGLE .) + COMMENT reduce using rule 38 (citations -> LANGLE RANGLE .) + LANGLE reduce using rule 38 (citations -> LANGLE RANGLE .) + END reduce using rule 38 (citations -> LANGLE RANGLE .) + PROTEIN_ENTRY reduce using rule 38 (citations -> LANGLE RANGLE .) + REFERENCE_ENTRY reduce using rule 38 (citations -> LANGLE RANGLE .) + ENTRY reduce using rule 38 (citations -> LANGLE RANGLE .) + $end reduce using rule 38 (citations -> LANGLE RANGLE .) + POUND reduce using rule 38 (citations -> LANGLE RANGLE .) + PROTEIN reduce using rule 38 (citations -> LANGLE RANGLE .) + LCURLY reduce using rule 38 (citations -> LANGLE RANGLE .) + SPECIAL reduce using rule 38 (citations -> LANGLE RANGLE .) + RANGLE reduce using rule 38 (citations -> LANGLE RANGLE .) state 45 - (30) citations -> LANGLE citations RANGLE . - - CITATION reduce using rule 30 (citations -> LANGLE citations RANGLE .) - CONTENT reduce using rule 30 (citations -> LANGLE citations RANGLE .) - ACCESSION reduce using rule 30 (citations -> LANGLE citations RANGLE .) - LANGLE reduce using rule 30 (citations -> LANGLE citations RANGLE .) - END reduce using rule 30 (citations -> LANGLE citations RANGLE .) - LPARENS reduce using rule 30 (citations -> LANGLE citations RANGLE .) - COMMENT reduce using rule 30 (citations -> LANGLE citations RANGLE .) - PROTEIN_ENTRY reduce using rule 30 (citations -> LANGLE citations RANGLE .) - REFERENCE_ENTRY reduce using rule 30 (citations -> LANGLE citations RANGLE .) - ENTRY reduce using rule 30 (citations -> LANGLE citations RANGLE .) - $end reduce using rule 30 (citations -> LANGLE citations RANGLE .) - RANGLE reduce using rule 30 (citations -> LANGLE citations RANGLE .) - LCURLY reduce using rule 30 (citations -> LANGLE citations RANGLE .) - SPECIAL reduce using rule 30 (citations -> LANGLE citations RANGLE .) + (31) special -> special SPECIAL . + + SPECIAL reduce using rule 31 (special -> special SPECIAL .) + CONTENT reduce using rule 31 (special -> special SPECIAL .) + LPARENS reduce using rule 31 (special -> special SPECIAL .) + COMMENT reduce using rule 31 (special -> special SPECIAL .) + LCURLY reduce using rule 31 (special -> special SPECIAL .) + END reduce using rule 31 (special -> special SPECIAL .) + PROTEIN_ENTRY reduce using rule 31 (special -> special SPECIAL .) + REFERENCE_ENTRY reduce using rule 31 (special -> special SPECIAL .) + ENTRY reduce using rule 31 (special -> special SPECIAL .) + $end reduce using rule 31 (special -> special SPECIAL .) + POUND reduce using rule 31 (special -> special SPECIAL .) + PROTEIN reduce using rule 31 (special -> special SPECIAL .) + LANGLE reduce using rule 31 (special -> special SPECIAL .) + CITATION reduce using rule 31 (special -> special SPECIAL .) + RCURLY reduce using rule 31 (special -> special SPECIAL .) state 46 - (22) special -> LCURLY special RCURLY . + (29) special -> LCURLY special . RCURLY + (31) special -> special . SPECIAL - SPECIAL reduce using rule 22 (special -> LCURLY special RCURLY .) - CONTENT reduce using rule 22 (special -> LCURLY special RCURLY .) - LPARENS reduce using rule 22 (special -> LCURLY special RCURLY .) - COMMENT reduce using rule 22 (special -> LCURLY special RCURLY .) - LCURLY reduce using rule 22 (special -> LCURLY special RCURLY .) - END reduce using rule 22 (special -> LCURLY special RCURLY .) - PROTEIN_ENTRY reduce using rule 22 (special -> LCURLY special RCURLY .) - REFERENCE_ENTRY reduce using rule 22 (special -> LCURLY special RCURLY .) - ENTRY reduce using rule 22 (special -> LCURLY special RCURLY .) - $end reduce using rule 22 (special -> LCURLY special RCURLY .) - RCURLY reduce using rule 22 (special -> LCURLY special RCURLY .) + RCURLY shift and go to state 56 + SPECIAL shift and go to state 45 state 47 - (28) proteins -> proteins PROTEIN . - - PROTEIN reduce using rule 28 (proteins -> proteins PROTEIN .) - CONTENT reduce using rule 28 (proteins -> proteins PROTEIN .) - ACCESSION reduce using rule 28 (proteins -> proteins PROTEIN .) - LANGLE reduce using rule 28 (proteins -> proteins PROTEIN .) - CITATION reduce using rule 28 (proteins -> proteins PROTEIN .) - END reduce using rule 28 (proteins -> proteins PROTEIN .) - LPARENS reduce using rule 28 (proteins -> proteins PROTEIN .) - COMMENT reduce using rule 28 (proteins -> proteins PROTEIN .) - PROTEIN_ENTRY reduce using rule 28 (proteins -> proteins PROTEIN .) - REFERENCE_ENTRY reduce using rule 28 (proteins -> proteins PROTEIN .) - ENTRY reduce using rule 28 (proteins -> proteins PROTEIN .) - $end reduce using rule 28 (proteins -> proteins PROTEIN .) - POUND reduce using rule 28 (proteins -> proteins PROTEIN .) + (30) special -> LCURLY RCURLY . + + SPECIAL reduce using rule 30 (special -> LCURLY RCURLY .) + CONTENT reduce using rule 30 (special -> LCURLY RCURLY .) + LPARENS reduce using rule 30 (special -> LCURLY RCURLY .) + COMMENT reduce using rule 30 (special -> LCURLY RCURLY .) + LCURLY reduce using rule 30 (special -> LCURLY RCURLY .) + END reduce using rule 30 (special -> LCURLY RCURLY .) + PROTEIN_ENTRY reduce using rule 30 (special -> LCURLY RCURLY .) + REFERENCE_ENTRY reduce using rule 30 (special -> LCURLY RCURLY .) + ENTRY reduce using rule 30 (special -> LCURLY RCURLY .) + $end reduce using rule 30 (special -> LCURLY RCURLY .) + POUND reduce using rule 30 (special -> LCURLY RCURLY .) + PROTEIN reduce using rule 30 (special -> LCURLY RCURLY .) + LANGLE reduce using rule 30 (special -> LCURLY RCURLY .) + CITATION reduce using rule 30 (special -> LCURLY RCURLY .) + RCURLY reduce using rule 30 (special -> LCURLY RCURLY .) state 48 - (27) proteins -> POUND POUND . - (26) proteins -> POUND . proteins POUND - (27) proteins -> POUND . POUND - (26) proteins -> . POUND proteins POUND - (27) proteins -> . POUND POUND - (28) proteins -> . proteins PROTEIN - (29) proteins -> . PROTEIN - - ! shift/reduce conflict for POUND resolved as shift - ! shift/reduce conflict for PROTEIN resolved as shift - CONTENT reduce using rule 27 (proteins -> POUND POUND .) - ACCESSION reduce using rule 27 (proteins -> POUND POUND .) - LANGLE reduce using rule 27 (proteins -> POUND POUND .) - CITATION reduce using rule 27 (proteins -> POUND POUND .) - END reduce using rule 27 (proteins -> POUND POUND .) - LPARENS reduce using rule 27 (proteins -> POUND POUND .) - COMMENT reduce using rule 27 (proteins -> POUND POUND .) - PROTEIN_ENTRY reduce using rule 27 (proteins -> POUND POUND .) - REFERENCE_ENTRY reduce using rule 27 (proteins -> POUND POUND .) - ENTRY reduce using rule 27 (proteins -> POUND POUND .) - $end reduce using rule 27 (proteins -> POUND POUND .) - POUND shift and go to state 48 - PROTEIN shift and go to state 43 - - ! PROTEIN [ reduce using rule 27 (proteins -> POUND POUND .) ] - ! POUND [ reduce using rule 27 (proteins -> POUND POUND .) ] - - proteins shift and go to state 49 - -state 49 + (35) proteins -> proteins PROTEIN . + + PROTEIN reduce using rule 35 (proteins -> proteins PROTEIN .) + CONTENT reduce using rule 35 (proteins -> proteins PROTEIN .) + POUND reduce using rule 35 (proteins -> proteins PROTEIN .) + LPARENS reduce using rule 35 (proteins -> proteins PROTEIN .) + COMMENT reduce using rule 35 (proteins -> proteins PROTEIN .) + LCURLY reduce using rule 35 (proteins -> proteins PROTEIN .) + SPECIAL reduce using rule 35 (proteins -> proteins PROTEIN .) + LANGLE reduce using rule 35 (proteins -> proteins PROTEIN .) + CITATION reduce using rule 35 (proteins -> proteins PROTEIN .) + END reduce using rule 35 (proteins -> proteins PROTEIN .) + PROTEIN_ENTRY reduce using rule 35 (proteins -> proteins PROTEIN .) + REFERENCE_ENTRY reduce using rule 35 (proteins -> proteins PROTEIN .) + ENTRY reduce using rule 35 (proteins -> proteins PROTEIN .) + $end reduce using rule 35 (proteins -> proteins PROTEIN .) + ACCESSION reduce using rule 35 (proteins -> proteins PROTEIN .) - (26) proteins -> POUND proteins . POUND - (28) proteins -> proteins . PROTEIN - POUND shift and go to state 50 - PROTEIN shift and go to state 47 +state 49 + (34) proteins -> POUND POUND . + (33) proteins -> POUND . proteins POUND + (34) proteins -> POUND . POUND + (33) proteins -> . POUND proteins POUND + (34) proteins -> . POUND POUND + (35) proteins -> . proteins PROTEIN + (36) proteins -> . PROTEIN + + PROTEIN reduce using rule 34 (proteins -> POUND POUND .) + CONTENT reduce using rule 34 (proteins -> POUND POUND .) + POUND reduce using rule 34 (proteins -> POUND POUND .) + LPARENS reduce using rule 34 (proteins -> POUND POUND .) + COMMENT reduce using rule 34 (proteins -> POUND POUND .) + LCURLY reduce using rule 34 (proteins -> POUND POUND .) + SPECIAL reduce using rule 34 (proteins -> POUND POUND .) + LANGLE reduce using rule 34 (proteins -> POUND POUND .) + CITATION reduce using rule 34 (proteins -> POUND POUND .) + END reduce using rule 34 (proteins -> POUND POUND .) + PROTEIN_ENTRY reduce using rule 34 (proteins -> POUND POUND .) + REFERENCE_ENTRY reduce using rule 34 (proteins -> POUND POUND .) + ENTRY reduce using rule 34 (proteins -> POUND POUND .) + $end reduce using rule 34 (proteins -> POUND POUND .) + ACCESSION reduce using rule 34 (proteins -> POUND POUND .) + + ! POUND [ shift and go to state 49 ] + ! PROTEIN [ shift and go to state 33 ] + + proteins shift and go to state 50 state 50 - (26) proteins -> POUND proteins POUND . - - PROTEIN reduce using rule 26 (proteins -> POUND proteins POUND .) - CONTENT reduce using rule 26 (proteins -> POUND proteins POUND .) - ACCESSION reduce using rule 26 (proteins -> POUND proteins POUND .) - LANGLE reduce using rule 26 (proteins -> POUND proteins POUND .) - CITATION reduce using rule 26 (proteins -> POUND proteins POUND .) - END reduce using rule 26 (proteins -> POUND proteins POUND .) - LPARENS reduce using rule 26 (proteins -> POUND proteins POUND .) - COMMENT reduce using rule 26 (proteins -> POUND proteins POUND .) - PROTEIN_ENTRY reduce using rule 26 (proteins -> POUND proteins POUND .) - REFERENCE_ENTRY reduce using rule 26 (proteins -> POUND proteins POUND .) - ENTRY reduce using rule 26 (proteins -> POUND proteins POUND .) - $end reduce using rule 26 (proteins -> POUND proteins POUND .) - POUND reduce using rule 26 (proteins -> POUND proteins POUND .) + (33) proteins -> POUND proteins . POUND + (35) proteins -> proteins . PROTEIN + + POUND shift and go to state 57 + PROTEIN shift and go to state 48 + + +state 51 + + (41) comment -> LPARENS comment RPARENS . + + COMMENT reduce using rule 41 (comment -> LPARENS comment RPARENS .) + END reduce using rule 41 (comment -> LPARENS comment RPARENS .) + LPARENS reduce using rule 41 (comment -> LPARENS comment RPARENS .) + PROTEIN_ENTRY reduce using rule 41 (comment -> LPARENS comment RPARENS .) + REFERENCE_ENTRY reduce using rule 41 (comment -> LPARENS comment RPARENS .) + ENTRY reduce using rule 41 (comment -> LPARENS comment RPARENS .) + $end reduce using rule 41 (comment -> LPARENS comment RPARENS .) + CONTENT reduce using rule 41 (comment -> LPARENS comment RPARENS .) + ACCESSION reduce using rule 41 (comment -> LPARENS comment RPARENS .) + LANGLE reduce using rule 41 (comment -> LPARENS comment RPARENS .) + CITATION reduce using rule 41 (comment -> LPARENS comment RPARENS .) + LCURLY reduce using rule 41 (comment -> LPARENS comment RPARENS .) + SPECIAL reduce using rule 41 (comment -> LPARENS comment RPARENS .) + POUND reduce using rule 41 (comment -> LPARENS comment RPARENS .) + PROTEIN reduce using rule 41 (comment -> LPARENS comment RPARENS .) + RPARENS reduce using rule 41 (comment -> LPARENS comment RPARENS .) + + +state 52 + + (20) protein_entry -> PROTEIN_ENTRY new_protein proteins . + (35) proteins -> proteins . PROTEIN + + CONTENT reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + ACCESSION reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + LPARENS reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + COMMENT reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + LANGLE reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + CITATION reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + END reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + PROTEIN_ENTRY reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + REFERENCE_ENTRY reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + ENTRY reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + $end reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) + PROTEIN shift and go to state 48 + + +state 53 + + (15) reference_entry -> REFERENCE_ENTRY new_reference citations . + (39) citations -> citations . CITATION + + CONTENT reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + LPARENS reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + COMMENT reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + LCURLY reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + SPECIAL reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + END reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + PROTEIN_ENTRY reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + REFERENCE_ENTRY reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + ENTRY reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + $end reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) + CITATION shift and go to state 42 + + +state 54 + + (26) accession -> accession AND ACCESSION . + + AND reduce using rule 26 (accession -> accession AND ACCESSION .) + CONTENT reduce using rule 26 (accession -> accession AND ACCESSION .) + ACCESSION reduce using rule 26 (accession -> accession AND ACCESSION .) + LPARENS reduce using rule 26 (accession -> accession AND ACCESSION .) + COMMENT reduce using rule 26 (accession -> accession AND ACCESSION .) + LANGLE reduce using rule 26 (accession -> accession AND ACCESSION .) + CITATION reduce using rule 26 (accession -> accession AND ACCESSION .) + END reduce using rule 26 (accession -> accession AND ACCESSION .) + PROTEIN_ENTRY reduce using rule 26 (accession -> accession AND ACCESSION .) + REFERENCE_ENTRY reduce using rule 26 (accession -> accession AND ACCESSION .) + ENTRY reduce using rule 26 (accession -> accession AND ACCESSION .) + $end reduce using rule 26 (accession -> accession AND ACCESSION .) + + +state 55 + + (37) citations -> LANGLE citations RANGLE . + + CITATION reduce using rule 37 (citations -> LANGLE citations RANGLE .) + CONTENT reduce using rule 37 (citations -> LANGLE citations RANGLE .) + ACCESSION reduce using rule 37 (citations -> LANGLE citations RANGLE .) + LPARENS reduce using rule 37 (citations -> LANGLE citations RANGLE .) + COMMENT reduce using rule 37 (citations -> LANGLE citations RANGLE .) + LANGLE reduce using rule 37 (citations -> LANGLE citations RANGLE .) + END reduce using rule 37 (citations -> LANGLE citations RANGLE .) + PROTEIN_ENTRY reduce using rule 37 (citations -> LANGLE citations RANGLE .) + REFERENCE_ENTRY reduce using rule 37 (citations -> LANGLE citations RANGLE .) + ENTRY reduce using rule 37 (citations -> LANGLE citations RANGLE .) + $end reduce using rule 37 (citations -> LANGLE citations RANGLE .) + POUND reduce using rule 37 (citations -> LANGLE citations RANGLE .) + PROTEIN reduce using rule 37 (citations -> LANGLE citations RANGLE .) + LCURLY reduce using rule 37 (citations -> LANGLE citations RANGLE .) + SPECIAL reduce using rule 37 (citations -> LANGLE citations RANGLE .) + RANGLE reduce using rule 37 (citations -> LANGLE citations RANGLE .) + + +state 56 + + (29) special -> LCURLY special RCURLY . + + SPECIAL reduce using rule 29 (special -> LCURLY special RCURLY .) + CONTENT reduce using rule 29 (special -> LCURLY special RCURLY .) + LPARENS reduce using rule 29 (special -> LCURLY special RCURLY .) + COMMENT reduce using rule 29 (special -> LCURLY special RCURLY .) + LCURLY reduce using rule 29 (special -> LCURLY special RCURLY .) + END reduce using rule 29 (special -> LCURLY special RCURLY .) + PROTEIN_ENTRY reduce using rule 29 (special -> LCURLY special RCURLY .) + REFERENCE_ENTRY reduce using rule 29 (special -> LCURLY special RCURLY .) + ENTRY reduce using rule 29 (special -> LCURLY special RCURLY .) + $end reduce using rule 29 (special -> LCURLY special RCURLY .) + POUND reduce using rule 29 (special -> LCURLY special RCURLY .) + PROTEIN reduce using rule 29 (special -> LCURLY special RCURLY .) + LANGLE reduce using rule 29 (special -> LCURLY special RCURLY .) + CITATION reduce using rule 29 (special -> LCURLY special RCURLY .) + RCURLY reduce using rule 29 (special -> LCURLY special RCURLY .) + + +state 57 + + (33) proteins -> POUND proteins POUND . + + PROTEIN reduce using rule 33 (proteins -> POUND proteins POUND .) + CONTENT reduce using rule 33 (proteins -> POUND proteins POUND .) + POUND reduce using rule 33 (proteins -> POUND proteins POUND .) + LPARENS reduce using rule 33 (proteins -> POUND proteins POUND .) + COMMENT reduce using rule 33 (proteins -> POUND proteins POUND .) + LCURLY reduce using rule 33 (proteins -> POUND proteins POUND .) + SPECIAL reduce using rule 33 (proteins -> POUND proteins POUND .) + LANGLE reduce using rule 33 (proteins -> POUND proteins POUND .) + CITATION reduce using rule 33 (proteins -> POUND proteins POUND .) + END reduce using rule 33 (proteins -> POUND proteins POUND .) + PROTEIN_ENTRY reduce using rule 33 (proteins -> POUND proteins POUND .) + REFERENCE_ENTRY reduce using rule 33 (proteins -> POUND proteins POUND .) + ENTRY reduce using rule 33 (proteins -> POUND proteins POUND .) + $end reduce using rule 33 (proteins -> POUND proteins POUND .) + ACCESSION reduce using rule 33 (proteins -> POUND proteins POUND .) WARNING: WARNING: Conflicts: WARNING: -WARNING: shift/reduce conflict for POUND in state 48 resolved as shift -WARNING: shift/reduce conflict for PROTEIN in state 48 resolved as shift +WARNING: shift/reduce conflict for COMMENT in state 3 resolved as shift +WARNING: shift/reduce conflict for LPARENS in state 4 resolved as shift +WARNING: shift/reduce conflict for COMMENT in state 4 resolved as shift +WARNING: shift/reduce conflict for LPARENS in state 5 resolved as shift +WARNING: shift/reduce conflict for COMMENT in state 5 resolved as shift +WARNING: shift/reduce conflict for LPARENS in state 6 resolved as shift +WARNING: shift/reduce conflict for COMMENT in state 6 resolved as shift diff --git a/src/brenda_parser/parsing/parser.py b/src/brenda_parser/parsing/parser.py index 4bc1349..9ece655 100644 --- a/src/brenda_parser/parsing/parser.py +++ b/src/brenda_parser/parsing/parser.py @@ -87,13 +87,13 @@ class BRENDAParser(object): """ precedence = ( - ("left", "ENZYME"), + # ("left", "ENZYME"), ("left", "ASSEMBLE"), ("left", "REDUCE"), ("left", "COMBINE") ) - def __init__(self, lexer=None, **kw_args): + def __init__(self, lexer=None, **kwargs): """ Instantiate a BRENDA parser. @@ -102,19 +102,19 @@ def __init__(self, lexer=None, **kw_args): lexer : ply.lex (optional) Any ply.lex lexer instance that generates the tokens listed in the rules. The default uses a BRENDALexer instance. - kw_args : + kwargs : Keyword arguments are passed to the ply.yacc.yacc call. """ super(BRENDAParser, self).__init__() self._lexer = BRENDALexer() if lexer is None else lexer self.tokens = self._lexer.tokens - self.parser = yacc(module=self, errorlog=LOGGER, **kw_args) + self.parser = yacc(module=self, errorlog=LOGGER, **kwargs) self._session = None self.proteins = dict() self.citations = dict() self._current_entry = None - def parse(self, section, session, **kw_args): + def parse(self, section, session, **kwargs): """ Parse an entire enzyme section according to the rules. @@ -127,7 +127,7 @@ def parse(self, section, session, **kw_args): A BRENDA enzyme section starting from 'ID x.x.x.x' until '///'. session : sqlalchemy.Session A running session for querying database connections. - kw_args : + kwargs : Keyword arguments are passed on to the ply.yacc.yacc.parse call. """ @@ -135,60 +135,52 @@ def parse(self, section, session, **kw_args): self.proteins.clear() self.citations.clear() self._current_entry = None - return self.parser.parse(section, lexer=self._lexer, **kw_args) + return self.parser.parse(section, lexer=self._lexer, **kwargs) def p_enzyme(self, p): - """enzyme : ENTRY EC_NUMBER new_enzyme""" - LOGGER.debug("%s: %s", self.p_enzyme.__doc__, p[3].ec_number) + """enzyme : ENZYME_ENTRY EC_NUMBER new_enzyme""" p[0] = p[3] def p_new_enzyme(self, p): """new_enzyme :""" - LOGGER.debug("%s: %s", self.p_new_enzyme.__doc__, p[-1]) + LOGGER.debug("%s %s", self.p_new_enzyme.__doc__, p[-1]) assert p[-2] == "ID" p[0] = models.Enzyme(ec_number=p[-1]) def p_enzyme_comment(self, p): - """enzyme : enzyme comment %prec ENZYME""" - LOGGER.debug("%s: %s", self.p_enzyme_comment.__doc__, p[1].ec_number) + """enzyme : enzyme comment""" if p[2] is not None: p[1].comments.append(p[2]) p[0] = p[1] def p_enzyme_protein(self, p): - """enzyme : enzyme protein_entry %prec ENZYME""" - LOGGER.debug("%s: %s", self.p_enzyme_protein.__doc__, p[1].ec_number) - p[1].proteins.append(p[2]) + """enzyme : enzyme protein_entry""" + p[1].protein_references.append(p[2]) p[0] = p[1] def p_enzyme_reference(self, p): - """enzyme : enzyme reference_entry %prec ENZYME""" - LOGGER.debug("%s: %s", self.p_enzyme_reference.__doc__, p[1].ec_number) - p[1].references.append(p[2]) + """enzyme : enzyme reference_entry""" + p[1].citation_references.append(p[2]) p[0] = p[1] def p_enzyme_entry(self, p): - """enzyme : enzyme entry %prec ENZYME""" - LOGGER.debug("%s: %s", self.p_enzyme_entry.__doc__, p[1].ec_number) + """enzyme : enzyme entry""" # TODO: In future, add to specific children based on acronym. p[1].entries.append(p[2]) p[0] = p[1] def p_enzyme_end(self, p): """enzyme : enzyme END""" - LOGGER.debug("%s: %s", self.p_enzyme_end.__doc__, p[1].ec_number) # TODO: Finalize protein and citation references. p[0] = p[1] def p_entry(self, p): - """entry : ENTRY new_entry""" - LOGGER.debug("%s: %s", self.p_entry.__doc__, p[1]) + """entry : ENTRY new_entry %prec REDUCE""" assert p[1] == p[2].field.acronym p[0] = p[2] def p_new_entry(self, p): - """new_entry :""" - LOGGER.debug("%s: %s", self.p_new_entry.__doc__, p[-1]) + """new_entry : %prec REDUCE""" field = self._session.query(models.InformationField) \ .filter_by(acronym=p[-1]) \ .one() @@ -196,29 +188,42 @@ def p_new_entry(self, p): def p_entry_content(self, p): """entry : entry CONTENT""" - LOGGER.debug("%s: %s", self.p_entry_content.__doc__, p[1].field.acronym) assert len(p[2]) > 0 p[1].body += " {}".format(p[2]) p[0] = p[1] + def p_entry_proteins(self, p): + """entry : entry proteins %prec ASSEMBLE""" + if p[2] is not None: + p[1].protein_references.extend(p[2]) + p[0] = p[1] + def p_entry_comment(self, p): """entry : entry comment %prec ASSEMBLE""" - LOGGER.debug("%s: %s", self.p_entry_comment.__doc__, p[1].field.acronym) if p[2] is not None: - p[1].comment_references.append(p[2]) + p[1].comments.append(p[2]) + p[0] = p[1] + + def p_entry_special(self, p): + """entry : entry special %prec ASSEMBLE""" + if p[2] is not None: + p[1].special = p[2] + p[0] = p[1] + + def p_entry_citations(self, p): + """entry : entry citations %prec ASSEMBLE""" + if p[2] is not None: + p[1].citation_references.extend(p[2]) p[0] = p[1] def p_reference_entry(self, p): """reference_entry : REFERENCE_ENTRY new_reference citations""" - LOGGER.debug("%s: %s", self.p_reference_entry.__doc__, - p[2].field.acronym) assert len(p[3]) == 1 # Reference entry only has its own number. self.citations[p[3][0]] = p[2] p[0] = p[2] def p_new_reference(self, p): """new_reference :""" - LOGGER.debug("%s: %s", self.p_new_reference.__doc__, p[-1]) assert p[-1] == "RF" field = self._session.query(models.InformationField) \ .filter_by(acronym=p[-1]) \ @@ -227,24 +232,18 @@ def p_new_reference(self, p): def p_reference_content(self, p): """reference_entry : reference_entry CONTENT""" - LOGGER.debug("%s: %s", self.p_reference_content.__doc__, - p[1].field.acronym) assert len(p[2]) > 0 p[1].body += " {}".format(p[2]) p[0] = p[1] def p_reference_year(self, p): """reference_entry : reference_entry comment %prec ASSEMBLE""" - LOGGER.debug("%s: %s", self.p_reference_year.__doc__, - p[1].field.acronym) if p[2] is not None: - p[1].body += " ({})".format(p[2]) + p[1].body += " ({})".format(p[2].body) p[0] = p[1] def p_reference_pubmed(self, p): """reference_entry : reference_entry special %prec ASSEMBLE""" - LOGGER.debug("%s: %s", self.p_reference_pubmed.__doc__, - p[1].field.acronym) try: p[1].pubmed = p[2] except ValidationError: @@ -252,15 +251,13 @@ def p_reference_pubmed(self, p): p[0] = p[1] def p_protein_entry(self, p): - """protein_entry : PROTEIN_ENTRY new_protein proteins""" - LOGGER.debug("%s: %s", self.p_protein_entry.__doc__, p[1]) + """protein_entry : PROTEIN_ENTRY new_protein proteins %prec COMBINE""" assert len(p[3]) == 1 # Protein entry only has its own number. self.proteins[p[3][0]] = p[2] p[0] = p[2] def p_new_protein(self, p): """new_protein :""" - LOGGER.debug("%s: %s", self.p_new_protein.__doc__, p[-1]) assert p[-1] == "PR" field = self._session.query(models.InformationField) \ .filter_by(acronym=p[-1]) \ @@ -268,116 +265,112 @@ def p_new_protein(self, p): p[0] = models.Protein(field=field) def p_protein_organism(self, p): - """protein_entry : protein_entry CONTENT""" - LOGGER.debug("%s: %s", self.p_protein_organism.__doc__, - p[1].field.acronym) + """protein_entry : protein_entry CONTENT %prec ASSEMBLE""" assert len(p[2]) > 0 # TODO: Find or create the organism. p[1].organism_name += p[2] p[0] = p[1] def p_protein_accession(self, p): - """protein_entry : protein_entry ACCESSION CONTENT""" - LOGGER.debug("%s: %s", self.p_protein_accession.__doc__, - p[1].field.acronym) - # Might have to be split into its own rule if ACCESSION occurs without - # database (CONTENT). + """protein_entry : protein_entry accession %prec ASSEMBLE""" p[1].accession = p[2] - p[1].database = p[3] + p[0] = p[1] + + def p_protein_comment(self, p): + """protein_entry : protein_entry comment %prec ASSEMBLE""" + if p[2] is not None: + p[1].comments.append(p[2]) p[0] = p[1] def p_protein_citations(self, p): """protein_entry : protein_entry citations %prec ASSEMBLE""" - LOGGER.debug("%s: %s", self.p_protein_citations.__doc__, - p[1].field.acronym) if p[2] is not None: p[1].citation_references.extend(p[2]) p[0] = p[1] + def p_accession_combine(self, p): + """accession : accession AND ACCESSION %prec COMBINE""" + p[1].accession = "{} & {}".format(p[1].accession, p[3]) + p[0] = p[1] + + def p_accession_database(self, p): + """accession : accession CONTENT %prec COMBINE""" + p[1].database = p[2] + p[0] = p[1] + + def p_accession(self, p): + """accession : ACCESSION %prec REDUCE""" + p[0] = models.Accession(accession=p[1]) + def p_special(self, p): """special : LCURLY special RCURLY""" - LOGGER.debug("%s", self.p_special.__doc__) p[0] = p[2] def p_special_empty(self, p): """special : LCURLY RCURLY""" - LOGGER.debug("%s", self.p_special_empty.__doc__) pass def p_special_combine(self, p): """special : special SPECIAL %prec COMBINE""" - LOGGER.debug("%s", self.p_special_combine.__doc__) p[0] = "{0} {1}".format(p[1], p[2]) def p_special_end(self, p): """special : SPECIAL %prec REDUCE""" - LOGGER.debug("%s", self.p_special_end.__doc__) p[0] = p[1].strip() def p_proteins(self, p): - """proteins : POUND proteins POUND""" - LOGGER.debug("%s", self.p_proteins.__doc__) + """proteins : POUND proteins POUND %prec ASSEMBLE""" p[0] = p[2] def p_proteins_empty(self, p): - """proteins : POUND POUND """ - LOGGER.debug("%s", self.p_proteins_empty.__doc__) + """proteins : POUND POUND %prec ASSEMBLE""" pass def p_proteins_combine(self, p): """proteins : proteins PROTEIN %prec COMBINE""" - LOGGER.debug("%s", self.p_proteins_combine.__doc__) p[1].append(p[2]) p[0] = p[1] def p_proteins_end(self, p): """proteins : PROTEIN %prec REDUCE""" - LOGGER.debug("%s", self.p_proteins_end.__doc__) p[0] = [p[1]] def p_citations(self, p): - """citations : LANGLE citations RANGLE""" - LOGGER.debug("%s", self.p_citations.__doc__) + """citations : LANGLE citations RANGLE %prec ASSEMBLE""" p[0] = p[2] def p_citations_empty(self, p): - """citations : LANGLE RANGLE """ - LOGGER.debug("%s", self.p_citations_empty.__doc__) + """citations : LANGLE RANGLE %prec ASSEMBLE""" pass def p_citations_combine(self, p): """citations : citations CITATION %prec COMBINE""" - LOGGER.debug("%s", self.p_citations_combine.__doc__) p[1].append(p[2]) p[0] = p[1] def p_citations_end(self, p): """citations : CITATION %prec REDUCE""" - LOGGER.debug("%s", self.p_citations_end.__doc__) p[0] = [p[1]] def p_comment(self, p): - """comment : LPARENS comment RPARENS""" - LOGGER.debug("%s", self.p_comment.__doc__) + """comment : LPARENS comment RPARENS %prec ASSEMBLE""" p[0] = p[2] def p_comment_empty(self, p): - """comment : LPARENS RPARENS""" - LOGGER.debug("%s", self.p_comment_empty.__doc__) + """comment : LPARENS RPARENS %prec ASSEMBLE""" pass def p_comment_combine(self, p): """comment : comment COMMENT %prec COMBINE""" - LOGGER.debug("%s", self.p_comment_combine.__doc__) - p[0] = "{0} {1}".format(p[1], p[2]) + p[1].body = "{0} {1}".format(p[1].body, p[2]) + p[0] = p[1] def p_comment_end(self, p): """comment : COMMENT %prec REDUCE""" - LOGGER.debug("%s", self.p_comment_end.__doc__) - p[0] = p[1] + p[0] = models.Comment(body=p[1]) def p_error(self, p): - LOGGER.debug("error: %s", str(p)) + LOGGER.debug("Error: %s", str(p)) # TODO: If `p` is None (we allow some empty rules) it's only an error # if any parentheses or similar are unbalanced. if False: diff --git a/src/brenda_parser/parsing/parsetab.py b/src/brenda_parser/parsing/parsetab.py index fa23024..978cc8e 100644 --- a/src/brenda_parser/parsing/parsetab.py +++ b/src/brenda_parser/parsing/parsetab.py @@ -5,9 +5,9 @@ _lr_method = 'LALR' -_lr_signature = 'leftENZYMEleftASSEMBLEleftREDUCEleftCOMBINEPROTEIN CITATION ENTRY PROTEIN_ENTRY REFERENCE_ENTRY POUND LPARENS RPARENS LANGLE RANGLE LCURLY RCURLY EC_NUMBER END CONTENT SPECIAL COMMENT ACCESSIONenzyme : ENTRY EC_NUMBER new_enzymenew_enzyme :enzyme : enzyme comment %prec ENZYMEenzyme : enzyme protein_entry %prec ENZYMEenzyme : enzyme reference_entry %prec ENZYMEenzyme : enzyme entry %prec ENZYMEenzyme : enzyme ENDentry : ENTRY new_entrynew_entry :entry : entry CONTENTentry : entry comment %prec ASSEMBLEreference_entry : REFERENCE_ENTRY new_reference citationsnew_reference :reference_entry : reference_entry CONTENTreference_entry : reference_entry comment %prec ASSEMBLEreference_entry : reference_entry special %prec ASSEMBLEprotein_entry : PROTEIN_ENTRY new_protein proteinsnew_protein :protein_entry : protein_entry CONTENTprotein_entry : protein_entry ACCESSION CONTENTprotein_entry : protein_entry citations %prec ASSEMBLEspecial : LCURLY special RCURLYspecial : LCURLY RCURLYspecial : special SPECIAL %prec COMBINEspecial : SPECIAL %prec REDUCEproteins : POUND proteins POUNDproteins : POUND POUND proteins : proteins PROTEIN %prec COMBINEproteins : PROTEIN %prec REDUCEcitations : LANGLE citations RANGLEcitations : LANGLE RANGLE citations : citations CITATION %prec COMBINEcitations : CITATION %prec REDUCEcomment : LPARENS comment RPARENS %prec REDUCEcomment : LPARENS RPARENS %prec REDUCEcomment : comment COMMENT %prec COMBINEcomment : COMMENT %prec REDUCE' +_lr_signature = 'leftASSEMBLEleftREDUCEleftCOMBINEENZYME_ENTRY PROTEIN CITATION ENTRY PROTEIN_ENTRY REFERENCE_ENTRY POUND LPARENS RPARENS LANGLE RANGLE LCURLY RCURLY EC_NUMBER END CONTENT SPECIAL COMMENT AND ACCESSIONenzyme : ENZYME_ENTRY EC_NUMBER new_enzymenew_enzyme :enzyme : enzyme commentenzyme : enzyme protein_entryenzyme : enzyme reference_entryenzyme : enzyme entryenzyme : enzyme ENDentry : ENTRY new_entry %prec REDUCEnew_entry : %prec REDUCEentry : entry CONTENTentry : entry proteins %prec ASSEMBLEentry : entry comment %prec ASSEMBLEentry : entry special %prec ASSEMBLEentry : entry citations %prec ASSEMBLEreference_entry : REFERENCE_ENTRY new_reference citationsnew_reference :reference_entry : reference_entry CONTENTreference_entry : reference_entry comment %prec ASSEMBLEreference_entry : reference_entry special %prec ASSEMBLEprotein_entry : PROTEIN_ENTRY new_protein proteins %prec COMBINEnew_protein :protein_entry : protein_entry CONTENT %prec ASSEMBLEprotein_entry : protein_entry accession %prec ASSEMBLEprotein_entry : protein_entry comment %prec ASSEMBLEprotein_entry : protein_entry citations %prec ASSEMBLEaccession : accession AND ACCESSION %prec COMBINEaccession : accession CONTENT %prec COMBINEaccession : ACCESSION %prec REDUCEspecial : LCURLY special RCURLYspecial : LCURLY RCURLYspecial : special SPECIAL %prec COMBINEspecial : SPECIAL %prec REDUCEproteins : POUND proteins POUND %prec ASSEMBLEproteins : POUND POUND %prec ASSEMBLEproteins : proteins PROTEIN %prec COMBINEproteins : PROTEIN %prec REDUCEcitations : LANGLE citations RANGLE %prec ASSEMBLEcitations : LANGLE RANGLE %prec ASSEMBLEcitations : citations CITATION %prec COMBINEcitations : CITATION %prec REDUCEcomment : LPARENS comment RPARENS %prec ASSEMBLEcomment : LPARENS RPARENS %prec ASSEMBLEcomment : comment COMMENT %prec COMBINEcomment : COMMENT %prec REDUCE' -_lr_action_items = {'ENTRY':([0,1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[2,12,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'$end':([1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[0,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'END':([1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[7,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'LPARENS':([1,3,4,5,6,7,8,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[8,-3,-4,-5,-6,-7,8,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'COMMENT':([1,3,4,5,6,7,8,9,12,13,14,15,17,19,20,21,22,24,25,26,27,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[9,-3,-4,-5,-6,-7,9,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,14,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'PROTEIN_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[10,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'REFERENCE_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,17,19,20,21,22,24,25,26,28,31,32,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[11,-3,-4,-5,-6,-7,-37,-9,-2,-36,-19,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-1,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'EC_NUMBER':([2,],[13,]),'CONTENT':([4,5,6,9,12,14,15,16,17,19,20,21,22,24,25,26,28,31,33,34,36,37,39,40,41,43,44,45,46,47,48,50,],[15,20,25,-37,-9,-36,-19,33,-21,-33,-14,-15,-16,-25,-10,-11,-35,-8,-20,-32,-31,-24,-23,-34,-17,-29,-12,-30,-22,-28,-27,-26,]),'ACCESSION':([4,15,17,19,33,34,36,41,43,45,47,48,50,],[16,-19,-21,-33,-20,-32,-31,-17,-29,-30,-28,-27,-26,]),'LANGLE':([4,11,15,17,18,19,30,33,34,36,41,43,45,47,48,50,],[18,-13,-19,-21,18,-33,18,-20,-32,-31,-17,-29,-30,-28,-27,-26,]),'CITATION':([4,11,15,17,18,19,30,33,34,35,36,41,43,44,45,47,48,50,],[19,-13,-19,-21,19,-33,19,-20,-32,34,-31,-17,-29,34,-30,-28,-27,-26,]),'LCURLY':([5,9,14,19,20,21,22,23,24,28,34,36,37,39,40,44,45,46,],[23,-37,-36,-33,-14,-15,-16,23,-25,-35,-32,-31,-24,-23,-34,-12,-30,-22,]),'SPECIAL':([5,9,14,19,20,21,22,23,24,28,34,36,37,38,39,40,44,45,46,],[24,-37,-36,-33,-14,-15,-16,24,-25,-35,-32,-31,-24,37,-23,-34,-12,-30,-22,]),'RPARENS':([8,9,14,27,28,40,],[28,-37,-36,40,-35,-34,]),'POUND':([10,29,42,43,47,48,49,50,],[-18,42,48,-29,-28,48,50,-26,]),'PROTEIN':([10,29,41,42,43,47,48,49,50,],[-18,43,47,43,-29,-28,43,47,-26,]),'RANGLE':([18,19,34,35,36,45,],[36,-33,-32,45,-31,-30,]),'RCURLY':([23,24,37,38,39,46,],[39,-25,-24,46,-23,-22,]),} +_lr_action_items = {'ENZYME_ENTRY':([0,],[2,]),'$end':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[0,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'END':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[7,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'LPARENS':([1,3,4,5,6,7,8,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[8,-3,8,8,8,-7,8,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'COMMENT':([1,3,4,5,6,7,8,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,34,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[9,14,9,9,9,-7,9,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,14,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'PROTEIN_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[10,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'REFERENCE_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[11,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[12,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'EC_NUMBER':([2,],[13,]),'CONTENT':([4,5,6,9,12,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[15,22,27,-44,-9,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'ACCESSION':([4,9,14,15,16,17,18,19,21,33,35,40,41,42,44,48,49,51,52,54,55,57,],[19,-44,-43,-22,-23,-24,-25,-28,-40,-36,-42,54,-27,-39,-38,-35,-34,-41,-20,-26,-37,-33,]),'LANGLE':([4,6,9,11,12,14,15,16,17,18,19,20,21,26,27,28,29,30,31,33,35,37,38,41,42,44,45,47,48,49,51,52,54,55,56,57,],[20,20,-44,-16,-9,-43,-22,-23,-24,-25,-28,20,-40,-32,-10,-11,-12,-13,-14,-36,-42,20,-8,-27,-39,-38,-31,-30,-35,-34,-41,-20,-26,-37,-29,-33,]),'CITATION':([4,6,9,11,12,14,15,16,17,18,19,20,21,26,27,28,29,30,31,33,35,37,38,41,42,43,44,45,47,48,49,51,52,53,54,55,56,57,],[21,21,-44,-16,-9,-43,-22,-23,-24,-25,-28,21,-40,-32,-10,-11,-12,-13,-14,-36,-42,21,-8,-27,-39,42,-38,-31,-30,-35,-34,-41,-20,42,-26,-37,-29,-33,]),'LCURLY':([5,6,9,12,14,21,22,23,24,25,26,27,28,29,30,31,33,35,38,42,44,45,47,48,49,51,53,55,56,57,],[25,25,-44,-9,-43,-40,-17,-18,-19,25,-32,-10,-11,-12,-13,-14,-36,-42,-8,-39,-38,-31,-30,-35,-34,-41,-15,-37,-29,-33,]),'SPECIAL':([5,6,9,12,14,21,22,23,24,25,26,27,28,29,30,31,33,35,38,42,44,45,46,47,48,49,51,53,55,56,57,],[26,26,-44,-9,-43,-40,-17,-18,-19,26,-32,-10,-11,-12,-13,-14,-36,-42,-8,-39,-38,-31,45,-30,-35,-34,-41,-15,-37,-29,-33,]),'POUND':([6,9,10,12,14,21,26,27,28,29,30,31,32,33,35,36,38,42,44,45,47,48,49,50,51,55,56,57,],[32,-44,-21,-9,-43,-40,-32,-10,-11,-12,-13,-14,49,-36,-42,32,-8,-39,-38,-31,-30,-35,-34,57,-41,-37,-29,-33,]),'PROTEIN':([6,9,10,12,14,21,26,27,28,29,30,31,32,33,35,36,38,42,44,45,47,48,49,50,51,52,55,56,57,],[33,-44,-21,-9,-43,-40,-32,-10,-11,-12,-13,-14,33,-36,-42,33,-8,-39,-38,-31,-30,-35,-34,48,-41,48,-37,-29,-33,]),'RPARENS':([8,9,14,34,35,51,],[35,-44,-43,51,-42,-41,]),'AND':([16,19,41,54,],[40,-28,-27,-26,]),'RANGLE':([20,21,42,43,44,55,],[44,-40,-39,55,-38,-37,]),'RCURLY':([25,26,45,46,47,56,],[47,-32,-31,56,-30,-29,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -16,7 +16,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'enzyme':([0,],[1,]),'comment':([1,5,6,8,],[3,21,26,27,]),'protein_entry':([1,],[4,]),'reference_entry':([1,],[5,]),'entry':([1,],[6,]),'citations':([4,18,30,],[17,35,44,]),'special':([5,23,],[22,38,]),'new_protein':([10,],[29,]),'new_reference':([11,],[30,]),'new_entry':([12,],[31,]),'new_enzyme':([13,],[32,]),'proteins':([29,42,48,],[41,49,49,]),} +_lr_goto_items = {'enzyme':([0,],[1,]),'comment':([1,4,5,6,8,],[3,17,23,29,34,]),'protein_entry':([1,],[4,]),'reference_entry':([1,],[5,]),'entry':([1,],[6,]),'accession':([4,],[16,]),'citations':([4,6,20,37,],[18,31,43,53,]),'special':([5,6,25,],[24,30,46,]),'proteins':([6,32,36,49,],[28,50,52,50,]),'new_protein':([10,],[36,]),'new_reference':([11,],[37,]),'new_entry':([12,],[38,]),'new_enzyme':([13,],[39,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -26,41 +26,48 @@ del _lr_goto_items _lr_productions = [ ("S' -> enzyme","S'",1,None,None,None), - ('enzyme -> ENTRY EC_NUMBER new_enzyme','enzyme',3,'p_enzyme','parser.py',141), - ('new_enzyme -> ','new_enzyme',0,'p_new_enzyme','parser.py',146), - ('enzyme -> enzyme comment','enzyme',2,'p_enzyme_comment','parser.py',152), - ('enzyme -> enzyme protein_entry','enzyme',2,'p_enzyme_protein','parser.py',159), - ('enzyme -> enzyme reference_entry','enzyme',2,'p_enzyme_reference','parser.py',165), - ('enzyme -> enzyme entry','enzyme',2,'p_enzyme_entry','parser.py',171), - ('enzyme -> enzyme END','enzyme',2,'p_enzyme_end','parser.py',178), - ('entry -> ENTRY new_entry','entry',2,'p_entry','parser.py',184), - ('new_entry -> ','new_entry',0,'p_new_entry','parser.py',190), - ('entry -> entry CONTENT','entry',2,'p_entry_content','parser.py',198), - ('entry -> entry comment','entry',2,'p_entry_comment','parser.py',205), - ('reference_entry -> REFERENCE_ENTRY new_reference citations','reference_entry',3,'p_reference_entry','parser.py',212), - ('new_reference -> ','new_reference',0,'p_new_reference','parser.py',220), - ('reference_entry -> reference_entry CONTENT','reference_entry',2,'p_reference_content','parser.py',229), - ('reference_entry -> reference_entry comment','reference_entry',2,'p_reference_year','parser.py',237), - ('reference_entry -> reference_entry special','reference_entry',2,'p_reference_pubmed','parser.py',245), - ('protein_entry -> PROTEIN_ENTRY new_protein proteins','protein_entry',3,'p_protein_entry','parser.py',255), - ('new_protein -> ','new_protein',0,'p_new_protein','parser.py',262), - ('protein_entry -> protein_entry CONTENT','protein_entry',2,'p_protein_organism','parser.py',271), - ('protein_entry -> protein_entry ACCESSION CONTENT','protein_entry',3,'p_protein_accession','parser.py',280), - ('protein_entry -> protein_entry citations','protein_entry',2,'p_protein_citations','parser.py',290), - ('special -> LCURLY special RCURLY','special',3,'p_special','parser.py',298), - ('special -> LCURLY RCURLY','special',2,'p_special_empty','parser.py',303), - ('special -> special SPECIAL','special',2,'p_special_combine','parser.py',308), - ('special -> SPECIAL','special',1,'p_special_end','parser.py',313), - ('proteins -> POUND proteins POUND','proteins',3,'p_proteins','parser.py',318), - ('proteins -> POUND POUND','proteins',2,'p_proteins_empty','parser.py',323), - ('proteins -> proteins PROTEIN','proteins',2,'p_proteins_combine','parser.py',328), - ('proteins -> PROTEIN','proteins',1,'p_proteins_end','parser.py',334), + ('enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme','enzyme',3,'p_enzyme','parser.py',141), + ('new_enzyme -> ','new_enzyme',0,'p_new_enzyme','parser.py',145), + ('enzyme -> enzyme comment','enzyme',2,'p_enzyme_comment','parser.py',151), + ('enzyme -> enzyme protein_entry','enzyme',2,'p_enzyme_protein','parser.py',157), + ('enzyme -> enzyme reference_entry','enzyme',2,'p_enzyme_reference','parser.py',162), + ('enzyme -> enzyme entry','enzyme',2,'p_enzyme_entry','parser.py',167), + ('enzyme -> enzyme END','enzyme',2,'p_enzyme_end','parser.py',173), + ('entry -> ENTRY new_entry','entry',2,'p_entry','parser.py',178), + ('new_entry -> ','new_entry',0,'p_new_entry','parser.py',183), + ('entry -> entry CONTENT','entry',2,'p_entry_content','parser.py',190), + ('entry -> entry proteins','entry',2,'p_entry_proteins','parser.py',196), + ('entry -> entry comment','entry',2,'p_entry_comment','parser.py',202), + ('entry -> entry special','entry',2,'p_entry_special','parser.py',208), + ('entry -> entry citations','entry',2,'p_entry_citations','parser.py',214), + ('reference_entry -> REFERENCE_ENTRY new_reference citations','reference_entry',3,'p_reference_entry','parser.py',220), + ('new_reference -> ','new_reference',0,'p_new_reference','parser.py',226), + ('reference_entry -> reference_entry CONTENT','reference_entry',2,'p_reference_content','parser.py',234), + ('reference_entry -> reference_entry comment','reference_entry',2,'p_reference_year','parser.py',240), + ('reference_entry -> reference_entry special','reference_entry',2,'p_reference_pubmed','parser.py',246), + ('protein_entry -> PROTEIN_ENTRY new_protein proteins','protein_entry',3,'p_protein_entry','parser.py',254), + ('new_protein -> ','new_protein',0,'p_new_protein','parser.py',260), + ('protein_entry -> protein_entry CONTENT','protein_entry',2,'p_protein_organism','parser.py',268), + ('protein_entry -> protein_entry accession','protein_entry',2,'p_protein_accession','parser.py',275), + ('protein_entry -> protein_entry comment','protein_entry',2,'p_protein_comment','parser.py',280), + ('protein_entry -> protein_entry citations','protein_entry',2,'p_protein_citations','parser.py',286), + ('accession -> accession AND ACCESSION','accession',3,'p_accession_combine','parser.py',292), + ('accession -> accession CONTENT','accession',2,'p_accession_database','parser.py',297), + ('accession -> ACCESSION','accession',1,'p_accession','parser.py',302), + ('special -> LCURLY special RCURLY','special',3,'p_special','parser.py',306), + ('special -> LCURLY RCURLY','special',2,'p_special_empty','parser.py',310), + ('special -> special SPECIAL','special',2,'p_special_combine','parser.py',314), + ('special -> SPECIAL','special',1,'p_special_end','parser.py',318), + ('proteins -> POUND proteins POUND','proteins',3,'p_proteins','parser.py',322), + ('proteins -> POUND POUND','proteins',2,'p_proteins_empty','parser.py',326), + ('proteins -> proteins PROTEIN','proteins',2,'p_proteins_combine','parser.py',330), + ('proteins -> PROTEIN','proteins',1,'p_proteins_end','parser.py',335), ('citations -> LANGLE citations RANGLE','citations',3,'p_citations','parser.py',339), - ('citations -> LANGLE RANGLE','citations',2,'p_citations_empty','parser.py',344), - ('citations -> citations CITATION','citations',2,'p_citations_combine','parser.py',349), - ('citations -> CITATION','citations',1,'p_citations_end','parser.py',355), - ('comment -> LPARENS comment RPARENS','comment',3,'p_comment','parser.py',360), - ('comment -> LPARENS RPARENS','comment',2,'p_comment_empty','parser.py',365), - ('comment -> comment COMMENT','comment',2,'p_comment_combine','parser.py',370), - ('comment -> COMMENT','comment',1,'p_comment_end','parser.py',375), + ('citations -> LANGLE RANGLE','citations',2,'p_citations_empty','parser.py',343), + ('citations -> citations CITATION','citations',2,'p_citations_combine','parser.py',347), + ('citations -> CITATION','citations',1,'p_citations_end','parser.py',352), + ('comment -> LPARENS comment RPARENS','comment',3,'p_comment','parser.py',356), + ('comment -> LPARENS RPARENS','comment',2,'p_comment_empty','parser.py',360), + ('comment -> comment COMMENT','comment',2,'p_comment_combine','parser.py',364), + ('comment -> COMMENT','comment',1,'p_comment_end','parser.py',369), ] diff --git a/tests/test_parsing/data/long_comments.txt b/tests/test_parsing/data/long_comments.txt new file mode 100644 index 0000000..2959872 --- /dev/null +++ b/tests/test_parsing/data/long_comments.txt @@ -0,0 +1,155 @@ +ID 1.1.1.1 + +IN #2,4,5,8,27,34,36,38# more (#8# high ionic strength inhibits the enzyme + to a higher extent when NADPH instead of NADH is used as a cofactor + <17>; #5# model of inhibitor binding interactions <34>; #5,8# scarcely + inhibitory: sorbinil <44>; #4# aldose reductase inhibitors have + considerable potential for the treatment of diabetes, without increased + risk of hypoglycemia, structure-activity relationship study, the + applicable side alkyl chain length and the presence of a OCH3 group at + C3 in the aromatic ring are essential features for enzyme recognition + and binding, no or poor inhibition by gingerol, shogaol, + 2-(4-hydroxy-3-nitrophenyl)ethanoic acid, + 2-(3,4-dihydroxyphenyl)ethanoic acid, and 2-(4-hydroxyphenyl)ethanoic + acid <71>; #5# enzyme inhibition counteracts nitrosative stress and + poly(ADP-ribose) polymerase activation in diabetic kidney cortex <69>; + #4# enzyme inhibition counteracts nitrosative stress and + poly(ADP-ribose) polymerase activation in high-glucose exposed + mesengial cells <69>; #4# enzyme-inhibitor complex structures, the + hydrophobic nature of the enzyme active site makes significant + contributions to inhibitor binding rather than a reliance on pi-pi + orbital interactions with Trp 20, overview <60>; #4,5# inhibition of AR + protects the ischemic myocardium and is associated with improved energy + metabolism <68>; #2# inhibition of the aldehyde-metabolizing enzyme + modulates NF-kappaB-dependent activation of inflammatory cytokines and + chemokines in mouse serum, liver, heart, and spleen, overview <74>; #5# + inhibitor synthesis, overview, enzyme docking study, modeling, no + inhibition by + (1,3,3-trioxo-2,3-dihydronaphtho[2,3-d]isothiazol-2-yl)acetic acid and + 2-methyl-1,3,3-trioxo-1,2-dihydronaphtho[1,2-d]isothiazole-4-carboxylic + acid <77>; #8# molecular modelling, enzyme docking at the active site + of the enzyme, structure-activity relationships of + 5-arylidene-2,4-thiazolidinediones, an additional aromatic ring or an + H-bond donor group on the 5-benzylidene ring enhance ALR2 inhibitory + potency, the presence of a carboxylic anionic chain on N-3 is + important, and the length of the carboxylic chain is critical, + overview, no inhibition by 5b + 4-[2,4-dioxo-5-(4-phenoxybenzylidene)thiazolidin-3-yl]-2-butenoic acid + methyl ester <61>; #8# no inhibition by + 3,5-bis(3,4-dimethoxybenzylidene)-4-piperidone, + 1,5-bis(3,4-dimethoxyphenyl)-1,4-pentadiene-3-one, + 2,5-bis(3,4-dimethoxybenzylidene)cyclopentanone, and + 2,6-bis(3,4-dimethoxybenzylidene)cyclohexanone, at 0.1 mM <56>; #8# + poor inhibition by + [2,4-dioxo-5-(4-phenoxybenzyl)thiazolidin-3-yl]acetic acid methyl ester + <62>; #5# synthesis and structure-activity relationship study of + inhibitors, overview <76>; #4# Arg312 in ALR1 contributes favourably to + the binding of 3,5-dichlorosalicylic acid through an electrostatic + interaction with the inhibitors electronegative halide atom and + undergoes a conformational change upon tolrestat binding. Tyr116 in + ALR1 forms electrostatic interactions with the fluorobenzyl moiety of + minalrestat and the 3- and 4-hydroxy groups on the phenyl ring of + quercetin. <109>; #5# berberine and palmatine exhibit no RLAR + inhibitory activities within the test concentration of 0.012.5-0.05 + mg/ml <105>; #5# extract and fractions of the rhizome of Coptis + chinensis exhibit broad and moderate RLAR inhibitory activities of + approximately 0.038.9-0.067.5 mg/ml <105>; #5# methanolic and ethanolic + extracts of Litchi chinensis fruits are potent inhibitors of rat lens + aldose reductase <117>; #4# not inibited by + (Z)-2-[2,4-dioxo-5-(4-phenoxybenzylidene)thiazolidin-3-yl]acetamide, + (Z)-2-[5-(4-methoxybenzylidene)-2,4-dioxothiazolidin-3-yl]acetamide, + and + (Z)-2-[5-(3-hydroxy-4-methoxybenzylidene)-2 + 4-dioxothiazolidin-3-yl]acetamide <108>; #5# the enzyme activity is not + affected by 0.1 mM Wy14643 <110>; #5# design and synthesis of pyrrole + based inhibitors and evaluation as selective aldose reductase + inhibitors, bioisosterism between a carboxylic acid moiety and that of + a tetrazole, overview <131>; #4# development of series of highly potent + and selective + [3-(4,5,7-trifluoro-benzothiazol-2-ylmethyl)-pyrrolo[2 + 3-b]pyridin-1-yl]acetic acid aldose reductase inhibitors. The compounds + inhibit aldose reductase, but are inactive against aldehyde reductase + <129>; #4# enzyme active site interactions with the + 3-carboxymethoxy-4-methoxy-phenyl moiety of the inhibitor, binding + structure, overview <135>; #4# identification of inhibitory compounds + from Glycyrrhiza uralensis, overview <128>; #5# identification of + inhibitory compounds from Glycyrrhiza uralensis, overview. Inhibitory + effect of the compounds on the sorbitol accumulation in rat lenses + incubated with high glucose <128>; #4# inhibition of the enzyme + activity also inhibits the expression of the enzyme protein in + xenograft tissue <141>; #5# inhibitory effect of total lignan from + fructus Arctii on aldose reductase, ethanolic extract from dry ripe + fruits of Arctium lappa <143>; #4# structure analysis of a series of + 2,4-thiazolidinediones derivative ALR2 inhibitors, 3D-QSAR molcular + modeling, detailed overview. A large volume group next to the + R-substituent will increase the ALR2 inhibitory activity, and adding a + -CH2COOH substituent at the R-position can generate a compound with + higher predicted activity <140>; #5# structure-activity relationship of + a series of coumarins as ALR1 inhibitors, overview. The C6 OH group + interferes with ALR1 inhibition activity <130>; #5# structure-activity + relationship of a series of coumarins as ALR2 inhibitors and their + suppressive effect on the accumulation of galactitol in the rat lens, + overview. Substitutions in the C7 OH group enhanced the potency toward + ALR2 <130>; #8# synthesis and evaluation of 2,4-thiazolidinedione + inhibitors, structure-activity relationships, overview. No inhibition + by + (Z)-5-[(4-benzyloxyphenyl)methylidene]-3-(3,3 + 3-trifluoro-2-oxopropyl)-2,4-thiazolidinedione <132>; #5# inhibitor + development, synthesis and molecular docking, overview <148>; #4# + inhibitor molecular docking study with ALR2, overview <149>; #5# + inhibitors isolated from Prunus mume flower buds, cultivated in + Zhejiang province, China, structure analysis, overview <152>; #5# + synthesis of quinoxalinone derivatives as potent inhibitors of aldose + reductase, Structure-activity relationship and molecular docking + studies, overview <146>; #27# analysis of pterin-7-carboxamides as + aldose reductase inhibitors, evaluation of the inhibitory activity of + the compounds <159>; #27# design and synthesis of chiral + 2H-chromene-N-imidazolo-imino acid conjugates as aldose reductase + inhibitors, identification by NMR and mass spectrometry, in vitro + inhibition screening, molecular docking study, overview <162>; #34# + design and synthesis of potent and multifunctional aldose reductase + inhibitors based on quinoxalinones, overview. Phenolic structure is + installed in the compounds for the combination of antioxidant activity + and strengthening the ability to fight against diabetic complications, + radical scavenging activity using the model reaction with the stable + free radicals of 2,2-diphenyl-1-picrylhydrazyl. Molecular docking study + using the lidorestat-bound conformation of ALR2, PDB ID 1Z3N <169>; + #34# flavonoids from Litsea japonica inhibit advanced glycation end + products formation and rat lense aldose reductase in vitro with IC50 + values of 0.0074-0.072 mM, flavonoid structure determinations by NMR + spectroscopy, overview. No significant inhibition by 1, 2, afzelin, + quercitrin, rutin, and lyoniside <173>; #27# identification of aldose + reductase inhibitors based on carboxymethylated mercaptotriazinoindole + scaffold, structure-activity relationships, overview <170>; #27,36# no + inhibition by the triazole + 1-(beta-D-glucopyranosyl)-4-(3,4,5-trihydroxyphenyl)-1,2,3-triazole, + the amide N-phenylacetyl beta-D-glucopyranosylamine, and the glycosides + of beta-glucogallin, 2-(3,4,5-trihydroxyphenyl)ethyl + beta-D-glucopyranoside, + [1-(3,4,5-trihydroxybenzyl)-1,2,3-triazole-4-yl]methyl + beta-D-glucopyranoside, and 3-(3,4,5-trihydroxyphenyl)propyl + beta-D-glucopyranoside, synthesis and evaluation, overview <168>; + #27,38# partial nonclassical competitive inhibition is exerted by the + aldose hemiacetal on the reduction of the free aldehyde, aldose + reductase modulation by hemiacetals, negative cooperative behavior of + AR acting on L-idose, mechanism of inhibition, kinetic modelling, + nonclassical competitive model, detailed overview <158>; #34# + structure-activity relationships study of quinoxalinone derivatives as + aldose reductase inhibitors. Among them, N1-acetate derivatives have + significant activity, molecular modeling and docking, overview. Both + C3-phenethyl and C6-NO2 groups play an important role in enhancing the + activity and selectivity of the quinoxalinone based inhibitors <163>; + #38# synthesis, characterization, hypoglycemic and aldose reductase + inhibition activity of + arylsulfonylspiro[fluorene-9,5-imidazolidine]-2,4-diones, analysis of + the Kador-Sharpless model for minimal pharmacophoric requirements for + an aldose reductase inhibitor, and superposition of target molecules on + a hypoglycemic pharmacophoric model and a aldose reductase + pharmacophoric model, overview. Molecular dynamics simulations and + inhibitor binding model. Effects of the compounds on diabetic BALB/c + mice <164>) + <17,34,44,56,60,61,62,68,69,71,74,76,77,105,108,109,110,117,128,129,130 + 131,132,135,140,141,143,146,148,149,152,158,159,162,163,164,168,169,170 + 173> + +/// diff --git a/tests/test_parsing/test_comments.py b/tests/test_parsing/test_comments.py new file mode 100644 index 0000000..416eb9d --- /dev/null +++ b/tests/test_parsing/test_comments.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Moritz E. Beber +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + +from builtins import open +from os.path import dirname, join + +import pytest +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker + +from brenda_parser.models import Base, InformationField +from brenda_parser.parsing.parser import BRENDAParser + +Session = sessionmaker() + + +@pytest.fixture(scope="module") +def connection(): + """ + Use a connection such transactions can be used. + + Notes + ----- + Follows a transaction pattern described in the following: + http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#session-begin-nested + """ + engine = create_engine("sqlite:///:memory:") + Base.metadata.create_all(engine) + session = Session(bind=engine) + InformationField.preload(session) + session.close() + del session + connection = engine.connect() + yield connection + connection.close() + + +@pytest.fixture(scope="function") +def session(connection): + """ + Create a transaction and session per test unit. + + Rolling back a transaction removes even committed rows + (``session.commit``) from the database. + """ + transaction = connection.begin() + session = Session(bind=connection) + yield session + session.close() + transaction.rollback() + + +@pytest.fixture(scope="module") +def parser(): + return BRENDAParser() + + +def test_long_comment(session, parser): + with open(join( + dirname(__file__), "data", "long_comments.txt")) as file_handle: + enzyme = parser.parse(file_handle.read(), session) + assert len(enzyme.entries) == 1 + entry = enzyme.entries[0] + assert entry.field.acronym == "IN" + assert len(entry.protein_references) == 8 + assert len(entry.citation_references) == 40 + assert len(entry.comments) == 40 diff --git a/tests/test_parsing/test_lexer.py b/tests/test_parsing/test_lexer.py index 8b8fffb..0aaa89c 100644 --- a/tests/test_parsing/test_lexer.py +++ b/tests/test_parsing/test_lexer.py @@ -107,7 +107,7 @@ def test_special_tokens(tokenizer, expected): ("( 12,423,23)", ["LPARENS", "COMMENT", "RPARENS"]), ("(12) 13 (", ["LPARENS", "COMMENT", "RPARENS", "CONTENT", "LPARENS"]), ], indirect=["tokenizer"]) -def test_special_tokens(tokenizer, expected): +def test_comment_tokens(tokenizer, expected): tokens = [t.type for t in tokenizer] assert tokens == expected diff --git a/tests/test_parsing/test_parser.py b/tests/test_parsing/test_parser.py index d2c16be..8d2ba38 100644 --- a/tests/test_parsing/test_parser.py +++ b/tests/test_parsing/test_parser.py @@ -123,11 +123,12 @@ def comment_parser(): @pytest.mark.parametrize("text, expected", [ - (" ( )", None), + pytest.mark.raises((" ( )", None), exception=AttributeError, + message="NoneType"), (" ( I am important content. )", "I am important content.") ]) def test_comment(comment_parser, text, expected): - assert comment_parser.parse(text, None) == expected + assert comment_parser.parse(text, None).body == expected @pytest.fixture(scope="module") diff --git a/tox.ini b/tox.ini index 8d66a4a..185a33c 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,8 @@ usedevelop = true deps = -r{toxinidir}/test_requirements.txt commands = - {posargs:pytest --cov-append=brenda_parser} + {posargs:pytest --cov=brenda_parser} + - codecov [testenv:flake8] skip_install = True From 96132f2784f1ac05e6348f09edbf20d6f18dfcfc Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sun, 18 Feb 2018 22:58:14 +0100 Subject: [PATCH 03/15] refactor: update the Travis configuration --- .travis.yml | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0460603..43ad321 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,45 +1,40 @@ language: python sudo: false cache: pip +git: + depth: 1 env: global: - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so - SEGFAULT_SIGNALS=all - matrix: - - TOXENV=check - - TOXENV=docs +branches: + only: + - master + - develop + - "/^\\d+\\.\\d+\\.\\d+[a]?\\d*$/" matrix: + fast_finish: true include: - - python: '2.7' - env: - - TOXENV=py27,report,codecov - - python: '3.3' + - python: '3.5' env: - - TOXENV=py33,report,codecov - - python: '3.4' + - TOXENV=flake8 + - python: '2.7' env: - - TOXENV=py34,report,codecov + - TOXENV=py27 - python: '3.5' env: - - TOXENV=py35,report,codecov + - TOXENV=py35 - python: '3.6' env: - - TOXENV=py36,report,codecov - - python: 'pypy-5.4' - env: - - TOXENV=pypy,report,codecov + - TOXENV=py36 before_install: - python --version - uname -a - lsb_release -a install: - - pip install tox - - virtualenv --version - - easy_install --version - - pip --version - - tox --version + - travis_retry pip install -U pip setuptools wheel tox script: - - tox -v + - travis_wait tox -v after_failure: - more .tox/log/* | cat - more .tox/*/log/* | cat From dd4226dd0541bb543b1cc7963bef1136f1e671c0 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sun, 21 Oct 2018 23:38:30 +0200 Subject: [PATCH 04/15] chore: update tools --- .coveragerc | 19 ------- .editorconfig | 3 + .travis.yml | 62 ++++++++++++++------- setup.cfg | 15 ++--- setup.py | 4 +- src/brenda_parser/parsing/parser.out | 2 +- src/brenda_parser/parsing/parsetab.py | 3 +- test_requirements.txt | 5 -- tests/test_models/test_information_field.py | 18 +++--- tests/test_models/test_organism.py | 6 +- tests/test_models/test_reference.py | 14 ++--- tests/test_parsing/test_parser.py | 5 +- tox.ini | 48 +++++++++++----- 13 files changed, 119 insertions(+), 85 deletions(-) delete mode 100644 .coveragerc delete mode 100644 test_requirements.txt diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index f052d25..0000000 --- a/.coveragerc +++ /dev/null @@ -1,19 +0,0 @@ -[paths] -source = - src/brenda_parser - */site-packages/brenda_parser - -[run] -branch = true -source = - brenda_parser -parallel = true -omit = - */_version.py - */lextab.py - */parsetab.py - -[report] -show_missing = true -precision = 2 -omit = *migrations* diff --git a/.editorconfig b/.editorconfig index 4000618..caa8b29 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,6 @@ charset = utf-8 [*.{bat,cmd,ps1}] end_of_line = crlf + +[*.{yml,json}] +indent_size = 2 diff --git a/.travis.yml b/.travis.yml index 43ad321..2215dba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,17 @@ language: python sudo: false -cache: pip +python: + - '2.7' + - '3.5' + - '3.6' + - '3.7-dev' +cache: + pip: true git: - depth: 1 + depth: 2 env: global: + - GITHUB_REPO=Midnighter/BRENDA-Parser - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so - SEGFAULT_SIGNALS=all branches: @@ -14,31 +21,46 @@ branches: - "/^\\d+\\.\\d+\\.\\d+[a]?\\d*$/" matrix: fast_finish: true - include: - - python: '3.5' - env: - - TOXENV=flake8 - - python: '2.7' - env: - - TOXENV=py27 - - python: '3.5' - env: - - TOXENV=py35 - - python: '3.6' - env: - - TOXENV=py36 before_install: - python --version - uname -a - lsb_release -a install: - - travis_retry pip install -U pip setuptools wheel tox + - pip install --upgrade pip setuptools wheel tox tox-travis script: - - travis_wait tox -v -after_failure: - - more .tox/log/* | cat - - more .tox/*/log/* | cat + - tox -- --cov-report xml --cov-report term + - bash <(curl -s https://codecov.io/bash) + +stages: +- test +- name: deploy + if: tag IS present + +jobs: + include: + - stage: deploy + before_install: skip + install: skip + script: + - echo "Deploying brenda-parser." + deploy: + - provider: pypi + skip_cleanup: true + user: midnighter + password: $PYPI_PASSWORD + on: + tags: true + repo: $GITHUB_REPO + - provider: releases + skip_cleanup: true + api_key: $GITHUB_TOKEN + body: "Please see https://github.com/${GITHUB_REPO}/blob/${TRAVIS_TAG}/CHANGELOG.rst for the full release notes." + on: + tags: true + repo: $GITHUB_REPO + notifications: email: on_success: never on_failure: always + on_pull_requests: false diff --git a/setup.cfg b/setup.cfg index c889b31..88b6158 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,9 @@ [metadata] name = brenda-parser url = https://github.com/Midnighter/BRENDA-Parser -download_url = https://pypi.python.org/pypi/brenda-parser +download_url = https://pypi.org/project/brenda-parser/ author = Moritz E. Beber -author_email = moritz.beber@gmail.com +author_email = midnighter@posteo.net classifiers = Development Status :: 4 - Beta Intended Audience :: Science/Research @@ -15,12 +15,14 @@ classifiers = Programming Language :: Python :: 3 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 license = BSD 3-Clause License description = A parser for the BRENDA flat file distribution. long_description = file: README.rst keywords = BRENDA parser + enzyme [options] zip_safe = True @@ -34,9 +36,11 @@ install_requires = SQLAlchemy tqdm include_package_data = True +python_requires = >=2.7.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.* packages = find: -package_dir = - = src + +[options.packages.find] +where = src [options.entry_points] console_scripts = @@ -52,9 +56,6 @@ universal = 1 max-line-length = 80 exclude = __init__.py,docs -[pydocstyle] -match_dir = src/brenda_parser - [tool:pytest] testpaths = tests diff --git a/setup.py b/setup.py index e16772c..f11980e 100644 --- a/setup.py +++ b/setup.py @@ -10,5 +10,7 @@ # All other arguments are defined in `setup.cfg`. setup( version=versioneer.get_version(), - cmdclass=versioneer.get_cmdclass() + cmdclass=versioneer.get_cmdclass(), + # Temporary workaround for https://github.com/pypa/setuptools/issues/1136. + package_dir={"": "src"} ) diff --git a/src/brenda_parser/parsing/parser.out b/src/brenda_parser/parsing/parser.out index 9058129..fbfcf91 100644 --- a/src/brenda_parser/parsing/parser.out +++ b/src/brenda_parser/parsing/parser.out @@ -1,4 +1,4 @@ -Created by PLY version 3.10 (http://www.dabeaz.com/ply) +Created by PLY version 3.11 (http://www.dabeaz.com/ply) Grammar diff --git a/src/brenda_parser/parsing/parsetab.py b/src/brenda_parser/parsing/parsetab.py index 978cc8e..d131116 100644 --- a/src/brenda_parser/parsing/parsetab.py +++ b/src/brenda_parser/parsing/parsetab.py @@ -1,11 +1,12 @@ # parsetab.py # This file is automatically generated. Do not edit. +# pylint: disable=W,C,R _tabversion = '3.10' _lr_method = 'LALR' -_lr_signature = 'leftASSEMBLEleftREDUCEleftCOMBINEENZYME_ENTRY PROTEIN CITATION ENTRY PROTEIN_ENTRY REFERENCE_ENTRY POUND LPARENS RPARENS LANGLE RANGLE LCURLY RCURLY EC_NUMBER END CONTENT SPECIAL COMMENT AND ACCESSIONenzyme : ENZYME_ENTRY EC_NUMBER new_enzymenew_enzyme :enzyme : enzyme commentenzyme : enzyme protein_entryenzyme : enzyme reference_entryenzyme : enzyme entryenzyme : enzyme ENDentry : ENTRY new_entry %prec REDUCEnew_entry : %prec REDUCEentry : entry CONTENTentry : entry proteins %prec ASSEMBLEentry : entry comment %prec ASSEMBLEentry : entry special %prec ASSEMBLEentry : entry citations %prec ASSEMBLEreference_entry : REFERENCE_ENTRY new_reference citationsnew_reference :reference_entry : reference_entry CONTENTreference_entry : reference_entry comment %prec ASSEMBLEreference_entry : reference_entry special %prec ASSEMBLEprotein_entry : PROTEIN_ENTRY new_protein proteins %prec COMBINEnew_protein :protein_entry : protein_entry CONTENT %prec ASSEMBLEprotein_entry : protein_entry accession %prec ASSEMBLEprotein_entry : protein_entry comment %prec ASSEMBLEprotein_entry : protein_entry citations %prec ASSEMBLEaccession : accession AND ACCESSION %prec COMBINEaccession : accession CONTENT %prec COMBINEaccession : ACCESSION %prec REDUCEspecial : LCURLY special RCURLYspecial : LCURLY RCURLYspecial : special SPECIAL %prec COMBINEspecial : SPECIAL %prec REDUCEproteins : POUND proteins POUND %prec ASSEMBLEproteins : POUND POUND %prec ASSEMBLEproteins : proteins PROTEIN %prec COMBINEproteins : PROTEIN %prec REDUCEcitations : LANGLE citations RANGLE %prec ASSEMBLEcitations : LANGLE RANGLE %prec ASSEMBLEcitations : citations CITATION %prec COMBINEcitations : CITATION %prec REDUCEcomment : LPARENS comment RPARENS %prec ASSEMBLEcomment : LPARENS RPARENS %prec ASSEMBLEcomment : comment COMMENT %prec COMBINEcomment : COMMENT %prec REDUCE' +_lr_signature = 'leftASSEMBLEleftREDUCEleftCOMBINEACCESSION AND CITATION COMMENT CONTENT EC_NUMBER END ENTRY ENZYME_ENTRY LANGLE LCURLY LPARENS POUND PROTEIN PROTEIN_ENTRY RANGLE RCURLY REFERENCE_ENTRY RPARENS SPECIALenzyme : ENZYME_ENTRY EC_NUMBER new_enzymenew_enzyme :enzyme : enzyme commentenzyme : enzyme protein_entryenzyme : enzyme reference_entryenzyme : enzyme entryenzyme : enzyme ENDentry : ENTRY new_entry %prec REDUCEnew_entry : %prec REDUCEentry : entry CONTENTentry : entry proteins %prec ASSEMBLEentry : entry comment %prec ASSEMBLEentry : entry special %prec ASSEMBLEentry : entry citations %prec ASSEMBLEreference_entry : REFERENCE_ENTRY new_reference citationsnew_reference :reference_entry : reference_entry CONTENTreference_entry : reference_entry comment %prec ASSEMBLEreference_entry : reference_entry special %prec ASSEMBLEprotein_entry : PROTEIN_ENTRY new_protein proteins %prec COMBINEnew_protein :protein_entry : protein_entry CONTENT %prec ASSEMBLEprotein_entry : protein_entry accession %prec ASSEMBLEprotein_entry : protein_entry comment %prec ASSEMBLEprotein_entry : protein_entry citations %prec ASSEMBLEaccession : accession AND ACCESSION %prec COMBINEaccession : accession CONTENT %prec COMBINEaccession : ACCESSION %prec REDUCEspecial : LCURLY special RCURLYspecial : LCURLY RCURLYspecial : special SPECIAL %prec COMBINEspecial : SPECIAL %prec REDUCEproteins : POUND proteins POUND %prec ASSEMBLEproteins : POUND POUND %prec ASSEMBLEproteins : proteins PROTEIN %prec COMBINEproteins : PROTEIN %prec REDUCEcitations : LANGLE citations RANGLE %prec ASSEMBLEcitations : LANGLE RANGLE %prec ASSEMBLEcitations : citations CITATION %prec COMBINEcitations : CITATION %prec REDUCEcomment : LPARENS comment RPARENS %prec ASSEMBLEcomment : LPARENS RPARENS %prec ASSEMBLEcomment : comment COMMENT %prec COMBINEcomment : COMMENT %prec REDUCE' _lr_action_items = {'ENZYME_ENTRY':([0,],[2,]),'$end':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[0,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'END':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[7,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'LPARENS':([1,3,4,5,6,7,8,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[8,-3,8,8,8,-7,8,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'COMMENT':([1,3,4,5,6,7,8,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,34,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[9,14,9,9,9,-7,9,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,14,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'PROTEIN_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[10,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'REFERENCE_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[11,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[12,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'EC_NUMBER':([2,],[13,]),'CONTENT':([4,5,6,9,12,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[15,22,27,-44,-9,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'ACCESSION':([4,9,14,15,16,17,18,19,21,33,35,40,41,42,44,48,49,51,52,54,55,57,],[19,-44,-43,-22,-23,-24,-25,-28,-40,-36,-42,54,-27,-39,-38,-35,-34,-41,-20,-26,-37,-33,]),'LANGLE':([4,6,9,11,12,14,15,16,17,18,19,20,21,26,27,28,29,30,31,33,35,37,38,41,42,44,45,47,48,49,51,52,54,55,56,57,],[20,20,-44,-16,-9,-43,-22,-23,-24,-25,-28,20,-40,-32,-10,-11,-12,-13,-14,-36,-42,20,-8,-27,-39,-38,-31,-30,-35,-34,-41,-20,-26,-37,-29,-33,]),'CITATION':([4,6,9,11,12,14,15,16,17,18,19,20,21,26,27,28,29,30,31,33,35,37,38,41,42,43,44,45,47,48,49,51,52,53,54,55,56,57,],[21,21,-44,-16,-9,-43,-22,-23,-24,-25,-28,21,-40,-32,-10,-11,-12,-13,-14,-36,-42,21,-8,-27,-39,42,-38,-31,-30,-35,-34,-41,-20,42,-26,-37,-29,-33,]),'LCURLY':([5,6,9,12,14,21,22,23,24,25,26,27,28,29,30,31,33,35,38,42,44,45,47,48,49,51,53,55,56,57,],[25,25,-44,-9,-43,-40,-17,-18,-19,25,-32,-10,-11,-12,-13,-14,-36,-42,-8,-39,-38,-31,-30,-35,-34,-41,-15,-37,-29,-33,]),'SPECIAL':([5,6,9,12,14,21,22,23,24,25,26,27,28,29,30,31,33,35,38,42,44,45,46,47,48,49,51,53,55,56,57,],[26,26,-44,-9,-43,-40,-17,-18,-19,26,-32,-10,-11,-12,-13,-14,-36,-42,-8,-39,-38,-31,45,-30,-35,-34,-41,-15,-37,-29,-33,]),'POUND':([6,9,10,12,14,21,26,27,28,29,30,31,32,33,35,36,38,42,44,45,47,48,49,50,51,55,56,57,],[32,-44,-21,-9,-43,-40,-32,-10,-11,-12,-13,-14,49,-36,-42,32,-8,-39,-38,-31,-30,-35,-34,57,-41,-37,-29,-33,]),'PROTEIN':([6,9,10,12,14,21,26,27,28,29,30,31,32,33,35,36,38,42,44,45,47,48,49,50,51,52,55,56,57,],[33,-44,-21,-9,-43,-40,-32,-10,-11,-12,-13,-14,33,-36,-42,33,-8,-39,-38,-31,-30,-35,-34,48,-41,48,-37,-29,-33,]),'RPARENS':([8,9,14,34,35,51,],[35,-44,-43,51,-42,-41,]),'AND':([16,19,41,54,],[40,-28,-27,-26,]),'RANGLE':([20,21,42,43,44,55,],[44,-40,-39,55,-38,-37,]),'RCURLY':([25,26,45,46,47,56,],[47,-32,-31,56,-30,-29,]),} diff --git a/test_requirements.txt b/test_requirements.txt deleted file mode 100644 index c86521f..0000000 --- a/test_requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -pytest>=3.1 -pytest-mock -pytest-raises -pytest-cov -codecov diff --git a/tests/test_models/test_information_field.py b/tests/test_models/test_information_field.py index 9c44107..d4ee082 100644 --- a/tests/test_models/test_information_field.py +++ b/tests/test_models/test_information_field.py @@ -31,23 +31,27 @@ import pytest from six import iteritems -from sqlalchemy.exc import IntegrityError +# from sqlalchemy.exc import IntegrityError from brenda_parser.exceptions import ValidationError from brenda_parser.models import InformationField @pytest.mark.parametrize("attributes", [ - pytest.mark.raises({"acronym": ""}, exception=ValidationError), - pytest.mark.raises({"acronym": "I"}, exception=ValidationError), - pytest.mark.raises({"acronym": "on"}, exception=ValidationError), + pytest.param({"acronym": ""}, + marks=pytest.mark.raises(exception=ValidationError)), + pytest.param({"acronym": "I"}, + marks=pytest.mark.raises(exception=ValidationError)), + pytest.param({"acronym": "on"}, + marks=pytest.mark.raises(exception=ValidationError)), {"acronym": "RN"}, {"acronym": "REF"}, {"acronym": "IC50"}, - pytest.mark.raises({"acronym": "too long"}, exception=ValidationError), + pytest.param({"acronym": "too long"}, + marks=pytest.mark.raises(exception=ValidationError)), {"acronym": "SM", "name": "Super Man"}, - # pytest.mark.raises({"acronym": "SM", "name": "an" * 51}, - # exception=IntegrityError) + pytest.param({"acronym": "SM", "name": "an" * 51}) + # marks=pytest.mark.raises(exception=IntegrityError)), ]) def test_create_information_field(session, attributes): obj = InformationField(**attributes) diff --git a/tests/test_models/test_organism.py b/tests/test_models/test_organism.py index 64bf9bf..afcc75c 100644 --- a/tests/test_models/test_organism.py +++ b/tests/test_models/test_organism.py @@ -37,7 +37,8 @@ @pytest.mark.parametrize("attributes", [ - pytest.mark.raises({"name": None}, exception=IntegrityError), + pytest.param({"name": None}, + marks=pytest.mark.raises(exception=IntegrityError)), {"name": ""}, {"name": "Homo sapiens"} ]) @@ -50,7 +51,8 @@ def test_create_organism(session, attributes): @pytest.mark.parametrize("name_a, name_b", [ - pytest.mark.raises(("same", "same"), exception=IntegrityError), + pytest.param("same", "same", + marks=pytest.mark.raises(exception=IntegrityError)), ("way", "different") ]) def test_unique_name(session, name_a, name_b): diff --git a/tests/test_models/test_reference.py b/tests/test_models/test_reference.py index bbf0bce..1533bd0 100644 --- a/tests/test_models/test_reference.py +++ b/tests/test_models/test_reference.py @@ -38,10 +38,11 @@ @pytest.mark.parametrize("attributes", [ - pytest.mark.raises({"body": None}, exception=IntegrityError), + pytest.param({"body": None}, + marks=pytest.mark.raises(exception=IntegrityError)), {"body": "Cunning et al."}, - pytest.mark.raises({"body": "Evil Inc.", "pubmed": "fail"}, - exception=ValidationError), + pytest.param({"body": "Evil Inc.", "pubmed": "fail"}, + marks=pytest.mark.raises(exception=ValidationError)), {"body": "Vitello et al.", "pubmed": "Pubmed:1234567"} ]) def test_create_reference(session, attributes): @@ -53,10 +54,9 @@ def test_create_reference(session, attributes): @pytest.mark.parametrize("ref_a, ref_b", [ - pytest.mark.raises( - ({"body": "Vitello et al.", "pubmed": "Pubmed:1234567"}, - {"body": "The Others", "pubmed": "Pubmed:1234567"}), - exception=IntegrityError), + pytest.param({"body": "Vitello et al.", "pubmed": "Pubmed:1234567"}, + {"body": "The Others", "pubmed": "Pubmed:1234567"}, + marks=pytest.mark.raises(exception=IntegrityError)), ({"body": "Batman", "pubmed": "Pubmed:1111111"}, {"body": "Robin", "pubmed": "Pubmed:2222222"}) ]) diff --git a/tests/test_parsing/test_parser.py b/tests/test_parsing/test_parser.py index 8d2ba38..92508ea 100644 --- a/tests/test_parsing/test_parser.py +++ b/tests/test_parsing/test_parser.py @@ -123,8 +123,9 @@ def comment_parser(): @pytest.mark.parametrize("text, expected", [ - pytest.mark.raises((" ( )", None), exception=AttributeError, - message="NoneType"), + pytest.param(" ( )", None, + marks=pytest.mark.raises(exception=AttributeError, + message="NoneType")), (" ( I am important content. )", "I am important content.") ]) def test_comment(comment_parser, text, expected): diff --git a/tox.ini b/tox.ini index 185a33c..1215235 100644 --- a/tox.ini +++ b/tox.ini @@ -1,24 +1,46 @@ [tox] -envlist = flake8, py{27,35,36} +envlist = flake8, isort, docs, py{27,35,36,37} + +[travis] +os = + linux: flake8, isort, docs, py{27,35,36,37} + osx: py{27,35} +python = + 2.7: py27, flake8 + 3.5: py35, flake8, docs, isort + 3.6: py36 + 3.7: py37 [testenv] -setenv = - PYTHONUNBUFFERED=yes -passenv = - CI - TRAVIS - TRAVIS_* -usedevelop = true deps = - -r{toxinidir}/test_requirements.txt + pytest + pytest-cov + pytest-mock + pytest-raises commands = - {posargs:pytest --cov=brenda_parser} - - codecov + pytest {posargs} --cov={envsitepackagesdir}/brenda_parser [testenv:flake8] skip_install = True -deps= +deps = flake8 flake8-docstrings +commands = + flake8 {toxinidir}/src/brenda_parser {toxinidir}/tests + +[testenv:isort] +skip_install = True +deps= + isort +commands= + isort --check-only --diff --recursive {toxinidir}/src/brenda_parser {toxinidir}/tests + +[testenv:docs] +skip_install = True +deps= + -r{toxinidir}/docs/requirements.txt +whitelist_externals = + make commands= - flake8 src/brenda_parser + make -C {toxinidir}/docs linkcheck + make docs From bbf68882c014ea2ad29c89da4086f76625ff6992 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Thu, 25 Oct 2018 10:07:38 +0200 Subject: [PATCH 05/15] style: sort imports --- brenda/parser.py | 2 +- setup.cfg | 28 ++++++++++++++++++- src/brenda_parser/api.py | 5 ++-- src/brenda_parser/cli.py | 1 + src/brenda_parser/exceptions.py | 3 +- src/brenda_parser/models/accession.py | 3 +- src/brenda_parser/models/comment.py | 4 +-- src/brenda_parser/models/enzyme.py | 3 +- src/brenda_parser/models/field_entry.py | 3 +- src/brenda_parser/models/information_field.py | 3 +- src/brenda_parser/models/organism.py | 1 + src/brenda_parser/models/protein.py | 5 ++-- src/brenda_parser/models/reference.py | 3 +- src/brenda_parser/parsing/lexer.py | 1 + src/brenda_parser/parsing/lextab.py | 4 +-- src/brenda_parser/parsing/parser.py | 2 ++ testing.py | 16 +++++++++++ tests/test_models/conftest.py | 3 +- tests/test_models/test_information_field.py | 5 +++- tests/test_models/test_protein.py | 2 +- tests/test_parsing/test_comments.py | 3 +- tests/test_parsing/test_parser.py | 1 + 22 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 testing.py diff --git a/brenda/parser.py b/brenda/parser.py index e8923bb..24b9d38 100644 --- a/brenda/parser.py +++ b/brenda/parser.py @@ -274,7 +274,7 @@ class BRENDAParser(object): "SS", "ST", "SU", - "SY", + "SY",models.Comment(body=c) "TN", "TO", "TR", diff --git a/setup.cfg b/setup.cfg index 88b6158..fb4e7c7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,7 +54,33 @@ universal = 1 [flake8] max-line-length = 80 -exclude = __init__.py,docs +exclude = + __init__.py + docs + _version.py + lexer.py + lextab.py + parser.py + parsetab.py + +[coverage:run] +omit = + */_version.py + */lextab.py + */parsetab.py + +[isort] +line_length = 80 +indent = 4 +multi_line_output = 4 +lines_after_imports = 2 +known_first_party = brenda_parser +known_third_party = + click + depinfo + six + sqlalchemy + tqdm [tool:pytest] testpaths = tests diff --git a/src/brenda_parser/api.py b/src/brenda_parser/api.py index 8f8c107..21cee33 100644 --- a/src/brenda_parser/api.py +++ b/src/brenda_parser/api.py @@ -41,7 +41,8 @@ from tqdm import tqdm import brenda_parser.models as models -from brenda_parser.parsing import BRENDAParser, BRENDALexer +from brenda_parser.parsing import BRENDALexer, BRENDAParser + __all__ = ("initialize", "parse") @@ -113,7 +114,7 @@ def parse(lines, connection="sqlite:///:memory:", processes=1): else: init_worker(engine) single_parse(sections) - return session + return engine, session def single_parse(sections): diff --git a/src/brenda_parser/cli.py b/src/brenda_parser/cli.py index 053d830..4bb5e8c 100644 --- a/src/brenda_parser/cli.py +++ b/src/brenda_parser/cli.py @@ -41,6 +41,7 @@ import brenda_parser.api as api from brenda_parser import __version__ + LOGGER = logging.getLogger(__name__.split(".", 1)[0]) click_log.basic_config(LOGGER) diff --git a/src/brenda_parser/exceptions.py b/src/brenda_parser/exceptions.py index 5124d58..9bf8896 100644 --- a/src/brenda_parser/exceptions.py +++ b/src/brenda_parser/exceptions.py @@ -32,10 +32,9 @@ from __future__ import absolute_import + __all__ = ("ValidationError",) class ValidationError(AssertionError): pass - - diff --git a/src/brenda_parser/models/accession.py b/src/brenda_parser/models/accession.py index 7763565..947793b 100644 --- a/src/brenda_parser/models/accession.py +++ b/src/brenda_parser/models/accession.py @@ -38,8 +38,9 @@ from sqlalchemy import Column, Integer, String from sqlalchemy.orm import relationship, validates -from brenda_parser.models import Base from brenda_parser.exceptions import ValidationError +from brenda_parser.models import Base + __all__ = ("Accession",) diff --git a/src/brenda_parser/models/comment.py b/src/brenda_parser/models/comment.py index 8fad56d..190ac6c 100644 --- a/src/brenda_parser/models/comment.py +++ b/src/brenda_parser/models/comment.py @@ -34,11 +34,12 @@ import logging -from sqlalchemy import Table, Column, String, Integer, ForeignKey +from sqlalchemy import Column, ForeignKey, Integer, String, Table from sqlalchemy.orm import relationship from brenda_parser.models import Base + __all__ = ("Comment",) LOGGER = logging.getLogger(__name__) @@ -70,4 +71,3 @@ class Comment(Base): secondary=comment_protein_association) citations = relationship("Reference", secondary=comment_citation_association) - diff --git a/src/brenda_parser/models/enzyme.py b/src/brenda_parser/models/enzyme.py index 25a4b9d..87ceff1 100644 --- a/src/brenda_parser/models/enzyme.py +++ b/src/brenda_parser/models/enzyme.py @@ -34,11 +34,12 @@ import logging -from sqlalchemy import Table, Column, Integer, String, ForeignKey +from sqlalchemy import Column, ForeignKey, Integer, String, Table from sqlalchemy.orm import relationship from brenda_parser.models import Base + __all__ = ("Enzyme",) LOGGER = logging.getLogger(__name__) diff --git a/src/brenda_parser/models/field_entry.py b/src/brenda_parser/models/field_entry.py index c2bb7b2..891651a 100644 --- a/src/brenda_parser/models/field_entry.py +++ b/src/brenda_parser/models/field_entry.py @@ -34,11 +34,12 @@ import logging -from sqlalchemy import Table, Column, Integer, String, ForeignKey +from sqlalchemy import Column, ForeignKey, Integer, String, Table from sqlalchemy.orm import relationship from brenda_parser.models import Base + __all__ = ("FieldEntry",) LOGGER = logging.getLogger(__name__) diff --git a/src/brenda_parser/models/information_field.py b/src/brenda_parser/models/information_field.py index e867166..5118c66 100644 --- a/src/brenda_parser/models/information_field.py +++ b/src/brenda_parser/models/information_field.py @@ -38,13 +38,14 @@ from importlib_resources import open_text from sqlalchemy import Column, Integer, String -from sqlalchemy.orm import validates from sqlalchemy.exc import IntegrityError +from sqlalchemy.orm import validates import brenda_parser.data from brenda_parser.exceptions import ValidationError from brenda_parser.models import Base + __all__ = ("InformationField",) LOGGER = logging.getLogger(__name__) diff --git a/src/brenda_parser/models/organism.py b/src/brenda_parser/models/organism.py index 2296b6f..46920c1 100644 --- a/src/brenda_parser/models/organism.py +++ b/src/brenda_parser/models/organism.py @@ -38,6 +38,7 @@ from brenda_parser.models import Base + __all__ = ("Organism",) LOGGER = logging.getLogger(__name__) diff --git a/src/brenda_parser/models/protein.py b/src/brenda_parser/models/protein.py index 1d2246c..0aa2376 100644 --- a/src/brenda_parser/models/protein.py +++ b/src/brenda_parser/models/protein.py @@ -34,12 +34,13 @@ import logging -from sqlalchemy import Table, Column, Integer, ForeignKey -from sqlalchemy.orm import validates, relationship +from sqlalchemy import Column, ForeignKey, Integer, Table +from sqlalchemy.orm import relationship, validates from brenda_parser.exceptions import ValidationError from brenda_parser.models import Base + __all__ = ("Protein",) LOGGER = logging.getLogger(__name__) diff --git a/src/brenda_parser/models/reference.py b/src/brenda_parser/models/reference.py index 15304f0..0b7e84c 100644 --- a/src/brenda_parser/models/reference.py +++ b/src/brenda_parser/models/reference.py @@ -35,12 +35,13 @@ import logging import re -from sqlalchemy import Column, Integer, String, ForeignKey +from sqlalchemy import Column, ForeignKey, Integer, String from sqlalchemy.orm import relationship, validates from brenda_parser.exceptions import ValidationError from brenda_parser.models import Base + __all__ = ("Reference",) LOGGER = logging.getLogger(__name__) diff --git a/src/brenda_parser/parsing/lexer.py b/src/brenda_parser/parsing/lexer.py index 84204dc..b3ea34d 100644 --- a/src/brenda_parser/parsing/lexer.py +++ b/src/brenda_parser/parsing/lexer.py @@ -35,6 +35,7 @@ from ply.lex import lex + __all__ = ("BRENDALexer",) LOGGER = logging.getLogger(__name__) diff --git a/src/brenda_parser/parsing/lextab.py b/src/brenda_parser/parsing/lextab.py index ead6c92..a8d2460 100644 --- a/src/brenda_parser/parsing/lextab.py +++ b/src/brenda_parser/parsing/lextab.py @@ -1,6 +1,6 @@ -# lextab.py. This file automatically created by PLY (version 3.10). Don't edit! +# lextab.py. This file automatically created by PLY (version 3.11). Don't edit! _tabversion = '3.10' -_lextokens = set(('COMMENT', 'RCURLY', 'REFERENCE_ENTRY', 'EC_NUMBER', 'CONTENT', 'ENTRY', 'RANGLE', 'LPARENS', 'RPARENS', 'LCURLY', 'ENZYME_ENTRY', 'PROTEIN', 'END', 'LANGLE', 'SPECIAL', 'AND', 'PROTEIN_ENTRY', 'CITATION', 'POUND', 'ACCESSION')) +_lextokens = set(('ACCESSION', 'AND', 'CITATION', 'COMMENT', 'CONTENT', 'EC_NUMBER', 'END', 'ENTRY', 'ENZYME_ENTRY', 'LANGLE', 'LCURLY', 'LPARENS', 'POUND', 'PROTEIN', 'PROTEIN_ENTRY', 'RANGLE', 'RCURLY', 'REFERENCE_ENTRY', 'RPARENS', 'SPECIAL')) _lexreflags = 64 _lexliterals = '' _lexstateinfo = {'INITIAL': 'inclusive', 'citation': 'exclusive', 'protein': 'exclusive', 'special': 'exclusive', 'comment': 'exclusive', 'enzyme': 'exclusive', 'protentry': 'inclusive'} diff --git a/src/brenda_parser/parsing/parser.py b/src/brenda_parser/parsing/parser.py index 9ece655..76f37fb 100644 --- a/src/brenda_parser/parsing/parser.py +++ b/src/brenda_parser/parsing/parser.py @@ -40,6 +40,7 @@ from brenda_parser.exceptions import ValidationError from brenda_parser.parsing.lexer import BRENDALexer + __all__ = ("BRENDAParser",) LOGGER = logging.getLogger(__name__) @@ -368,6 +369,7 @@ def p_comment_combine(self, p): def p_comment_end(self, p): """comment : COMMENT %prec REDUCE""" p[0] = models.Comment(body=p[1]) + # p[0] = [models.Comment(body=c) for c in p[1].split(";")] def p_error(self, p): LOGGER.debug("Error: %s", str(p)) diff --git a/testing.py b/testing.py new file mode 100644 index 0000000..0e032f3 --- /dev/null +++ b/testing.py @@ -0,0 +1,16 @@ +import logging + +from brenda_parser import parse + + +logging.basicConfig(level="DEBUG") + + +def main(): + with open("tests/test_parsing/data/long_comments.txt") as fh: + content = fh.read() + engine, session = parse(content.split("\n")) + + +if __name__ == "__main__": + main() diff --git a/tests/test_models/conftest.py b/tests/test_models/conftest.py index 8b0b773..0ce95f0 100644 --- a/tests/test_models/conftest.py +++ b/tests/test_models/conftest.py @@ -35,6 +35,7 @@ from brenda_parser.models import Base + Session = sessionmaker() @@ -68,5 +69,3 @@ def session(connection): yield session session.close() transaction.rollback() - - diff --git a/tests/test_models/test_information_field.py b/tests/test_models/test_information_field.py index d4ee082..ba67813 100644 --- a/tests/test_models/test_information_field.py +++ b/tests/test_models/test_information_field.py @@ -31,12 +31,15 @@ import pytest from six import iteritems -# from sqlalchemy.exc import IntegrityError from brenda_parser.exceptions import ValidationError from brenda_parser.models import InformationField +# from sqlalchemy.exc import IntegrityError + + + @pytest.mark.parametrize("attributes", [ pytest.param({"acronym": ""}, marks=pytest.mark.raises(exception=ValidationError)), diff --git a/tests/test_models/test_protein.py b/tests/test_models/test_protein.py index 45e5064..a4b1052 100644 --- a/tests/test_models/test_protein.py +++ b/tests/test_models/test_protein.py @@ -33,8 +33,8 @@ from six import iteritems from sqlalchemy.exc import IntegrityError -from brenda_parser.exceptions import ValidationError import brenda_parser.models as models +from brenda_parser.exceptions import ValidationError def test_create_protein(session): diff --git a/tests/test_parsing/test_comments.py b/tests/test_parsing/test_comments.py index 416eb9d..9434ee1 100644 --- a/tests/test_parsing/test_comments.py +++ b/tests/test_parsing/test_comments.py @@ -39,6 +39,7 @@ from brenda_parser.models import Base, InformationField from brenda_parser.parsing.parser import BRENDAParser + Session = sessionmaker() @@ -92,4 +93,4 @@ def test_long_comment(session, parser): assert entry.field.acronym == "IN" assert len(entry.protein_references) == 8 assert len(entry.citation_references) == 40 - assert len(entry.comments) == 40 + assert len(entry.comments) == 44 diff --git a/tests/test_parsing/test_parser.py b/tests/test_parsing/test_parser.py index 92508ea..b57c982 100644 --- a/tests/test_parsing/test_parser.py +++ b/tests/test_parsing/test_parser.py @@ -39,6 +39,7 @@ from brenda_parser.models import Base, InformationField from brenda_parser.parsing.parser import BRENDAParser + Session = sessionmaker() From 5b5e9820a393c2aae9883e15b7a263a5eff0dcf3 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Thu, 25 Oct 2018 10:10:58 +0200 Subject: [PATCH 06/15] chore: add more known third party packages --- setup.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup.cfg b/setup.cfg index fb4e7c7..c7662dc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -77,7 +77,11 @@ lines_after_imports = 2 known_first_party = brenda_parser known_third_party = click + click_log depinfo + importlib_resources + ply + pytest six sqlalchemy tqdm From 67aa0476d239e6a2e35191260a19c54ce09e3c72 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Thu, 25 Oct 2018 10:33:17 +0200 Subject: [PATCH 07/15] test: add transferred stub section --- testing.py | 16 ---------------- tests/test_parsing/data/transferred.txt | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) delete mode 100644 testing.py create mode 100644 tests/test_parsing/data/transferred.txt diff --git a/testing.py b/testing.py deleted file mode 100644 index 0e032f3..0000000 --- a/testing.py +++ /dev/null @@ -1,16 +0,0 @@ -import logging - -from brenda_parser import parse - - -logging.basicConfig(level="DEBUG") - - -def main(): - with open("tests/test_parsing/data/long_comments.txt") as fh: - content = fh.read() - engine, session = parse(content.split("\n")) - - -if __name__ == "__main__": - main() diff --git a/tests/test_parsing/data/transferred.txt b/tests/test_parsing/data/transferred.txt new file mode 100644 index 0000000..c2a2ab6 --- /dev/null +++ b/tests/test_parsing/data/transferred.txt @@ -0,0 +1,17 @@ +ID 1.4.99.4 (transferred to EC 1.4.9.2) +******************************************************************************** +* * +* Copyrighted by Dietmar Schomburg, Techn. University Braunschweig, GERMANY * +* Distributed under the License as stated at http:/www.brenda-enzymes.org * +* * +******************************************************************************** + +RECOMMENDED_NAME +RN aralkylamine dehydrogenase + + +SYSTEMATIC_NAME +SN + + +/// From 94d533472cb41ba4eba6fd0f1469906097148f27 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sat, 1 Dec 2018 18:16:40 +0100 Subject: [PATCH 08/15] chore: remove Python 2.7 compatibility --- MANIFEST.in | 10 ---------- setup.cfg | 17 ++++++++++------- setup.py | 4 ---- src/brenda_parser/__init__.py | 10 ++++------ src/brenda_parser/api.py | 4 ---- src/brenda_parser/cli.py | 3 --- src/brenda_parser/data/__init__.py | 4 ---- src/brenda_parser/exceptions.py | 4 ---- src/brenda_parser/models/__init__.py | 4 ---- src/brenda_parser/models/accession.py | 3 --- src/brenda_parser/models/comment.py | 3 --- src/brenda_parser/models/enzyme.py | 3 --- src/brenda_parser/models/field_entry.py | 3 --- src/brenda_parser/models/information_field.py | 3 --- src/brenda_parser/models/organism.py | 3 --- src/brenda_parser/models/protein.py | 3 --- src/brenda_parser/models/reference.py | 3 --- src/brenda_parser/parsing/__init__.py | 3 --- src/brenda_parser/parsing/lexer.py | 3 --- src/brenda_parser/parsing/parser.py | 3 --- tox.ini | 7 +++---- 21 files changed, 17 insertions(+), 83 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 78ed655..ea32ebb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,12 +1,2 @@ -graft src - -include AUTHORS.rst -include CHANGELOG.rst -include CONTRIBUTING.rst -include LICENSE -include README.rst include versioneer.py include src/brenda_parser/_version.py -include src/brenda_parser/data/*.csv - -global-exclude *.py[cod] __pycache__ *.so *.dylib diff --git a/setup.cfg b/setup.cfg index c7662dc..73218f5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,8 +10,6 @@ classifiers = Topic :: Scientific/Engineering :: Bio-Informatics License :: OSI Approved :: BSD License Natural Language :: English - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 @@ -27,18 +25,24 @@ keywords = [options] zip_safe = True install_requires = - six - future importlib-resources click click-log ply SQLAlchemy tqdm -include_package_data = True -python_requires = >=2.7.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.* +python_requires = >=3.5.* +package_dir = + = src packages = find: +[options.package_data] +brenda_parser.data = + information_fields.csv + +brenda_parser.parsing = + parser.out + [options.packages.find] where = src @@ -56,7 +60,6 @@ universal = 1 max-line-length = 80 exclude = __init__.py - docs _version.py lexer.py lextab.py diff --git a/setup.py b/setup.py index f11980e..ac077c8 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ #!/usr/bin/env python -# -*- encoding: utf-8 -*- -from __future__ import absolute_import import versioneer from setuptools import setup @@ -11,6 +9,4 @@ setup( version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), - # Temporary workaround for https://github.com/pypa/setuptools/issues/1136. - package_dir={"": "src"} ) diff --git a/src/brenda_parser/__init__.py b/src/brenda_parser/__init__.py index 88b74d3..bda5a94 100644 --- a/src/brenda_parser/__init__.py +++ b/src/brenda_parser/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2013 Jacobs University Bremen gGmbH # Copyright (c) 2018 Moritz E. Beber # @@ -28,15 +26,15 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """BRENDA Enzyme Database Parser.""" -from __future__ import absolute_import -__author__ = 'Moritz E. Beber' -__email__ = 'moritz.beber@gmail.com' +__author__ = "Moritz E. Beber" +__email__ = "midnighter@posteo.net" from ._version import get_versions -__version__ = get_versions()['version'] +__version__ = get_versions()["version"] del get_versions diff --git a/src/brenda_parser/api.py b/src/brenda_parser/api.py index 21cee33..3adb38c 100644 --- a/src/brenda_parser/api.py +++ b/src/brenda_parser/api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -29,12 +27,10 @@ """Provide an API to the BRENDA parser.""" -from __future__ import absolute_import, division import logging import multiprocessing import re -from warnings import warn from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker diff --git a/src/brenda_parser/cli.py b/src/brenda_parser/cli.py index 4bb5e8c..ae129a9 100644 --- a/src/brenda_parser/cli.py +++ b/src/brenda_parser/cli.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -29,7 +27,6 @@ """Provide a command line interface for the parser.""" -from __future__ import absolute_import import logging from multiprocessing import cpu_count diff --git a/src/brenda_parser/data/__init__.py b/src/brenda_parser/data/__init__.py index a85f09c..d49ac50 100644 --- a/src/brenda_parser/data/__init__.py +++ b/src/brenda_parser/data/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2013 Jacobs University Bremen gGmbH # Copyright (c) 2018 Moritz E. Beber # @@ -29,5 +27,3 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Provide data resources.""" - -from __future__ import absolute_import diff --git a/src/brenda_parser/exceptions.py b/src/brenda_parser/exceptions.py index 9bf8896..7646cef 100644 --- a/src/brenda_parser/exceptions.py +++ b/src/brenda_parser/exceptions.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2013 Jacobs University Bremen gGmbH # Copyright (c) 2018 Moritz E. Beber # @@ -30,8 +28,6 @@ """Provide custom exceptions.""" -from __future__ import absolute_import - __all__ = ("ValidationError",) diff --git a/src/brenda_parser/models/__init__.py b/src/brenda_parser/models/__init__.py index c34dce0..1d97a4c 100644 --- a/src/brenda_parser/models/__init__.py +++ b/src/brenda_parser/models/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2013 Jacobs University Bremen gGmbH # Copyright (c) 2018 Moritz E. Beber # @@ -30,8 +28,6 @@ """Provide data models for storing BRENDA EC-number information.""" -from __future__ import absolute_import - from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() diff --git a/src/brenda_parser/models/accession.py b/src/brenda_parser/models/accession.py index 947793b..dc2c5fa 100644 --- a/src/brenda_parser/models/accession.py +++ b/src/brenda_parser/models/accession.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -30,7 +28,6 @@ """Provide a data model for a protein database cross reference.""" -from __future__ import absolute_import import logging import re diff --git a/src/brenda_parser/models/comment.py b/src/brenda_parser/models/comment.py index 190ac6c..6aaca3a 100644 --- a/src/brenda_parser/models/comment.py +++ b/src/brenda_parser/models/comment.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -30,7 +28,6 @@ """Provide a data model for a comment.""" -from __future__ import absolute_import import logging diff --git a/src/brenda_parser/models/enzyme.py b/src/brenda_parser/models/enzyme.py index 87ceff1..102726b 100644 --- a/src/brenda_parser/models/enzyme.py +++ b/src/brenda_parser/models/enzyme.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -30,7 +28,6 @@ """Provide a data model for an information field entry.""" -from __future__ import absolute_import import logging diff --git a/src/brenda_parser/models/field_entry.py b/src/brenda_parser/models/field_entry.py index 891651a..6a67a99 100644 --- a/src/brenda_parser/models/field_entry.py +++ b/src/brenda_parser/models/field_entry.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -30,7 +28,6 @@ """Provide a data model for an information field entry.""" -from __future__ import absolute_import import logging diff --git a/src/brenda_parser/models/information_field.py b/src/brenda_parser/models/information_field.py index 5118c66..207534d 100644 --- a/src/brenda_parser/models/information_field.py +++ b/src/brenda_parser/models/information_field.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -30,7 +28,6 @@ """Provide a data model for an information field.""" -from __future__ import absolute_import import csv import logging diff --git a/src/brenda_parser/models/organism.py b/src/brenda_parser/models/organism.py index 46920c1..ba94e00 100644 --- a/src/brenda_parser/models/organism.py +++ b/src/brenda_parser/models/organism.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -30,7 +28,6 @@ """Provide a data model for an organism.""" -from __future__ import absolute_import import logging diff --git a/src/brenda_parser/models/protein.py b/src/brenda_parser/models/protein.py index 0aa2376..eb98199 100644 --- a/src/brenda_parser/models/protein.py +++ b/src/brenda_parser/models/protein.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -30,7 +28,6 @@ """Provide a data model for a protein.""" -from __future__ import absolute_import import logging diff --git a/src/brenda_parser/models/reference.py b/src/brenda_parser/models/reference.py index 0b7e84c..f54974e 100644 --- a/src/brenda_parser/models/reference.py +++ b/src/brenda_parser/models/reference.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -30,7 +28,6 @@ """Provide a data model for a reference.""" -from __future__ import absolute_import import logging import re diff --git a/src/brenda_parser/parsing/__init__.py b/src/brenda_parser/parsing/__init__.py index acc07ba..17b8724 100644 --- a/src/brenda_parser/parsing/__init__.py +++ b/src/brenda_parser/parsing/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2013 Jacobs University Bremen gGmbH # Copyright (c) 2018 Moritz E. Beber # @@ -30,7 +28,6 @@ """Provide the BRENDA flat file parsing capabilities.""" -from __future__ import absolute_import from brenda_parser.parsing.lexer import * from brenda_parser.parsing.parser import * diff --git a/src/brenda_parser/parsing/lexer.py b/src/brenda_parser/parsing/lexer.py index b3ea34d..ae81d06 100644 --- a/src/brenda_parser/parsing/lexer.py +++ b/src/brenda_parser/parsing/lexer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -29,7 +27,6 @@ """Tokenize the BRENDA flat file.""" -from __future__ import absolute_import import logging diff --git a/src/brenda_parser/parsing/parser.py b/src/brenda_parser/parsing/parser.py index 76f37fb..0a4f33d 100644 --- a/src/brenda_parser/parsing/parser.py +++ b/src/brenda_parser/parsing/parser.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2011 Jacobs University Bremen gGmbH # Copyright (c) 2018 Moritz E. Beber # @@ -30,7 +28,6 @@ """Parse BRENDA tokens using the provided grammar.""" -from __future__ import absolute_import import logging diff --git a/tox.ini b/tox.ini index 1215235..160659b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,11 @@ [tox] -envlist = flake8, isort, docs, py{27,35,36,37} +envlist = flake8, isort, docs, py{35,36,37} [travis] os = - linux: flake8, isort, docs, py{27,35,36,37} + linux: flake8, isort, docs, py{35,36,37} osx: py{27,35} python = - 2.7: py27, flake8 3.5: py35, flake8, docs, isort 3.6: py36 3.7: py37 @@ -18,7 +17,7 @@ deps = pytest-mock pytest-raises commands = - pytest {posargs} --cov={envsitepackagesdir}/brenda_parser + pytest --cov={envsitepackagesdir}/brenda_parser {posargs} [testenv:flake8] skip_install = True From 622053c58ec56ba5d540d11b4f9ea64ca33a4a96 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sat, 1 Dec 2018 18:20:32 +0100 Subject: [PATCH 09/15] chore: remove Python 2 compatibility from tests --- setup.cfg | 2 +- tests/{ => test_integration}/test_brenda_parser.py | 1 - tests/{test_models => test_unit/models}/conftest.py | 3 --- .../models}/test_information_field.py | 3 --- tests/{test_models => test_unit/models}/test_organism.py | 3 --- tests/{test_models => test_unit/models}/test_protein.py | 2 -- tests/{test_models => test_unit/models}/test_reference.py | 3 --- tests/{ => test_unit}/test_parsing/data/long_comments.txt | 0 tests/{ => test_unit}/test_parsing/data/small_section.txt | 0 tests/{ => test_unit}/test_parsing/data/transferred.txt | 0 tests/{ => test_unit}/test_parsing/test_comments.py | 4 ---- tests/{ => test_unit}/test_parsing/test_lexer.py | 3 --- tests/{ => test_unit}/test_parsing/test_parser.py | 4 ---- 13 files changed, 1 insertion(+), 27 deletions(-) rename tests/{ => test_integration}/test_brenda_parser.py (99%) rename tests/{test_models => test_unit/models}/conftest.py (97%) rename tests/{test_models => test_unit/models}/test_information_field.py (97%) rename tests/{test_models => test_unit/models}/test_organism.py (97%) rename tests/{test_models => test_unit/models}/test_protein.py (98%) rename tests/{test_models => test_unit/models}/test_reference.py (97%) rename tests/{ => test_unit}/test_parsing/data/long_comments.txt (100%) rename tests/{ => test_unit}/test_parsing/data/small_section.txt (100%) rename tests/{ => test_unit}/test_parsing/data/transferred.txt (100%) rename tests/{ => test_unit}/test_parsing/test_comments.py (97%) rename tests/{ => test_unit}/test_parsing/test_lexer.py (98%) rename tests/{ => test_unit}/test_parsing/test_parser.py (98%) diff --git a/setup.cfg b/setup.cfg index 73218f5..3d33edf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,9 +25,9 @@ keywords = [options] zip_safe = True install_requires = - importlib-resources click click-log + importlib-resources ply SQLAlchemy tqdm diff --git a/tests/test_brenda_parser.py b/tests/test_integration/test_brenda_parser.py similarity index 99% rename from tests/test_brenda_parser.py rename to tests/test_integration/test_brenda_parser.py index 961fce7..1a3758f 100644 --- a/tests/test_brenda_parser.py +++ b/tests/test_integration/test_brenda_parser.py @@ -1,4 +1,3 @@ - # from click.testing import CliRunner # from brenda_parser.cli import main diff --git a/tests/test_models/conftest.py b/tests/test_unit/models/conftest.py similarity index 97% rename from tests/test_models/conftest.py rename to tests/test_unit/models/conftest.py index 0ce95f0..a2dd211 100644 --- a/tests/test_models/conftest.py +++ b/tests/test_unit/models/conftest.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -27,7 +25,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import import pytest from sqlalchemy import create_engine diff --git a/tests/test_models/test_information_field.py b/tests/test_unit/models/test_information_field.py similarity index 97% rename from tests/test_models/test_information_field.py rename to tests/test_unit/models/test_information_field.py index ba67813..139d960 100644 --- a/tests/test_models/test_information_field.py +++ b/tests/test_unit/models/test_information_field.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -27,7 +25,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import import pytest from six import iteritems diff --git a/tests/test_models/test_organism.py b/tests/test_unit/models/test_organism.py similarity index 97% rename from tests/test_models/test_organism.py rename to tests/test_unit/models/test_organism.py index afcc75c..e8fbf0d 100644 --- a/tests/test_models/test_organism.py +++ b/tests/test_unit/models/test_organism.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -27,7 +25,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import import pytest from six import iteritems diff --git a/tests/test_models/test_protein.py b/tests/test_unit/models/test_protein.py similarity index 98% rename from tests/test_models/test_protein.py rename to tests/test_unit/models/test_protein.py index a4b1052..1da0d46 100644 --- a/tests/test_models/test_protein.py +++ b/tests/test_unit/models/test_protein.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without diff --git a/tests/test_models/test_reference.py b/tests/test_unit/models/test_reference.py similarity index 97% rename from tests/test_models/test_reference.py rename to tests/test_unit/models/test_reference.py index 1533bd0..d9cb0c1 100644 --- a/tests/test_models/test_reference.py +++ b/tests/test_unit/models/test_reference.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -27,7 +25,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import import pytest from six import iteritems diff --git a/tests/test_parsing/data/long_comments.txt b/tests/test_unit/test_parsing/data/long_comments.txt similarity index 100% rename from tests/test_parsing/data/long_comments.txt rename to tests/test_unit/test_parsing/data/long_comments.txt diff --git a/tests/test_parsing/data/small_section.txt b/tests/test_unit/test_parsing/data/small_section.txt similarity index 100% rename from tests/test_parsing/data/small_section.txt rename to tests/test_unit/test_parsing/data/small_section.txt diff --git a/tests/test_parsing/data/transferred.txt b/tests/test_unit/test_parsing/data/transferred.txt similarity index 100% rename from tests/test_parsing/data/transferred.txt rename to tests/test_unit/test_parsing/data/transferred.txt diff --git a/tests/test_parsing/test_comments.py b/tests/test_unit/test_parsing/test_comments.py similarity index 97% rename from tests/test_parsing/test_comments.py rename to tests/test_unit/test_parsing/test_comments.py index 9434ee1..1134b44 100644 --- a/tests/test_parsing/test_comments.py +++ b/tests/test_unit/test_parsing/test_comments.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -27,9 +25,7 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import -from builtins import open from os.path import dirname, join import pytest diff --git a/tests/test_parsing/test_lexer.py b/tests/test_unit/test_parsing/test_lexer.py similarity index 98% rename from tests/test_parsing/test_lexer.py rename to tests/test_unit/test_parsing/test_lexer.py index 0aaa89c..0f883ae 100644 --- a/tests/test_parsing/test_lexer.py +++ b/tests/test_unit/test_parsing/test_lexer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -27,7 +25,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import import pytest diff --git a/tests/test_parsing/test_parser.py b/tests/test_unit/test_parsing/test_parser.py similarity index 98% rename from tests/test_parsing/test_parser.py rename to tests/test_unit/test_parsing/test_parser.py index b57c982..6650b12 100644 --- a/tests/test_parsing/test_parser.py +++ b/tests/test_unit/test_parsing/test_parser.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (c) 2018 Moritz E. Beber # # Redistribution and use in source and binary forms, with or without @@ -27,9 +25,7 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import -from builtins import open from os.path import dirname, join import pytest From 0d83d27aa7654bebfbaceec95dcde087f4facb72 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sat, 1 Dec 2018 18:25:28 +0100 Subject: [PATCH 10/15] chore: update settings --- .editorconfig | 15 ++++-- .gitignore | 132 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 98 insertions(+), 49 deletions(-) diff --git a/.editorconfig b/.editorconfig index caa8b29..2b92106 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,15 +2,22 @@ root = true [*] +charset = utf-8 end_of_line = lf -trim_trailing_whitespace = true -insert_final_newline = true -indent_style = space indent_size = 4 -charset = utf-8 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true [*.{bat,cmd,ps1}] end_of_line = crlf +indent_style = tab [*.{yml,json}] indent_size = 2 + +[*.{md,rst}] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab diff --git a/.gitignore b/.gitignore index 7519585..5647b9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,65 +1,107 @@ +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ *.py[cod] +*$py.class # C extensions *.so -# Packages -*.egg -*.egg-info -dist -build -eggs -.eggs -parts -bin -var -sdist -wheelhouse -develop-eggs +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ .installed.cfg -lib -lib64 -venv*/ -pyvenv*/ +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec # Installer logs pip-log.txt +pip-delete-this-directory.txt # Unit test / coverage reports +htmlcov/ +.tox/ .coverage -.tox .coverage.* +.cache nosetests.xml coverage.xml -htmlcov +*.cover +.hypothesis/ +.pytest_cache/ # Translations *.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints -# Mr Developer -.mr.developer.cfg -.project -.pydevproject -.idea -*.iml -*.komodoproject - -# Complexity -output/*.html -output/*/index.html - -# Sphinx -docs/_build - -.DS_Store -*~ -.*.sw[po] -.build -.ve +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments .env -.cache -.pytest -.bootstrap -.appveyor.token -*.bak -.pytest_cache/ +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + From 8af9ebccb0eb3bebaac51f181a3b73036253fff0 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sat, 1 Dec 2018 18:47:49 +0100 Subject: [PATCH 11/15] chore: introduce black --- README.rst | 5 + pyproject.toml | 11 + setup.cfg | 18 +- src/brenda_parser/__init__.py | 1 + src/brenda_parser/_version.py | 164 +- src/brenda_parser/api.py | 8 +- src/brenda_parser/cli.py | 45 +- src/brenda_parser/models/accession.py | 6 +- src/brenda_parser/models/comment.py | 16 +- src/brenda_parser/models/enzyme.py | 8 +- src/brenda_parser/models/field_entry.py | 23 +- src/brenda_parser/models/information_field.py | 9 +- src/brenda_parser/models/protein.py | 16 +- src/brenda_parser/models/reference.py | 3 +- src/brenda_parser/parsing/lexer.py | 9 +- src/brenda_parser/parsing/lextab.py | 172 +- src/brenda_parser/parsing/parser.py | 20 +- src/brenda_parser/parsing/parsetab.py | 1571 ++++++++++++++++- tests/test_integration/test_brenda_parser.py | 4 +- .../models/test_information_field.py | 46 +- tests/test_unit/models/test_organism.py | 33 +- tests/test_unit/models/test_protein.py | 1 - tests/test_unit/models/test_reference.py | 46 +- tests/test_unit/test_parsing/test_comments.py | 5 +- tests/test_unit/test_parsing/test_lexer.py | 132 +- tests/test_unit/test_parsing/test_parser.py | 105 +- tox.ini | 27 +- 27 files changed, 2154 insertions(+), 350 deletions(-) diff --git a/README.rst b/README.rst index 94c4b6c..277359e 100644 --- a/README.rst +++ b/README.rst @@ -12,6 +12,7 @@ Overview * - tests - | |travis| |appveyor| | |codecov| + | |black| * - package - | |version| |wheel| |supported-versions| |supported-implementations| | |commits-since| @@ -32,6 +33,10 @@ Overview :alt: Coverage Status :target: https://codecov.io/github/Midnighter/BRENDA-Parser +.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg + :alt: code style: black + :target: https://github.com/ambv/black + .. |version| image:: https://img.shields.io/pypi/v/brenda-parser.svg :alt: PyPI Package latest release :target: https://pypi.python.org/pypi/brenda-parser diff --git a/pyproject.toml b/pyproject.toml index c69cf5b..088e4c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,3 +3,14 @@ requires = [ "setuptools>=30.3.0", "wheel" ] + +[tool.black] +line-length = 80 +py36 = true +exclude = ''' +/( + _version.py + | lextab.py + | parsetab.py +)/ +''' diff --git a/setup.cfg b/setup.cfg index 3d33edf..6b0d111 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,10 +27,13 @@ zip_safe = True install_requires = click click-log + depinfo importlib-resources ply SQLAlchemy tqdm +tests_require = + tox python_requires = >=3.5.* package_dir = = src @@ -68,14 +71,17 @@ exclude = [coverage:run] omit = - */_version.py - */lextab.py - */parsetab.py + _version.py + lextab.py + parsetab.py [isort] line_length = 80 indent = 4 -multi_line_output = 4 +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +use_parentheses = true lines_after_imports = 2 known_first_party = brenda_parser known_third_party = @@ -85,13 +91,9 @@ known_third_party = importlib_resources ply pytest - six sqlalchemy tqdm -[tool:pytest] -testpaths = tests - # See the docstring in versioneer.py for instructions. Note that you must # re-run 'versioneer.py setup' after changing this section, and commit the # resulting files. diff --git a/src/brenda_parser/__init__.py b/src/brenda_parser/__init__.py index bda5a94..d270a70 100644 --- a/src/brenda_parser/__init__.py +++ b/src/brenda_parser/__init__.py @@ -34,6 +34,7 @@ __email__ = "midnighter@posteo.net" from ._version import get_versions + __version__ = get_versions()["version"] del get_versions diff --git a/src/brenda_parser/_version.py b/src/brenda_parser/_version.py index e88bd30..a63271a 100644 --- a/src/brenda_parser/_version.py +++ b/src/brenda_parser/_version.py @@ -1,4 +1,3 @@ - # This file helps to compute a version number in source trees obtained from # git-archive tarball (such as those provided by githubs download-from-tag # feature). Distribution tarballs (built by setup.py sdist) and build @@ -58,17 +57,20 @@ class NotThisMethod(Exception): def register_vcs_handler(vcs, method): # decorator """Decorator to mark a method as the handler for a particular VCS.""" + def decorate(f): """Store f in HANDLERS[vcs][method].""" if vcs not in HANDLERS: HANDLERS[vcs] = {} HANDLERS[vcs][method] = f return f + return decorate -def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, - env=None): +def run_command( + commands, args, cwd=None, verbose=False, hide_stderr=False, env=None +): """Call the given command(s).""" assert isinstance(commands, list) p = None @@ -76,10 +78,13 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, try: dispcmd = str([c] + args) # remember shell=False, so use git.cmd on windows, not just git - p = subprocess.Popen([c] + args, cwd=cwd, env=env, - stdout=subprocess.PIPE, - stderr=(subprocess.PIPE if hide_stderr - else None)) + p = subprocess.Popen( + [c] + args, + cwd=cwd, + env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr else None), + ) break except EnvironmentError: e = sys.exc_info()[1] @@ -116,16 +121,22 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): for i in range(3): dirname = os.path.basename(root) if dirname.startswith(parentdir_prefix): - return {"version": dirname[len(parentdir_prefix):], - "full-revisionid": None, - "dirty": False, "error": None, "date": None} + return { + "version": dirname[len(parentdir_prefix) :], + "full-revisionid": None, + "dirty": False, + "error": None, + "date": None, + } else: rootdirs.append(root) root = os.path.dirname(root) # up a level if verbose: - print("Tried directories %s but none started with prefix %s" % - (str(rootdirs), parentdir_prefix)) + print( + "Tried directories %s but none started with prefix %s" + % (str(rootdirs), parentdir_prefix) + ) raise NotThisMethod("rootdir doesn't start with parentdir_prefix") @@ -181,7 +192,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of # just "foo-1.0". If we see a "tag: " prefix, prefer those. TAG = "tag: " - tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) + tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)]) if not tags: # Either we're using git < 1.8.3, or there really are no tags. We use # a heuristic: assume all version tags have a digit. The old git %d @@ -190,7 +201,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # between branches and tags. By ignoring refnames without digits, we # filter out many common branch names like "release" and # "stabilization", as well as "HEAD" and "master". - tags = set([r for r in refs if re.search(r'\d', r)]) + tags = set([r for r in refs if re.search(r"\d", r)]) if verbose: print("discarding '%s', no digits" % ",".join(refs - tags)) if verbose: @@ -198,19 +209,26 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): for ref in sorted(tags): # sorting will prefer e.g. "2.0" over "2.0rc1" if ref.startswith(tag_prefix): - r = ref[len(tag_prefix):] + r = ref[len(tag_prefix) :] if verbose: print("picking %s" % r) - return {"version": r, - "full-revisionid": keywords["full"].strip(), - "dirty": False, "error": None, - "date": date} + return { + "version": r, + "full-revisionid": keywords["full"].strip(), + "dirty": False, + "error": None, + "date": date, + } # no suitable tags, so version is "0+unknown", but full hex is still there if verbose: print("no suitable tags, using unknown + full revision id") - return {"version": "0+unknown", - "full-revisionid": keywords["full"].strip(), - "dirty": False, "error": "no suitable tags", "date": None} + return { + "version": "0+unknown", + "full-revisionid": keywords["full"].strip(), + "dirty": False, + "error": "no suitable tags", + "date": None, + } @register_vcs_handler("git", "pieces_from_vcs") @@ -225,8 +243,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): if sys.platform == "win32": GITS = ["git.cmd", "git.exe"] - out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, - hide_stderr=True) + out, rc = run_command( + GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True + ) if rc != 0: if verbose: print("Directory %s not under git control" % root) @@ -234,10 +253,19 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] # if there isn't one, this yields HEX[-dirty] (no NUM) - describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", - "--always", "--long", - "--match", "%s*" % tag_prefix], - cwd=root) + describe_out, rc = run_command( + GITS, + [ + "describe", + "--tags", + "--dirty", + "--always", + "--long", + "--match", + "%s*" % tag_prefix, + ], + cwd=root, + ) # --long was added in git-1.5.5 if describe_out is None: raise NotThisMethod("'git describe' failed") @@ -260,17 +288,18 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): dirty = git_describe.endswith("-dirty") pieces["dirty"] = dirty if dirty: - git_describe = git_describe[:git_describe.rindex("-dirty")] + git_describe = git_describe[: git_describe.rindex("-dirty")] # now we have TAG-NUM-gHEX or HEX if "-" in git_describe: # TAG-NUM-gHEX - mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) + mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe) if not mo: # unparseable. Maybe git-describe is misbehaving? - pieces["error"] = ("unable to parse git-describe output: '%s'" - % describe_out) + pieces["error"] = ( + "unable to parse git-describe output: '%s'" % describe_out + ) return pieces # tag @@ -279,10 +308,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): if verbose: fmt = "tag '%s' doesn't start with prefix '%s'" print(fmt % (full_tag, tag_prefix)) - pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" - % (full_tag, tag_prefix)) + pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % ( + full_tag, + tag_prefix, + ) return pieces - pieces["closest-tag"] = full_tag[len(tag_prefix):] + pieces["closest-tag"] = full_tag[len(tag_prefix) :] # distance: number of commits since tag pieces["distance"] = int(mo.group(2)) @@ -293,13 +324,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): else: # HEX: no tags pieces["closest-tag"] = None - count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], - cwd=root) + count_out, rc = run_command( + GITS, ["rev-list", "HEAD", "--count"], cwd=root + ) pieces["distance"] = int(count_out) # total number of commits # commit date: see ISO-8601 comment in git_versions_from_keywords() - date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], - cwd=root)[0].strip() + date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[ + 0 + ].strip() pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) return pieces @@ -330,8 +363,7 @@ def render_pep440(pieces): rendered += ".dirty" else: # exception #1 - rendered = "0+untagged.%d.g%s" % (pieces["distance"], - pieces["short"]) + rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"]) if pieces["dirty"]: rendered += ".dirty" return rendered @@ -445,11 +477,13 @@ def render_git_describe_long(pieces): def render(pieces, style): """Render the given version pieces into the requested style.""" if pieces["error"]: - return {"version": "unknown", - "full-revisionid": pieces.get("long"), - "dirty": None, - "error": pieces["error"], - "date": None} + return { + "version": "unknown", + "full-revisionid": pieces.get("long"), + "dirty": None, + "error": pieces["error"], + "date": None, + } if not style or style == "default": style = "pep440" # the default @@ -469,9 +503,13 @@ def render(pieces, style): else: raise ValueError("unknown style '%s'" % style) - return {"version": rendered, "full-revisionid": pieces["long"], - "dirty": pieces["dirty"], "error": None, - "date": pieces.get("date")} + return { + "version": rendered, + "full-revisionid": pieces["long"], + "dirty": pieces["dirty"], + "error": None, + "date": pieces.get("date"), + } def get_versions(): @@ -485,8 +523,9 @@ def get_versions(): verbose = cfg.verbose try: - return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, - verbose) + return git_versions_from_keywords( + get_keywords(), cfg.tag_prefix, verbose + ) except NotThisMethod: pass @@ -495,13 +534,16 @@ def get_versions(): # versionfile_source is the relative path from the top of the source # tree (where the .git directory might live) to this file. Invert # this to find the root from __file__. - for i in cfg.versionfile_source.split('/'): + for i in cfg.versionfile_source.split("/"): root = os.path.dirname(root) except NameError: - return {"version": "0+unknown", "full-revisionid": None, - "dirty": None, - "error": "unable to find root of source tree", - "date": None} + return { + "version": "0+unknown", + "full-revisionid": None, + "dirty": None, + "error": "unable to find root of source tree", + "date": None, + } try: pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) @@ -515,6 +557,10 @@ def get_versions(): except NotThisMethod: pass - return {"version": "0+unknown", "full-revisionid": None, - "dirty": None, - "error": "unable to compute version", "date": None} + return { + "version": "0+unknown", + "full-revisionid": None, + "dirty": None, + "error": "unable to compute version", + "date": None, + } diff --git a/src/brenda_parser/api.py b/src/brenda_parser/api.py index 3adb38c..513e7e6 100644 --- a/src/brenda_parser/api.py +++ b/src/brenda_parser/api.py @@ -103,7 +103,7 @@ def parse(lines, connection="sqlite:///:memory:", processes=1): start = i continue if lines[i].startswith("///"): - sections.append("".join(lines[start:i + 1])) + sections.append("".join(lines[start : i + 1])) processes = min(processes, len(sections)) if processes > 1: multi_parse(sections, engine, processes=processes) @@ -139,9 +139,11 @@ def single_parse(sections): def multi_parse(sections, engine, processes=2): pool = multiprocessing.Pool( - processes=processes, initializer=init_worker, initargs=(engine,)) + processes=processes, initializer=init_worker, initargs=(engine,) + ) result_iter = pool.imap_unordered( - worker, sections, chunksize=len(sections) // processes) + worker, sections, chunksize=len(sections) // processes + ) with tqdm(total=len(sections)) as pbar: for success, enzyme in result_iter: if success: diff --git a/src/brenda_parser/cli.py b/src/brenda_parser/cli.py index ae129a9..360e41b 100644 --- a/src/brenda_parser/cli.py +++ b/src/brenda_parser/cli.py @@ -45,8 +45,7 @@ try: PROCESSES = cpu_count() except NotImplementedError: - warn("Could not detect the number of CPUs - assuming 1.", - UserWarning) + warn("Could not detect the number of CPUs - assuming 1.", UserWarning) PROCESSES = 1 @@ -54,8 +53,11 @@ @click.help_option("--help", "-h") @click.version_option(__version__, "--version", "-V") @click_log.simple_verbosity_option( - LOGGER, default="INFO", show_default=True, - type=click.Choice(["CRITICAL", "ERROR", "WARN", "INFO", "DEBUG"])) + LOGGER, + default="INFO", + show_default=True, + type=click.Choice(["CRITICAL", "ERROR", "WARN", "INFO", "DEBUG"]), +) def cli(): """Parse the BRENDA Enzyme flat file distribution to a local database.""" pass @@ -63,16 +65,31 @@ def cli(): @cli.command() @click.help_option("--help", "-h") -@click.option("--filename", type=click.Path(exists=False, writable=True), - default="brenda.db", show_default=True, - help="Path to where the SQLite3 database is stored.") -@click.option("--connection", default=None, show_default=True, metavar="URL", - help="An rfc1738 compatible database URL. Overrides the " - "filename option.") -@click.option("--processes", type=int, default=PROCESSES, show_default=True, - help="The number of parallel processes to use during parsing.") -@click.argument("flat_file", type=click.Path(exists=True, dir_okay=False), - envvar="FILENAME") +@click.option( + "--filename", + type=click.Path(exists=False, writable=True), + default="brenda.db", + show_default=True, + help="Path to where the SQLite3 database is stored.", +) +@click.option( + "--connection", + default=None, + show_default=True, + metavar="URL", + help="An rfc1738 compatible database URL. Overrides the " + "filename option.", +) +@click.option( + "--processes", + type=int, + default=PROCESSES, + show_default=True, + help="The number of parallel processes to use during parsing.", +) +@click.argument( + "flat_file", type=click.Path(exists=True, dir_okay=False), envvar="FILENAME" +) def parse(flat_file, filename, connection, processes): if connection is None: connection = "sqlite:///{}".format(filename) diff --git a/src/brenda_parser/models/accession.py b/src/brenda_parser/models/accession.py index dc2c5fa..9b66083 100644 --- a/src/brenda_parser/models/accession.py +++ b/src/brenda_parser/models/accession.py @@ -51,7 +51,8 @@ class Accession(Base): # http://identifiers.org/uniprot/ UNIPROT_PATTERN = re.compile( r"([A-NR-Z][0-9]([A-Z][A-Z0-9][A-Z0-9][0-9]){1,2})|" - r"([OPQ][0-9][A-Z0-9][A-Z0-9][A-Z0-9][0-9])(\.\d+)?") + r"([OPQ][0-9][A-Z0-9][A-Z0-9][A-Z0-9][0-9])(\.\d+)?" + ) id = Column(Integer, primary_key=True) accession = Column(String(255), nullable=False, unique=True, index=True) @@ -65,5 +66,6 @@ def validate_accession(self, key, value): if self.UNIPROT_PATTERN.match(value) is None: raise ValidationError( "'{}' does not match the required pattern '{}'." - "".format(value, self.UNIPROT_PATTERN)) + "".format(value, self.UNIPROT_PATTERN) + ) return value diff --git a/src/brenda_parser/models/comment.py b/src/brenda_parser/models/comment.py index 6aaca3a..23927d3 100644 --- a/src/brenda_parser/models/comment.py +++ b/src/brenda_parser/models/comment.py @@ -45,16 +45,16 @@ comment_protein_association = Table( "comment_protein_association", Base.metadata, - Column('comment_id', Integer, ForeignKey('comment.id')), - Column('protein_id', Integer, ForeignKey('protein.id')) + Column("comment_id", Integer, ForeignKey("comment.id")), + Column("protein_id", Integer, ForeignKey("protein.id")), ) comment_citation_association = Table( "comment_citation_association", Base.metadata, - Column('comment_id', Integer, ForeignKey('comment.id')), - Column('reference_id', Integer, ForeignKey('reference.id')) + Column("comment_id", Integer, ForeignKey("comment.id")), + Column("reference_id", Integer, ForeignKey("reference.id")), ) @@ -64,7 +64,7 @@ class Comment(Base): id = Column(Integer, primary_key=True) body = Column(String(255)) - proteins = relationship("Protein", - secondary=comment_protein_association) - citations = relationship("Reference", - secondary=comment_citation_association) + proteins = relationship("Protein", secondary=comment_protein_association) + citations = relationship( + "Reference", secondary=comment_citation_association + ) diff --git a/src/brenda_parser/models/enzyme.py b/src/brenda_parser/models/enzyme.py index 102726b..5b9f96d 100644 --- a/src/brenda_parser/models/enzyme.py +++ b/src/brenda_parser/models/enzyme.py @@ -45,16 +45,16 @@ enzyme_entry_association = Table( "enzyme_entry_association", Base.metadata, - Column('enzyme_id', Integer, ForeignKey('enzyme.id')), - Column('fieldentry_id', Integer, ForeignKey('fieldentry.id')) + Column("enzyme_id", Integer, ForeignKey("enzyme.id")), + Column("fieldentry_id", Integer, ForeignKey("fieldentry.id")), ) enzyme_comment_association = Table( "enzyme_comment_association", Base.metadata, - Column('enzyme_id', Integer, ForeignKey('enzyme.id')), - Column('comment_id', Integer, ForeignKey('comment.id')) + Column("enzyme_id", Integer, ForeignKey("enzyme.id")), + Column("comment_id", Integer, ForeignKey("comment.id")), ) diff --git a/src/brenda_parser/models/field_entry.py b/src/brenda_parser/models/field_entry.py index 6a67a99..786ad66 100644 --- a/src/brenda_parser/models/field_entry.py +++ b/src/brenda_parser/models/field_entry.py @@ -45,24 +45,24 @@ fieldentry_protein_association = Table( "fieldentry_protein_association", Base.metadata, - Column('fieldentry_id', Integer, ForeignKey('fieldentry.id')), - Column('protein_id', Integer, ForeignKey('protein.id')) + Column("fieldentry_id", Integer, ForeignKey("fieldentry.id")), + Column("protein_id", Integer, ForeignKey("protein.id")), ) fieldentry_citation_association = Table( "fieldentry_citation_association", Base.metadata, - Column('fieldentry_id', Integer, ForeignKey('fieldentry.id')), - Column('reference_id', Integer, ForeignKey('reference.id')) + Column("fieldentry_id", Integer, ForeignKey("fieldentry.id")), + Column("reference_id", Integer, ForeignKey("reference.id")), ) fieldentry_comment_association = Table( "fieldentry_comment_association", Base.metadata, - Column('fieldentry_id', Integer, ForeignKey('fieldentry.id')), - Column('comment_id', Integer, ForeignKey('comment.id')) + Column("fieldentry_id", Integer, ForeignKey("fieldentry.id")), + Column("comment_id", Integer, ForeignKey("comment.id")), ) @@ -78,12 +78,11 @@ class FieldEntry(Base): special = Column(String(255), nullable=True) enzyme_id = Column(Integer, ForeignKey("enzyme.id")) enzyme = relationship("Enzyme") - proteins = relationship("Protein", - secondary=fieldentry_protein_association) - citations = relationship("Reference", - secondary=fieldentry_citation_association) - comments = relationship("Comment", - secondary=fieldentry_comment_association) + proteins = relationship("Protein", secondary=fieldentry_protein_association) + citations = relationship( + "Reference", secondary=fieldentry_citation_association + ) + comments = relationship("Comment", secondary=fieldentry_comment_association) def __init__(self, **kwargs): """ diff --git a/src/brenda_parser/models/information_field.py b/src/brenda_parser/models/information_field.py index 207534d..e857b91 100644 --- a/src/brenda_parser/models/information_field.py +++ b/src/brenda_parser/models/information_field.py @@ -63,7 +63,8 @@ def validate_acronym(self, key, value): if self.ACRONYM_PATTERN.match(value) is None: raise ValidationError( "'{}' does not match the required pattern '{}'." - "".format(value, self.ACRONYM_PATTERN)) + "".format(value, self.ACRONYM_PATTERN) + ) return value @classmethod @@ -88,8 +89,8 @@ def preload(cls, session): for row in rows: # This query will ignore or fail on non-existent # `row["acronym"]`. - session.query(InformationField) \ - .filter_by(acronym=row["acronym"]) \ - .update(row) + session.query(InformationField).filter_by( + acronym=row["acronym"] + ).update(row) LOGGER.debug("Updated field '%s'.", row["acronym"]) session.commit() diff --git a/src/brenda_parser/models/protein.py b/src/brenda_parser/models/protein.py index eb98199..ab243fd 100644 --- a/src/brenda_parser/models/protein.py +++ b/src/brenda_parser/models/protein.py @@ -46,16 +46,16 @@ protein_citation_association = Table( "protein_citation_association", Base.metadata, - Column('protein_id', Integer, ForeignKey('protein.id')), - Column('reference_id', Integer, ForeignKey('reference.id')) + Column("protein_id", Integer, ForeignKey("protein.id")), + Column("reference_id", Integer, ForeignKey("reference.id")), ) protein_comment_association = Table( "protein_comment_association", Base.metadata, - Column('protein_id', Integer, ForeignKey('protein.id')), - Column('comment_id', Integer, ForeignKey('comment.id')) + Column("protein_id", Integer, ForeignKey("protein.id")), + Column("comment_id", Integer, ForeignKey("comment.id")), ) @@ -70,10 +70,10 @@ class Protein(Base): organism = relationship("Organism") accession_id = Column(Integer, ForeignKey("accession.id")) accession = relationship("Accession") - citations = relationship("Reference", - secondary=protein_citation_association) - comments = relationship("Comment", - secondary=protein_comment_association) + citations = relationship( + "Reference", secondary=protein_citation_association + ) + comments = relationship("Comment", secondary=protein_comment_association) def __init__(self, **kwargs): super(Protein, self).__init__(**kwargs) diff --git a/src/brenda_parser/models/reference.py b/src/brenda_parser/models/reference.py index f54974e..3996779 100644 --- a/src/brenda_parser/models/reference.py +++ b/src/brenda_parser/models/reference.py @@ -64,5 +64,6 @@ def validate_pubmed(self, key, value): if self.PUBMED_PATTERN.match(value) is None: raise ValidationError( "'{}' does not match the required pattern '{}'." - "".format(value, self.PUBMED_PATTERN)) + "".format(value, self.PUBMED_PATTERN) + ) return value diff --git a/src/brenda_parser/parsing/lexer.py b/src/brenda_parser/parsing/lexer.py index ae81d06..02acde9 100644 --- a/src/brenda_parser/parsing/lexer.py +++ b/src/brenda_parser/parsing/lexer.py @@ -74,7 +74,7 @@ class BRENDALexer(object): "SPECIAL", "COMMENT", "AND", - "ACCESSION" + "ACCESSION", ) # A string containing ignored characters interpreted literally not as regex. @@ -132,7 +132,7 @@ def t_ANY_error(self, t): t.lexer.skip(1) def t_ANY_newline(self, t): - r'\n+' + r"\n+" LOGGER.debug("lineno %d +%d", t.lineno, len(t.value)) t.lexer.lineno += len(t.value) @@ -260,8 +260,9 @@ def t_ENTRY(self, t): def t_brenda_header(self, t): r"[A-Z0-9_]{4,}\n" - LOGGER.debug("lineno %d: Section header '%s'.", t.lineno, - t.value.strip()) + LOGGER.debug( + "lineno %d: Section header '%s'.", t.lineno, t.value.strip() + ) t.lexer.lineno += 1 def t_protentry_AND(self, t): diff --git a/src/brenda_parser/parsing/lextab.py b/src/brenda_parser/parsing/lextab.py index a8d2460..ca27fa4 100644 --- a/src/brenda_parser/parsing/lextab.py +++ b/src/brenda_parser/parsing/lextab.py @@ -1,10 +1,166 @@ # lextab.py. This file automatically created by PLY (version 3.11). Don't edit! -_tabversion = '3.10' -_lextokens = set(('ACCESSION', 'AND', 'CITATION', 'COMMENT', 'CONTENT', 'EC_NUMBER', 'END', 'ENTRY', 'ENZYME_ENTRY', 'LANGLE', 'LCURLY', 'LPARENS', 'POUND', 'PROTEIN', 'PROTEIN_ENTRY', 'RANGLE', 'RCURLY', 'REFERENCE_ENTRY', 'RPARENS', 'SPECIAL')) -_lexreflags = 64 -_lexliterals = '' -_lexstateinfo = {'INITIAL': 'inclusive', 'citation': 'exclusive', 'protein': 'exclusive', 'special': 'exclusive', 'comment': 'exclusive', 'enzyme': 'exclusive', 'protentry': 'inclusive'} -_lexstatere = {'INITIAL': [('(?P\\n+)|(?P\\*.+\\n)|(?P[#])|(?P<)|(?P{)|(?P\\()|(?P[/]{3}\\s)|(?PID\\t)|(?PPR\\t)|(?PRF\\t)|(?P[A-Z0-9]{2,4}\\t)|(?P[A-Z0-9_]{4,}\\n)|(?P[^\\{\\}\\(\\)\\<\\>\\# \t\r\x0c\x0b\n]+)', [None, ('t_ANY_newline', 'newline'), ('t_brenda_comment', 'brenda_comment'), ('t_POUND', 'POUND'), ('t_LANGLE', 'LANGLE'), ('t_LCURLY', 'LCURLY'), ('t_LPARENS', 'LPARENS'), ('t_END', 'END'), ('t_ENZYME_ENTRY', 'ENZYME_ENTRY'), ('t_PROTEIN_ENTRY', 'PROTEIN_ENTRY'), ('t_REFERENCE_ENTRY', 'REFERENCE_ENTRY'), ('t_ENTRY', 'ENTRY'), ('t_brenda_header', 'brenda_header'), (None, 'CONTENT')])], 'citation': [('(?P\\n+)|(?P\\d+)|(?P>)', [None, ('t_ANY_newline', 'newline'), ('t_citation_CITATION', 'CITATION'), ('t_citation_RANGLE', 'RANGLE')])], 'protein': [('(?P\\n+)|(?P\\d+)|(?P[#])', [None, ('t_ANY_newline', 'newline'), ('t_protein_PROTEIN', 'PROTEIN'), ('t_protein_POUND', 'POUND')])], 'special': [('(?P\\n+)|(?P[^\\{\\}\\s]+)|(?P})', [None, ('t_ANY_newline', 'newline'), ('t_special_SPECIAL', 'SPECIAL'), ('t_special_RCURLY', 'RCURLY')])], 'comment': [('(?P\\n+)|(?P[^\\(\\)\\s]+)|(?P\\()|(?P\\))', [None, ('t_ANY_newline', 'newline'), ('t_comment_COMMENT', 'COMMENT'), ('t_comment_LPARENS', 'LPARENS'), ('t_comment_RPARENS', 'RPARENS')])], 'enzyme': [('(?P\\n+)|(?P(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+))', [None, ('t_ANY_newline', 'newline'), ('t_enzyme_EC_NUMBER', 'EC_NUMBER')])], 'protentry': [('(?P\\n+)|(?PPR\\t)|(?P[A-Z0-9]{2,4}\\t)|(?PAND)|(?P([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?)', [None, ('t_ANY_newline', 'newline'), ('t_protentry_PROTEIN_ENTRY', 'PROTEIN_ENTRY'), ('t_protentry_ENTRY', 'ENTRY'), ('t_protentry_AND', 'AND'), ('t_protentry_ACCESSION', 'ACCESSION')]), ('(?P\\n+)|(?P\\*.+\\n)|(?P[#])|(?P<)|(?P{)|(?P\\()|(?P[/]{3}\\s)|(?PID\\t)|(?PPR\\t)|(?PRF\\t)|(?P[A-Z0-9]{2,4}\\t)|(?P[A-Z0-9_]{4,}\\n)|(?P[^\\{\\}\\(\\)\\<\\>\\# \t\r\x0c\x0b\n]+)', [None, ('t_ANY_newline', 'newline'), ('t_brenda_comment', 'brenda_comment'), ('t_POUND', 'POUND'), ('t_LANGLE', 'LANGLE'), ('t_LCURLY', 'LCURLY'), ('t_LPARENS', 'LPARENS'), ('t_END', 'END'), ('t_ENZYME_ENTRY', 'ENZYME_ENTRY'), ('t_PROTEIN_ENTRY', 'PROTEIN_ENTRY'), ('t_REFERENCE_ENTRY', 'REFERENCE_ENTRY'), ('t_ENTRY', 'ENTRY'), ('t_brenda_header', 'brenda_header'), (None, 'CONTENT')])]} -_lexstateignore = {'citation': ' ,\t', 'protein': ' ,\t', 'INITIAL': ' \t\r\x0c\x0b', 'special': ' \t\r\x0c\x0b', 'comment': ' \t\r\x0c\x0b', 'enzyme': ' \t\r\x0c\x0b', 'protentry': ' \t\r\x0c\x0b'} -_lexstateerrorf = {'INITIAL': 't_ANY_error', 'citation': 't_ANY_error', 'protein': 't_ANY_error', 'special': 't_ANY_error', 'comment': 't_ANY_error', 'enzyme': 't_ANY_error', 'protentry': 't_ANY_error'} +_tabversion = "3.10" +_lextokens = set( + ( + "ACCESSION", + "AND", + "CITATION", + "COMMENT", + "CONTENT", + "EC_NUMBER", + "END", + "ENTRY", + "ENZYME_ENTRY", + "LANGLE", + "LCURLY", + "LPARENS", + "POUND", + "PROTEIN", + "PROTEIN_ENTRY", + "RANGLE", + "RCURLY", + "REFERENCE_ENTRY", + "RPARENS", + "SPECIAL", + ) +) +_lexreflags = 64 +_lexliterals = "" +_lexstateinfo = { + "INITIAL": "inclusive", + "citation": "exclusive", + "protein": "exclusive", + "special": "exclusive", + "comment": "exclusive", + "enzyme": "exclusive", + "protentry": "inclusive", +} +_lexstatere = { + "INITIAL": [ + ( + "(?P\\n+)|(?P\\*.+\\n)|(?P[#])|(?P<)|(?P{)|(?P\\()|(?P[/]{3}\\s)|(?PID\\t)|(?PPR\\t)|(?PRF\\t)|(?P[A-Z0-9]{2,4}\\t)|(?P[A-Z0-9_]{4,}\\n)|(?P[^\\{\\}\\(\\)\\<\\>\\# \t\r\x0c\x0b\n]+)", + [ + None, + ("t_ANY_newline", "newline"), + ("t_brenda_comment", "brenda_comment"), + ("t_POUND", "POUND"), + ("t_LANGLE", "LANGLE"), + ("t_LCURLY", "LCURLY"), + ("t_LPARENS", "LPARENS"), + ("t_END", "END"), + ("t_ENZYME_ENTRY", "ENZYME_ENTRY"), + ("t_PROTEIN_ENTRY", "PROTEIN_ENTRY"), + ("t_REFERENCE_ENTRY", "REFERENCE_ENTRY"), + ("t_ENTRY", "ENTRY"), + ("t_brenda_header", "brenda_header"), + (None, "CONTENT"), + ], + ) + ], + "citation": [ + ( + "(?P\\n+)|(?P\\d+)|(?P>)", + [ + None, + ("t_ANY_newline", "newline"), + ("t_citation_CITATION", "CITATION"), + ("t_citation_RANGLE", "RANGLE"), + ], + ) + ], + "protein": [ + ( + "(?P\\n+)|(?P\\d+)|(?P[#])", + [ + None, + ("t_ANY_newline", "newline"), + ("t_protein_PROTEIN", "PROTEIN"), + ("t_protein_POUND", "POUND"), + ], + ) + ], + "special": [ + ( + "(?P\\n+)|(?P[^\\{\\}\\s]+)|(?P})", + [ + None, + ("t_ANY_newline", "newline"), + ("t_special_SPECIAL", "SPECIAL"), + ("t_special_RCURLY", "RCURLY"), + ], + ) + ], + "comment": [ + ( + "(?P\\n+)|(?P[^\\(\\)\\s]+)|(?P\\()|(?P\\))", + [ + None, + ("t_ANY_newline", "newline"), + ("t_comment_COMMENT", "COMMENT"), + ("t_comment_LPARENS", "LPARENS"), + ("t_comment_RPARENS", "RPARENS"), + ], + ) + ], + "enzyme": [ + ( + "(?P\\n+)|(?P(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+))", + [ + None, + ("t_ANY_newline", "newline"), + ("t_enzyme_EC_NUMBER", "EC_NUMBER"), + ], + ) + ], + "protentry": [ + ( + "(?P\\n+)|(?PPR\\t)|(?P[A-Z0-9]{2,4}\\t)|(?PAND)|(?P([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?)", + [ + None, + ("t_ANY_newline", "newline"), + ("t_protentry_PROTEIN_ENTRY", "PROTEIN_ENTRY"), + ("t_protentry_ENTRY", "ENTRY"), + ("t_protentry_AND", "AND"), + ("t_protentry_ACCESSION", "ACCESSION"), + ], + ), + ( + "(?P\\n+)|(?P\\*.+\\n)|(?P[#])|(?P<)|(?P{)|(?P\\()|(?P[/]{3}\\s)|(?PID\\t)|(?PPR\\t)|(?PRF\\t)|(?P[A-Z0-9]{2,4}\\t)|(?P[A-Z0-9_]{4,}\\n)|(?P[^\\{\\}\\(\\)\\<\\>\\# \t\r\x0c\x0b\n]+)", + [ + None, + ("t_ANY_newline", "newline"), + ("t_brenda_comment", "brenda_comment"), + ("t_POUND", "POUND"), + ("t_LANGLE", "LANGLE"), + ("t_LCURLY", "LCURLY"), + ("t_LPARENS", "LPARENS"), + ("t_END", "END"), + ("t_ENZYME_ENTRY", "ENZYME_ENTRY"), + ("t_PROTEIN_ENTRY", "PROTEIN_ENTRY"), + ("t_REFERENCE_ENTRY", "REFERENCE_ENTRY"), + ("t_ENTRY", "ENTRY"), + ("t_brenda_header", "brenda_header"), + (None, "CONTENT"), + ], + ), + ], +} +_lexstateignore = { + "citation": " ,\t", + "protein": " ,\t", + "INITIAL": " \t\r\x0c\x0b", + "special": " \t\r\x0c\x0b", + "comment": " \t\r\x0c\x0b", + "enzyme": " \t\r\x0c\x0b", + "protentry": " \t\r\x0c\x0b", +} +_lexstateerrorf = { + "INITIAL": "t_ANY_error", + "citation": "t_ANY_error", + "protein": "t_ANY_error", + "special": "t_ANY_error", + "comment": "t_ANY_error", + "enzyme": "t_ANY_error", + "protentry": "t_ANY_error", +} _lexstateeoff = {} diff --git a/src/brenda_parser/parsing/parser.py b/src/brenda_parser/parsing/parser.py index 0a4f33d..60ea40c 100644 --- a/src/brenda_parser/parsing/parser.py +++ b/src/brenda_parser/parsing/parser.py @@ -88,7 +88,7 @@ class BRENDAParser(object): # ("left", "ENZYME"), ("left", "ASSEMBLE"), ("left", "REDUCE"), - ("left", "COMBINE") + ("left", "COMBINE"), ) def __init__(self, lexer=None, **kwargs): @@ -179,9 +179,11 @@ def p_entry(self, p): def p_new_entry(self, p): """new_entry : %prec REDUCE""" - field = self._session.query(models.InformationField) \ - .filter_by(acronym=p[-1]) \ + field = ( + self._session.query(models.InformationField) + .filter_by(acronym=p[-1]) .one() + ) p[0] = models.FieldEntry(field=field, body="") def p_entry_content(self, p): @@ -223,9 +225,11 @@ def p_reference_entry(self, p): def p_new_reference(self, p): """new_reference :""" assert p[-1] == "RF" - field = self._session.query(models.InformationField) \ - .filter_by(acronym=p[-1]) \ + field = ( + self._session.query(models.InformationField) + .filter_by(acronym=p[-1]) .one() + ) p[0] = models.Reference(field=field, body="") def p_reference_content(self, p): @@ -257,9 +261,11 @@ def p_protein_entry(self, p): def p_new_protein(self, p): """new_protein :""" assert p[-1] == "PR" - field = self._session.query(models.InformationField) \ - .filter_by(acronym=p[-1]) \ + field = ( + self._session.query(models.InformationField) + .filter_by(acronym=p[-1]) .one() + ) p[0] = models.Protein(field=field) def p_protein_organism(self, p): diff --git a/src/brenda_parser/parsing/parsetab.py b/src/brenda_parser/parsing/parsetab.py index d131116..c0662ab 100644 --- a/src/brenda_parser/parsing/parsetab.py +++ b/src/brenda_parser/parsing/parsetab.py @@ -1,74 +1,1529 @@ - # parsetab.py # This file is automatically generated. Do not edit. # pylint: disable=W,C,R -_tabversion = '3.10' +_tabversion = "3.10" + +_lr_method = "LALR" -_lr_method = 'LALR' +_lr_signature = "leftASSEMBLEleftREDUCEleftCOMBINEACCESSION AND CITATION COMMENT CONTENT EC_NUMBER END ENTRY ENZYME_ENTRY LANGLE LCURLY LPARENS POUND PROTEIN PROTEIN_ENTRY RANGLE RCURLY REFERENCE_ENTRY RPARENS SPECIALenzyme : ENZYME_ENTRY EC_NUMBER new_enzymenew_enzyme :enzyme : enzyme commentenzyme : enzyme protein_entryenzyme : enzyme reference_entryenzyme : enzyme entryenzyme : enzyme ENDentry : ENTRY new_entry %prec REDUCEnew_entry : %prec REDUCEentry : entry CONTENTentry : entry proteins %prec ASSEMBLEentry : entry comment %prec ASSEMBLEentry : entry special %prec ASSEMBLEentry : entry citations %prec ASSEMBLEreference_entry : REFERENCE_ENTRY new_reference citationsnew_reference :reference_entry : reference_entry CONTENTreference_entry : reference_entry comment %prec ASSEMBLEreference_entry : reference_entry special %prec ASSEMBLEprotein_entry : PROTEIN_ENTRY new_protein proteins %prec COMBINEnew_protein :protein_entry : protein_entry CONTENT %prec ASSEMBLEprotein_entry : protein_entry accession %prec ASSEMBLEprotein_entry : protein_entry comment %prec ASSEMBLEprotein_entry : protein_entry citations %prec ASSEMBLEaccession : accession AND ACCESSION %prec COMBINEaccession : accession CONTENT %prec COMBINEaccession : ACCESSION %prec REDUCEspecial : LCURLY special RCURLYspecial : LCURLY RCURLYspecial : special SPECIAL %prec COMBINEspecial : SPECIAL %prec REDUCEproteins : POUND proteins POUND %prec ASSEMBLEproteins : POUND POUND %prec ASSEMBLEproteins : proteins PROTEIN %prec COMBINEproteins : PROTEIN %prec REDUCEcitations : LANGLE citations RANGLE %prec ASSEMBLEcitations : LANGLE RANGLE %prec ASSEMBLEcitations : citations CITATION %prec COMBINEcitations : CITATION %prec REDUCEcomment : LPARENS comment RPARENS %prec ASSEMBLEcomment : LPARENS RPARENS %prec ASSEMBLEcomment : comment COMMENT %prec COMBINEcomment : COMMENT %prec REDUCE" -_lr_signature = 'leftASSEMBLEleftREDUCEleftCOMBINEACCESSION AND CITATION COMMENT CONTENT EC_NUMBER END ENTRY ENZYME_ENTRY LANGLE LCURLY LPARENS POUND PROTEIN PROTEIN_ENTRY RANGLE RCURLY REFERENCE_ENTRY RPARENS SPECIALenzyme : ENZYME_ENTRY EC_NUMBER new_enzymenew_enzyme :enzyme : enzyme commentenzyme : enzyme protein_entryenzyme : enzyme reference_entryenzyme : enzyme entryenzyme : enzyme ENDentry : ENTRY new_entry %prec REDUCEnew_entry : %prec REDUCEentry : entry CONTENTentry : entry proteins %prec ASSEMBLEentry : entry comment %prec ASSEMBLEentry : entry special %prec ASSEMBLEentry : entry citations %prec ASSEMBLEreference_entry : REFERENCE_ENTRY new_reference citationsnew_reference :reference_entry : reference_entry CONTENTreference_entry : reference_entry comment %prec ASSEMBLEreference_entry : reference_entry special %prec ASSEMBLEprotein_entry : PROTEIN_ENTRY new_protein proteins %prec COMBINEnew_protein :protein_entry : protein_entry CONTENT %prec ASSEMBLEprotein_entry : protein_entry accession %prec ASSEMBLEprotein_entry : protein_entry comment %prec ASSEMBLEprotein_entry : protein_entry citations %prec ASSEMBLEaccession : accession AND ACCESSION %prec COMBINEaccession : accession CONTENT %prec COMBINEaccession : ACCESSION %prec REDUCEspecial : LCURLY special RCURLYspecial : LCURLY RCURLYspecial : special SPECIAL %prec COMBINEspecial : SPECIAL %prec REDUCEproteins : POUND proteins POUND %prec ASSEMBLEproteins : POUND POUND %prec ASSEMBLEproteins : proteins PROTEIN %prec COMBINEproteins : PROTEIN %prec REDUCEcitations : LANGLE citations RANGLE %prec ASSEMBLEcitations : LANGLE RANGLE %prec ASSEMBLEcitations : citations CITATION %prec COMBINEcitations : CITATION %prec REDUCEcomment : LPARENS comment RPARENS %prec ASSEMBLEcomment : LPARENS RPARENS %prec ASSEMBLEcomment : comment COMMENT %prec COMBINEcomment : COMMENT %prec REDUCE' - -_lr_action_items = {'ENZYME_ENTRY':([0,],[2,]),'$end':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[0,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'END':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[7,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'LPARENS':([1,3,4,5,6,7,8,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[8,-3,8,8,8,-7,8,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'COMMENT':([1,3,4,5,6,7,8,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,34,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[9,14,9,9,9,-7,9,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,14,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'PROTEIN_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[10,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'REFERENCE_ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[11,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'ENTRY':([1,3,4,5,6,7,9,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,39,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[12,-3,-4,-5,-6,-7,-44,-9,-2,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-1,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'EC_NUMBER':([2,],[13,]),'CONTENT':([4,5,6,9,12,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,33,35,38,41,42,44,45,47,48,49,51,52,53,54,55,56,57,],[15,22,27,-44,-9,-43,-22,-23,-24,-25,-28,-40,-17,-18,-19,-32,-10,-11,-12,-13,-14,-36,-42,-8,-27,-39,-38,-31,-30,-35,-34,-41,-20,-15,-26,-37,-29,-33,]),'ACCESSION':([4,9,14,15,16,17,18,19,21,33,35,40,41,42,44,48,49,51,52,54,55,57,],[19,-44,-43,-22,-23,-24,-25,-28,-40,-36,-42,54,-27,-39,-38,-35,-34,-41,-20,-26,-37,-33,]),'LANGLE':([4,6,9,11,12,14,15,16,17,18,19,20,21,26,27,28,29,30,31,33,35,37,38,41,42,44,45,47,48,49,51,52,54,55,56,57,],[20,20,-44,-16,-9,-43,-22,-23,-24,-25,-28,20,-40,-32,-10,-11,-12,-13,-14,-36,-42,20,-8,-27,-39,-38,-31,-30,-35,-34,-41,-20,-26,-37,-29,-33,]),'CITATION':([4,6,9,11,12,14,15,16,17,18,19,20,21,26,27,28,29,30,31,33,35,37,38,41,42,43,44,45,47,48,49,51,52,53,54,55,56,57,],[21,21,-44,-16,-9,-43,-22,-23,-24,-25,-28,21,-40,-32,-10,-11,-12,-13,-14,-36,-42,21,-8,-27,-39,42,-38,-31,-30,-35,-34,-41,-20,42,-26,-37,-29,-33,]),'LCURLY':([5,6,9,12,14,21,22,23,24,25,26,27,28,29,30,31,33,35,38,42,44,45,47,48,49,51,53,55,56,57,],[25,25,-44,-9,-43,-40,-17,-18,-19,25,-32,-10,-11,-12,-13,-14,-36,-42,-8,-39,-38,-31,-30,-35,-34,-41,-15,-37,-29,-33,]),'SPECIAL':([5,6,9,12,14,21,22,23,24,25,26,27,28,29,30,31,33,35,38,42,44,45,46,47,48,49,51,53,55,56,57,],[26,26,-44,-9,-43,-40,-17,-18,-19,26,-32,-10,-11,-12,-13,-14,-36,-42,-8,-39,-38,-31,45,-30,-35,-34,-41,-15,-37,-29,-33,]),'POUND':([6,9,10,12,14,21,26,27,28,29,30,31,32,33,35,36,38,42,44,45,47,48,49,50,51,55,56,57,],[32,-44,-21,-9,-43,-40,-32,-10,-11,-12,-13,-14,49,-36,-42,32,-8,-39,-38,-31,-30,-35,-34,57,-41,-37,-29,-33,]),'PROTEIN':([6,9,10,12,14,21,26,27,28,29,30,31,32,33,35,36,38,42,44,45,47,48,49,50,51,52,55,56,57,],[33,-44,-21,-9,-43,-40,-32,-10,-11,-12,-13,-14,33,-36,-42,33,-8,-39,-38,-31,-30,-35,-34,48,-41,48,-37,-29,-33,]),'RPARENS':([8,9,14,34,35,51,],[35,-44,-43,51,-42,-41,]),'AND':([16,19,41,54,],[40,-28,-27,-26,]),'RANGLE':([20,21,42,43,44,55,],[44,-40,-39,55,-38,-37,]),'RCURLY':([25,26,45,46,47,56,],[47,-32,-31,56,-30,-29,]),} +_lr_action_items = { + "ENZYME_ENTRY": ([0], [2]), + "$end": ( + [ + 1, + 3, + 4, + 5, + 6, + 7, + 9, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 22, + 23, + 24, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 39, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 0, + -3, + -4, + -5, + -6, + -7, + -44, + -9, + -2, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -17, + -18, + -19, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -1, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -15, + -26, + -37, + -29, + -33, + ], + ), + "END": ( + [ + 1, + 3, + 4, + 5, + 6, + 7, + 9, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 22, + 23, + 24, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 39, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 7, + -3, + -4, + -5, + -6, + -7, + -44, + -9, + -2, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -17, + -18, + -19, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -1, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -15, + -26, + -37, + -29, + -33, + ], + ), + "LPARENS": ( + [ + 1, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 22, + 23, + 24, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 39, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 8, + -3, + 8, + 8, + 8, + -7, + 8, + -44, + -9, + -2, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -17, + -18, + -19, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -1, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -15, + -26, + -37, + -29, + -33, + ], + ), + "COMMENT": ( + [ + 1, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 22, + 23, + 24, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 34, + 35, + 38, + 39, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 9, + 14, + 9, + 9, + 9, + -7, + 9, + -44, + -9, + -2, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -17, + -18, + -19, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + 14, + -42, + -8, + -1, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -15, + -26, + -37, + -29, + -33, + ], + ), + "PROTEIN_ENTRY": ( + [ + 1, + 3, + 4, + 5, + 6, + 7, + 9, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 22, + 23, + 24, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 39, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 10, + -3, + -4, + -5, + -6, + -7, + -44, + -9, + -2, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -17, + -18, + -19, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -1, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -15, + -26, + -37, + -29, + -33, + ], + ), + "REFERENCE_ENTRY": ( + [ + 1, + 3, + 4, + 5, + 6, + 7, + 9, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 22, + 23, + 24, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 39, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 11, + -3, + -4, + -5, + -6, + -7, + -44, + -9, + -2, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -17, + -18, + -19, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -1, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -15, + -26, + -37, + -29, + -33, + ], + ), + "ENTRY": ( + [ + 1, + 3, + 4, + 5, + 6, + 7, + 9, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 22, + 23, + 24, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 39, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 12, + -3, + -4, + -5, + -6, + -7, + -44, + -9, + -2, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -17, + -18, + -19, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -1, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -15, + -26, + -37, + -29, + -33, + ], + ), + "EC_NUMBER": ([2], [13]), + "CONTENT": ( + [ + 4, + 5, + 6, + 9, + 12, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 22, + 23, + 24, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 15, + 22, + 27, + -44, + -9, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -17, + -18, + -19, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -15, + -26, + -37, + -29, + -33, + ], + ), + "ACCESSION": ( + [ + 4, + 9, + 14, + 15, + 16, + 17, + 18, + 19, + 21, + 33, + 35, + 40, + 41, + 42, + 44, + 48, + 49, + 51, + 52, + 54, + 55, + 57, + ], + [ + 19, + -44, + -43, + -22, + -23, + -24, + -25, + -28, + -40, + -36, + -42, + 54, + -27, + -39, + -38, + -35, + -34, + -41, + -20, + -26, + -37, + -33, + ], + ), + "LANGLE": ( + [ + 4, + 6, + 9, + 11, + 12, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 37, + 38, + 41, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 54, + 55, + 56, + 57, + ], + [ + 20, + 20, + -44, + -16, + -9, + -43, + -22, + -23, + -24, + -25, + -28, + 20, + -40, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + 20, + -8, + -27, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + -26, + -37, + -29, + -33, + ], + ), + "CITATION": ( + [ + 4, + 6, + 9, + 11, + 12, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 37, + 38, + 41, + 42, + 43, + 44, + 45, + 47, + 48, + 49, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + ], + [ + 21, + 21, + -44, + -16, + -9, + -43, + -22, + -23, + -24, + -25, + -28, + 21, + -40, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + 21, + -8, + -27, + -39, + 42, + -38, + -31, + -30, + -35, + -34, + -41, + -20, + 42, + -26, + -37, + -29, + -33, + ], + ), + "LCURLY": ( + [ + 5, + 6, + 9, + 12, + 14, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 42, + 44, + 45, + 47, + 48, + 49, + 51, + 53, + 55, + 56, + 57, + ], + [ + 25, + 25, + -44, + -9, + -43, + -40, + -17, + -18, + -19, + 25, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -39, + -38, + -31, + -30, + -35, + -34, + -41, + -15, + -37, + -29, + -33, + ], + ), + "SPECIAL": ( + [ + 5, + 6, + 9, + 12, + 14, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 33, + 35, + 38, + 42, + 44, + 45, + 46, + 47, + 48, + 49, + 51, + 53, + 55, + 56, + 57, + ], + [ + 26, + 26, + -44, + -9, + -43, + -40, + -17, + -18, + -19, + 26, + -32, + -10, + -11, + -12, + -13, + -14, + -36, + -42, + -8, + -39, + -38, + -31, + 45, + -30, + -35, + -34, + -41, + -15, + -37, + -29, + -33, + ], + ), + "POUND": ( + [ + 6, + 9, + 10, + 12, + 14, + 21, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 35, + 36, + 38, + 42, + 44, + 45, + 47, + 48, + 49, + 50, + 51, + 55, + 56, + 57, + ], + [ + 32, + -44, + -21, + -9, + -43, + -40, + -32, + -10, + -11, + -12, + -13, + -14, + 49, + -36, + -42, + 32, + -8, + -39, + -38, + -31, + -30, + -35, + -34, + 57, + -41, + -37, + -29, + -33, + ], + ), + "PROTEIN": ( + [ + 6, + 9, + 10, + 12, + 14, + 21, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 35, + 36, + 38, + 42, + 44, + 45, + 47, + 48, + 49, + 50, + 51, + 52, + 55, + 56, + 57, + ], + [ + 33, + -44, + -21, + -9, + -43, + -40, + -32, + -10, + -11, + -12, + -13, + -14, + 33, + -36, + -42, + 33, + -8, + -39, + -38, + -31, + -30, + -35, + -34, + 48, + -41, + 48, + -37, + -29, + -33, + ], + ), + "RPARENS": ([8, 9, 14, 34, 35, 51], [35, -44, -43, 51, -42, -41]), + "AND": ([16, 19, 41, 54], [40, -28, -27, -26]), + "RANGLE": ([20, 21, 42, 43, 44, 55], [44, -40, -39, 55, -38, -37]), + "RCURLY": ([25, 26, 45, 46, 47, 56], [47, -32, -31, 56, -30, -29]), +} _lr_action = {} for _k, _v in _lr_action_items.items(): - for _x,_y in zip(_v[0],_v[1]): - if not _x in _lr_action: _lr_action[_x] = {} - _lr_action[_x][_k] = _y + for _x, _y in zip(_v[0], _v[1]): + if not _x in _lr_action: + _lr_action[_x] = {} + _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'enzyme':([0,],[1,]),'comment':([1,4,5,6,8,],[3,17,23,29,34,]),'protein_entry':([1,],[4,]),'reference_entry':([1,],[5,]),'entry':([1,],[6,]),'accession':([4,],[16,]),'citations':([4,6,20,37,],[18,31,43,53,]),'special':([5,6,25,],[24,30,46,]),'proteins':([6,32,36,49,],[28,50,52,50,]),'new_protein':([10,],[36,]),'new_reference':([11,],[37,]),'new_entry':([12,],[38,]),'new_enzyme':([13,],[39,]),} +_lr_goto_items = { + "enzyme": ([0], [1]), + "comment": ([1, 4, 5, 6, 8], [3, 17, 23, 29, 34]), + "protein_entry": ([1], [4]), + "reference_entry": ([1], [5]), + "entry": ([1], [6]), + "accession": ([4], [16]), + "citations": ([4, 6, 20, 37], [18, 31, 43, 53]), + "special": ([5, 6, 25], [24, 30, 46]), + "proteins": ([6, 32, 36, 49], [28, 50, 52, 50]), + "new_protein": ([10], [36]), + "new_reference": ([11], [37]), + "new_entry": ([12], [38]), + "new_enzyme": ([13], [39]), +} _lr_goto = {} for _k, _v in _lr_goto_items.items(): - for _x, _y in zip(_v[0], _v[1]): - if not _x in _lr_goto: _lr_goto[_x] = {} - _lr_goto[_x][_k] = _y + for _x, _y in zip(_v[0], _v[1]): + if not _x in _lr_goto: + _lr_goto[_x] = {} + _lr_goto[_x][_k] = _y del _lr_goto_items _lr_productions = [ - ("S' -> enzyme","S'",1,None,None,None), - ('enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme','enzyme',3,'p_enzyme','parser.py',141), - ('new_enzyme -> ','new_enzyme',0,'p_new_enzyme','parser.py',145), - ('enzyme -> enzyme comment','enzyme',2,'p_enzyme_comment','parser.py',151), - ('enzyme -> enzyme protein_entry','enzyme',2,'p_enzyme_protein','parser.py',157), - ('enzyme -> enzyme reference_entry','enzyme',2,'p_enzyme_reference','parser.py',162), - ('enzyme -> enzyme entry','enzyme',2,'p_enzyme_entry','parser.py',167), - ('enzyme -> enzyme END','enzyme',2,'p_enzyme_end','parser.py',173), - ('entry -> ENTRY new_entry','entry',2,'p_entry','parser.py',178), - ('new_entry -> ','new_entry',0,'p_new_entry','parser.py',183), - ('entry -> entry CONTENT','entry',2,'p_entry_content','parser.py',190), - ('entry -> entry proteins','entry',2,'p_entry_proteins','parser.py',196), - ('entry -> entry comment','entry',2,'p_entry_comment','parser.py',202), - ('entry -> entry special','entry',2,'p_entry_special','parser.py',208), - ('entry -> entry citations','entry',2,'p_entry_citations','parser.py',214), - ('reference_entry -> REFERENCE_ENTRY new_reference citations','reference_entry',3,'p_reference_entry','parser.py',220), - ('new_reference -> ','new_reference',0,'p_new_reference','parser.py',226), - ('reference_entry -> reference_entry CONTENT','reference_entry',2,'p_reference_content','parser.py',234), - ('reference_entry -> reference_entry comment','reference_entry',2,'p_reference_year','parser.py',240), - ('reference_entry -> reference_entry special','reference_entry',2,'p_reference_pubmed','parser.py',246), - ('protein_entry -> PROTEIN_ENTRY new_protein proteins','protein_entry',3,'p_protein_entry','parser.py',254), - ('new_protein -> ','new_protein',0,'p_new_protein','parser.py',260), - ('protein_entry -> protein_entry CONTENT','protein_entry',2,'p_protein_organism','parser.py',268), - ('protein_entry -> protein_entry accession','protein_entry',2,'p_protein_accession','parser.py',275), - ('protein_entry -> protein_entry comment','protein_entry',2,'p_protein_comment','parser.py',280), - ('protein_entry -> protein_entry citations','protein_entry',2,'p_protein_citations','parser.py',286), - ('accession -> accession AND ACCESSION','accession',3,'p_accession_combine','parser.py',292), - ('accession -> accession CONTENT','accession',2,'p_accession_database','parser.py',297), - ('accession -> ACCESSION','accession',1,'p_accession','parser.py',302), - ('special -> LCURLY special RCURLY','special',3,'p_special','parser.py',306), - ('special -> LCURLY RCURLY','special',2,'p_special_empty','parser.py',310), - ('special -> special SPECIAL','special',2,'p_special_combine','parser.py',314), - ('special -> SPECIAL','special',1,'p_special_end','parser.py',318), - ('proteins -> POUND proteins POUND','proteins',3,'p_proteins','parser.py',322), - ('proteins -> POUND POUND','proteins',2,'p_proteins_empty','parser.py',326), - ('proteins -> proteins PROTEIN','proteins',2,'p_proteins_combine','parser.py',330), - ('proteins -> PROTEIN','proteins',1,'p_proteins_end','parser.py',335), - ('citations -> LANGLE citations RANGLE','citations',3,'p_citations','parser.py',339), - ('citations -> LANGLE RANGLE','citations',2,'p_citations_empty','parser.py',343), - ('citations -> citations CITATION','citations',2,'p_citations_combine','parser.py',347), - ('citations -> CITATION','citations',1,'p_citations_end','parser.py',352), - ('comment -> LPARENS comment RPARENS','comment',3,'p_comment','parser.py',356), - ('comment -> LPARENS RPARENS','comment',2,'p_comment_empty','parser.py',360), - ('comment -> comment COMMENT','comment',2,'p_comment_combine','parser.py',364), - ('comment -> COMMENT','comment',1,'p_comment_end','parser.py',369), + ("S' -> enzyme", "S'", 1, None, None, None), + ( + "enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme", + "enzyme", + 3, + "p_enzyme", + "parser.py", + 141, + ), + ( + "new_enzyme -> ", + "new_enzyme", + 0, + "p_new_enzyme", + "parser.py", + 145, + ), + ( + "enzyme -> enzyme comment", + "enzyme", + 2, + "p_enzyme_comment", + "parser.py", + 151, + ), + ( + "enzyme -> enzyme protein_entry", + "enzyme", + 2, + "p_enzyme_protein", + "parser.py", + 157, + ), + ( + "enzyme -> enzyme reference_entry", + "enzyme", + 2, + "p_enzyme_reference", + "parser.py", + 162, + ), + ("enzyme -> enzyme entry", "enzyme", 2, "p_enzyme_entry", "parser.py", 167), + ("enzyme -> enzyme END", "enzyme", 2, "p_enzyme_end", "parser.py", 173), + ("entry -> ENTRY new_entry", "entry", 2, "p_entry", "parser.py", 178), + ("new_entry -> ", "new_entry", 0, "p_new_entry", "parser.py", 183), + ("entry -> entry CONTENT", "entry", 2, "p_entry_content", "parser.py", 190), + ( + "entry -> entry proteins", + "entry", + 2, + "p_entry_proteins", + "parser.py", + 196, + ), + ("entry -> entry comment", "entry", 2, "p_entry_comment", "parser.py", 202), + ("entry -> entry special", "entry", 2, "p_entry_special", "parser.py", 208), + ( + "entry -> entry citations", + "entry", + 2, + "p_entry_citations", + "parser.py", + 214, + ), + ( + "reference_entry -> REFERENCE_ENTRY new_reference citations", + "reference_entry", + 3, + "p_reference_entry", + "parser.py", + 220, + ), + ( + "new_reference -> ", + "new_reference", + 0, + "p_new_reference", + "parser.py", + 226, + ), + ( + "reference_entry -> reference_entry CONTENT", + "reference_entry", + 2, + "p_reference_content", + "parser.py", + 234, + ), + ( + "reference_entry -> reference_entry comment", + "reference_entry", + 2, + "p_reference_year", + "parser.py", + 240, + ), + ( + "reference_entry -> reference_entry special", + "reference_entry", + 2, + "p_reference_pubmed", + "parser.py", + 246, + ), + ( + "protein_entry -> PROTEIN_ENTRY new_protein proteins", + "protein_entry", + 3, + "p_protein_entry", + "parser.py", + 254, + ), + ( + "new_protein -> ", + "new_protein", + 0, + "p_new_protein", + "parser.py", + 260, + ), + ( + "protein_entry -> protein_entry CONTENT", + "protein_entry", + 2, + "p_protein_organism", + "parser.py", + 268, + ), + ( + "protein_entry -> protein_entry accession", + "protein_entry", + 2, + "p_protein_accession", + "parser.py", + 275, + ), + ( + "protein_entry -> protein_entry comment", + "protein_entry", + 2, + "p_protein_comment", + "parser.py", + 280, + ), + ( + "protein_entry -> protein_entry citations", + "protein_entry", + 2, + "p_protein_citations", + "parser.py", + 286, + ), + ( + "accession -> accession AND ACCESSION", + "accession", + 3, + "p_accession_combine", + "parser.py", + 292, + ), + ( + "accession -> accession CONTENT", + "accession", + 2, + "p_accession_database", + "parser.py", + 297, + ), + ("accession -> ACCESSION", "accession", 1, "p_accession", "parser.py", 302), + ( + "special -> LCURLY special RCURLY", + "special", + 3, + "p_special", + "parser.py", + 306, + ), + ( + "special -> LCURLY RCURLY", + "special", + 2, + "p_special_empty", + "parser.py", + 310, + ), + ( + "special -> special SPECIAL", + "special", + 2, + "p_special_combine", + "parser.py", + 314, + ), + ("special -> SPECIAL", "special", 1, "p_special_end", "parser.py", 318), + ( + "proteins -> POUND proteins POUND", + "proteins", + 3, + "p_proteins", + "parser.py", + 322, + ), + ( + "proteins -> POUND POUND", + "proteins", + 2, + "p_proteins_empty", + "parser.py", + 326, + ), + ( + "proteins -> proteins PROTEIN", + "proteins", + 2, + "p_proteins_combine", + "parser.py", + 330, + ), + ("proteins -> PROTEIN", "proteins", 1, "p_proteins_end", "parser.py", 335), + ( + "citations -> LANGLE citations RANGLE", + "citations", + 3, + "p_citations", + "parser.py", + 339, + ), + ( + "citations -> LANGLE RANGLE", + "citations", + 2, + "p_citations_empty", + "parser.py", + 343, + ), + ( + "citations -> citations CITATION", + "citations", + 2, + "p_citations_combine", + "parser.py", + 347, + ), + ( + "citations -> CITATION", + "citations", + 1, + "p_citations_end", + "parser.py", + 352, + ), + ( + "comment -> LPARENS comment RPARENS", + "comment", + 3, + "p_comment", + "parser.py", + 356, + ), + ( + "comment -> LPARENS RPARENS", + "comment", + 2, + "p_comment_empty", + "parser.py", + 360, + ), + ( + "comment -> comment COMMENT", + "comment", + 2, + "p_comment_combine", + "parser.py", + 364, + ), + ("comment -> COMMENT", "comment", 1, "p_comment_end", "parser.py", 369), ] diff --git a/tests/test_integration/test_brenda_parser.py b/tests/test_integration/test_brenda_parser.py index 1a3758f..8379d51 100644 --- a/tests/test_integration/test_brenda_parser.py +++ b/tests/test_integration/test_brenda_parser.py @@ -7,5 +7,5 @@ # runner = CliRunner() # result = runner.invoke(main, []) - # assert result.output == '()\n' - # assert result.exit_code == 0 +# assert result.output == '()\n' +# assert result.exit_code == 0 diff --git a/tests/test_unit/models/test_information_field.py b/tests/test_unit/models/test_information_field.py index 139d960..49c20ff 100644 --- a/tests/test_unit/models/test_information_field.py +++ b/tests/test_unit/models/test_information_field.py @@ -27,7 +27,6 @@ import pytest -from six import iteritems from brenda_parser.exceptions import ValidationError from brenda_parser.models import InformationField @@ -36,26 +35,35 @@ # from sqlalchemy.exc import IntegrityError - -@pytest.mark.parametrize("attributes", [ - pytest.param({"acronym": ""}, - marks=pytest.mark.raises(exception=ValidationError)), - pytest.param({"acronym": "I"}, - marks=pytest.mark.raises(exception=ValidationError)), - pytest.param({"acronym": "on"}, - marks=pytest.mark.raises(exception=ValidationError)), - {"acronym": "RN"}, - {"acronym": "REF"}, - {"acronym": "IC50"}, - pytest.param({"acronym": "too long"}, - marks=pytest.mark.raises(exception=ValidationError)), - {"acronym": "SM", "name": "Super Man"}, - pytest.param({"acronym": "SM", "name": "an" * 51}) - # marks=pytest.mark.raises(exception=IntegrityError)), -]) +@pytest.mark.parametrize( + "attributes", + [ + pytest.param( + {"acronym": ""}, marks=pytest.mark.raises(exception=ValidationError) + ), + pytest.param( + {"acronym": "I"}, + marks=pytest.mark.raises(exception=ValidationError), + ), + pytest.param( + {"acronym": "on"}, + marks=pytest.mark.raises(exception=ValidationError), + ), + {"acronym": "RN"}, + {"acronym": "REF"}, + {"acronym": "IC50"}, + pytest.param( + {"acronym": "too long"}, + marks=pytest.mark.raises(exception=ValidationError), + ), + {"acronym": "SM", "name": "Super Man"}, + pytest.param({"acronym": "SM", "name": "an" * 51}) + # marks=pytest.mark.raises(exception=IntegrityError)), + ], +) def test_create_information_field(session, attributes): obj = InformationField(**attributes) session.add(obj) session.commit() - for attr, value in iteritems(attributes): + for attr, value in attributes.items(): assert getattr(obj, attr) == value diff --git a/tests/test_unit/models/test_organism.py b/tests/test_unit/models/test_organism.py index e8fbf0d..ceba2a1 100644 --- a/tests/test_unit/models/test_organism.py +++ b/tests/test_unit/models/test_organism.py @@ -27,31 +27,38 @@ import pytest -from six import iteritems from sqlalchemy.exc import IntegrityError from brenda_parser.models import Organism -@pytest.mark.parametrize("attributes", [ - pytest.param({"name": None}, - marks=pytest.mark.raises(exception=IntegrityError)), - {"name": ""}, - {"name": "Homo sapiens"} -]) +@pytest.mark.parametrize( + "attributes", + [ + pytest.param( + {"name": None}, marks=pytest.mark.raises(exception=IntegrityError) + ), + {"name": ""}, + {"name": "Homo sapiens"}, + ], +) def test_create_organism(session, attributes): obj = Organism(**attributes) session.add(obj) session.commit() - for attr, value in iteritems(attributes): + for attr, value in attributes.items(): assert getattr(obj, attr) == value -@pytest.mark.parametrize("name_a, name_b", [ - pytest.param("same", "same", - marks=pytest.mark.raises(exception=IntegrityError)), - ("way", "different") -]) +@pytest.mark.parametrize( + "name_a, name_b", + [ + pytest.param( + "same", "same", marks=pytest.mark.raises(exception=IntegrityError) + ), + ("way", "different"), + ], +) def test_unique_name(session, name_a, name_b): obj_a = Organism(name=name_a) obj_b = Organism(name=name_b) diff --git a/tests/test_unit/models/test_protein.py b/tests/test_unit/models/test_protein.py index 1da0d46..d6326eb 100644 --- a/tests/test_unit/models/test_protein.py +++ b/tests/test_unit/models/test_protein.py @@ -28,7 +28,6 @@ from __future__ import absolute_import import pytest -from six import iteritems from sqlalchemy.exc import IntegrityError import brenda_parser.models as models diff --git a/tests/test_unit/models/test_reference.py b/tests/test_unit/models/test_reference.py index d9cb0c1..1609777 100644 --- a/tests/test_unit/models/test_reference.py +++ b/tests/test_unit/models/test_reference.py @@ -27,36 +27,48 @@ import pytest -from six import iteritems from sqlalchemy.exc import IntegrityError from brenda_parser.exceptions import ValidationError from brenda_parser.models import Reference -@pytest.mark.parametrize("attributes", [ - pytest.param({"body": None}, - marks=pytest.mark.raises(exception=IntegrityError)), - {"body": "Cunning et al."}, - pytest.param({"body": "Evil Inc.", "pubmed": "fail"}, - marks=pytest.mark.raises(exception=ValidationError)), - {"body": "Vitello et al.", "pubmed": "Pubmed:1234567"} -]) +@pytest.mark.parametrize( + "attributes", + [ + pytest.param( + {"body": None}, marks=pytest.mark.raises(exception=IntegrityError) + ), + {"body": "Cunning et al."}, + pytest.param( + {"body": "Evil Inc.", "pubmed": "fail"}, + marks=pytest.mark.raises(exception=ValidationError), + ), + {"body": "Vitello et al.", "pubmed": "Pubmed:1234567"}, + ], +) def test_create_reference(session, attributes): obj = Reference(**attributes) session.add(obj) session.commit() - for attr, value in iteritems(attributes): + for attr, value in attributes.items(): assert getattr(obj, attr) == value -@pytest.mark.parametrize("ref_a, ref_b", [ - pytest.param({"body": "Vitello et al.", "pubmed": "Pubmed:1234567"}, - {"body": "The Others", "pubmed": "Pubmed:1234567"}, - marks=pytest.mark.raises(exception=IntegrityError)), - ({"body": "Batman", "pubmed": "Pubmed:1111111"}, - {"body": "Robin", "pubmed": "Pubmed:2222222"}) -]) +@pytest.mark.parametrize( + "ref_a, ref_b", + [ + pytest.param( + {"body": "Vitello et al.", "pubmed": "Pubmed:1234567"}, + {"body": "The Others", "pubmed": "Pubmed:1234567"}, + marks=pytest.mark.raises(exception=IntegrityError), + ), + ( + {"body": "Batman", "pubmed": "Pubmed:1111111"}, + {"body": "Robin", "pubmed": "Pubmed:2222222"}, + ), + ], +) def test_unique_name(session, ref_a, ref_b): obj_a = Reference(**ref_a) obj_b = Reference(**ref_b) diff --git a/tests/test_unit/test_parsing/test_comments.py b/tests/test_unit/test_parsing/test_comments.py index 1134b44..bdd126c 100644 --- a/tests/test_unit/test_parsing/test_comments.py +++ b/tests/test_unit/test_parsing/test_comments.py @@ -81,8 +81,9 @@ def parser(): def test_long_comment(session, parser): - with open(join( - dirname(__file__), "data", "long_comments.txt")) as file_handle: + with open( + join(dirname(__file__), "data", "long_comments.txt") + ) as file_handle: enzyme = parser.parse(file_handle.read(), session) assert len(enzyme.entries) == 1 entry = enzyme.entries[0] diff --git a/tests/test_unit/test_parsing/test_lexer.py b/tests/test_unit/test_parsing/test_lexer.py index 0f883ae..e6f9ad0 100644 --- a/tests/test_unit/test_parsing/test_lexer.py +++ b/tests/test_unit/test_parsing/test_lexer.py @@ -42,80 +42,124 @@ def tokenizer(lexer, request): return lexer -@pytest.mark.parametrize("tokenizer, expected", [ - ("KM\tRF\tKI\t", ["INITIAL", "INITIAL", "INITIAL"]), - ("KM\tPR\tKI\t", ["INITIAL", "protentry", "INITIAL"]), - ("KM\tPR\tPR\tKI\t", ["INITIAL", "protentry", "protentry", "INITIAL"]), - ("KM\tPR\tRF\t", ["INITIAL", "protentry", "INITIAL"]) -], indirect=["tokenizer"]) +@pytest.mark.parametrize( + "tokenizer, expected", + [ + ("KM\tRF\tKI\t", ["INITIAL", "INITIAL", "INITIAL"]), + ("KM\tPR\tKI\t", ["INITIAL", "protentry", "INITIAL"]), + ("KM\tPR\tPR\tKI\t", ["INITIAL", "protentry", "protentry", "INITIAL"]), + ("KM\tPR\tRF\t", ["INITIAL", "protentry", "INITIAL"]), + ], + indirect=["tokenizer"], +) def test_inclusive_entry_states(tokenizer, expected): states = [t.lexer.current_state() for t in tokenizer] assert states == expected -@pytest.mark.parametrize("tokenizer, expected", [ - ("<13>", ["citation", "citation", "INITIAL"]), - ("#13#", ["protein", "protein", "INITIAL"]), - ("#13##", ["protein", "protein", "INITIAL", "protein"]), - ("{13}", ["special", "special", "INITIAL"]), - ("(13)", ["comment", "comment", "INITIAL"]), -], indirect=["tokenizer"]) +@pytest.mark.parametrize( + "tokenizer, expected", + [ + ("<13>", ["citation", "citation", "INITIAL"]), + ("#13#", ["protein", "protein", "INITIAL"]), + ("#13##", ["protein", "protein", "INITIAL", "protein"]), + ("{13}", ["special", "special", "INITIAL"]), + ("(13)", ["comment", "comment", "INITIAL"]), + ], + indirect=["tokenizer"], +) def test_exclusive_states(tokenizer, expected): states = [t.lexer.current_state() for t in tokenizer] assert states == expected -@pytest.mark.parametrize("tokenizer, expected", [ - ("# ,,#", ["POUND", "POUND"]), - ("#12#", ["POUND", "PROTEIN", "POUND"]), - ("# 12,423,23#", ["POUND", "PROTEIN", "PROTEIN", "PROTEIN", "POUND"]), - ("# # 13 #", ["POUND", "POUND", "CONTENT", "POUND"]), -], indirect=["tokenizer"]) +@pytest.mark.parametrize( + "tokenizer, expected", + [ + ("# ,,#", ["POUND", "POUND"]), + ("#12#", ["POUND", "PROTEIN", "POUND"]), + ("# 12,423,23#", ["POUND", "PROTEIN", "PROTEIN", "PROTEIN", "POUND"]), + ("# # 13 #", ["POUND", "POUND", "CONTENT", "POUND"]), + ], + indirect=["tokenizer"], +) def test_protein_tokens(tokenizer, expected): tokens = [t.type for t in tokenizer] assert tokens == expected -@pytest.mark.parametrize("tokenizer, expected", [ - ("< ,,>", ["LANGLE", "RANGLE"]), - ("<12>", ["LANGLE", "CITATION", "RANGLE"]), - ("< 12,423,23>", ["LANGLE", "CITATION", "CITATION", "CITATION", "RANGLE"]), - ("<12> 13 <", ["LANGLE", "CITATION", "RANGLE", "CONTENT", "LANGLE"]), -], indirect=["tokenizer"]) +@pytest.mark.parametrize( + "tokenizer, expected", + [ + ("< ,,>", ["LANGLE", "RANGLE"]), + ("<12>", ["LANGLE", "CITATION", "RANGLE"]), + ( + "< 12,423,23>", + ["LANGLE", "CITATION", "CITATION", "CITATION", "RANGLE"], + ), + ("<12> 13 <", ["LANGLE", "CITATION", "RANGLE", "CONTENT", "LANGLE"]), + ], + indirect=["tokenizer"], +) def test_citation_tokens(tokenizer, expected): tokens = [t.type for t in tokenizer] assert tokens == expected -@pytest.mark.parametrize("tokenizer, expected", [ - ("{ }", ["LCURLY", "RCURLY"]), - ("{12}", ["LCURLY", "SPECIAL", "RCURLY"]), - ("{ 12,423,23}", ["LCURLY", "SPECIAL", "RCURLY"]), - ("{12} 13 {", ["LCURLY", "SPECIAL", "RCURLY", "CONTENT", "LCURLY"]), -], indirect=["tokenizer"]) +@pytest.mark.parametrize( + "tokenizer, expected", + [ + ("{ }", ["LCURLY", "RCURLY"]), + ("{12}", ["LCURLY", "SPECIAL", "RCURLY"]), + ("{ 12,423,23}", ["LCURLY", "SPECIAL", "RCURLY"]), + ("{12} 13 {", ["LCURLY", "SPECIAL", "RCURLY", "CONTENT", "LCURLY"]), + ], + indirect=["tokenizer"], +) def test_special_tokens(tokenizer, expected): tokens = [t.type for t in tokenizer] assert tokens == expected -@pytest.mark.parametrize("tokenizer, expected", [ - ("( )", ["LPARENS", "RPARENS"]), - ("(12)", ["LPARENS", "COMMENT", "RPARENS"]), - ("( 12,423,23)", ["LPARENS", "COMMENT", "RPARENS"]), - ("(12) 13 (", ["LPARENS", "COMMENT", "RPARENS", "CONTENT", "LPARENS"]), -], indirect=["tokenizer"]) +@pytest.mark.parametrize( + "tokenizer, expected", + [ + ("( )", ["LPARENS", "RPARENS"]), + ("(12)", ["LPARENS", "COMMENT", "RPARENS"]), + ("( 12,423,23)", ["LPARENS", "COMMENT", "RPARENS"]), + ("(12) 13 (", ["LPARENS", "COMMENT", "RPARENS", "CONTENT", "LPARENS"]), + ], + indirect=["tokenizer"], +) def test_comment_tokens(tokenizer, expected): tokens = [t.type for t in tokenizer] assert tokens == expected -@pytest.mark.parametrize("tokenizer, expected", [ - ("KM\t#13# Q4AE87 SwissProt\n", - ["ENTRY", "POUND", "PROTEIN", "POUND", "CONTENT", "CONTENT"]), - ("PR\t#41# Pseudomonas sp. Q4AE87 SwissProt\nPI\t", - ["PROTEIN_ENTRY", "POUND", "PROTEIN", "POUND", "CONTENT", "CONTENT", - "ACCESSION", "CONTENT", "ENTRY"]), -], indirect=["tokenizer"]) +@pytest.mark.parametrize( + "tokenizer, expected", + [ + ( + "KM\t#13# Q4AE87 SwissProt\n", + ["ENTRY", "POUND", "PROTEIN", "POUND", "CONTENT", "CONTENT"], + ), + ( + "PR\t#41# Pseudomonas sp. Q4AE87 SwissProt\nPI\t", + [ + "PROTEIN_ENTRY", + "POUND", + "PROTEIN", + "POUND", + "CONTENT", + "CONTENT", + "ACCESSION", + "CONTENT", + "ENTRY", + ], + ), + ], + indirect=["tokenizer"], +) def test_protein_entry_state(tokenizer, expected): tokens = [t.type for t in tokenizer] assert tokens == expected diff --git a/tests/test_unit/test_parsing/test_parser.py b/tests/test_unit/test_parsing/test_parser.py index 6650b12..0853f77 100644 --- a/tests/test_unit/test_parsing/test_parser.py +++ b/tests/test_unit/test_parsing/test_parser.py @@ -80,10 +80,9 @@ def proteins_parser(): return BRENDAParser(start="proteins") -@pytest.mark.parametrize("text, expected", [ - (" #, #", None), - (" #13, 334,23 #", [13, 334, 23]), -]) +@pytest.mark.parametrize( + "text, expected", [(" #, #", None), (" #13, 334,23 #", [13, 334, 23])] +) def test_proteins(proteins_parser, text, expected): assert proteins_parser.parse(text, None) == expected @@ -93,10 +92,9 @@ def citations_parser(): return BRENDAParser(start="citations") -@pytest.mark.parametrize("text, expected", [ - (" <, >", None), - (" <13, 334,23 >", [13, 334, 23]), -]) +@pytest.mark.parametrize( + "text, expected", [(" <, >", None), (" <13, 334,23 >", [13, 334, 23])] +) def test_citations(citations_parser, text, expected): assert citations_parser.parse(text, None) == expected @@ -106,10 +104,13 @@ def special_parser(): return BRENDAParser(start="special") -@pytest.mark.parametrize("text, expected", [ - (" { }", None), - (" { I am important content. }", "I am important content.") -]) +@pytest.mark.parametrize( + "text, expected", + [ + (" { }", None), + (" { I am important content. }", "I am important content."), + ], +) def test_special(special_parser, text, expected): assert special_parser.parse(text, None) == expected @@ -119,12 +120,19 @@ def comment_parser(): return BRENDAParser(start="comment") -@pytest.mark.parametrize("text, expected", [ - pytest.param(" ( )", None, - marks=pytest.mark.raises(exception=AttributeError, - message="NoneType")), - (" ( I am important content. )", "I am important content.") -]) +@pytest.mark.parametrize( + "text, expected", + [ + pytest.param( + " ( )", + None, + marks=pytest.mark.raises( + exception=AttributeError, message="NoneType" + ), + ), + (" ( I am important content. )", "I am important content."), + ], +) def test_comment(comment_parser, text, expected): assert comment_parser.parse(text, None).body == expected @@ -134,12 +142,15 @@ def protein_entry_parser(): return BRENDAParser(start="protein_entry") -@pytest.mark.parametrize("text, expected", [ - ("PR\t#2#", "PR"), - ("PR\t#2# alpha omega", "PR"), - ("PR\t#2# <12, 14>", "PR"), - ("PR\t#2# Q4AE87 SwissProt", "PR"), -]) +@pytest.mark.parametrize( + "text, expected", + [ + ("PR\t#2#", "PR"), + ("PR\t#2# alpha omega", "PR"), + ("PR\t#2# <12, 14>", "PR"), + ("PR\t#2# Q4AE87 SwissProt", "PR"), + ], +) def test_protein_entry(session, protein_entry_parser, text, expected): protein = protein_entry_parser.parse(text, session) assert protein.field.acronym == expected @@ -151,12 +162,15 @@ def reference_entry_parser(): return BRENDAParser(start="reference_entry") -@pytest.mark.parametrize("text, expected", [ - ("RF\t<2>", "RF"), - ("RF\t<2> Dogbert & Co", "RF"), - ("RF\t<2> Dogbert & Co (1748) Cool", "RF"), - ("RF\t<2> Dogbert & Co {Pubmed:1234567}", "RF"), -]) +@pytest.mark.parametrize( + "text, expected", + [ + ("RF\t<2>", "RF"), + ("RF\t<2> Dogbert & Co", "RF"), + ("RF\t<2> Dogbert & Co (1748) Cool", "RF"), + ("RF\t<2> Dogbert & Co {Pubmed:1234567}", "RF"), + ], +) def test_reference_entry(session, reference_entry_parser, text, expected): reference = reference_entry_parser.parse(text, session) assert reference.field.acronym == expected @@ -168,11 +182,14 @@ def entry_parser(): return BRENDAParser(start="entry") -@pytest.mark.parametrize("text, expected", [ - ("PI\thigh point", "PI"), - ("KI\t(high point)", "KI"), - ("KM\thigh point (this is a comment)", "KM"), -]) +@pytest.mark.parametrize( + "text, expected", + [ + ("PI\thigh point", "PI"), + ("KI\t(high point)", "KI"), + ("KM\thigh point (this is a comment)", "KM"), + ], +) def test_entry(session, entry_parser, text, expected): entry = entry_parser.parse(text, session) assert entry.field.acronym == expected @@ -183,11 +200,14 @@ def enzyme_parser(): return BRENDAParser(start="enzyme") -@pytest.mark.parametrize("text, expected", [ - ("ID\t1.1.1.1", "1.1.1.1"), - ("ID\t1.1.2.1\n///\n", "1.1.2.1"), - ("ID\t1.1.2.3 (mighty comment)\n///\n", "1.1.2.3"), -]) +@pytest.mark.parametrize( + "text, expected", + [ + ("ID\t1.1.1.1", "1.1.1.1"), + ("ID\t1.1.2.1\n///\n", "1.1.2.1"), + ("ID\t1.1.2.3 (mighty comment)\n///\n", "1.1.2.3"), + ], +) def test_enzyme(session, enzyme_parser, text, expected): enzyme = enzyme_parser.parse(text, session) assert enzyme.ec_number == expected @@ -195,7 +215,8 @@ def test_enzyme(session, enzyme_parser, text, expected): def test_section(session): parser = BRENDAParser() - with open(join( - dirname(__file__), "data", "small_section.txt")) as file_handle: + with open( + join(dirname(__file__), "data", "small_section.txt") + ) as file_handle: enzyme = parser.parse(file_handle.read(), session) print(enzyme.__dict__) diff --git a/tox.ini b/tox.ini index 160659b..64ebdb1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,12 @@ [tox] -envlist = flake8, isort, docs, py{35,36,37} +envlist = isort, black, flake8, docs, py{35,36,37} [travis] os = - linux: flake8, isort, docs, py{35,36,37} + linux: isort, black, flake8, docs, py{35,36,37} osx: py{27,35} python = - 3.5: py35, flake8, docs, isort + 3.5: isort, black, flake8, docs, py35 3.6: py36 3.7: py37 @@ -19,6 +19,20 @@ deps = commands = pytest --cov={envsitepackagesdir}/brenda_parser {posargs} +[testenv:isort] +skip_install = True +deps= + isort +commands= + isort --check-only --diff --recursive {toxinidir}/src/brenda_parser {toxinidir}/tests + +[testenv:black] +skip_install = True +deps= + black +commands= + black --check --diff {toxinidir}/src/brenda_parser {toxinidir}/tests + [testenv:flake8] skip_install = True deps = @@ -27,13 +41,6 @@ deps = commands = flake8 {toxinidir}/src/brenda_parser {toxinidir}/tests -[testenv:isort] -skip_install = True -deps= - isort -commands= - isort --check-only --diff --recursive {toxinidir}/src/brenda_parser {toxinidir}/tests - [testenv:docs] skip_install = True deps= From 1ee971b550ffe2b72228a68a66d6d85cd0d1bbe4 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sun, 2 Dec 2018 14:40:57 +0100 Subject: [PATCH 12/15] chore: rename parsing directory --- .../data/long_comments.txt | 0 .../data/small_section.txt | 0 tests/test_unit/parsing/data/transferred.txt | 35 +++++++++++++++++++ .../test_comments.py | 0 .../{test_parsing => parsing}/test_lexer.py | 0 .../{test_parsing => parsing}/test_parser.py | 0 .../test_parsing/data/transferred.txt | 17 --------- 7 files changed, 35 insertions(+), 17 deletions(-) rename tests/test_unit/{test_parsing => parsing}/data/long_comments.txt (100%) rename tests/test_unit/{test_parsing => parsing}/data/small_section.txt (100%) create mode 100644 tests/test_unit/parsing/data/transferred.txt rename tests/test_unit/{test_parsing => parsing}/test_comments.py (100%) rename tests/test_unit/{test_parsing => parsing}/test_lexer.py (100%) rename tests/test_unit/{test_parsing => parsing}/test_parser.py (100%) delete mode 100644 tests/test_unit/test_parsing/data/transferred.txt diff --git a/tests/test_unit/test_parsing/data/long_comments.txt b/tests/test_unit/parsing/data/long_comments.txt similarity index 100% rename from tests/test_unit/test_parsing/data/long_comments.txt rename to tests/test_unit/parsing/data/long_comments.txt diff --git a/tests/test_unit/test_parsing/data/small_section.txt b/tests/test_unit/parsing/data/small_section.txt similarity index 100% rename from tests/test_unit/test_parsing/data/small_section.txt rename to tests/test_unit/parsing/data/small_section.txt diff --git a/tests/test_unit/parsing/data/transferred.txt b/tests/test_unit/parsing/data/transferred.txt new file mode 100644 index 0000000..68e582d --- /dev/null +++ b/tests/test_unit/parsing/data/transferred.txt @@ -0,0 +1,35 @@ +ID 1.4.99.4 (transferred to EC 1.4.9.2) +******************************************************************************** +* * +* Copyrighted by Dietmar Schomburg, Techn. University Braunschweig, GERMANY * +* Distributed under the License as stated at http:/www.brenda-enzymes.org * +* * +******************************************************************************** + +RECOMMENDED_NAME +RN aralkylamine dehydrogenase + + +SYSTEMATIC_NAME +SN + + +/// + +ID 2.7.1.37 (transferred entry: protein kinase. Now divided into EC 2.7.11.1 (non-specific serine/threonine protein kinase), EC 2.7.11.8 (Fas-activated serine/threonine kinase), EC 2.7.11.9 (Goodpasture antigen-binding protein kinase), EC 2.7.11.10 (IkB kinase), EC 2.7.11.11 (cAMP-dependent protein kinase), EC 2.7.11.12 (cGMP-dependent protein kinase), EC 2.7.11.13 (protein kinase C), EC 2.7.11.21 (polo kinase), EC 2.7.11.22 (cyclin-dependent kinase), EC 2.7.11.24 (mitogen-activated protein kinase), EC 2.7.11.25 (mitogen-activated protein kinase kinase kinase), EC 2.7.11.30 (receptor protein serine/threonine kinase) and EC 2.7.12.1 (dual-specificity kinase).) +******************************************************************************** +* * +* Copyrighted by Dietmar Schomburg, Techn. University Braunschweig, GERMANY * +* Distributed under the License as stated at http:/www.brenda-enzymes.org * +* * +******************************************************************************** + +RECOMMENDED_NAME +RN protein kinase + + +SYSTEMATIC_NAME +SN + + +/// diff --git a/tests/test_unit/test_parsing/test_comments.py b/tests/test_unit/parsing/test_comments.py similarity index 100% rename from tests/test_unit/test_parsing/test_comments.py rename to tests/test_unit/parsing/test_comments.py diff --git a/tests/test_unit/test_parsing/test_lexer.py b/tests/test_unit/parsing/test_lexer.py similarity index 100% rename from tests/test_unit/test_parsing/test_lexer.py rename to tests/test_unit/parsing/test_lexer.py diff --git a/tests/test_unit/test_parsing/test_parser.py b/tests/test_unit/parsing/test_parser.py similarity index 100% rename from tests/test_unit/test_parsing/test_parser.py rename to tests/test_unit/parsing/test_parser.py diff --git a/tests/test_unit/test_parsing/data/transferred.txt b/tests/test_unit/test_parsing/data/transferred.txt deleted file mode 100644 index c2a2ab6..0000000 --- a/tests/test_unit/test_parsing/data/transferred.txt +++ /dev/null @@ -1,17 +0,0 @@ -ID 1.4.99.4 (transferred to EC 1.4.9.2) -******************************************************************************** -* * -* Copyrighted by Dietmar Schomburg, Techn. University Braunschweig, GERMANY * -* Distributed under the License as stated at http:/www.brenda-enzymes.org * -* * -******************************************************************************** - -RECOMMENDED_NAME -RN aralkylamine dehydrogenase - - -SYSTEMATIC_NAME -SN - - -/// From c905bf0cb878e7b720677481fb11e40f39effd93 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sun, 2 Dec 2018 14:41:25 +0100 Subject: [PATCH 13/15] style: change global names * Remove loggers where superfluous --- src/brenda_parser/api.py | 16 +++++++++------- src/brenda_parser/cli.py | 10 +++++----- src/brenda_parser/models/__init__.py | 4 ++++ src/brenda_parser/models/accession.py | 3 --- src/brenda_parser/models/comment.py | 4 ---- src/brenda_parser/models/enzyme.py | 4 ---- src/brenda_parser/models/field_entry.py | 4 ---- src/brenda_parser/models/information_field.py | 7 ++++--- src/brenda_parser/models/organism.py | 4 ---- src/brenda_parser/models/protein.py | 4 ---- src/brenda_parser/models/reference.py | 9 +++------ src/brenda_parser/parsing/lexer.py | 13 +++++++------ src/brenda_parser/parsing/parser.py | 9 +++++---- 13 files changed, 37 insertions(+), 54 deletions(-) diff --git a/src/brenda_parser/api.py b/src/brenda_parser/api.py index 513e7e6..23fc5a6 100644 --- a/src/brenda_parser/api.py +++ b/src/brenda_parser/api.py @@ -42,8 +42,10 @@ __all__ = ("initialize", "parse") -LOGGER = logging.getLogger(__name__) -EC_PATTERN = re.compile(r"ID\t((\d+)\.(\d+)\.(\d+)\.(\d+))") + +logger = logging.getLogger(__name__) +ec_pattern = re.compile(r"ID\t((\d+)\.(\d+)\.(\d+)\.(\d+))") + Session = sessionmaker() @@ -62,7 +64,7 @@ def worker(section): global session enzyme = parser.parse(section, session) if enzyme is None: - match = EC_PATTERN.match(section) + match = ec_pattern.match(section) return False, match.group(1) else: return True, enzyme @@ -129,9 +131,9 @@ def single_parse(sections): for section in tqdm(sections): enzyme = parser.parse(section, session) if enzyme is None: - match = EC_PATTERN.match(section) - LOGGER.error("Problem with enzyme '%s'.", match.group(1)) - LOGGER.debug("%s", section) + match = ec_pattern.match(section) + logger.error("Problem with enzyme '%s'.", match.group(1)) + logger.debug("%s", section) else: session.add(enzyme) session.commit() @@ -150,7 +152,7 @@ def multi_parse(sections, engine, processes=2): session.add(enzyme) session.commit() else: - LOGGER.error("Problem with enzyme '%s'.", enzyme) + logger.error("Problem with enzyme '%s'.", enzyme) pbar.update() pool.close() pool.join() diff --git a/src/brenda_parser/cli.py b/src/brenda_parser/cli.py index 360e41b..5adc3e9 100644 --- a/src/brenda_parser/cli.py +++ b/src/brenda_parser/cli.py @@ -30,7 +30,6 @@ import logging from multiprocessing import cpu_count -from warnings import warn import click import click_log @@ -39,13 +38,14 @@ from brenda_parser import __version__ -LOGGER = logging.getLogger(__name__.split(".", 1)[0]) -click_log.basic_config(LOGGER) +logger = logging.getLogger(__name__.split(".", 1)[0]) +click_log.basic_config(logger) + try: PROCESSES = cpu_count() except NotImplementedError: - warn("Could not detect the number of CPUs - assuming 1.", UserWarning) + logger.warning("Could not detect the number of CPUs - assuming 1.") PROCESSES = 1 @@ -53,7 +53,7 @@ @click.help_option("--help", "-h") @click.version_option(__version__, "--version", "-V") @click_log.simple_verbosity_option( - LOGGER, + logger, default="INFO", show_default=True, type=click.Choice(["CRITICAL", "ERROR", "WARN", "INFO", "DEBUG"]), diff --git a/src/brenda_parser/models/__init__.py b/src/brenda_parser/models/__init__.py index 1d97a4c..88942b8 100644 --- a/src/brenda_parser/models/__init__.py +++ b/src/brenda_parser/models/__init__.py @@ -26,12 +26,16 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """Provide data models for storing BRENDA EC-number information.""" + from sqlalchemy.ext.declarative import declarative_base + Base = declarative_base() + from brenda_parser.models.information_field import * from brenda_parser.models.accession import * from brenda_parser.models.organism import * diff --git a/src/brenda_parser/models/accession.py b/src/brenda_parser/models/accession.py index 9b66083..050b5a3 100644 --- a/src/brenda_parser/models/accession.py +++ b/src/brenda_parser/models/accession.py @@ -29,7 +29,6 @@ """Provide a data model for a protein database cross reference.""" -import logging import re from sqlalchemy import Column, Integer, String @@ -41,8 +40,6 @@ __all__ = ("Accession",) -LOGGER = logging.getLogger(__name__) - class Accession(Base): diff --git a/src/brenda_parser/models/comment.py b/src/brenda_parser/models/comment.py index 23927d3..e3335e2 100644 --- a/src/brenda_parser/models/comment.py +++ b/src/brenda_parser/models/comment.py @@ -29,8 +29,6 @@ """Provide a data model for a comment.""" -import logging - from sqlalchemy import Column, ForeignKey, Integer, String, Table from sqlalchemy.orm import relationship @@ -39,8 +37,6 @@ __all__ = ("Comment",) -LOGGER = logging.getLogger(__name__) - comment_protein_association = Table( "comment_protein_association", diff --git a/src/brenda_parser/models/enzyme.py b/src/brenda_parser/models/enzyme.py index 5b9f96d..0c518ce 100644 --- a/src/brenda_parser/models/enzyme.py +++ b/src/brenda_parser/models/enzyme.py @@ -29,8 +29,6 @@ """Provide a data model for an information field entry.""" -import logging - from sqlalchemy import Column, ForeignKey, Integer, String, Table from sqlalchemy.orm import relationship @@ -39,8 +37,6 @@ __all__ = ("Enzyme",) -LOGGER = logging.getLogger(__name__) - enzyme_entry_association = Table( "enzyme_entry_association", diff --git a/src/brenda_parser/models/field_entry.py b/src/brenda_parser/models/field_entry.py index 786ad66..45f137d 100644 --- a/src/brenda_parser/models/field_entry.py +++ b/src/brenda_parser/models/field_entry.py @@ -29,8 +29,6 @@ """Provide a data model for an information field entry.""" -import logging - from sqlalchemy import Column, ForeignKey, Integer, String, Table from sqlalchemy.orm import relationship @@ -39,8 +37,6 @@ __all__ = ("FieldEntry",) -LOGGER = logging.getLogger(__name__) - fieldentry_protein_association = Table( "fieldentry_protein_association", diff --git a/src/brenda_parser/models/information_field.py b/src/brenda_parser/models/information_field.py index e857b91..6baf3d4 100644 --- a/src/brenda_parser/models/information_field.py +++ b/src/brenda_parser/models/information_field.py @@ -45,7 +45,8 @@ __all__ = ("InformationField",) -LOGGER = logging.getLogger(__name__) + +logger = logging.getLogger(__name__) class InformationField(Base): @@ -83,7 +84,7 @@ def preload(cls, session): table = cls.__table__ try: session.execute(table.insert().values(rows)) - LOGGER.debug("Successfully loaded information fields.") + logger.debug("Successfully loaded information fields.") except IntegrityError: session.rollback() for row in rows: @@ -92,5 +93,5 @@ def preload(cls, session): session.query(InformationField).filter_by( acronym=row["acronym"] ).update(row) - LOGGER.debug("Updated field '%s'.", row["acronym"]) + logger.debug("Updated field '%s'.", row["acronym"]) session.commit() diff --git a/src/brenda_parser/models/organism.py b/src/brenda_parser/models/organism.py index ba94e00..3969367 100644 --- a/src/brenda_parser/models/organism.py +++ b/src/brenda_parser/models/organism.py @@ -29,8 +29,6 @@ """Provide a data model for an organism.""" -import logging - from sqlalchemy import Column, Integer, String from brenda_parser.models import Base @@ -38,8 +36,6 @@ __all__ = ("Organism",) -LOGGER = logging.getLogger(__name__) - class Organism(Base): diff --git a/src/brenda_parser/models/protein.py b/src/brenda_parser/models/protein.py index ab243fd..6667bfc 100644 --- a/src/brenda_parser/models/protein.py +++ b/src/brenda_parser/models/protein.py @@ -29,8 +29,6 @@ """Provide a data model for a protein.""" -import logging - from sqlalchemy import Column, ForeignKey, Integer, Table from sqlalchemy.orm import relationship, validates @@ -40,8 +38,6 @@ __all__ = ("Protein",) -LOGGER = logging.getLogger(__name__) - protein_citation_association = Table( "protein_citation_association", diff --git a/src/brenda_parser/models/reference.py b/src/brenda_parser/models/reference.py index 3996779..3746c61 100644 --- a/src/brenda_parser/models/reference.py +++ b/src/brenda_parser/models/reference.py @@ -29,7 +29,6 @@ """Provide a data model for a reference.""" -import logging import re from sqlalchemy import Column, ForeignKey, Integer, String @@ -41,8 +40,6 @@ __all__ = ("Reference",) -LOGGER = logging.getLogger(__name__) - class Reference(Base): @@ -55,15 +52,15 @@ class Reference(Base): # The `body` might have to be Text. body = Column(String(255), nullable=False) - PUBMED_PATTERN = re.compile(r"^Pubmed:\d{7}$") + pubmed_pattern = re.compile(r"^Pubmed:\d{7}$") @validates("pubmed") def validate_pubmed(self, key, value): if value is None: return value - if self.PUBMED_PATTERN.match(value) is None: + if self.pubmed_pattern.match(value) is None: raise ValidationError( "'{}' does not match the required pattern '{}'." - "".format(value, self.PUBMED_PATTERN) + "".format(value, self.pubmed_pattern) ) return value diff --git a/src/brenda_parser/parsing/lexer.py b/src/brenda_parser/parsing/lexer.py index 02acde9..8ee6000 100644 --- a/src/brenda_parser/parsing/lexer.py +++ b/src/brenda_parser/parsing/lexer.py @@ -35,7 +35,8 @@ __all__ = ("BRENDALexer",) -LOGGER = logging.getLogger(__name__) + +logger = logging.getLogger(__name__) class BRENDALexer(object): @@ -101,7 +102,7 @@ def __init__(self, **kwargs): Keyword arguments are passed to the ply.lex.lex call. """ super(BRENDALexer, self).__init__() - self.lexer = lex(module=self, errorlog=LOGGER, **kwargs) + self.lexer = lex(module=self, errorlog=logger, **kwargs) self.parens_level = 0 self.last_lparens = 0 self.last_rparens = 0 @@ -128,17 +129,17 @@ def input(self, data): self.lexer.input(data) def t_ANY_error(self, t): - LOGGER.error("Invalid token '%s' at line %d.", t.value[0], t.lineno) + logger.error("Invalid token '%s' at line %d.", t.value[0], t.lineno) t.lexer.skip(1) def t_ANY_newline(self, t): r"\n+" - LOGGER.debug("lineno %d +%d", t.lineno, len(t.value)) + logger.debug("lineno %d +%d", t.lineno, len(t.value)) t.lexer.lineno += len(t.value) def t_brenda_comment(self, t): r"\*.+\n" - LOGGER.debug("lineno %d: Skipping comment line.", t.lineno) + logger.debug("lineno %d: Skipping comment line.", t.lineno) t.lexer.lineno += 1 def t_POUND(self, t): @@ -260,7 +261,7 @@ def t_ENTRY(self, t): def t_brenda_header(self, t): r"[A-Z0-9_]{4,}\n" - LOGGER.debug( + logger.debug( "lineno %d: Section header '%s'.", t.lineno, t.value.strip() ) t.lexer.lineno += 1 diff --git a/src/brenda_parser/parsing/parser.py b/src/brenda_parser/parsing/parser.py index 60ea40c..6dd7414 100644 --- a/src/brenda_parser/parsing/parser.py +++ b/src/brenda_parser/parsing/parser.py @@ -40,7 +40,8 @@ __all__ = ("BRENDAParser",) -LOGGER = logging.getLogger(__name__) + +logger = logging.getLogger(__name__) class BRENDAParser(object): @@ -106,7 +107,7 @@ def __init__(self, lexer=None, **kwargs): super(BRENDAParser, self).__init__() self._lexer = BRENDALexer() if lexer is None else lexer self.tokens = self._lexer.tokens - self.parser = yacc(module=self, errorlog=LOGGER, **kwargs) + self.parser = yacc(module=self, errorlog=logger, **kwargs) self._session = None self.proteins = dict() self.citations = dict() @@ -141,7 +142,7 @@ def p_enzyme(self, p): def p_new_enzyme(self, p): """new_enzyme :""" - LOGGER.debug("%s %s", self.p_new_enzyme.__doc__, p[-1]) + logger.debug("%s %s", self.p_new_enzyme.__doc__, p[-1]) assert p[-2] == "ID" p[0] = models.Enzyme(ec_number=p[-1]) @@ -375,7 +376,7 @@ def p_comment_end(self, p): # p[0] = [models.Comment(body=c) for c in p[1].split(";")] def p_error(self, p): - LOGGER.debug("Error: %s", str(p)) + logger.debug("Error: %s", str(p)) # TODO: If `p` is None (we allow some empty rules) it's only an error # if any parentheses or similar are unbalanced. if False: From 9bb016e3d6f93728ad7408cb1eb1544b36cd1510 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sun, 2 Dec 2018 14:56:08 +0100 Subject: [PATCH 14/15] refactor: drop Python 3.5 and use fstrings --- setup.cfg | 4 +--- src/brenda_parser/cli.py | 2 +- src/brenda_parser/data/__init__.py | 1 + src/brenda_parser/models/accession.py | 8 ++++---- src/brenda_parser/models/information_field.py | 8 ++++---- src/brenda_parser/models/reference.py | 4 ++-- src/brenda_parser/parsing/parser.py | 12 ++++++------ tox.ini | 8 +++----- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/setup.cfg b/setup.cfg index 6b0d111..65b0fc2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,8 +10,6 @@ classifiers = Topic :: Scientific/Engineering :: Bio-Informatics License :: OSI Approved :: BSD License Natural Language :: English - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 license = BSD 3-Clause License @@ -34,7 +32,7 @@ install_requires = tqdm tests_require = tox -python_requires = >=3.5.* +python_requires = >=3.6.* package_dir = = src packages = find: diff --git a/src/brenda_parser/cli.py b/src/brenda_parser/cli.py index 5adc3e9..012663a 100644 --- a/src/brenda_parser/cli.py +++ b/src/brenda_parser/cli.py @@ -92,7 +92,7 @@ def cli(): ) def parse(flat_file, filename, connection, processes): if connection is None: - connection = "sqlite:///{}".format(filename) + connection = f"sqlite:///{filename}" with open(flat_file) as file_handle: lines = file_handle.readlines() api.parse(lines, connection, processes=processes) diff --git a/src/brenda_parser/data/__init__.py b/src/brenda_parser/data/__init__.py index d49ac50..5f9651f 100644 --- a/src/brenda_parser/data/__init__.py +++ b/src/brenda_parser/data/__init__.py @@ -26,4 +26,5 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """Provide data resources.""" diff --git a/src/brenda_parser/models/accession.py b/src/brenda_parser/models/accession.py index 050b5a3..1393137 100644 --- a/src/brenda_parser/models/accession.py +++ b/src/brenda_parser/models/accession.py @@ -46,7 +46,7 @@ class Accession(Base): __tablename__ = "accession" # http://identifiers.org/uniprot/ - UNIPROT_PATTERN = re.compile( + uniprot_pattern = re.compile( r"([A-NR-Z][0-9]([A-Z][A-Z0-9][A-Z0-9][0-9]){1,2})|" r"([OPQ][0-9][A-Z0-9][A-Z0-9][A-Z0-9][0-9])(\.\d+)?" ) @@ -60,9 +60,9 @@ class Accession(Base): def validate_accession(self, key, value): if value is None: return value - if self.UNIPROT_PATTERN.match(value) is None: + if self.uniprot_pattern.match(value) is None: raise ValidationError( - "'{}' does not match the required pattern '{}'." - "".format(value, self.UNIPROT_PATTERN) + f"'{value}' does not match the required pattern " + f"'{self.uniprot_pattern}'." ) return value diff --git a/src/brenda_parser/models/information_field.py b/src/brenda_parser/models/information_field.py index 6baf3d4..a1f2de3 100644 --- a/src/brenda_parser/models/information_field.py +++ b/src/brenda_parser/models/information_field.py @@ -57,14 +57,14 @@ class InformationField(Base): acronym = Column(String(4), nullable=False, unique=True, index=True) name = Column(String(100), nullable=True) - ACRONYM_PATTERN = re.compile(r"^[A-Z0-9]{2,4}$") + acronym_pattern = re.compile(r"^[A-Z0-9]{2,4}$") @validates("acronym") def validate_acronym(self, key, value): - if self.ACRONYM_PATTERN.match(value) is None: + if self.acronym_pattern.match(value) is None: raise ValidationError( - "'{}' does not match the required pattern '{}'." - "".format(value, self.ACRONYM_PATTERN) + f"'{value}' does not match the required pattern " + f"'{self.acronym_pattern}'." ) return value diff --git a/src/brenda_parser/models/reference.py b/src/brenda_parser/models/reference.py index 3746c61..c491d38 100644 --- a/src/brenda_parser/models/reference.py +++ b/src/brenda_parser/models/reference.py @@ -60,7 +60,7 @@ def validate_pubmed(self, key, value): return value if self.pubmed_pattern.match(value) is None: raise ValidationError( - "'{}' does not match the required pattern '{}'." - "".format(value, self.pubmed_pattern) + f"'{value}' does not match the required pattern " + f"'{self.pubmed_pattern}'." ) return value diff --git a/src/brenda_parser/parsing/parser.py b/src/brenda_parser/parsing/parser.py index 6dd7414..4714989 100644 --- a/src/brenda_parser/parsing/parser.py +++ b/src/brenda_parser/parsing/parser.py @@ -190,7 +190,7 @@ def p_new_entry(self, p): def p_entry_content(self, p): """entry : entry CONTENT""" assert len(p[2]) > 0 - p[1].body += " {}".format(p[2]) + p[1].body = f"{p[1].body} {p[2]}" p[0] = p[1] def p_entry_proteins(self, p): @@ -236,13 +236,13 @@ def p_new_reference(self, p): def p_reference_content(self, p): """reference_entry : reference_entry CONTENT""" assert len(p[2]) > 0 - p[1].body += " {}".format(p[2]) + p[1].body = f"{p[1].body} {p[2]}" p[0] = p[1] def p_reference_year(self, p): """reference_entry : reference_entry comment %prec ASSEMBLE""" if p[2] is not None: - p[1].body += " ({})".format(p[2].body) + p[1].body = f"{p[1].body} ({p[2].body})" p[0] = p[1] def p_reference_pubmed(self, p): @@ -295,7 +295,7 @@ def p_protein_citations(self, p): def p_accession_combine(self, p): """accession : accession AND ACCESSION %prec COMBINE""" - p[1].accession = "{} & {}".format(p[1].accession, p[3]) + p[1].accession = f"{p[1].accession} & {p[3]}" p[0] = p[1] def p_accession_database(self, p): @@ -317,7 +317,7 @@ def p_special_empty(self, p): def p_special_combine(self, p): """special : special SPECIAL %prec COMBINE""" - p[0] = "{0} {1}".format(p[1], p[2]) + p[0] = f"{p[1]} {p[2]}" def p_special_end(self, p): """special : SPECIAL %prec REDUCE""" @@ -367,7 +367,7 @@ def p_comment_empty(self, p): def p_comment_combine(self, p): """comment : comment COMMENT %prec COMBINE""" - p[1].body = "{0} {1}".format(p[1].body, p[2]) + p[1].body = f"{p[1].body} {p[2]}" p[0] = p[1] def p_comment_end(self, p): diff --git a/tox.ini b/tox.ini index 64ebdb1..8d2d6f3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,11 @@ [tox] -envlist = isort, black, flake8, docs, py{35,36,37} +envlist = isort, black, flake8, docs, py{36,37} [travis] os = - linux: isort, black, flake8, docs, py{35,36,37} - osx: py{27,35} + linux: isort, black, flake8, docs, py{36,37} python = - 3.5: isort, black, flake8, docs, py35 - 3.6: py36 + 3.6: isort, black, flake8, docs, py36 3.7: py37 [testenv] From 95e9b3c97008b92b84908724f804d0f0b5304d0b Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Sun, 2 Dec 2018 18:13:11 +0100 Subject: [PATCH 15/15] wip --- .gitignore | 4 + src/brenda_parser/api.py | 2 +- src/brenda_parser/parsing/lexer.py | 11 +- src/brenda_parser/parsing/lextab.py | 166 --- src/brenda_parser/parsing/parser.out | 1224 -------------------- src/brenda_parser/parsing/parser.py | 290 +++-- src/brenda_parser/parsing/parsetab.py | 1529 ------------------------- 7 files changed, 187 insertions(+), 3039 deletions(-) delete mode 100644 src/brenda_parser/parsing/lextab.py delete mode 100644 src/brenda_parser/parsing/parser.out delete mode 100644 src/brenda_parser/parsing/parsetab.py diff --git a/.gitignore b/.gitignore index 5647b9a..3d8de36 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,7 @@ venv.bak/ # mypy .mypy_cache/ +# Project settings +src/brenda_parser/parsing/lextab.py +src/brenda_parser/parsing/parser.out +src/brenda_parser/parsing/parsetab.py diff --git a/src/brenda_parser/api.py b/src/brenda_parser/api.py index 23fc5a6..a9b4d74 100644 --- a/src/brenda_parser/api.py +++ b/src/brenda_parser/api.py @@ -105,7 +105,7 @@ def parse(lines, connection="sqlite:///:memory:", processes=1): start = i continue if lines[i].startswith("///"): - sections.append("".join(lines[start : i + 1])) + sections.append("\n".join(lines[start : i + 1])) processes = min(processes, len(sections)) if processes > 1: multi_parse(sections, engine, processes=processes) diff --git a/src/brenda_parser/parsing/lexer.py b/src/brenda_parser/parsing/lexer.py index 8ee6000..4534521 100644 --- a/src/brenda_parser/parsing/lexer.py +++ b/src/brenda_parser/parsing/lexer.py @@ -39,7 +39,7 @@ logger = logging.getLogger(__name__) -class BRENDALexer(object): +class BRENDALexer: """ We use functions for most tokens in order to fully control pattern @@ -76,6 +76,7 @@ class BRENDALexer(object): "COMMENT", "AND", "ACCESSION", + "HEADER", ) # A string containing ignored characters interpreted literally not as regex. @@ -213,8 +214,9 @@ def t_comment_RPARENS(self, t): t.type = "COMMENT" return t - def t_END(self, t): - r"[/]{3}\s" + def t_ANY_END(self, t): + r"[/]{3}\n" + t.lexer.lineno += 1 t.lexer.push_state("INITIAL") t.value = t.value.strip() return t @@ -259,12 +261,13 @@ def t_ENTRY(self, t): t.value = t.value.strip() return t - def t_brenda_header(self, t): + def t_HEADER(self, t): r"[A-Z0-9_]{4,}\n" logger.debug( "lineno %d: Section header '%s'.", t.lineno, t.value.strip() ) t.lexer.lineno += 1 + return t def t_protentry_AND(self, t): r"AND" diff --git a/src/brenda_parser/parsing/lextab.py b/src/brenda_parser/parsing/lextab.py deleted file mode 100644 index ca27fa4..0000000 --- a/src/brenda_parser/parsing/lextab.py +++ /dev/null @@ -1,166 +0,0 @@ -# lextab.py. This file automatically created by PLY (version 3.11). Don't edit! -_tabversion = "3.10" -_lextokens = set( - ( - "ACCESSION", - "AND", - "CITATION", - "COMMENT", - "CONTENT", - "EC_NUMBER", - "END", - "ENTRY", - "ENZYME_ENTRY", - "LANGLE", - "LCURLY", - "LPARENS", - "POUND", - "PROTEIN", - "PROTEIN_ENTRY", - "RANGLE", - "RCURLY", - "REFERENCE_ENTRY", - "RPARENS", - "SPECIAL", - ) -) -_lexreflags = 64 -_lexliterals = "" -_lexstateinfo = { - "INITIAL": "inclusive", - "citation": "exclusive", - "protein": "exclusive", - "special": "exclusive", - "comment": "exclusive", - "enzyme": "exclusive", - "protentry": "inclusive", -} -_lexstatere = { - "INITIAL": [ - ( - "(?P\\n+)|(?P\\*.+\\n)|(?P[#])|(?P<)|(?P{)|(?P\\()|(?P[/]{3}\\s)|(?PID\\t)|(?PPR\\t)|(?PRF\\t)|(?P[A-Z0-9]{2,4}\\t)|(?P[A-Z0-9_]{4,}\\n)|(?P[^\\{\\}\\(\\)\\<\\>\\# \t\r\x0c\x0b\n]+)", - [ - None, - ("t_ANY_newline", "newline"), - ("t_brenda_comment", "brenda_comment"), - ("t_POUND", "POUND"), - ("t_LANGLE", "LANGLE"), - ("t_LCURLY", "LCURLY"), - ("t_LPARENS", "LPARENS"), - ("t_END", "END"), - ("t_ENZYME_ENTRY", "ENZYME_ENTRY"), - ("t_PROTEIN_ENTRY", "PROTEIN_ENTRY"), - ("t_REFERENCE_ENTRY", "REFERENCE_ENTRY"), - ("t_ENTRY", "ENTRY"), - ("t_brenda_header", "brenda_header"), - (None, "CONTENT"), - ], - ) - ], - "citation": [ - ( - "(?P\\n+)|(?P\\d+)|(?P>)", - [ - None, - ("t_ANY_newline", "newline"), - ("t_citation_CITATION", "CITATION"), - ("t_citation_RANGLE", "RANGLE"), - ], - ) - ], - "protein": [ - ( - "(?P\\n+)|(?P\\d+)|(?P[#])", - [ - None, - ("t_ANY_newline", "newline"), - ("t_protein_PROTEIN", "PROTEIN"), - ("t_protein_POUND", "POUND"), - ], - ) - ], - "special": [ - ( - "(?P\\n+)|(?P[^\\{\\}\\s]+)|(?P})", - [ - None, - ("t_ANY_newline", "newline"), - ("t_special_SPECIAL", "SPECIAL"), - ("t_special_RCURLY", "RCURLY"), - ], - ) - ], - "comment": [ - ( - "(?P\\n+)|(?P[^\\(\\)\\s]+)|(?P\\()|(?P\\))", - [ - None, - ("t_ANY_newline", "newline"), - ("t_comment_COMMENT", "COMMENT"), - ("t_comment_LPARENS", "LPARENS"), - ("t_comment_RPARENS", "RPARENS"), - ], - ) - ], - "enzyme": [ - ( - "(?P\\n+)|(?P(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+))", - [ - None, - ("t_ANY_newline", "newline"), - ("t_enzyme_EC_NUMBER", "EC_NUMBER"), - ], - ) - ], - "protentry": [ - ( - "(?P\\n+)|(?PPR\\t)|(?P[A-Z0-9]{2,4}\\t)|(?PAND)|(?P([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?)", - [ - None, - ("t_ANY_newline", "newline"), - ("t_protentry_PROTEIN_ENTRY", "PROTEIN_ENTRY"), - ("t_protentry_ENTRY", "ENTRY"), - ("t_protentry_AND", "AND"), - ("t_protentry_ACCESSION", "ACCESSION"), - ], - ), - ( - "(?P\\n+)|(?P\\*.+\\n)|(?P[#])|(?P<)|(?P{)|(?P\\()|(?P[/]{3}\\s)|(?PID\\t)|(?PPR\\t)|(?PRF\\t)|(?P[A-Z0-9]{2,4}\\t)|(?P[A-Z0-9_]{4,}\\n)|(?P[^\\{\\}\\(\\)\\<\\>\\# \t\r\x0c\x0b\n]+)", - [ - None, - ("t_ANY_newline", "newline"), - ("t_brenda_comment", "brenda_comment"), - ("t_POUND", "POUND"), - ("t_LANGLE", "LANGLE"), - ("t_LCURLY", "LCURLY"), - ("t_LPARENS", "LPARENS"), - ("t_END", "END"), - ("t_ENZYME_ENTRY", "ENZYME_ENTRY"), - ("t_PROTEIN_ENTRY", "PROTEIN_ENTRY"), - ("t_REFERENCE_ENTRY", "REFERENCE_ENTRY"), - ("t_ENTRY", "ENTRY"), - ("t_brenda_header", "brenda_header"), - (None, "CONTENT"), - ], - ), - ], -} -_lexstateignore = { - "citation": " ,\t", - "protein": " ,\t", - "INITIAL": " \t\r\x0c\x0b", - "special": " \t\r\x0c\x0b", - "comment": " \t\r\x0c\x0b", - "enzyme": " \t\r\x0c\x0b", - "protentry": " \t\r\x0c\x0b", -} -_lexstateerrorf = { - "INITIAL": "t_ANY_error", - "citation": "t_ANY_error", - "protein": "t_ANY_error", - "special": "t_ANY_error", - "comment": "t_ANY_error", - "enzyme": "t_ANY_error", - "protentry": "t_ANY_error", -} -_lexstateeoff = {} diff --git a/src/brenda_parser/parsing/parser.out b/src/brenda_parser/parsing/parser.out deleted file mode 100644 index fbfcf91..0000000 --- a/src/brenda_parser/parsing/parser.out +++ /dev/null @@ -1,1224 +0,0 @@ -Created by PLY version 3.11 (http://www.dabeaz.com/ply) - -Grammar - -Rule 0 S' -> enzyme -Rule 1 enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme -Rule 2 new_enzyme -> -Rule 3 enzyme -> enzyme comment -Rule 4 enzyme -> enzyme protein_entry -Rule 5 enzyme -> enzyme reference_entry -Rule 6 enzyme -> enzyme entry -Rule 7 enzyme -> enzyme END -Rule 8 entry -> ENTRY new_entry -Rule 9 new_entry -> -Rule 10 entry -> entry CONTENT -Rule 11 entry -> entry proteins -Rule 12 entry -> entry comment -Rule 13 entry -> entry special -Rule 14 entry -> entry citations -Rule 15 reference_entry -> REFERENCE_ENTRY new_reference citations -Rule 16 new_reference -> -Rule 17 reference_entry -> reference_entry CONTENT -Rule 18 reference_entry -> reference_entry comment -Rule 19 reference_entry -> reference_entry special -Rule 20 protein_entry -> PROTEIN_ENTRY new_protein proteins -Rule 21 new_protein -> -Rule 22 protein_entry -> protein_entry CONTENT -Rule 23 protein_entry -> protein_entry accession -Rule 24 protein_entry -> protein_entry comment -Rule 25 protein_entry -> protein_entry citations -Rule 26 accession -> accession AND ACCESSION -Rule 27 accession -> accession CONTENT -Rule 28 accession -> ACCESSION -Rule 29 special -> LCURLY special RCURLY -Rule 30 special -> LCURLY RCURLY -Rule 31 special -> special SPECIAL -Rule 32 special -> SPECIAL -Rule 33 proteins -> POUND proteins POUND -Rule 34 proteins -> POUND POUND -Rule 35 proteins -> proteins PROTEIN -Rule 36 proteins -> PROTEIN -Rule 37 citations -> LANGLE citations RANGLE -Rule 38 citations -> LANGLE RANGLE -Rule 39 citations -> citations CITATION -Rule 40 citations -> CITATION -Rule 41 comment -> LPARENS comment RPARENS -Rule 42 comment -> LPARENS RPARENS -Rule 43 comment -> comment COMMENT -Rule 44 comment -> COMMENT - -Terminals, with rules where they appear - -ACCESSION : 26 28 -AND : 26 -CITATION : 39 40 -COMMENT : 43 44 -CONTENT : 10 17 22 27 -EC_NUMBER : 1 -END : 7 -ENTRY : 8 -ENZYME_ENTRY : 1 -LANGLE : 37 38 -LCURLY : 29 30 -LPARENS : 41 42 -POUND : 33 33 34 34 -PROTEIN : 35 36 -PROTEIN_ENTRY : 20 -RANGLE : 37 38 -RCURLY : 29 30 -REFERENCE_ENTRY : 15 -RPARENS : 41 42 -SPECIAL : 31 32 -error : - -Nonterminals, with rules where they appear - -accession : 23 26 27 -citations : 14 15 25 37 39 -comment : 3 12 18 24 41 43 -entry : 6 10 11 12 13 14 -enzyme : 3 4 5 6 7 0 -new_entry : 8 -new_enzyme : 1 -new_protein : 20 -new_reference : 15 -protein_entry : 4 22 23 24 25 -proteins : 11 20 33 35 -reference_entry : 5 17 18 19 -special : 13 19 29 31 - -Parsing method: LALR - -state 0 - - (0) S' -> . enzyme - (1) enzyme -> . ENZYME_ENTRY EC_NUMBER new_enzyme - (3) enzyme -> . enzyme comment - (4) enzyme -> . enzyme protein_entry - (5) enzyme -> . enzyme reference_entry - (6) enzyme -> . enzyme entry - (7) enzyme -> . enzyme END - - ENZYME_ENTRY shift and go to state 2 - - enzyme shift and go to state 1 - -state 1 - - (0) S' -> enzyme . - (3) enzyme -> enzyme . comment - (4) enzyme -> enzyme . protein_entry - (5) enzyme -> enzyme . reference_entry - (6) enzyme -> enzyme . entry - (7) enzyme -> enzyme . END - (41) comment -> . LPARENS comment RPARENS - (42) comment -> . LPARENS RPARENS - (43) comment -> . comment COMMENT - (44) comment -> . COMMENT - (20) protein_entry -> . PROTEIN_ENTRY new_protein proteins - (22) protein_entry -> . protein_entry CONTENT - (23) protein_entry -> . protein_entry accession - (24) protein_entry -> . protein_entry comment - (25) protein_entry -> . protein_entry citations - (15) reference_entry -> . REFERENCE_ENTRY new_reference citations - (17) reference_entry -> . reference_entry CONTENT - (18) reference_entry -> . reference_entry comment - (19) reference_entry -> . reference_entry special - (8) entry -> . ENTRY new_entry - (10) entry -> . entry CONTENT - (11) entry -> . entry proteins - (12) entry -> . entry comment - (13) entry -> . entry special - (14) entry -> . entry citations - - END shift and go to state 7 - LPARENS shift and go to state 8 - COMMENT shift and go to state 9 - PROTEIN_ENTRY shift and go to state 10 - REFERENCE_ENTRY shift and go to state 11 - ENTRY shift and go to state 12 - - comment shift and go to state 3 - protein_entry shift and go to state 4 - reference_entry shift and go to state 5 - entry shift and go to state 6 - -state 2 - - (1) enzyme -> ENZYME_ENTRY . EC_NUMBER new_enzyme - - EC_NUMBER shift and go to state 13 - - -state 3 - - (3) enzyme -> enzyme comment . - (43) comment -> comment . COMMENT - - ! shift/reduce conflict for COMMENT resolved as shift - END reduce using rule 3 (enzyme -> enzyme comment .) - LPARENS reduce using rule 3 (enzyme -> enzyme comment .) - PROTEIN_ENTRY reduce using rule 3 (enzyme -> enzyme comment .) - REFERENCE_ENTRY reduce using rule 3 (enzyme -> enzyme comment .) - ENTRY reduce using rule 3 (enzyme -> enzyme comment .) - $end reduce using rule 3 (enzyme -> enzyme comment .) - COMMENT shift and go to state 14 - - ! COMMENT [ reduce using rule 3 (enzyme -> enzyme comment .) ] - - -state 4 - - (4) enzyme -> enzyme protein_entry . - (22) protein_entry -> protein_entry . CONTENT - (23) protein_entry -> protein_entry . accession - (24) protein_entry -> protein_entry . comment - (25) protein_entry -> protein_entry . citations - (26) accession -> . accession AND ACCESSION - (27) accession -> . accession CONTENT - (28) accession -> . ACCESSION - (41) comment -> . LPARENS comment RPARENS - (42) comment -> . LPARENS RPARENS - (43) comment -> . comment COMMENT - (44) comment -> . COMMENT - (37) citations -> . LANGLE citations RANGLE - (38) citations -> . LANGLE RANGLE - (39) citations -> . citations CITATION - (40) citations -> . CITATION - - ! shift/reduce conflict for LPARENS resolved as shift - ! shift/reduce conflict for COMMENT resolved as shift - END reduce using rule 4 (enzyme -> enzyme protein_entry .) - PROTEIN_ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) - REFERENCE_ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) - ENTRY reduce using rule 4 (enzyme -> enzyme protein_entry .) - $end reduce using rule 4 (enzyme -> enzyme protein_entry .) - CONTENT shift and go to state 15 - ACCESSION shift and go to state 19 - LPARENS shift and go to state 8 - COMMENT shift and go to state 9 - LANGLE shift and go to state 20 - CITATION shift and go to state 21 - - ! LPARENS [ reduce using rule 4 (enzyme -> enzyme protein_entry .) ] - ! COMMENT [ reduce using rule 4 (enzyme -> enzyme protein_entry .) ] - - accession shift and go to state 16 - comment shift and go to state 17 - citations shift and go to state 18 - -state 5 - - (5) enzyme -> enzyme reference_entry . - (17) reference_entry -> reference_entry . CONTENT - (18) reference_entry -> reference_entry . comment - (19) reference_entry -> reference_entry . special - (41) comment -> . LPARENS comment RPARENS - (42) comment -> . LPARENS RPARENS - (43) comment -> . comment COMMENT - (44) comment -> . COMMENT - (29) special -> . LCURLY special RCURLY - (30) special -> . LCURLY RCURLY - (31) special -> . special SPECIAL - (32) special -> . SPECIAL - - ! shift/reduce conflict for LPARENS resolved as shift - ! shift/reduce conflict for COMMENT resolved as shift - END reduce using rule 5 (enzyme -> enzyme reference_entry .) - PROTEIN_ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) - REFERENCE_ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) - ENTRY reduce using rule 5 (enzyme -> enzyme reference_entry .) - $end reduce using rule 5 (enzyme -> enzyme reference_entry .) - CONTENT shift and go to state 22 - LPARENS shift and go to state 8 - COMMENT shift and go to state 9 - LCURLY shift and go to state 25 - SPECIAL shift and go to state 26 - - ! LPARENS [ reduce using rule 5 (enzyme -> enzyme reference_entry .) ] - ! COMMENT [ reduce using rule 5 (enzyme -> enzyme reference_entry .) ] - - comment shift and go to state 23 - special shift and go to state 24 - -state 6 - - (6) enzyme -> enzyme entry . - (10) entry -> entry . CONTENT - (11) entry -> entry . proteins - (12) entry -> entry . comment - (13) entry -> entry . special - (14) entry -> entry . citations - (33) proteins -> . POUND proteins POUND - (34) proteins -> . POUND POUND - (35) proteins -> . proteins PROTEIN - (36) proteins -> . PROTEIN - (41) comment -> . LPARENS comment RPARENS - (42) comment -> . LPARENS RPARENS - (43) comment -> . comment COMMENT - (44) comment -> . COMMENT - (29) special -> . LCURLY special RCURLY - (30) special -> . LCURLY RCURLY - (31) special -> . special SPECIAL - (32) special -> . SPECIAL - (37) citations -> . LANGLE citations RANGLE - (38) citations -> . LANGLE RANGLE - (39) citations -> . citations CITATION - (40) citations -> . CITATION - - ! shift/reduce conflict for LPARENS resolved as shift - ! shift/reduce conflict for COMMENT resolved as shift - END reduce using rule 6 (enzyme -> enzyme entry .) - PROTEIN_ENTRY reduce using rule 6 (enzyme -> enzyme entry .) - REFERENCE_ENTRY reduce using rule 6 (enzyme -> enzyme entry .) - ENTRY reduce using rule 6 (enzyme -> enzyme entry .) - $end reduce using rule 6 (enzyme -> enzyme entry .) - CONTENT shift and go to state 27 - POUND shift and go to state 32 - PROTEIN shift and go to state 33 - LPARENS shift and go to state 8 - COMMENT shift and go to state 9 - LCURLY shift and go to state 25 - SPECIAL shift and go to state 26 - LANGLE shift and go to state 20 - CITATION shift and go to state 21 - - ! LPARENS [ reduce using rule 6 (enzyme -> enzyme entry .) ] - ! COMMENT [ reduce using rule 6 (enzyme -> enzyme entry .) ] - - proteins shift and go to state 28 - comment shift and go to state 29 - special shift and go to state 30 - citations shift and go to state 31 - -state 7 - - (7) enzyme -> enzyme END . - - END reduce using rule 7 (enzyme -> enzyme END .) - LPARENS reduce using rule 7 (enzyme -> enzyme END .) - COMMENT reduce using rule 7 (enzyme -> enzyme END .) - PROTEIN_ENTRY reduce using rule 7 (enzyme -> enzyme END .) - REFERENCE_ENTRY reduce using rule 7 (enzyme -> enzyme END .) - ENTRY reduce using rule 7 (enzyme -> enzyme END .) - $end reduce using rule 7 (enzyme -> enzyme END .) - - -state 8 - - (41) comment -> LPARENS . comment RPARENS - (42) comment -> LPARENS . RPARENS - (41) comment -> . LPARENS comment RPARENS - (42) comment -> . LPARENS RPARENS - (43) comment -> . comment COMMENT - (44) comment -> . COMMENT - - RPARENS shift and go to state 35 - LPARENS shift and go to state 8 - COMMENT shift and go to state 9 - - comment shift and go to state 34 - -state 9 - - (44) comment -> COMMENT . - - COMMENT reduce using rule 44 (comment -> COMMENT .) - END reduce using rule 44 (comment -> COMMENT .) - LPARENS reduce using rule 44 (comment -> COMMENT .) - PROTEIN_ENTRY reduce using rule 44 (comment -> COMMENT .) - REFERENCE_ENTRY reduce using rule 44 (comment -> COMMENT .) - ENTRY reduce using rule 44 (comment -> COMMENT .) - $end reduce using rule 44 (comment -> COMMENT .) - CONTENT reduce using rule 44 (comment -> COMMENT .) - ACCESSION reduce using rule 44 (comment -> COMMENT .) - LANGLE reduce using rule 44 (comment -> COMMENT .) - CITATION reduce using rule 44 (comment -> COMMENT .) - LCURLY reduce using rule 44 (comment -> COMMENT .) - SPECIAL reduce using rule 44 (comment -> COMMENT .) - POUND reduce using rule 44 (comment -> COMMENT .) - PROTEIN reduce using rule 44 (comment -> COMMENT .) - RPARENS reduce using rule 44 (comment -> COMMENT .) - - -state 10 - - (20) protein_entry -> PROTEIN_ENTRY . new_protein proteins - (21) new_protein -> . - - POUND reduce using rule 21 (new_protein -> .) - PROTEIN reduce using rule 21 (new_protein -> .) - - new_protein shift and go to state 36 - -state 11 - - (15) reference_entry -> REFERENCE_ENTRY . new_reference citations - (16) new_reference -> . - - LANGLE reduce using rule 16 (new_reference -> .) - CITATION reduce using rule 16 (new_reference -> .) - - new_reference shift and go to state 37 - -state 12 - - (8) entry -> ENTRY . new_entry - (9) new_entry -> . - - CONTENT reduce using rule 9 (new_entry -> .) - POUND reduce using rule 9 (new_entry -> .) - PROTEIN reduce using rule 9 (new_entry -> .) - LPARENS reduce using rule 9 (new_entry -> .) - COMMENT reduce using rule 9 (new_entry -> .) - LCURLY reduce using rule 9 (new_entry -> .) - SPECIAL reduce using rule 9 (new_entry -> .) - LANGLE reduce using rule 9 (new_entry -> .) - CITATION reduce using rule 9 (new_entry -> .) - END reduce using rule 9 (new_entry -> .) - PROTEIN_ENTRY reduce using rule 9 (new_entry -> .) - REFERENCE_ENTRY reduce using rule 9 (new_entry -> .) - ENTRY reduce using rule 9 (new_entry -> .) - $end reduce using rule 9 (new_entry -> .) - - new_entry shift and go to state 38 - -state 13 - - (1) enzyme -> ENZYME_ENTRY EC_NUMBER . new_enzyme - (2) new_enzyme -> . - - END reduce using rule 2 (new_enzyme -> .) - LPARENS reduce using rule 2 (new_enzyme -> .) - COMMENT reduce using rule 2 (new_enzyme -> .) - PROTEIN_ENTRY reduce using rule 2 (new_enzyme -> .) - REFERENCE_ENTRY reduce using rule 2 (new_enzyme -> .) - ENTRY reduce using rule 2 (new_enzyme -> .) - $end reduce using rule 2 (new_enzyme -> .) - - new_enzyme shift and go to state 39 - -state 14 - - (43) comment -> comment COMMENT . - - COMMENT reduce using rule 43 (comment -> comment COMMENT .) - END reduce using rule 43 (comment -> comment COMMENT .) - LPARENS reduce using rule 43 (comment -> comment COMMENT .) - PROTEIN_ENTRY reduce using rule 43 (comment -> comment COMMENT .) - REFERENCE_ENTRY reduce using rule 43 (comment -> comment COMMENT .) - ENTRY reduce using rule 43 (comment -> comment COMMENT .) - $end reduce using rule 43 (comment -> comment COMMENT .) - CONTENT reduce using rule 43 (comment -> comment COMMENT .) - ACCESSION reduce using rule 43 (comment -> comment COMMENT .) - LANGLE reduce using rule 43 (comment -> comment COMMENT .) - CITATION reduce using rule 43 (comment -> comment COMMENT .) - LCURLY reduce using rule 43 (comment -> comment COMMENT .) - SPECIAL reduce using rule 43 (comment -> comment COMMENT .) - POUND reduce using rule 43 (comment -> comment COMMENT .) - PROTEIN reduce using rule 43 (comment -> comment COMMENT .) - RPARENS reduce using rule 43 (comment -> comment COMMENT .) - - -state 15 - - (22) protein_entry -> protein_entry CONTENT . - - CONTENT reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - ACCESSION reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - LPARENS reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - COMMENT reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - LANGLE reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - CITATION reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - END reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - PROTEIN_ENTRY reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - REFERENCE_ENTRY reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - ENTRY reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - $end reduce using rule 22 (protein_entry -> protein_entry CONTENT .) - - -state 16 - - (23) protein_entry -> protein_entry accession . - (26) accession -> accession . AND ACCESSION - (27) accession -> accession . CONTENT - - CONTENT reduce using rule 23 (protein_entry -> protein_entry accession .) - ACCESSION reduce using rule 23 (protein_entry -> protein_entry accession .) - LPARENS reduce using rule 23 (protein_entry -> protein_entry accession .) - COMMENT reduce using rule 23 (protein_entry -> protein_entry accession .) - LANGLE reduce using rule 23 (protein_entry -> protein_entry accession .) - CITATION reduce using rule 23 (protein_entry -> protein_entry accession .) - END reduce using rule 23 (protein_entry -> protein_entry accession .) - PROTEIN_ENTRY reduce using rule 23 (protein_entry -> protein_entry accession .) - REFERENCE_ENTRY reduce using rule 23 (protein_entry -> protein_entry accession .) - ENTRY reduce using rule 23 (protein_entry -> protein_entry accession .) - $end reduce using rule 23 (protein_entry -> protein_entry accession .) - AND shift and go to state 40 - - ! CONTENT [ shift and go to state 41 ] - - -state 17 - - (24) protein_entry -> protein_entry comment . - (43) comment -> comment . COMMENT - - CONTENT reduce using rule 24 (protein_entry -> protein_entry comment .) - ACCESSION reduce using rule 24 (protein_entry -> protein_entry comment .) - LPARENS reduce using rule 24 (protein_entry -> protein_entry comment .) - COMMENT reduce using rule 24 (protein_entry -> protein_entry comment .) - LANGLE reduce using rule 24 (protein_entry -> protein_entry comment .) - CITATION reduce using rule 24 (protein_entry -> protein_entry comment .) - END reduce using rule 24 (protein_entry -> protein_entry comment .) - PROTEIN_ENTRY reduce using rule 24 (protein_entry -> protein_entry comment .) - REFERENCE_ENTRY reduce using rule 24 (protein_entry -> protein_entry comment .) - ENTRY reduce using rule 24 (protein_entry -> protein_entry comment .) - $end reduce using rule 24 (protein_entry -> protein_entry comment .) - - ! COMMENT [ shift and go to state 14 ] - - -state 18 - - (25) protein_entry -> protein_entry citations . - (39) citations -> citations . CITATION - - CONTENT reduce using rule 25 (protein_entry -> protein_entry citations .) - ACCESSION reduce using rule 25 (protein_entry -> protein_entry citations .) - LPARENS reduce using rule 25 (protein_entry -> protein_entry citations .) - COMMENT reduce using rule 25 (protein_entry -> protein_entry citations .) - LANGLE reduce using rule 25 (protein_entry -> protein_entry citations .) - CITATION reduce using rule 25 (protein_entry -> protein_entry citations .) - END reduce using rule 25 (protein_entry -> protein_entry citations .) - PROTEIN_ENTRY reduce using rule 25 (protein_entry -> protein_entry citations .) - REFERENCE_ENTRY reduce using rule 25 (protein_entry -> protein_entry citations .) - ENTRY reduce using rule 25 (protein_entry -> protein_entry citations .) - $end reduce using rule 25 (protein_entry -> protein_entry citations .) - - ! CITATION [ shift and go to state 42 ] - - -state 19 - - (28) accession -> ACCESSION . - - AND reduce using rule 28 (accession -> ACCESSION .) - CONTENT reduce using rule 28 (accession -> ACCESSION .) - ACCESSION reduce using rule 28 (accession -> ACCESSION .) - LPARENS reduce using rule 28 (accession -> ACCESSION .) - COMMENT reduce using rule 28 (accession -> ACCESSION .) - LANGLE reduce using rule 28 (accession -> ACCESSION .) - CITATION reduce using rule 28 (accession -> ACCESSION .) - END reduce using rule 28 (accession -> ACCESSION .) - PROTEIN_ENTRY reduce using rule 28 (accession -> ACCESSION .) - REFERENCE_ENTRY reduce using rule 28 (accession -> ACCESSION .) - ENTRY reduce using rule 28 (accession -> ACCESSION .) - $end reduce using rule 28 (accession -> ACCESSION .) - - -state 20 - - (37) citations -> LANGLE . citations RANGLE - (38) citations -> LANGLE . RANGLE - (37) citations -> . LANGLE citations RANGLE - (38) citations -> . LANGLE RANGLE - (39) citations -> . citations CITATION - (40) citations -> . CITATION - - RANGLE shift and go to state 44 - LANGLE shift and go to state 20 - CITATION shift and go to state 21 - - citations shift and go to state 43 - -state 21 - - (40) citations -> CITATION . - - CITATION reduce using rule 40 (citations -> CITATION .) - CONTENT reduce using rule 40 (citations -> CITATION .) - ACCESSION reduce using rule 40 (citations -> CITATION .) - LPARENS reduce using rule 40 (citations -> CITATION .) - COMMENT reduce using rule 40 (citations -> CITATION .) - LANGLE reduce using rule 40 (citations -> CITATION .) - END reduce using rule 40 (citations -> CITATION .) - PROTEIN_ENTRY reduce using rule 40 (citations -> CITATION .) - REFERENCE_ENTRY reduce using rule 40 (citations -> CITATION .) - ENTRY reduce using rule 40 (citations -> CITATION .) - $end reduce using rule 40 (citations -> CITATION .) - POUND reduce using rule 40 (citations -> CITATION .) - PROTEIN reduce using rule 40 (citations -> CITATION .) - LCURLY reduce using rule 40 (citations -> CITATION .) - SPECIAL reduce using rule 40 (citations -> CITATION .) - RANGLE reduce using rule 40 (citations -> CITATION .) - - -state 22 - - (17) reference_entry -> reference_entry CONTENT . - - CONTENT reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - LPARENS reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - COMMENT reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - LCURLY reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - SPECIAL reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - END reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - PROTEIN_ENTRY reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - REFERENCE_ENTRY reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - ENTRY reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - $end reduce using rule 17 (reference_entry -> reference_entry CONTENT .) - - -state 23 - - (18) reference_entry -> reference_entry comment . - (43) comment -> comment . COMMENT - - CONTENT reduce using rule 18 (reference_entry -> reference_entry comment .) - LPARENS reduce using rule 18 (reference_entry -> reference_entry comment .) - COMMENT reduce using rule 18 (reference_entry -> reference_entry comment .) - LCURLY reduce using rule 18 (reference_entry -> reference_entry comment .) - SPECIAL reduce using rule 18 (reference_entry -> reference_entry comment .) - END reduce using rule 18 (reference_entry -> reference_entry comment .) - PROTEIN_ENTRY reduce using rule 18 (reference_entry -> reference_entry comment .) - REFERENCE_ENTRY reduce using rule 18 (reference_entry -> reference_entry comment .) - ENTRY reduce using rule 18 (reference_entry -> reference_entry comment .) - $end reduce using rule 18 (reference_entry -> reference_entry comment .) - - ! COMMENT [ shift and go to state 14 ] - - -state 24 - - (19) reference_entry -> reference_entry special . - (31) special -> special . SPECIAL - - CONTENT reduce using rule 19 (reference_entry -> reference_entry special .) - LPARENS reduce using rule 19 (reference_entry -> reference_entry special .) - COMMENT reduce using rule 19 (reference_entry -> reference_entry special .) - LCURLY reduce using rule 19 (reference_entry -> reference_entry special .) - SPECIAL reduce using rule 19 (reference_entry -> reference_entry special .) - END reduce using rule 19 (reference_entry -> reference_entry special .) - PROTEIN_ENTRY reduce using rule 19 (reference_entry -> reference_entry special .) - REFERENCE_ENTRY reduce using rule 19 (reference_entry -> reference_entry special .) - ENTRY reduce using rule 19 (reference_entry -> reference_entry special .) - $end reduce using rule 19 (reference_entry -> reference_entry special .) - - ! SPECIAL [ shift and go to state 45 ] - - -state 25 - - (29) special -> LCURLY . special RCURLY - (30) special -> LCURLY . RCURLY - (29) special -> . LCURLY special RCURLY - (30) special -> . LCURLY RCURLY - (31) special -> . special SPECIAL - (32) special -> . SPECIAL - - RCURLY shift and go to state 47 - LCURLY shift and go to state 25 - SPECIAL shift and go to state 26 - - special shift and go to state 46 - -state 26 - - (32) special -> SPECIAL . - - SPECIAL reduce using rule 32 (special -> SPECIAL .) - CONTENT reduce using rule 32 (special -> SPECIAL .) - LPARENS reduce using rule 32 (special -> SPECIAL .) - COMMENT reduce using rule 32 (special -> SPECIAL .) - LCURLY reduce using rule 32 (special -> SPECIAL .) - END reduce using rule 32 (special -> SPECIAL .) - PROTEIN_ENTRY reduce using rule 32 (special -> SPECIAL .) - REFERENCE_ENTRY reduce using rule 32 (special -> SPECIAL .) - ENTRY reduce using rule 32 (special -> SPECIAL .) - $end reduce using rule 32 (special -> SPECIAL .) - POUND reduce using rule 32 (special -> SPECIAL .) - PROTEIN reduce using rule 32 (special -> SPECIAL .) - LANGLE reduce using rule 32 (special -> SPECIAL .) - CITATION reduce using rule 32 (special -> SPECIAL .) - RCURLY reduce using rule 32 (special -> SPECIAL .) - - -state 27 - - (10) entry -> entry CONTENT . - - CONTENT reduce using rule 10 (entry -> entry CONTENT .) - POUND reduce using rule 10 (entry -> entry CONTENT .) - PROTEIN reduce using rule 10 (entry -> entry CONTENT .) - LPARENS reduce using rule 10 (entry -> entry CONTENT .) - COMMENT reduce using rule 10 (entry -> entry CONTENT .) - LCURLY reduce using rule 10 (entry -> entry CONTENT .) - SPECIAL reduce using rule 10 (entry -> entry CONTENT .) - LANGLE reduce using rule 10 (entry -> entry CONTENT .) - CITATION reduce using rule 10 (entry -> entry CONTENT .) - END reduce using rule 10 (entry -> entry CONTENT .) - PROTEIN_ENTRY reduce using rule 10 (entry -> entry CONTENT .) - REFERENCE_ENTRY reduce using rule 10 (entry -> entry CONTENT .) - ENTRY reduce using rule 10 (entry -> entry CONTENT .) - $end reduce using rule 10 (entry -> entry CONTENT .) - - -state 28 - - (11) entry -> entry proteins . - (35) proteins -> proteins . PROTEIN - - CONTENT reduce using rule 11 (entry -> entry proteins .) - POUND reduce using rule 11 (entry -> entry proteins .) - PROTEIN reduce using rule 11 (entry -> entry proteins .) - LPARENS reduce using rule 11 (entry -> entry proteins .) - COMMENT reduce using rule 11 (entry -> entry proteins .) - LCURLY reduce using rule 11 (entry -> entry proteins .) - SPECIAL reduce using rule 11 (entry -> entry proteins .) - LANGLE reduce using rule 11 (entry -> entry proteins .) - CITATION reduce using rule 11 (entry -> entry proteins .) - END reduce using rule 11 (entry -> entry proteins .) - PROTEIN_ENTRY reduce using rule 11 (entry -> entry proteins .) - REFERENCE_ENTRY reduce using rule 11 (entry -> entry proteins .) - ENTRY reduce using rule 11 (entry -> entry proteins .) - $end reduce using rule 11 (entry -> entry proteins .) - - ! PROTEIN [ shift and go to state 48 ] - - -state 29 - - (12) entry -> entry comment . - (43) comment -> comment . COMMENT - - CONTENT reduce using rule 12 (entry -> entry comment .) - POUND reduce using rule 12 (entry -> entry comment .) - PROTEIN reduce using rule 12 (entry -> entry comment .) - LPARENS reduce using rule 12 (entry -> entry comment .) - COMMENT reduce using rule 12 (entry -> entry comment .) - LCURLY reduce using rule 12 (entry -> entry comment .) - SPECIAL reduce using rule 12 (entry -> entry comment .) - LANGLE reduce using rule 12 (entry -> entry comment .) - CITATION reduce using rule 12 (entry -> entry comment .) - END reduce using rule 12 (entry -> entry comment .) - PROTEIN_ENTRY reduce using rule 12 (entry -> entry comment .) - REFERENCE_ENTRY reduce using rule 12 (entry -> entry comment .) - ENTRY reduce using rule 12 (entry -> entry comment .) - $end reduce using rule 12 (entry -> entry comment .) - - ! COMMENT [ shift and go to state 14 ] - - -state 30 - - (13) entry -> entry special . - (31) special -> special . SPECIAL - - CONTENT reduce using rule 13 (entry -> entry special .) - POUND reduce using rule 13 (entry -> entry special .) - PROTEIN reduce using rule 13 (entry -> entry special .) - LPARENS reduce using rule 13 (entry -> entry special .) - COMMENT reduce using rule 13 (entry -> entry special .) - LCURLY reduce using rule 13 (entry -> entry special .) - SPECIAL reduce using rule 13 (entry -> entry special .) - LANGLE reduce using rule 13 (entry -> entry special .) - CITATION reduce using rule 13 (entry -> entry special .) - END reduce using rule 13 (entry -> entry special .) - PROTEIN_ENTRY reduce using rule 13 (entry -> entry special .) - REFERENCE_ENTRY reduce using rule 13 (entry -> entry special .) - ENTRY reduce using rule 13 (entry -> entry special .) - $end reduce using rule 13 (entry -> entry special .) - - ! SPECIAL [ shift and go to state 45 ] - - -state 31 - - (14) entry -> entry citations . - (39) citations -> citations . CITATION - - CONTENT reduce using rule 14 (entry -> entry citations .) - POUND reduce using rule 14 (entry -> entry citations .) - PROTEIN reduce using rule 14 (entry -> entry citations .) - LPARENS reduce using rule 14 (entry -> entry citations .) - COMMENT reduce using rule 14 (entry -> entry citations .) - LCURLY reduce using rule 14 (entry -> entry citations .) - SPECIAL reduce using rule 14 (entry -> entry citations .) - LANGLE reduce using rule 14 (entry -> entry citations .) - CITATION reduce using rule 14 (entry -> entry citations .) - END reduce using rule 14 (entry -> entry citations .) - PROTEIN_ENTRY reduce using rule 14 (entry -> entry citations .) - REFERENCE_ENTRY reduce using rule 14 (entry -> entry citations .) - ENTRY reduce using rule 14 (entry -> entry citations .) - $end reduce using rule 14 (entry -> entry citations .) - - ! CITATION [ shift and go to state 42 ] - - -state 32 - - (33) proteins -> POUND . proteins POUND - (34) proteins -> POUND . POUND - (33) proteins -> . POUND proteins POUND - (34) proteins -> . POUND POUND - (35) proteins -> . proteins PROTEIN - (36) proteins -> . PROTEIN - - POUND shift and go to state 49 - PROTEIN shift and go to state 33 - - proteins shift and go to state 50 - -state 33 - - (36) proteins -> PROTEIN . - - PROTEIN reduce using rule 36 (proteins -> PROTEIN .) - CONTENT reduce using rule 36 (proteins -> PROTEIN .) - POUND reduce using rule 36 (proteins -> PROTEIN .) - LPARENS reduce using rule 36 (proteins -> PROTEIN .) - COMMENT reduce using rule 36 (proteins -> PROTEIN .) - LCURLY reduce using rule 36 (proteins -> PROTEIN .) - SPECIAL reduce using rule 36 (proteins -> PROTEIN .) - LANGLE reduce using rule 36 (proteins -> PROTEIN .) - CITATION reduce using rule 36 (proteins -> PROTEIN .) - END reduce using rule 36 (proteins -> PROTEIN .) - PROTEIN_ENTRY reduce using rule 36 (proteins -> PROTEIN .) - REFERENCE_ENTRY reduce using rule 36 (proteins -> PROTEIN .) - ENTRY reduce using rule 36 (proteins -> PROTEIN .) - $end reduce using rule 36 (proteins -> PROTEIN .) - ACCESSION reduce using rule 36 (proteins -> PROTEIN .) - - -state 34 - - (41) comment -> LPARENS comment . RPARENS - (43) comment -> comment . COMMENT - - RPARENS shift and go to state 51 - COMMENT shift and go to state 14 - - -state 35 - - (42) comment -> LPARENS RPARENS . - - COMMENT reduce using rule 42 (comment -> LPARENS RPARENS .) - END reduce using rule 42 (comment -> LPARENS RPARENS .) - LPARENS reduce using rule 42 (comment -> LPARENS RPARENS .) - PROTEIN_ENTRY reduce using rule 42 (comment -> LPARENS RPARENS .) - REFERENCE_ENTRY reduce using rule 42 (comment -> LPARENS RPARENS .) - ENTRY reduce using rule 42 (comment -> LPARENS RPARENS .) - $end reduce using rule 42 (comment -> LPARENS RPARENS .) - CONTENT reduce using rule 42 (comment -> LPARENS RPARENS .) - ACCESSION reduce using rule 42 (comment -> LPARENS RPARENS .) - LANGLE reduce using rule 42 (comment -> LPARENS RPARENS .) - CITATION reduce using rule 42 (comment -> LPARENS RPARENS .) - LCURLY reduce using rule 42 (comment -> LPARENS RPARENS .) - SPECIAL reduce using rule 42 (comment -> LPARENS RPARENS .) - POUND reduce using rule 42 (comment -> LPARENS RPARENS .) - PROTEIN reduce using rule 42 (comment -> LPARENS RPARENS .) - RPARENS reduce using rule 42 (comment -> LPARENS RPARENS .) - - -state 36 - - (20) protein_entry -> PROTEIN_ENTRY new_protein . proteins - (33) proteins -> . POUND proteins POUND - (34) proteins -> . POUND POUND - (35) proteins -> . proteins PROTEIN - (36) proteins -> . PROTEIN - - POUND shift and go to state 32 - PROTEIN shift and go to state 33 - - proteins shift and go to state 52 - -state 37 - - (15) reference_entry -> REFERENCE_ENTRY new_reference . citations - (37) citations -> . LANGLE citations RANGLE - (38) citations -> . LANGLE RANGLE - (39) citations -> . citations CITATION - (40) citations -> . CITATION - - LANGLE shift and go to state 20 - CITATION shift and go to state 21 - - citations shift and go to state 53 - -state 38 - - (8) entry -> ENTRY new_entry . - - CONTENT reduce using rule 8 (entry -> ENTRY new_entry .) - POUND reduce using rule 8 (entry -> ENTRY new_entry .) - PROTEIN reduce using rule 8 (entry -> ENTRY new_entry .) - LPARENS reduce using rule 8 (entry -> ENTRY new_entry .) - COMMENT reduce using rule 8 (entry -> ENTRY new_entry .) - LCURLY reduce using rule 8 (entry -> ENTRY new_entry .) - SPECIAL reduce using rule 8 (entry -> ENTRY new_entry .) - LANGLE reduce using rule 8 (entry -> ENTRY new_entry .) - CITATION reduce using rule 8 (entry -> ENTRY new_entry .) - END reduce using rule 8 (entry -> ENTRY new_entry .) - PROTEIN_ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) - REFERENCE_ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) - ENTRY reduce using rule 8 (entry -> ENTRY new_entry .) - $end reduce using rule 8 (entry -> ENTRY new_entry .) - - -state 39 - - (1) enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme . - - END reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) - LPARENS reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) - COMMENT reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) - PROTEIN_ENTRY reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) - REFERENCE_ENTRY reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) - ENTRY reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) - $end reduce using rule 1 (enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme .) - - -state 40 - - (26) accession -> accession AND . ACCESSION - - ACCESSION shift and go to state 54 - - -state 41 - - (27) accession -> accession CONTENT . - - AND reduce using rule 27 (accession -> accession CONTENT .) - CONTENT reduce using rule 27 (accession -> accession CONTENT .) - ACCESSION reduce using rule 27 (accession -> accession CONTENT .) - LPARENS reduce using rule 27 (accession -> accession CONTENT .) - COMMENT reduce using rule 27 (accession -> accession CONTENT .) - LANGLE reduce using rule 27 (accession -> accession CONTENT .) - CITATION reduce using rule 27 (accession -> accession CONTENT .) - END reduce using rule 27 (accession -> accession CONTENT .) - PROTEIN_ENTRY reduce using rule 27 (accession -> accession CONTENT .) - REFERENCE_ENTRY reduce using rule 27 (accession -> accession CONTENT .) - ENTRY reduce using rule 27 (accession -> accession CONTENT .) - $end reduce using rule 27 (accession -> accession CONTENT .) - - -state 42 - - (39) citations -> citations CITATION . - - CITATION reduce using rule 39 (citations -> citations CITATION .) - CONTENT reduce using rule 39 (citations -> citations CITATION .) - ACCESSION reduce using rule 39 (citations -> citations CITATION .) - LPARENS reduce using rule 39 (citations -> citations CITATION .) - COMMENT reduce using rule 39 (citations -> citations CITATION .) - LANGLE reduce using rule 39 (citations -> citations CITATION .) - END reduce using rule 39 (citations -> citations CITATION .) - PROTEIN_ENTRY reduce using rule 39 (citations -> citations CITATION .) - REFERENCE_ENTRY reduce using rule 39 (citations -> citations CITATION .) - ENTRY reduce using rule 39 (citations -> citations CITATION .) - $end reduce using rule 39 (citations -> citations CITATION .) - POUND reduce using rule 39 (citations -> citations CITATION .) - PROTEIN reduce using rule 39 (citations -> citations CITATION .) - LCURLY reduce using rule 39 (citations -> citations CITATION .) - SPECIAL reduce using rule 39 (citations -> citations CITATION .) - RANGLE reduce using rule 39 (citations -> citations CITATION .) - - -state 43 - - (37) citations -> LANGLE citations . RANGLE - (39) citations -> citations . CITATION - - RANGLE shift and go to state 55 - CITATION shift and go to state 42 - - -state 44 - - (38) citations -> LANGLE RANGLE . - - CITATION reduce using rule 38 (citations -> LANGLE RANGLE .) - CONTENT reduce using rule 38 (citations -> LANGLE RANGLE .) - ACCESSION reduce using rule 38 (citations -> LANGLE RANGLE .) - LPARENS reduce using rule 38 (citations -> LANGLE RANGLE .) - COMMENT reduce using rule 38 (citations -> LANGLE RANGLE .) - LANGLE reduce using rule 38 (citations -> LANGLE RANGLE .) - END reduce using rule 38 (citations -> LANGLE RANGLE .) - PROTEIN_ENTRY reduce using rule 38 (citations -> LANGLE RANGLE .) - REFERENCE_ENTRY reduce using rule 38 (citations -> LANGLE RANGLE .) - ENTRY reduce using rule 38 (citations -> LANGLE RANGLE .) - $end reduce using rule 38 (citations -> LANGLE RANGLE .) - POUND reduce using rule 38 (citations -> LANGLE RANGLE .) - PROTEIN reduce using rule 38 (citations -> LANGLE RANGLE .) - LCURLY reduce using rule 38 (citations -> LANGLE RANGLE .) - SPECIAL reduce using rule 38 (citations -> LANGLE RANGLE .) - RANGLE reduce using rule 38 (citations -> LANGLE RANGLE .) - - -state 45 - - (31) special -> special SPECIAL . - - SPECIAL reduce using rule 31 (special -> special SPECIAL .) - CONTENT reduce using rule 31 (special -> special SPECIAL .) - LPARENS reduce using rule 31 (special -> special SPECIAL .) - COMMENT reduce using rule 31 (special -> special SPECIAL .) - LCURLY reduce using rule 31 (special -> special SPECIAL .) - END reduce using rule 31 (special -> special SPECIAL .) - PROTEIN_ENTRY reduce using rule 31 (special -> special SPECIAL .) - REFERENCE_ENTRY reduce using rule 31 (special -> special SPECIAL .) - ENTRY reduce using rule 31 (special -> special SPECIAL .) - $end reduce using rule 31 (special -> special SPECIAL .) - POUND reduce using rule 31 (special -> special SPECIAL .) - PROTEIN reduce using rule 31 (special -> special SPECIAL .) - LANGLE reduce using rule 31 (special -> special SPECIAL .) - CITATION reduce using rule 31 (special -> special SPECIAL .) - RCURLY reduce using rule 31 (special -> special SPECIAL .) - - -state 46 - - (29) special -> LCURLY special . RCURLY - (31) special -> special . SPECIAL - - RCURLY shift and go to state 56 - SPECIAL shift and go to state 45 - - -state 47 - - (30) special -> LCURLY RCURLY . - - SPECIAL reduce using rule 30 (special -> LCURLY RCURLY .) - CONTENT reduce using rule 30 (special -> LCURLY RCURLY .) - LPARENS reduce using rule 30 (special -> LCURLY RCURLY .) - COMMENT reduce using rule 30 (special -> LCURLY RCURLY .) - LCURLY reduce using rule 30 (special -> LCURLY RCURLY .) - END reduce using rule 30 (special -> LCURLY RCURLY .) - PROTEIN_ENTRY reduce using rule 30 (special -> LCURLY RCURLY .) - REFERENCE_ENTRY reduce using rule 30 (special -> LCURLY RCURLY .) - ENTRY reduce using rule 30 (special -> LCURLY RCURLY .) - $end reduce using rule 30 (special -> LCURLY RCURLY .) - POUND reduce using rule 30 (special -> LCURLY RCURLY .) - PROTEIN reduce using rule 30 (special -> LCURLY RCURLY .) - LANGLE reduce using rule 30 (special -> LCURLY RCURLY .) - CITATION reduce using rule 30 (special -> LCURLY RCURLY .) - RCURLY reduce using rule 30 (special -> LCURLY RCURLY .) - - -state 48 - - (35) proteins -> proteins PROTEIN . - - PROTEIN reduce using rule 35 (proteins -> proteins PROTEIN .) - CONTENT reduce using rule 35 (proteins -> proteins PROTEIN .) - POUND reduce using rule 35 (proteins -> proteins PROTEIN .) - LPARENS reduce using rule 35 (proteins -> proteins PROTEIN .) - COMMENT reduce using rule 35 (proteins -> proteins PROTEIN .) - LCURLY reduce using rule 35 (proteins -> proteins PROTEIN .) - SPECIAL reduce using rule 35 (proteins -> proteins PROTEIN .) - LANGLE reduce using rule 35 (proteins -> proteins PROTEIN .) - CITATION reduce using rule 35 (proteins -> proteins PROTEIN .) - END reduce using rule 35 (proteins -> proteins PROTEIN .) - PROTEIN_ENTRY reduce using rule 35 (proteins -> proteins PROTEIN .) - REFERENCE_ENTRY reduce using rule 35 (proteins -> proteins PROTEIN .) - ENTRY reduce using rule 35 (proteins -> proteins PROTEIN .) - $end reduce using rule 35 (proteins -> proteins PROTEIN .) - ACCESSION reduce using rule 35 (proteins -> proteins PROTEIN .) - - -state 49 - - (34) proteins -> POUND POUND . - (33) proteins -> POUND . proteins POUND - (34) proteins -> POUND . POUND - (33) proteins -> . POUND proteins POUND - (34) proteins -> . POUND POUND - (35) proteins -> . proteins PROTEIN - (36) proteins -> . PROTEIN - - PROTEIN reduce using rule 34 (proteins -> POUND POUND .) - CONTENT reduce using rule 34 (proteins -> POUND POUND .) - POUND reduce using rule 34 (proteins -> POUND POUND .) - LPARENS reduce using rule 34 (proteins -> POUND POUND .) - COMMENT reduce using rule 34 (proteins -> POUND POUND .) - LCURLY reduce using rule 34 (proteins -> POUND POUND .) - SPECIAL reduce using rule 34 (proteins -> POUND POUND .) - LANGLE reduce using rule 34 (proteins -> POUND POUND .) - CITATION reduce using rule 34 (proteins -> POUND POUND .) - END reduce using rule 34 (proteins -> POUND POUND .) - PROTEIN_ENTRY reduce using rule 34 (proteins -> POUND POUND .) - REFERENCE_ENTRY reduce using rule 34 (proteins -> POUND POUND .) - ENTRY reduce using rule 34 (proteins -> POUND POUND .) - $end reduce using rule 34 (proteins -> POUND POUND .) - ACCESSION reduce using rule 34 (proteins -> POUND POUND .) - - ! POUND [ shift and go to state 49 ] - ! PROTEIN [ shift and go to state 33 ] - - proteins shift and go to state 50 - -state 50 - - (33) proteins -> POUND proteins . POUND - (35) proteins -> proteins . PROTEIN - - POUND shift and go to state 57 - PROTEIN shift and go to state 48 - - -state 51 - - (41) comment -> LPARENS comment RPARENS . - - COMMENT reduce using rule 41 (comment -> LPARENS comment RPARENS .) - END reduce using rule 41 (comment -> LPARENS comment RPARENS .) - LPARENS reduce using rule 41 (comment -> LPARENS comment RPARENS .) - PROTEIN_ENTRY reduce using rule 41 (comment -> LPARENS comment RPARENS .) - REFERENCE_ENTRY reduce using rule 41 (comment -> LPARENS comment RPARENS .) - ENTRY reduce using rule 41 (comment -> LPARENS comment RPARENS .) - $end reduce using rule 41 (comment -> LPARENS comment RPARENS .) - CONTENT reduce using rule 41 (comment -> LPARENS comment RPARENS .) - ACCESSION reduce using rule 41 (comment -> LPARENS comment RPARENS .) - LANGLE reduce using rule 41 (comment -> LPARENS comment RPARENS .) - CITATION reduce using rule 41 (comment -> LPARENS comment RPARENS .) - LCURLY reduce using rule 41 (comment -> LPARENS comment RPARENS .) - SPECIAL reduce using rule 41 (comment -> LPARENS comment RPARENS .) - POUND reduce using rule 41 (comment -> LPARENS comment RPARENS .) - PROTEIN reduce using rule 41 (comment -> LPARENS comment RPARENS .) - RPARENS reduce using rule 41 (comment -> LPARENS comment RPARENS .) - - -state 52 - - (20) protein_entry -> PROTEIN_ENTRY new_protein proteins . - (35) proteins -> proteins . PROTEIN - - CONTENT reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - ACCESSION reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - LPARENS reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - COMMENT reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - LANGLE reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - CITATION reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - END reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - PROTEIN_ENTRY reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - REFERENCE_ENTRY reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - ENTRY reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - $end reduce using rule 20 (protein_entry -> PROTEIN_ENTRY new_protein proteins .) - PROTEIN shift and go to state 48 - - -state 53 - - (15) reference_entry -> REFERENCE_ENTRY new_reference citations . - (39) citations -> citations . CITATION - - CONTENT reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - LPARENS reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - COMMENT reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - LCURLY reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - SPECIAL reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - END reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - PROTEIN_ENTRY reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - REFERENCE_ENTRY reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - ENTRY reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - $end reduce using rule 15 (reference_entry -> REFERENCE_ENTRY new_reference citations .) - CITATION shift and go to state 42 - - -state 54 - - (26) accession -> accession AND ACCESSION . - - AND reduce using rule 26 (accession -> accession AND ACCESSION .) - CONTENT reduce using rule 26 (accession -> accession AND ACCESSION .) - ACCESSION reduce using rule 26 (accession -> accession AND ACCESSION .) - LPARENS reduce using rule 26 (accession -> accession AND ACCESSION .) - COMMENT reduce using rule 26 (accession -> accession AND ACCESSION .) - LANGLE reduce using rule 26 (accession -> accession AND ACCESSION .) - CITATION reduce using rule 26 (accession -> accession AND ACCESSION .) - END reduce using rule 26 (accession -> accession AND ACCESSION .) - PROTEIN_ENTRY reduce using rule 26 (accession -> accession AND ACCESSION .) - REFERENCE_ENTRY reduce using rule 26 (accession -> accession AND ACCESSION .) - ENTRY reduce using rule 26 (accession -> accession AND ACCESSION .) - $end reduce using rule 26 (accession -> accession AND ACCESSION .) - - -state 55 - - (37) citations -> LANGLE citations RANGLE . - - CITATION reduce using rule 37 (citations -> LANGLE citations RANGLE .) - CONTENT reduce using rule 37 (citations -> LANGLE citations RANGLE .) - ACCESSION reduce using rule 37 (citations -> LANGLE citations RANGLE .) - LPARENS reduce using rule 37 (citations -> LANGLE citations RANGLE .) - COMMENT reduce using rule 37 (citations -> LANGLE citations RANGLE .) - LANGLE reduce using rule 37 (citations -> LANGLE citations RANGLE .) - END reduce using rule 37 (citations -> LANGLE citations RANGLE .) - PROTEIN_ENTRY reduce using rule 37 (citations -> LANGLE citations RANGLE .) - REFERENCE_ENTRY reduce using rule 37 (citations -> LANGLE citations RANGLE .) - ENTRY reduce using rule 37 (citations -> LANGLE citations RANGLE .) - $end reduce using rule 37 (citations -> LANGLE citations RANGLE .) - POUND reduce using rule 37 (citations -> LANGLE citations RANGLE .) - PROTEIN reduce using rule 37 (citations -> LANGLE citations RANGLE .) - LCURLY reduce using rule 37 (citations -> LANGLE citations RANGLE .) - SPECIAL reduce using rule 37 (citations -> LANGLE citations RANGLE .) - RANGLE reduce using rule 37 (citations -> LANGLE citations RANGLE .) - - -state 56 - - (29) special -> LCURLY special RCURLY . - - SPECIAL reduce using rule 29 (special -> LCURLY special RCURLY .) - CONTENT reduce using rule 29 (special -> LCURLY special RCURLY .) - LPARENS reduce using rule 29 (special -> LCURLY special RCURLY .) - COMMENT reduce using rule 29 (special -> LCURLY special RCURLY .) - LCURLY reduce using rule 29 (special -> LCURLY special RCURLY .) - END reduce using rule 29 (special -> LCURLY special RCURLY .) - PROTEIN_ENTRY reduce using rule 29 (special -> LCURLY special RCURLY .) - REFERENCE_ENTRY reduce using rule 29 (special -> LCURLY special RCURLY .) - ENTRY reduce using rule 29 (special -> LCURLY special RCURLY .) - $end reduce using rule 29 (special -> LCURLY special RCURLY .) - POUND reduce using rule 29 (special -> LCURLY special RCURLY .) - PROTEIN reduce using rule 29 (special -> LCURLY special RCURLY .) - LANGLE reduce using rule 29 (special -> LCURLY special RCURLY .) - CITATION reduce using rule 29 (special -> LCURLY special RCURLY .) - RCURLY reduce using rule 29 (special -> LCURLY special RCURLY .) - - -state 57 - - (33) proteins -> POUND proteins POUND . - - PROTEIN reduce using rule 33 (proteins -> POUND proteins POUND .) - CONTENT reduce using rule 33 (proteins -> POUND proteins POUND .) - POUND reduce using rule 33 (proteins -> POUND proteins POUND .) - LPARENS reduce using rule 33 (proteins -> POUND proteins POUND .) - COMMENT reduce using rule 33 (proteins -> POUND proteins POUND .) - LCURLY reduce using rule 33 (proteins -> POUND proteins POUND .) - SPECIAL reduce using rule 33 (proteins -> POUND proteins POUND .) - LANGLE reduce using rule 33 (proteins -> POUND proteins POUND .) - CITATION reduce using rule 33 (proteins -> POUND proteins POUND .) - END reduce using rule 33 (proteins -> POUND proteins POUND .) - PROTEIN_ENTRY reduce using rule 33 (proteins -> POUND proteins POUND .) - REFERENCE_ENTRY reduce using rule 33 (proteins -> POUND proteins POUND .) - ENTRY reduce using rule 33 (proteins -> POUND proteins POUND .) - $end reduce using rule 33 (proteins -> POUND proteins POUND .) - ACCESSION reduce using rule 33 (proteins -> POUND proteins POUND .) - -WARNING: -WARNING: Conflicts: -WARNING: -WARNING: shift/reduce conflict for COMMENT in state 3 resolved as shift -WARNING: shift/reduce conflict for LPARENS in state 4 resolved as shift -WARNING: shift/reduce conflict for COMMENT in state 4 resolved as shift -WARNING: shift/reduce conflict for LPARENS in state 5 resolved as shift -WARNING: shift/reduce conflict for COMMENT in state 5 resolved as shift -WARNING: shift/reduce conflict for LPARENS in state 6 resolved as shift -WARNING: shift/reduce conflict for COMMENT in state 6 resolved as shift diff --git a/src/brenda_parser/parsing/parser.py b/src/brenda_parser/parsing/parser.py index 4714989..5711a9c 100644 --- a/src/brenda_parser/parsing/parser.py +++ b/src/brenda_parser/parsing/parser.py @@ -28,23 +28,21 @@ """Parse BRENDA tokens using the provided grammar.""" - import logging from ply.yacc import yacc +from sqlalchemy.orm.exc import NoResultFound import brenda_parser.models as models from brenda_parser.exceptions import ValidationError from brenda_parser.parsing.lexer import BRENDALexer - __all__ = ("BRENDAParser",) - logger = logging.getLogger(__name__) -class BRENDAParser(object): +class BRENDAParser: """ Parse the BRENDA flat file into database models. @@ -57,6 +55,7 @@ class BRENDAParser(object): entry : ENTRY protein TEXT comment citation special | ENTRY protein TEXT comment | ENTRY protein TEXT + | ENTRY HEADER protein_entry : PROTEIN_ENTRY new_protein protein_entry | protein_entry protein_entry @@ -86,7 +85,6 @@ class BRENDAParser(object): """ precedence = ( - # ("left", "ENZYME"), ("left", "ASSEMBLE"), ("left", "REDUCE"), ("left", "COMBINE"), @@ -168,8 +166,12 @@ def p_enzyme_entry(self, p): p[1].entries.append(p[2]) p[0] = p[1] + def p_enzyme_header(self, p): + """enzyme : enzyme HEADER""" + p[0] = p[1] + def p_enzyme_end(self, p): - """enzyme : enzyme END""" + """enzyme : enzyme END %prec REDUCE""" # TODO: Finalize protein and citation references. p[0] = p[1] @@ -180,12 +182,23 @@ def p_entry(self, p): def p_new_entry(self, p): """new_entry : %prec REDUCE""" - field = ( - self._session.query(models.InformationField) - .filter_by(acronym=p[-1]) - .one() - ) - p[0] = models.FieldEntry(field=field, body="") + try: + field = ( + self._session.query(models.InformationField) + .filter_by(acronym=p[-1]) + .one() + ) + except NoResultFound: + logger.critical("Could not find any information field with " + "acronym '%s'.", p[-1]) + raise + else: + p[0] = models.FieldEntry(field=field, body="") + + def p_entry_header(self, p): + """entry : entry HEADER %prec ASSEMBLE""" + # A header introduces a new section and completes this section. + p[0] = p[1] def p_entry_content(self, p): """entry : entry CONTENT""" @@ -226,12 +239,23 @@ def p_reference_entry(self, p): def p_new_reference(self, p): """new_reference :""" assert p[-1] == "RF" - field = ( - self._session.query(models.InformationField) - .filter_by(acronym=p[-1]) - .one() - ) - p[0] = models.Reference(field=field, body="") + try: + field = ( + self._session.query(models.InformationField) + .filter_by(acronym=p[-1]) + .one() + ) + except NoResultFound: + logger.critical("Could not find any information field with " + "acronym '%s'.", p[-1]) + raise + else: + p[0] = models.Reference(field=field, body="") + + def p_reference_header(self, p): + """reference_entry : reference_entry HEADER %prec ASSEMBLE""" + # A header introduces a new section and completes this section. + p[0] = p[1] def p_reference_content(self, p): """reference_entry : reference_entry CONTENT""" @@ -262,122 +286,158 @@ def p_protein_entry(self, p): def p_new_protein(self, p): """new_protein :""" assert p[-1] == "PR" - field = ( - self._session.query(models.InformationField) - .filter_by(acronym=p[-1]) - .one() - ) - p[0] = models.Protein(field=field) - - def p_protein_organism(self, p): - """protein_entry : protein_entry CONTENT %prec ASSEMBLE""" - assert len(p[2]) > 0 - # TODO: Find or create the organism. - p[1].organism_name += p[2] - p[0] = p[1] + try: + field = ( + self._session.query(models.InformationField) + .filter_by(acronym=p[-1]) + .one() + ) + except NoResultFound: + logger.critical("Could not find any information field with " + "acronym '%s'.", p[-1]) + raise + else: + p[0] = models.Protein(field=field) - def p_protein_accession(self, p): - """protein_entry : protein_entry accession %prec ASSEMBLE""" - p[1].accession = p[2] - p[0] = p[1] - def p_protein_comment(self, p): - """protein_entry : protein_entry comment %prec ASSEMBLE""" - if p[2] is not None: - p[1].comments.append(p[2]) - p[0] = p[1] +def p_protein_header(self, p): + """protein_entry : protein_entry HEADER %prec ASSEMBLE""" + # A header introduces a new section and completes this section. + p[0] = p[1] - def p_protein_citations(self, p): - """protein_entry : protein_entry citations %prec ASSEMBLE""" - if p[2] is not None: - p[1].citation_references.extend(p[2]) - p[0] = p[1] - def p_accession_combine(self, p): - """accession : accession AND ACCESSION %prec COMBINE""" - p[1].accession = f"{p[1].accession} & {p[3]}" - p[0] = p[1] +def p_protein_organism(self, p): + """protein_entry : protein_entry CONTENT %prec ASSEMBLE""" + assert len(p[2]) > 0 + # TODO: Find or create the organism. + p[1].organism_name += p[2] + p[0] = p[1] - def p_accession_database(self, p): - """accession : accession CONTENT %prec COMBINE""" - p[1].database = p[2] - p[0] = p[1] - def p_accession(self, p): - """accession : ACCESSION %prec REDUCE""" - p[0] = models.Accession(accession=p[1]) +def p_protein_accession(self, p): + """protein_entry : protein_entry accession %prec ASSEMBLE""" + p[1].accession = p[2] + p[0] = p[1] - def p_special(self, p): - """special : LCURLY special RCURLY""" - p[0] = p[2] - def p_special_empty(self, p): - """special : LCURLY RCURLY""" - pass +def p_protein_comment(self, p): + """protein_entry : protein_entry comment %prec ASSEMBLE""" + if p[2] is not None: + p[1].comments.append(p[2]) + p[0] = p[1] - def p_special_combine(self, p): - """special : special SPECIAL %prec COMBINE""" - p[0] = f"{p[1]} {p[2]}" - def p_special_end(self, p): - """special : SPECIAL %prec REDUCE""" - p[0] = p[1].strip() +def p_protein_citations(self, p): + """protein_entry : protein_entry citations %prec ASSEMBLE""" + if p[2] is not None: + p[1].citation_references.extend(p[2]) + p[0] = p[1] - def p_proteins(self, p): - """proteins : POUND proteins POUND %prec ASSEMBLE""" - p[0] = p[2] - def p_proteins_empty(self, p): - """proteins : POUND POUND %prec ASSEMBLE""" - pass +def p_accession_combine(self, p): + """accession : accession AND ACCESSION %prec COMBINE""" + p[1].accession = f"{p[1].accession} & {p[3]}" + p[0] = p[1] - def p_proteins_combine(self, p): - """proteins : proteins PROTEIN %prec COMBINE""" - p[1].append(p[2]) - p[0] = p[1] - def p_proteins_end(self, p): - """proteins : PROTEIN %prec REDUCE""" - p[0] = [p[1]] +def p_accession_database(self, p): + """accession : accession CONTENT %prec COMBINE""" + p[1].database = p[2] + p[0] = p[1] - def p_citations(self, p): - """citations : LANGLE citations RANGLE %prec ASSEMBLE""" - p[0] = p[2] - def p_citations_empty(self, p): - """citations : LANGLE RANGLE %prec ASSEMBLE""" - pass +def p_accession(self, p): + """accession : ACCESSION %prec REDUCE""" + p[0] = models.Accession(accession=p[1]) - def p_citations_combine(self, p): - """citations : citations CITATION %prec COMBINE""" - p[1].append(p[2]) - p[0] = p[1] - def p_citations_end(self, p): - """citations : CITATION %prec REDUCE""" - p[0] = [p[1]] +def p_special(self, p): + """special : LCURLY special RCURLY""" + p[0] = p[2] - def p_comment(self, p): - """comment : LPARENS comment RPARENS %prec ASSEMBLE""" - p[0] = p[2] - def p_comment_empty(self, p): - """comment : LPARENS RPARENS %prec ASSEMBLE""" - pass +def p_special_empty(self, p): + """special : LCURLY RCURLY""" + pass + + +def p_special_combine(self, p): + """special : special SPECIAL %prec COMBINE""" + p[0] = f"{p[1]} {p[2]}" + + +def p_special_end(self, p): + """special : SPECIAL %prec REDUCE""" + p[0] = p[1].strip() + + +def p_proteins(self, p): + """proteins : POUND proteins POUND %prec ASSEMBLE""" + p[0] = p[2] + + +def p_proteins_empty(self, p): + """proteins : POUND POUND %prec ASSEMBLE""" + pass + + +def p_proteins_combine(self, p): + """proteins : proteins PROTEIN %prec COMBINE""" + p[1].append(p[2]) + p[0] = p[1] + + +def p_proteins_end(self, p): + """proteins : PROTEIN %prec REDUCE""" + p[0] = [p[1]] + + +def p_citations(self, p): + """citations : LANGLE citations RANGLE %prec ASSEMBLE""" + p[0] = p[2] + + +def p_citations_empty(self, p): + """citations : LANGLE RANGLE %prec ASSEMBLE""" + pass + + +def p_citations_combine(self, p): + """citations : citations CITATION %prec COMBINE""" + p[1].append(p[2]) + p[0] = p[1] + + +def p_citations_end(self, p): + """citations : CITATION %prec REDUCE""" + p[0] = [p[1]] + + +def p_comment(self, p): + """comment : LPARENS comment RPARENS %prec ASSEMBLE""" + p[0] = p[2] + + +def p_comment_empty(self, p): + """comment : LPARENS RPARENS %prec ASSEMBLE""" + pass + + +def p_comment_combine(self, p): + """comment : comment COMMENT %prec COMBINE""" + p[1].body = f"{p[1].body} {p[2]}" + p[0] = p[1] + + +def p_comment_end(self, p): + """comment : COMMENT %prec REDUCE""" + p[0] = models.Comment(body=p[1]) + # p[0] = [models.Comment(body=c) for c in p[1].split(";")] - def p_comment_combine(self, p): - """comment : comment COMMENT %prec COMBINE""" - p[1].body = f"{p[1].body} {p[2]}" - p[0] = p[1] - def p_comment_end(self, p): - """comment : COMMENT %prec REDUCE""" - p[0] = models.Comment(body=p[1]) - # p[0] = [models.Comment(body=c) for c in p[1].split(";")] - - def p_error(self, p): - logger.debug("Error: %s", str(p)) - # TODO: If `p` is None (we allow some empty rules) it's only an error - # if any parentheses or similar are unbalanced. - if False: - raise SyntaxError(str(p)) +def p_error(self, p): + logger.debug("Error: %s", str(p)) + # TODO: If `p` is None (we allow some empty rules) it's only an error + # if any parentheses or similar are unbalanced. + if False: + raise SyntaxError(str(p)) diff --git a/src/brenda_parser/parsing/parsetab.py b/src/brenda_parser/parsing/parsetab.py deleted file mode 100644 index c0662ab..0000000 --- a/src/brenda_parser/parsing/parsetab.py +++ /dev/null @@ -1,1529 +0,0 @@ -# parsetab.py -# This file is automatically generated. Do not edit. -# pylint: disable=W,C,R -_tabversion = "3.10" - -_lr_method = "LALR" - -_lr_signature = "leftASSEMBLEleftREDUCEleftCOMBINEACCESSION AND CITATION COMMENT CONTENT EC_NUMBER END ENTRY ENZYME_ENTRY LANGLE LCURLY LPARENS POUND PROTEIN PROTEIN_ENTRY RANGLE RCURLY REFERENCE_ENTRY RPARENS SPECIALenzyme : ENZYME_ENTRY EC_NUMBER new_enzymenew_enzyme :enzyme : enzyme commentenzyme : enzyme protein_entryenzyme : enzyme reference_entryenzyme : enzyme entryenzyme : enzyme ENDentry : ENTRY new_entry %prec REDUCEnew_entry : %prec REDUCEentry : entry CONTENTentry : entry proteins %prec ASSEMBLEentry : entry comment %prec ASSEMBLEentry : entry special %prec ASSEMBLEentry : entry citations %prec ASSEMBLEreference_entry : REFERENCE_ENTRY new_reference citationsnew_reference :reference_entry : reference_entry CONTENTreference_entry : reference_entry comment %prec ASSEMBLEreference_entry : reference_entry special %prec ASSEMBLEprotein_entry : PROTEIN_ENTRY new_protein proteins %prec COMBINEnew_protein :protein_entry : protein_entry CONTENT %prec ASSEMBLEprotein_entry : protein_entry accession %prec ASSEMBLEprotein_entry : protein_entry comment %prec ASSEMBLEprotein_entry : protein_entry citations %prec ASSEMBLEaccession : accession AND ACCESSION %prec COMBINEaccession : accession CONTENT %prec COMBINEaccession : ACCESSION %prec REDUCEspecial : LCURLY special RCURLYspecial : LCURLY RCURLYspecial : special SPECIAL %prec COMBINEspecial : SPECIAL %prec REDUCEproteins : POUND proteins POUND %prec ASSEMBLEproteins : POUND POUND %prec ASSEMBLEproteins : proteins PROTEIN %prec COMBINEproteins : PROTEIN %prec REDUCEcitations : LANGLE citations RANGLE %prec ASSEMBLEcitations : LANGLE RANGLE %prec ASSEMBLEcitations : citations CITATION %prec COMBINEcitations : CITATION %prec REDUCEcomment : LPARENS comment RPARENS %prec ASSEMBLEcomment : LPARENS RPARENS %prec ASSEMBLEcomment : comment COMMENT %prec COMBINEcomment : COMMENT %prec REDUCE" - -_lr_action_items = { - "ENZYME_ENTRY": ([0], [2]), - "$end": ( - [ - 1, - 3, - 4, - 5, - 6, - 7, - 9, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 22, - 23, - 24, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 39, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 0, - -3, - -4, - -5, - -6, - -7, - -44, - -9, - -2, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -17, - -18, - -19, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -1, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -15, - -26, - -37, - -29, - -33, - ], - ), - "END": ( - [ - 1, - 3, - 4, - 5, - 6, - 7, - 9, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 22, - 23, - 24, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 39, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 7, - -3, - -4, - -5, - -6, - -7, - -44, - -9, - -2, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -17, - -18, - -19, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -1, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -15, - -26, - -37, - -29, - -33, - ], - ), - "LPARENS": ( - [ - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 22, - 23, - 24, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 39, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 8, - -3, - 8, - 8, - 8, - -7, - 8, - -44, - -9, - -2, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -17, - -18, - -19, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -1, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -15, - -26, - -37, - -29, - -33, - ], - ), - "COMMENT": ( - [ - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 22, - 23, - 24, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 34, - 35, - 38, - 39, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 9, - 14, - 9, - 9, - 9, - -7, - 9, - -44, - -9, - -2, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -17, - -18, - -19, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - 14, - -42, - -8, - -1, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -15, - -26, - -37, - -29, - -33, - ], - ), - "PROTEIN_ENTRY": ( - [ - 1, - 3, - 4, - 5, - 6, - 7, - 9, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 22, - 23, - 24, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 39, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 10, - -3, - -4, - -5, - -6, - -7, - -44, - -9, - -2, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -17, - -18, - -19, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -1, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -15, - -26, - -37, - -29, - -33, - ], - ), - "REFERENCE_ENTRY": ( - [ - 1, - 3, - 4, - 5, - 6, - 7, - 9, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 22, - 23, - 24, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 39, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 11, - -3, - -4, - -5, - -6, - -7, - -44, - -9, - -2, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -17, - -18, - -19, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -1, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -15, - -26, - -37, - -29, - -33, - ], - ), - "ENTRY": ( - [ - 1, - 3, - 4, - 5, - 6, - 7, - 9, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 22, - 23, - 24, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 39, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 12, - -3, - -4, - -5, - -6, - -7, - -44, - -9, - -2, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -17, - -18, - -19, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -1, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -15, - -26, - -37, - -29, - -33, - ], - ), - "EC_NUMBER": ([2], [13]), - "CONTENT": ( - [ - 4, - 5, - 6, - 9, - 12, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 22, - 23, - 24, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 15, - 22, - 27, - -44, - -9, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -17, - -18, - -19, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -15, - -26, - -37, - -29, - -33, - ], - ), - "ACCESSION": ( - [ - 4, - 9, - 14, - 15, - 16, - 17, - 18, - 19, - 21, - 33, - 35, - 40, - 41, - 42, - 44, - 48, - 49, - 51, - 52, - 54, - 55, - 57, - ], - [ - 19, - -44, - -43, - -22, - -23, - -24, - -25, - -28, - -40, - -36, - -42, - 54, - -27, - -39, - -38, - -35, - -34, - -41, - -20, - -26, - -37, - -33, - ], - ), - "LANGLE": ( - [ - 4, - 6, - 9, - 11, - 12, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 37, - 38, - 41, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 54, - 55, - 56, - 57, - ], - [ - 20, - 20, - -44, - -16, - -9, - -43, - -22, - -23, - -24, - -25, - -28, - 20, - -40, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - 20, - -8, - -27, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - -26, - -37, - -29, - -33, - ], - ), - "CITATION": ( - [ - 4, - 6, - 9, - 11, - 12, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 37, - 38, - 41, - 42, - 43, - 44, - 45, - 47, - 48, - 49, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - ], - [ - 21, - 21, - -44, - -16, - -9, - -43, - -22, - -23, - -24, - -25, - -28, - 21, - -40, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - 21, - -8, - -27, - -39, - 42, - -38, - -31, - -30, - -35, - -34, - -41, - -20, - 42, - -26, - -37, - -29, - -33, - ], - ), - "LCURLY": ( - [ - 5, - 6, - 9, - 12, - 14, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 42, - 44, - 45, - 47, - 48, - 49, - 51, - 53, - 55, - 56, - 57, - ], - [ - 25, - 25, - -44, - -9, - -43, - -40, - -17, - -18, - -19, - 25, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -39, - -38, - -31, - -30, - -35, - -34, - -41, - -15, - -37, - -29, - -33, - ], - ), - "SPECIAL": ( - [ - 5, - 6, - 9, - 12, - 14, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 31, - 33, - 35, - 38, - 42, - 44, - 45, - 46, - 47, - 48, - 49, - 51, - 53, - 55, - 56, - 57, - ], - [ - 26, - 26, - -44, - -9, - -43, - -40, - -17, - -18, - -19, - 26, - -32, - -10, - -11, - -12, - -13, - -14, - -36, - -42, - -8, - -39, - -38, - -31, - 45, - -30, - -35, - -34, - -41, - -15, - -37, - -29, - -33, - ], - ), - "POUND": ( - [ - 6, - 9, - 10, - 12, - 14, - 21, - 26, - 27, - 28, - 29, - 30, - 31, - 32, - 33, - 35, - 36, - 38, - 42, - 44, - 45, - 47, - 48, - 49, - 50, - 51, - 55, - 56, - 57, - ], - [ - 32, - -44, - -21, - -9, - -43, - -40, - -32, - -10, - -11, - -12, - -13, - -14, - 49, - -36, - -42, - 32, - -8, - -39, - -38, - -31, - -30, - -35, - -34, - 57, - -41, - -37, - -29, - -33, - ], - ), - "PROTEIN": ( - [ - 6, - 9, - 10, - 12, - 14, - 21, - 26, - 27, - 28, - 29, - 30, - 31, - 32, - 33, - 35, - 36, - 38, - 42, - 44, - 45, - 47, - 48, - 49, - 50, - 51, - 52, - 55, - 56, - 57, - ], - [ - 33, - -44, - -21, - -9, - -43, - -40, - -32, - -10, - -11, - -12, - -13, - -14, - 33, - -36, - -42, - 33, - -8, - -39, - -38, - -31, - -30, - -35, - -34, - 48, - -41, - 48, - -37, - -29, - -33, - ], - ), - "RPARENS": ([8, 9, 14, 34, 35, 51], [35, -44, -43, 51, -42, -41]), - "AND": ([16, 19, 41, 54], [40, -28, -27, -26]), - "RANGLE": ([20, 21, 42, 43, 44, 55], [44, -40, -39, 55, -38, -37]), - "RCURLY": ([25, 26, 45, 46, 47, 56], [47, -32, -31, 56, -30, -29]), -} - -_lr_action = {} -for _k, _v in _lr_action_items.items(): - for _x, _y in zip(_v[0], _v[1]): - if not _x in _lr_action: - _lr_action[_x] = {} - _lr_action[_x][_k] = _y -del _lr_action_items - -_lr_goto_items = { - "enzyme": ([0], [1]), - "comment": ([1, 4, 5, 6, 8], [3, 17, 23, 29, 34]), - "protein_entry": ([1], [4]), - "reference_entry": ([1], [5]), - "entry": ([1], [6]), - "accession": ([4], [16]), - "citations": ([4, 6, 20, 37], [18, 31, 43, 53]), - "special": ([5, 6, 25], [24, 30, 46]), - "proteins": ([6, 32, 36, 49], [28, 50, 52, 50]), - "new_protein": ([10], [36]), - "new_reference": ([11], [37]), - "new_entry": ([12], [38]), - "new_enzyme": ([13], [39]), -} - -_lr_goto = {} -for _k, _v in _lr_goto_items.items(): - for _x, _y in zip(_v[0], _v[1]): - if not _x in _lr_goto: - _lr_goto[_x] = {} - _lr_goto[_x][_k] = _y -del _lr_goto_items -_lr_productions = [ - ("S' -> enzyme", "S'", 1, None, None, None), - ( - "enzyme -> ENZYME_ENTRY EC_NUMBER new_enzyme", - "enzyme", - 3, - "p_enzyme", - "parser.py", - 141, - ), - ( - "new_enzyme -> ", - "new_enzyme", - 0, - "p_new_enzyme", - "parser.py", - 145, - ), - ( - "enzyme -> enzyme comment", - "enzyme", - 2, - "p_enzyme_comment", - "parser.py", - 151, - ), - ( - "enzyme -> enzyme protein_entry", - "enzyme", - 2, - "p_enzyme_protein", - "parser.py", - 157, - ), - ( - "enzyme -> enzyme reference_entry", - "enzyme", - 2, - "p_enzyme_reference", - "parser.py", - 162, - ), - ("enzyme -> enzyme entry", "enzyme", 2, "p_enzyme_entry", "parser.py", 167), - ("enzyme -> enzyme END", "enzyme", 2, "p_enzyme_end", "parser.py", 173), - ("entry -> ENTRY new_entry", "entry", 2, "p_entry", "parser.py", 178), - ("new_entry -> ", "new_entry", 0, "p_new_entry", "parser.py", 183), - ("entry -> entry CONTENT", "entry", 2, "p_entry_content", "parser.py", 190), - ( - "entry -> entry proteins", - "entry", - 2, - "p_entry_proteins", - "parser.py", - 196, - ), - ("entry -> entry comment", "entry", 2, "p_entry_comment", "parser.py", 202), - ("entry -> entry special", "entry", 2, "p_entry_special", "parser.py", 208), - ( - "entry -> entry citations", - "entry", - 2, - "p_entry_citations", - "parser.py", - 214, - ), - ( - "reference_entry -> REFERENCE_ENTRY new_reference citations", - "reference_entry", - 3, - "p_reference_entry", - "parser.py", - 220, - ), - ( - "new_reference -> ", - "new_reference", - 0, - "p_new_reference", - "parser.py", - 226, - ), - ( - "reference_entry -> reference_entry CONTENT", - "reference_entry", - 2, - "p_reference_content", - "parser.py", - 234, - ), - ( - "reference_entry -> reference_entry comment", - "reference_entry", - 2, - "p_reference_year", - "parser.py", - 240, - ), - ( - "reference_entry -> reference_entry special", - "reference_entry", - 2, - "p_reference_pubmed", - "parser.py", - 246, - ), - ( - "protein_entry -> PROTEIN_ENTRY new_protein proteins", - "protein_entry", - 3, - "p_protein_entry", - "parser.py", - 254, - ), - ( - "new_protein -> ", - "new_protein", - 0, - "p_new_protein", - "parser.py", - 260, - ), - ( - "protein_entry -> protein_entry CONTENT", - "protein_entry", - 2, - "p_protein_organism", - "parser.py", - 268, - ), - ( - "protein_entry -> protein_entry accession", - "protein_entry", - 2, - "p_protein_accession", - "parser.py", - 275, - ), - ( - "protein_entry -> protein_entry comment", - "protein_entry", - 2, - "p_protein_comment", - "parser.py", - 280, - ), - ( - "protein_entry -> protein_entry citations", - "protein_entry", - 2, - "p_protein_citations", - "parser.py", - 286, - ), - ( - "accession -> accession AND ACCESSION", - "accession", - 3, - "p_accession_combine", - "parser.py", - 292, - ), - ( - "accession -> accession CONTENT", - "accession", - 2, - "p_accession_database", - "parser.py", - 297, - ), - ("accession -> ACCESSION", "accession", 1, "p_accession", "parser.py", 302), - ( - "special -> LCURLY special RCURLY", - "special", - 3, - "p_special", - "parser.py", - 306, - ), - ( - "special -> LCURLY RCURLY", - "special", - 2, - "p_special_empty", - "parser.py", - 310, - ), - ( - "special -> special SPECIAL", - "special", - 2, - "p_special_combine", - "parser.py", - 314, - ), - ("special -> SPECIAL", "special", 1, "p_special_end", "parser.py", 318), - ( - "proteins -> POUND proteins POUND", - "proteins", - 3, - "p_proteins", - "parser.py", - 322, - ), - ( - "proteins -> POUND POUND", - "proteins", - 2, - "p_proteins_empty", - "parser.py", - 326, - ), - ( - "proteins -> proteins PROTEIN", - "proteins", - 2, - "p_proteins_combine", - "parser.py", - 330, - ), - ("proteins -> PROTEIN", "proteins", 1, "p_proteins_end", "parser.py", 335), - ( - "citations -> LANGLE citations RANGLE", - "citations", - 3, - "p_citations", - "parser.py", - 339, - ), - ( - "citations -> LANGLE RANGLE", - "citations", - 2, - "p_citations_empty", - "parser.py", - 343, - ), - ( - "citations -> citations CITATION", - "citations", - 2, - "p_citations_combine", - "parser.py", - 347, - ), - ( - "citations -> CITATION", - "citations", - 1, - "p_citations_end", - "parser.py", - 352, - ), - ( - "comment -> LPARENS comment RPARENS", - "comment", - 3, - "p_comment", - "parser.py", - 356, - ), - ( - "comment -> LPARENS RPARENS", - "comment", - 2, - "p_comment_empty", - "parser.py", - 360, - ), - ( - "comment -> comment COMMENT", - "comment", - 2, - "p_comment_combine", - "parser.py", - 364, - ), - ("comment -> COMMENT", "comment", 1, "p_comment_end", "parser.py", 369), -]