Skip to content

Commit

Permalink
Merge branch 'main' into add-federated-queries-test-with-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt authored Dec 11, 2023
2 parents 7b66804 + 094ad63 commit 4dd192c
Show file tree
Hide file tree
Showing 36 changed files with 4,549 additions and 401 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.5.4-dev
current_version = 0.7.5-dev
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?:-(?P<release>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.7", "3.11" ]
python-version: [ "3.8", "3.11" ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.7", "3.11" ]
python-version: [ "3.8", "3.11" ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -57,7 +57,8 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.7", "3.11" ]
python-version: [ "3.8", "3.11" ]
pydantic: [ "1", "2" ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -74,7 +75,10 @@ jobs:
run: pip install tox
- name: Test with pytest and generate coverage file
run:
tox run -e py
tox run -e py-pydantic${{ matrix.pydantic }}
- name: Doctests
run:
tox run -e doctests
- name: Upload coverage report to codecov
uses: codecov/codecov-action@v1
if: success()
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ prune docs/source/api
recursive-include docs/source *.py
recursive-include docs/source *.rst
recursive-include docs/source *.png
recursive-include docs/source *.svg

global-exclude *.py[cod] __pycache__ *.so *.dylib .DS_Store *.gpickle

Expand Down
118 changes: 7 additions & 111 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,131 +44,22 @@
Idiomatic conversion between URIs and compact URIs (CURIEs).

```python
from curies import Converter
import curies

converter = Converter.from_prefix_map({
converter = curies.load_prefix_map({
"CHEBI": "http://purl.obolibrary.org/obo/CHEBI_",
"MONDO": "http://purl.obolibrary.org/obo/MONDO_",
"GO": "http://purl.obolibrary.org/obo/GO_",
# ... and so on
"OBO": "http://purl.obolibrary.org/obo/",
})

>>> converter.compress("http://purl.obolibrary.org/obo/CHEBI_1")
'CHEBI:1'

>>> converter.expand("CHEBI:1")
'http://purl.obolibrary.org/obo/CHEBI_1'

# Unparsable
>>> assert converter.compress("http://example.com/missing:0000000") is None
>>> assert converter.expand("missing:0000000") is None
```

When some URI prefixes are partially overlapping (e.g.,
`http://purl.obolibrary.org/obo/GO_` for `GO` and
`http://purl.obolibrary.org/obo/` for ``OBO``), the longest
URI prefix will always be matched. For example, compressing
`http://purl.obolibrary.org/obo/GO_0032571`
will return `GO:0032571` instead of `OBO:GO_0032571`.

Full documentation is available at [curies.readthedocs.io](https://curies.readthedocs.io).

### Standardization

The `curies.Converter` data structure supports prefix and URI prefix synonyms.
The following exampl demonstrates
using these synonyms to support standardizing prefixes, CURIEs, and URIs. Note below,
the colloquial prefix `gomf`, sometimes used to represent the subspace in the
[Gene Ontology (GO)](https://obofoundry.org/ontology/go) corresponding to molecular
functions, is upgraded to the preferred prefix, `GO`.

```python
from curies import Converter, Record

converter = Converter([
Record(
prefix="GO",
prefix_synonyms=["gomf", "gocc", "gobp", "go", ...],
uri_prefix="http://purl.obolibrary.org/obo/GO_",
uri_prefix_synonyms=[
"http://amigo.geneontology.org/amigo/term/GO:",
"https://identifiers.org/GO:",
...
],
),
# And so on
...
])

>>> converter.standardize_prefix("gomf")
'GO'
>>> converter.standardize_curie('gomf:0032571')
'GO:0032571'
>>> converter.standardize_uri('http://amigo.geneontology.org/amigo/term/GO:0032571')
'http://purl.obolibrary.org/obo/GO_0032571'
```

Note: non-standard URIs can still be parsed with `converter.parse_uri()` and compressed
into CURIEs with `converter.compress()`.

### Loading Prefix Maps

All loader function work on local file paths, remote URLs, and pre-loaded
data structures. For example, a converter can be instantiated from a web-based
resource in JSON-LD format:

```python
from curies import Converter

url = "https://raw.githubusercontent.com/biopragmatics/bioregistry/main/exports/contexts/semweb.context.jsonld"
converter = Converter.from_jsonld(url)
```

Several converters can be instantiated from pre-defined web-based resources:

```python
import curies

# Uses the Bioregistry, an integrative, comprehensive registry
bioregistry_converter = curies.get_bioregistry_converter()

# Uses the OBO Foundry, a registry of ontologies
obo_converter = curies.get_obo_converter()

# Uses the Monarch Initative's project-specific context
monarch_converter = curies.get_monarch_converter()
```

### Bulk Operations

Apply in bulk to a `pandas.DataFrame` with `Converter.pd_expand` and
`Converter.pd_compress`:

```python
import curies
import pandas as pd

df = pd.read_csv(...)
obo_converter = curies.get_obo_converter()
obo_converter.pd_compress(df, column=0)
obo_converter.pd_expand(df, column=0)
```

Apply in bulk to a CSV file with `Converter.file_expand` and
`Converter.file_compress` (defaults to using tab separator):

```python
import curies

path = ...
obo_converter = curies.get_obo_converter()
# modifies file in place
obo_converter.file_compress(path, column=0)
# modifies file in place
obo_converter.file_expand(path, column=0)
```

### CLI Usage

This package comes with a built-in CLI for running a resolver web application or a IRI mapper web application:
Expand Down Expand Up @@ -200,6 +91,7 @@ Other packages that convert between CURIEs and URIs:
- https://github.com/geneontology/curie-util-py (Python)
- https://github.com/geneontology/curie-util-es5 (Node.js)
- https://github.com/endoli/curie.rs (Rust)
- https://github.com/cthoyt/curies4j (Java)

## 🚀 Installation

Expand All @@ -210,6 +102,10 @@ The most recent release can be installed from
$ pip install curies
```

This package currently supports both Pydantic v1 and v2. See the
[Pydantic migration guide](https://docs.pydantic.dev/2.0/migration/)
for updating your code.

## 👐 Contributing

Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See
Expand Down
5 changes: 5 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
API Reference
-------------
.. automodapi:: curies
:no-inheritance-diagram:
:no-heading:
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
author = "Charles Tapley Hoyt"

# The full version, including alpha/beta/rc tags.
release = "0.5.4-dev"
release = "0.7.5-dev"

# The short X.Y version.
parsed_version = re.match(
Expand Down Expand Up @@ -63,7 +63,6 @@
"sphinx.ext.todo",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx_autodoc_typehints",
"sphinx_automodapi.automodapi",
"sphinx_automodapi.smart_resolver",
# 'texext',
Expand Down Expand Up @@ -226,10 +225,11 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"https://docs.python.org/3/": None,
"python": ("https://docs.python.org/3", None),
"bioregistry": ("https://bioregistry.readthedocs.io/en/stable/", None),
"pandas": ("https://pandas.pydata.org/docs/", None),
"flask": ("https://flask.palletsprojects.com/", None),
"pydantic": ("https://docs.pydantic.dev/latest/", None),
# "fastapi": ("https://fastapi.tiangolo.com/", None),
# "gunicorn": ("https://docs.gunicorn.org/", None),
# "uvicorn": ("https://www.uvicorn.org/", None),
Expand Down
Loading

0 comments on commit 4dd192c

Please sign in to comment.