Giter Club home page Giter Club logo

fastobo-py's Introduction

fastobo-py Star me

Faultless AST for Open Biomedical Ontologies in Python.

Actions Codecov License Source PyPI Wheel Bioconda Python Versions PyPI - Implementation Changelog Documentation GitHub issues DOI Downloads

Overview

fastobo is a Rust library implementing a reliable parser for the OBO file format 1.4. This extension module exports idiomatic Python bindings that can be used to load, edit and serialize ontologies in the OBO format.

Installation

If your platform has no pre-built binaries available, you will need to have the Rust compiler installed. See the documentation on rust-lang.org to learn how to install Rust on your machine.

Installation is then supported through pip:

$ pip install fastobo --user

Usage

An OboDoc instance can be instantiated from a path or from a binary file handle using the fastobo.load function, or from a string using the fastobo.loads function.

import fastobo
obodoc = fastobo.load("../data/ms.obo")

Loading from a gzip file is supported:

import fastobo
import gzip
gzdoc = fastobo.load(gzip.open("../data/cl.obo.gz"))

Comments can be parsed but neither edited nor serialized, because of a limitation with pyo3 (the library used to generate the Python bindings). They are supported in the Rust version of fastobo.

Feedback

Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker of the project if you need to report or ask something. If you are filling in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.

The following people have contributed to this project:

About

This project was developed by Martin Larralde as part of a Master's Degree internship in the BBOP team of the Lawrence Berkeley National Laboratory, under the supervision of Chris Mungall. Cite this project as:

Larralde M. Developing Python and Rust libraries to improve the ontology ecosystem [version 1; not peer reviewed]. F1000Research 2019, 8(ISCB Comm J):1500 (poster) (https://doi.org/10.7490/f1000research.1117405.1)

fastobo-py's People

Contributors

alexhenrie avatar althonos avatar dependabot-preview[bot] avatar imgbot[bot] avatar odidev avatar pkalita-lbl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fastobo-py's Issues

Installation fails on older Mac OSX versions

Hello, thank you for building this tool! Our cellxgene application depends on fastobo, and we're running into issues when our users are attempting to install cellxgene on old versions of OS X (e.g. 10.12). That version does not ship with a rust compiler, so our installation fails.

Would you be able to build wheels for older versions of OSX? We believe that should solve the issue we're seeing. The pypi standard appears to be to support versions from 10.9 to present.

Thanks!

cc @mckinsel @maniarathi

Exception "expected QuotedString/XrefList" when loading .obo files

Hello,

First of all, thanks for this very useful library. I've been running into a similar problem parsing some publicly available .obo files, where parsing crashes with the exception SyntaxError: expected QuotedString or a similar variation.

An example is the most recent version of the Cell Ontology (CL). I try to load it as follows:

from urllib.request import urlopen
fastobo.load(urlopen('http://purl.obolibrary.org/obo/cl.obo')) 

This results in:

  File "<stdin>", line 31344
    xref: xref (ILX:0770149)␊
               ^
SyntaxError: expected EOL or QuotedString

Similar errors occur when attempting to parse e.g. the following ontologies:

I'm not super familiar with the .obo format so it may be these files break the standard somehow. Still, it would be great to e.g. have an option to skip the unrecognized data without crashing. Also, if I'm doing something wrong myself, please let me know :)

I'm running the latest fastobo release (0.9.3) on Python 3.6 and Ubuntu Linux. If you need any further information, please let me know.

Install fails on Python 3.11

Overview

I am trying to pip install on Python 3.11, but I get an error.

System

  • OS: MacOS 11.4
  • Architecture: x64
  • Python: 3.11

Error

Short error

ERROR: Failed building wheel for fastobo

Log

/Library/Frameworks/Python.framework/Versions/3.11/bin/python3 -m pip install fastobo -vv:
pipfail.txt

Issue pip installing fastobo (specifically fastobo-graphs)

I am on macOS 12.6 (x86_64) and using Python3.10

I already have rustc, but I am using 1.66-nightly.

Perhaps the macro invocation needs ::crate:: in front of it?

