-
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.
Implement readers and writers for
MultiAssayExperiment
with the new…
… takane specification (#1) * Implement the savers and loaders * Add tests, documentation * Update README
- Loading branch information
Showing
13 changed files
with
557 additions
and
190 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@v2 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
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,37 @@ | ||
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@v2 | ||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
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 |
---|---|---|
|
@@ -2,6 +2,3 @@ | |
|
||
## Version 0.1 (development) | ||
|
||
- Feature A added | ||
- FIX: nasty bug #1729 fixed | ||
- add your changes here! |
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
# sphinx_rtd_theme | ||
myst-parser[linkify] | ||
sphinx>=3.2.1 | ||
furo | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,17 @@ | |
|
||
[metadata] | ||
name = dolomite-mae | ||
description = Add a short description here! | ||
description = Save and load multi-assay experiments in the dolomite framework! | ||
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/ArtifactDB/dolomite-mae | ||
# Add here related links, for example: | ||
project_urls = | ||
Documentation = https://pyscaffold.org/ | ||
Documentation = https://github.com/ArtifactDB/dolomite-mae | ||
# Source = https://github.com/pyscaffold/pyscaffold/ | ||
# Changelog = https://pyscaffold.org/en/latest/changelog.html | ||
# Tracker = https://github.com/pyscaffold/pyscaffold/issues | ||
|
@@ -41,15 +41,21 @@ 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" | ||
|
||
dolomite_base==0.2.0-alpha6 | ||
dolomite_sce==0.1.0-alpha | ||
dolomite_se==0.1.0-alpha2 | ||
multiassayexperiment>=0.4.2,<0.5.0 | ||
biocutils | ||
pandas | ||
numpy | ||
|
||
[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
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,101 @@ | ||
import json | ||
import os | ||
|
||
import dolomite_base as dl | ||
import h5py | ||
from biocframe import BiocFrame | ||
from dolomite_base.read_object import read_object_registry | ||
from multiassayexperiment import MultiAssayExperiment | ||
|
||
read_object_registry[ | ||
"multi_sample_dataset" | ||
] = "dolomite_mae.read_multi_assay_experiment" | ||
|
||
|
||
def read_multi_assay_experiment( | ||
path: str, metadata: dict, **kwargs | ||
) -> MultiAssayExperiment: | ||
"""Load a | ||
:py:class:`~multiassayexperiment.MultiAssayExperiment.MultiAssayExperiment` | ||
from its on-disk representation. | ||
This method should generally not be called directly but instead be invoked by | ||
:py:meth:`~dolomite_base.read_object.read_object`. | ||
Args: | ||
path: | ||
Path to the directory containing the object. | ||
metadata: | ||
Metadata for the object. | ||
kwargs: | ||
Further arguments, ignored. | ||
Returns: | ||
A | ||
:py:class:`~multiassayexperiment.MultiAssayExperiment.MultiAssayExperiment` | ||
with file-backed arrays in the assays. | ||
""" | ||
|
||
_sample_path = os.path.join(path, "sample_data") | ||
_sample_data = None | ||
if os.path.exists(_sample_path): | ||
_sample_data = dl.read_object(_sample_path) | ||
|
||
if _sample_data is None: | ||
raise RuntimeError("Cannot read 'sample_data'.") | ||
|
||
_srow_names = _sample_data.get_row_names() | ||
if _srow_names is None: | ||
raise RuntimeError("'sample_data' does not contain 'row_names'.") | ||
|
||
_expts_path = os.path.join(path, "experiments") | ||
_expts = {} | ||
_expt_names = [] | ||
_sample_map_data = None | ||
if os.path.exists(_expts_path): | ||
with open(os.path.join(_expts_path, "names.json"), "r") as handle: | ||
_expt_names = json.load(handle) | ||
|
||
if len(_expt_names) > 0: | ||
_sample_map_path = os.path.join(path, "sample_map.h5") | ||
_shandle = h5py.File(_sample_map_path, "r") | ||
_sghandle = _shandle["multi_sample_dataset"] | ||
_primary = [] | ||
_assay = [] | ||
_colname = [] | ||
|
||
for _aidx, _aname in enumerate(_expt_names): | ||
_expt_read_path = os.path.join(_expts_path, str(_aidx)) | ||
|
||
try: | ||
_expts[_aname] = dl.read_object(_expt_read_path) | ||
except Exception as ex: | ||
raise RuntimeError( | ||
f"failed to load experiment '{_aname}' from '{path}'; " | ||
+ str(ex) | ||
) | ||
|
||
_expt_map = dl.load_vector_from_hdf5( | ||
_sghandle[str(_aidx)], expected_type=int, report_1darray=True | ||
) | ||
|
||
_assay.extend([_aname] * _expts[_aname].shape[1]) | ||
_colname.extend(_expts[_aname].get_column_names()) | ||
_primary.extend([_srow_names[i] for i in _expt_map]) | ||
|
||
_sample_map_data = BiocFrame( | ||
{"primary": _primary, "colname": _colname, "assay": _assay} | ||
) | ||
|
||
mae = MultiAssayExperiment( | ||
experiments=_expts, column_data=_sample_data, sample_map=_sample_map_data | ||
) | ||
|
||
_meta_path = os.path.join(path, "other_data") | ||
if os.path.exists(_meta_path): | ||
_meta = dl.read_object(_meta_path) | ||
mae = mae.set_metadata(_meta.as_dict()) | ||
|
||
return mae |
Oops, something went wrong.