-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
275 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Publish to PyPI | ||
|
||
on: | ||
push: | ||
tags: "*" | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.9 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest tox | ||
# - name: Lint with flake8 | ||
# run: | | ||
# # stop the build if there are Python syntax errors or undefined names | ||
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
# # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with tox | ||
run: | | ||
tox | ||
- name: Build docs | ||
run: | | ||
tox -e docs | ||
- run: touch ./docs/_build/html/.nojekyll | ||
- name: GH Pages Deployment | ||
uses: JamesIves/[email protected] | ||
with: | ||
branch: gh-pages # The branch the action should deploy to. | ||
folder: ./docs/_build/html | ||
clean: true # Automatically remove deleted files from the deploy branch | ||
- name: Build Project and Publish | ||
run: | | ||
python -m tox -e clean,build | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_PASSWORD }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Test the library | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] | ||
|
||
name: Python ${{ matrix.python-version }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: 'pip' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest tox | ||
# - name: Lint with flake8 | ||
# run: | | ||
# # stop the build if there are Python syntax errors or undefined names | ||
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
# # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with tox | ||
run: | | ||
tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
exclude: '^docs/conf.py' | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: check-added-large-files | ||
- id: check-ast | ||
- id: check-json | ||
- id: check-merge-conflict | ||
- id: check-xml | ||
- id: check-yaml | ||
- id: debug-statements | ||
- id: end-of-file-fixer | ||
- id: requirements-txt-fixer | ||
- id: mixed-line-ending | ||
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows | ||
|
||
# - repo: https://github.com/PyCQA/docformatter | ||
# rev: master | ||
# hooks: | ||
# - id: docformatter | ||
# additional_dependencies: [tomli] | ||
# args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120] | ||
# # --config, ./pyproject.toml | ||
|
||
# - repo: https://github.com/psf/black | ||
# rev: 24.8.0 | ||
# hooks: | ||
# - id: black | ||
# language_version: python3 | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.6.8 | ||
hooks: | ||
- id: ruff | ||
args: [--fix, --exit-non-zero-on-fix] | ||
- id: ruff-format | ||
|
||
## If like to embrace black styles even in the docs: | ||
# - repo: https://github.com/asottile/blacken-docs | ||
# rev: v1.13.0 | ||
# hooks: | ||
# - id: blacken-docs | ||
# additional_dependencies: [black] | ||
|
||
## Check for misspells in documentation files: | ||
# - repo: https://github.com/codespell-project/codespell | ||
# rev: v2.2.5 | ||
# hooks: | ||
# - id: codespell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
furo | ||
myst-nb | ||
# Requirements file for ReadTheDocs, check .readthedocs.yml. | ||
# To build the module reference correctly, make sure every external package | ||
# under `install_requires` in `setup.cfg` is also listed here! | ||
# sphinx_rtd_theme | ||
myst-parser[linkify] | ||
sphinx>=3.2.1 | ||
sphinx-autodoc-typehints |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,17 @@ | |
|
||
[metadata] | ||
name = bioRAT | ||
description = Add a short description here! | ||
description = Bioinformatics random utilities and tools. | ||
author = Jayaram Kancherla | ||
author_email = [email protected] | ||
license = MIT | ||
license_files = LICENSE.txt | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown; charset=UTF-8; variant=GFM | ||
url = https://github.com/pyscaffold/pyscaffold/ | ||
url = https://github.com/biocpy/bioRAT | ||
# Add here related links, for example: | ||
project_urls = | ||
Documentation = https://pyscaffold.org/ | ||
Documentation = https://github.com/biocpy/bioRAT | ||
# Source = https://github.com/pyscaffold/pyscaffold/ | ||
# Changelog = https://pyscaffold.org/en/latest/changelog.html | ||
# Tracker = https://github.com/pyscaffold/pyscaffold/issues | ||
|
@@ -41,15 +41,16 @@ package_dir = | |
=src | ||
|
||
# Require a min/specific Python version (comma-separated conditions) | ||
# python_requires = >=3.8 | ||
python_requires = >=3.8 | ||
|
||
# Add here dependencies of your project (line-separated), e.g. requests>=2.2,<3.0. | ||
# Version specifiers like >=2.2,<3.0 avoid problems due to API changes in | ||
# new major versions. This works if the required packages follow Semantic Versioning. | ||
# For more information, check out https://semver.org/. | ||
install_requires = | ||
importlib-metadata; python_version<"3.8" | ||
|
||
owlready2 | ||
pandas | ||
|
||
[options.packages.find] | ||
where = src | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pandas as pd | ||
from owlready2 import ThingClass, get_ontology | ||
|
||
__author__ = "Jayaram Kancherla" | ||
__copyright__ = "Jayaram Kancherla" | ||
__license__ = "MIT" | ||
|
||
# originally published to gist | ||
# https://gist.github.com/jkanche/1f010c38a090cefd8f2f5e21c20fc1b8 | ||
|
||
|
||
def owl_to_dataframe(owl_location: str): | ||
"""Extract nodes and their lineages from ontologies as | ||
:py:class:`~pandas.DataFrame`. | ||
Example: | ||
.. code-block:: python | ||
from biorat.ontology import ( | ||
owl_to_dataframe, | ||
) | ||
result_df = owl_to_dataframe( | ||
"https://github.com/obophenotype/cell-ontology/releases/download/v2024-09-26/cl.owl" | ||
) | ||
print(result_df) | ||
Args: | ||
owl_location: | ||
Location or the URL of the OWL file. | ||
Supports any argument acceepted by | ||
:py:func:`~owlready.get_ontology`. | ||
Returns: | ||
A Pandas DataFrame of the nodes, their labels and lineages. | ||
""" | ||
onto = get_ontology(owl_location).load() | ||
|
||
recs = [] | ||
|
||
# recursively traverse the ontology | ||
def get_lineage(cls): | ||
lineage = [] | ||
for parent in cls.is_a: | ||
if isinstance(parent, ThingClass): | ||
lineage.append((parent.label.first() or parent.name, parent.name)) | ||
lineage.extend(get_lineage(parent)) | ||
return lineage | ||
|
||
# Iterate through all classes in the ontology | ||
for cls in onto.classes(): | ||
rec = {} | ||
|
||
rec["iri"] = cls.iri | ||
rec["term_id"] = cls.name | ||
|
||
# Get the label (use the first label if available, otherwise the class name) | ||
rec["label"] = cls.label.first() or cls.name | ||
|
||
# Get the lineage | ||
lineage_items = get_lineage(cls) | ||
rec["lineage_ids"] = " > ".join(reversed([item[0] for item in lineage_items])) | ||
rec["lineage_labels"] = " > ".join(reversed([item[1] for item in lineage_items])) | ||
|
||
recs.append(rec) | ||
|
||
df = pd.DataFrame(recs) | ||
|
||
return df |
Oops, something went wrong.