Or add a #[macro_export] above the macro?

     Compiling fastobo-graphs v0.3.0
       Running `/usr/local/bin/sccache rustc --crate-name fastobo_graphs --edition=2018 /Users/msamdars/.cargo/registry/src/github.com-1ecc6299db9ec823/fastobo-graphs-0.3.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="fastobo"' --cfg 'feature="mashup"' --cfg 'feature="obo"' -C metadata=b6e87cfe9da4aa65 -C extra-filename=-b6e87cfe9da4aa65 --out-dir /private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps -L dependency=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps --extern err_derive=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/liberr_derive-90d7d323a2fba856.dylib --extern fastobo=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libfastobo-67b48d7a2d770f06.rmeta --extern mashup=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libmashup-8d6d497e1fe25d20.rmeta --extern serde=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libserde-4abdf1ef08c39e1a.rmeta --extern serde_json=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libserde_json-2c41120a5d468e9c.rmeta --extern serde_yaml=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libserde_yaml-c94f899ad84a011d.rmeta --cap-lints allow`
  error: proc-macro derive panicked
    --> /Users/msamdars/.cargo/registry/src/github.com-1ecc6299db9ec823/fastobo-graphs-0.3.0/src/from_graph/entity.rs:82:17
     |
  82 |                 impl_frame_inner!(node, id, ClassIdent, Term)
     |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: message: assertion failed: source.starts_with(prefix)
     = note: this error originates in the macro `mashup_macro` which comes from the expansion of the macro `impl_frame_inner` (in Nightly builds, run with -Z macro-backtrace for more info)
  
  error: proc-macro derive panicked
    --> /Users/msamdars/.cargo/registry/src/github.com-1ecc6299db9ec823/fastobo-graphs-0.3.0/src/from_graph/entity.rs:85:17
     |
  85 |                 impl_frame_inner!(node, id, InstanceIdent, Instance)
     |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: message: assertion failed: source.starts_with(prefix)
     = note: this error originates in the macro `mashup_macro` which comes from the expansion of the macro `impl_frame_inner` (in Nightly builds, run with -Z macro-backtrace for more info)
  
  error: proc-macro derive panicked
    --> /Users/msamdars/.cargo/registry/src/github.com-1ecc6299db9ec823/fastobo-graphs-0.3.0/src/from_graph/entity.rs:89:23
     |
  89 |                 match impl_frame_inner!(node, id, RelationIdent, Typedef) {
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: message: assertion failed: source.starts_with(prefix)
     = note: this error originates in the macro `mashup_macro` which comes from the expansion of the macro `impl_frame_inner` (in Nightly builds, run with -Z macro-backtrace for more info)
  
  error: cannot find macro `m` in this scope
    --> /Users/msamdars/.cargo/registry/src/github.com-1ecc6299db9ec823/fastobo-graphs-0.3.0/src/from_graph/entity.rs:61:9
     |
  61 |         m! {
     |         ^
  ...
  82 |                 impl_frame_inner!(node, id, ClassIdent, Term)
     |                 --------------------------------------------- in this macro invocation
     |
     = note: this error originates in the macro `impl_frame_inner` (in Nightly builds, run with -Z macro-backtrace for more info)
  
  error: cannot find macro `m` in this scope
    --> /Users/msamdars/.cargo/registry/src/github.com-1ecc6299db9ec823/fastobo-graphs-0.3.0/src/from_graph/entity.rs:61:9
     |
  61 |         m! {
     |         ^
  ...
  85 |                 impl_frame_inner!(node, id, InstanceIdent, Instance)
     |                 ---------------------------------------------------- in this macro invocation
     |
     = note: this error originates in the macro `impl_frame_inner` (in Nightly builds, run with -Z macro-backtrace for more info)
  
  error: cannot find macro `m` in this scope
    --> /Users/msamdars/.cargo/registry/src/github.com-1ecc6299db9ec823/fastobo-graphs-0.3.0/src/from_graph/entity.rs:61:9
     |
  61 |         m! {
     |         ^
  ...
  89 |                 match impl_frame_inner!(node, id, RelationIdent, Typedef) {
     |                       --------------------------------------------------- in this macro invocation
     |
     = note: this error originates in the macro `impl_frame_inner` (in Nightly builds, run with -Z macro-backtrace for more info)
  
  error: could not compile `fastobo-graphs` due to 6 previous errors
  
  Caused by:
    process didn't exit successfully: `/usr/local/bin/sccache rustc --crate-name fastobo_graphs --edition=2018 /Users/msamdars/.cargo/registry/src/github.com-1ecc6299db9ec823/fastobo-graphs-0.3.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="fastobo"' --cfg 'feature="mashup"' --cfg 'feature="obo"' -C metadata=b6e87cfe9da4aa65 -C extra-filename=-b6e87cfe9da4aa65 --out-dir /private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps -L dependency=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps --extern err_derive=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/liberr_derive-90d7d323a2fba856.dylib --extern fastobo=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libfastobo-67b48d7a2d770f06.rmeta --extern mashup=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libmashup-8d6d497e1fe25d20.rmeta --extern serde=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libserde-4abdf1ef08c39e1a.rmeta --extern serde_json=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libserde_json-2c41120a5d468e9c.rmeta --extern serde_yaml=/private/var/folders/6h/5wpwnt3n70d_3zlpr7vbj3rc0000gn/T/pip-install-c0_bdfp5/fastobo_144ce1c226d74f61b766623c9e7f2f4d/target/release/deps/libserde_yaml-c94f899ad84a011d.rmeta --cap-lints allow` (exit status: 1)
  error: `cargo rustc --lib --message-format=json-render-diagnostics --manifest-path Cargo.toml --release -v --features 'pyo3/extension-module extension-module' -- --crate-type cdylib -C 'link-args=-undefined dynamic_lookup -Wl,-install_name,@rpath/fastobo.cpython-310-darwin.so'` failed with code 101

Error when installing via oaklib: subprocess-exited-with-error

I tried installing oak versions 0.1.32-0.1.36 and got this error for each.

Collecting fastobo~=0.12.1
  Using cached fastobo-0.12.1.tar.gz (20.1 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [20 lines of output]
      Traceback (most recent call last):
        File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/opt/homebrew/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/build_meta.py", line 177, in get_requires_for_build_wheel
          return self._get_build_requires(
        File "/opt/homebrew/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/build_meta.py", line 159, in _get_build_requires
          self.run_setup()
        File "/opt/homebrew/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/build_meta.py", line 174, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 13, in <module>
          import setuptools_rust as rust
        File "/private/var/folders/tt/t62pcpnn5bvbgf27x_pj70kr0000gp/T/pip-build-env-lsx2rjf7/overlay/lib/python3.9/site-packages/setuptools_rust/__init__.py", line 1, in <module>
          from .build import build_rust
        File "/private/var/folders/tt/t62pcpnn5bvbgf27x_pj70kr0000gp/T/pip-build-env-lsx2rjf7/overlay/lib/python3.9/site-packages/setuptools_rust/build.py", line 23, in <module>
          from setuptools.command.build import build as CommandBuild  # type: ignore[import]
      ModuleNotFoundError: No module named 'setuptools.command.build'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

I could solve the problem installing setuptools using the command line python3 -m pip install --upgrade pip setuptools wheel.
However, Chris Mungall asked to create this issue so OAK would be easier to install.

Failed to install fastobo in new virtual environment

I set up a fresh virtual environment (with Python 3.9) and attempted to install fastobo. In an empty directory:

python -m venv .venv
source .venv/bin/activate
pip install fastobo

This leads to an error message containing:

        File "setup.py", line 16, in <module>
          from setuptools_rust.utils import get_rust_version
      ModuleNotFoundError: No module named 'setuptools_rust.utils'

It looks like v1.4.0 of setuptools-rust made the utils module private and moved the get_rust_version function elsewhere.

Add support to release aarch64 wheels

Problem

On aarch64, ‘pip install fastobo’ build the wheels from source code and then installs it. It requires the user to have a development environment installed on his system. Also, it takes more time to build the wheels than downloading and extracting the wheels from PyPi.

Resolution

On aarch64, ‘pip install fastobo’ should download the wheels from PyPi

@althonos, Please let me know your interest in releasing aarch64 wheels. I can help with this.

ImportError on Mac M1 architecture

Trying fastobo in the Mac M1 results in the following errors:

Python 3.10.4 (main, Apr 26 2022, 19:36:29) [Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastobo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/utkarshchaurasia/Documents/Projects/venvpy/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so, 0x0002): tried: '/Users/utkarshchaurasia/Documents/Projects/venvpy/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/fastobo.cpython-310-darwin.so' (no such file), '/usr/lib/fastobo.cpython-310-darwin.so' (no such file)

@UtkarshChaurasia Have a look.

Add an arm64.whl for fastobo to pypi releases

Currently I am trying to combine ensmallen and fastobo in one package (oakx-grape) on an M1 Mac

Using ensmallen 0.8.28, which has an arm64.whl
https://pypi.org/project/ensmallen/0.8.28/#files

I don't see an equivalent for fastobo

This results in:

  File "/Users/cjm/Library/Caches/pypoetry/virtualenvs/oakx-grape-pUaGkv-X-py3.9/lib/python3.9/site-packages/pronto/xref.py", line 6, in <module>
    import fastobo
ImportError: dlopen(/Users/cjm/Library/Caches/pypoetry/virtualenvs/oakx-grape-pUaGkv-X-py3.9/lib/python3.9/site-packages/fastobo.cpython-39-darwin.so, 0x0002): tried: '/Users/cjm/Library/Caches/pypoetry/virtualenvs/oakx-grape-pUaGkv-X-py3.9/lib/python3.9/site-packages/fastobo.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

AFAICT I can't use ensmallen in x86 mode (cc @justaddcoffee) so I seem to be stuck here

I've been told that building arm wheels automatically as part of CI is hard, but I found this, don't know how hard this would be to integrate:

https://github.com/pypa/cibuildwheel

Support for a "contains" TermClause

When loading the PSI-MOD.obo ontology, the following error is raised:

>>> obo_mod = fastobo.load("PSI-MOD.obo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5923
    contains: MOD:02026 ! S-(cysteinyl-glycyl)-L-cysteine␊
    ^
SyntaxError: expected EOI or TermClause

Seems like fastobo-py does not recognize the contains term. Can this term be added to the supported TermClauses, or is there a way for me to add support for it within my project?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.