From 81e30d44989ff73b053ab59ddbe665c9d8358a3d Mon Sep 17 00:00:00 2001 From: js2264 Date: Wed, 31 Jul 2024 14:49:54 +0200 Subject: [PATCH] ci: fix doc --- .github/workflows/ci.yml | 24 +++++++++++ .github/workflows/doc.yml | 38 ----------------- .gitignore | 6 ++- docs/Makefile | 29 +++---------- docs/source/conf.py | 8 ++-- docs/source/index.rst | 2 +- pyproject.toml | 4 +- src/momics/__init__.py | 2 +- src/momics/api.py | 87 --------------------------------------- src/momics/utils.py | 27 ++++++++++++ tests/test_main.py | 6 +-- 11 files changed, 72 insertions(+), 161 deletions(-) delete mode 100644 .github/workflows/doc.yml delete mode 100644 src/momics/api.py create mode 100644 src/momics/utils.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28ea098..0ebfba0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ devel ] +permissions: + contents: write + jobs: Test: @@ -31,6 +34,11 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install package and dependencies on ${{ matrix.os }} + run: | + python -m pip install --upgrade pip + pip install -e .[dev] + - name: Run tests on ${{ matrix.os }} run: | python -m pip install --upgrade pip @@ -38,3 +46,19 @@ jobs: # stop the build if there are Python syntax errors or undefined names ruff check . --select=E9,F63,F7,F82 pytest + + - name: Buid Sphinx doc on ${{ matrix.os }} + if: runner.os == 'Linux' && ${{ github.event_name == 'push' && github.ref == 'refs/heads/devel' }} && ${{ matrix.python-version == '3.12'}} + run: | + sudo apt-get update && sudo apt-get -y install make + pip install -e .[dev,docs] + make -C docs html + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v4 + if: runner.os == 'Linux' && ${{ github.event_name == 'push' && github.ref == 'refs/heads/devel' }} && ${{ matrix.python-version == '3.12'}} + with: + publish_branch: gh-pages + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: docs/build/html + force_orphan: true diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml deleted file mode 100644 index 7c84366..0000000 --- a/.github/workflows/doc.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Build documentation - -on: [push, pull_request, workflow_dispatch] - -permissions: - contents: write - -jobs: - docs: - runs-on: ubuntu-latest - steps: - - - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - with: - python-version: 3.12 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -e .[dev,docs] - # stop the build if there are Python syntax errors or undefined names - ruff check . --select=E9,F63,F7,F82 - pytest - - - name: Sphinx build - run: | - sphinx-build docs/source/ docs/build - - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v4 - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/devel' }} - with: - publish_branch: gh-pages - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: docs/build/ - force_orphan: true diff --git a/.gitignore b/.gitignore index 8d3d828..4488788 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ __pycache__ .coverage.* coverage.xml htmlcov/ +tiledb/ # setup and build artifacts docs/_* @@ -31,6 +32,7 @@ venv/ .Trashes ehthumbs.db Thumbs.db - tmp/ -_scratch/ \ No newline at end of file +_scratch/ +.vscode +example.py diff --git a/docs/Makefile b/docs/Makefile index 43a0c52..334833c 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -4,8 +4,9 @@ # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build -PAPER = -BUILDDIR = _build +PAPER = a4 +SOURCEDIR = source +BUILDDIR = build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) @@ -15,11 +16,11 @@ endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(SOURCEDIR) # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . -.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext help: @echo "Please use \`make ' where is one of" @@ -29,9 +30,7 @@ help: @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" - @echo " qthelp to make HTML files and a qthelp project" @echo " applehelp to make an Apple Help Book" - @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @@ -82,15 +81,6 @@ htmlhelp: @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." -qthelp: - $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp - @echo - @echo "Build finished; now you can run "qcollectiongenerator" with the" \ - ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/cooler.qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/cooler.qhc" - applehelp: $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp @echo @@ -99,15 +89,6 @@ applehelp: "~/Library/Documentation/Help or install it in your application" \ "bundle." -devhelp: - $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp - @echo - @echo "Build finished." - @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/cooler" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/cooler" - @echo "# devhelp" - epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo diff --git a/docs/source/conf.py b/docs/source/conf.py index e46d426..be365b2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -31,7 +31,7 @@ "sphinx.ext.ifconfig", "sphinx.ext.viewcode", "sphinx.ext.autosummary", - "sphinx.ext.napoleon", + "sphinx.ext.napoleon", "recommonmark", ] @@ -39,7 +39,7 @@ napoleon_use_rtype = False autodoc_typehints = "description" autodoc_class_signature = "separated" -templates_path = ['_templates'] +templates_path = ["_templates"] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] source_suffix = { ".rst": "restructuredtext", @@ -52,8 +52,8 @@ # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = 'alabaster' -html_static_path = ['_static'] +html_theme = "furo" +html_static_path = ["_static"] htmlhelp_basename = "momicsdoc" # -- Options for manual page output --------------------------------------- diff --git a/docs/source/index.rst b/docs/source/index.rst index 796b97c..9ea9306 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -15,7 +15,7 @@ The `momics` package aims to facilitate: * Scalable: cloud-native, out-of-core operations on the data; * Export: data export. -Follow cooler development on `GitHub `_. +Follow `momics` development on `GitHub `_. Contents: diff --git a/pyproject.toml b/pyproject.toml index 69fbbbf..941075c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,9 +28,11 @@ classifiers = [ ] dependencies = [ "tiledb", + "libtiledb-sql-py", "pyBigWig", "numpy", - "pandas" + "pandas", + "pyarrow>=1.0", ] [project.urls] diff --git a/src/momics/__init__.py b/src/momics/__init__.py index 2c97e2e..951e2eb 100644 --- a/src/momics/__init__.py +++ b/src/momics/__init__.py @@ -10,7 +10,7 @@ """ from ._version import __format_version__, __version__ -from .api import Momics +from .Momics import Momics __all__ = [ "__version__", diff --git a/src/momics/api.py b/src/momics/api.py deleted file mode 100644 index 68e75d0..0000000 --- a/src/momics/api.py +++ /dev/null @@ -1,87 +0,0 @@ -import os -import tiledb -import numpy as np -import pandas as pd - -__all__ = ["Momics"] - -class Momics: - """ - A convenient interface to a momics data collection. - - Parameters - ---------- - store : str, Path to a momics file (URI string) - kwargs : Options passed to methods. - - Notes - ----- - If ``store`` is a file path, the file will be opened temporarily in - when performing operations. This allows :py:class:`Momics` objects to be - serialized for multiprocess and distributed computations. - - Table selectors, created using :py:meth:`genome`, :py:meth:`scores`, and - :py:meth:`intervals`, perform range queries over table rows, - returning :py:class:`pd.DataFrame`, :py:class:`pd.Series` or - :py:class:`numpy.ndarray` - - Metadata is accessible as a dictionary through the :py:attr:`info` - property. - - """ - - def __init__(self, store: str): - self._refresh() - - def _refresh(self) -> None: - try: - None - except KeyError: - raise KeyError("err_msg") from None - - def genome(self, **kwargs): - """Genome array selector - - Returns - ------- - Array - - """ - - return self - - def scores(self, **kwargs): - """Scores array selector - - Returns - ------- - Array - - """ - - return self - - def intervals(self, **kwargs): - """Intervals array selector - - Returns - ------- - Array - - """ - - return self - - # @property - # def info(self) -> dict: - # """File information and metadata - # - # Returns - # ------- - # dict - # - # """ - # with open_hdf5(self.store, **self.open_kws) as h5: - # grp = h5[self.root] - # return info(grp) - diff --git a/src/momics/utils.py b/src/momics/utils.py new file mode 100644 index 0000000..0414e97 --- /dev/null +++ b/src/momics/utils.py @@ -0,0 +1,27 @@ +import os +import shutil +import pyBigWig +import numpy as np + + +def get_chr_lengths(bw): + with pyBigWig.open(bw) as bw: + {chrom: length for chrom, length in bw.chroms().items()} + + +def _check_chr_lengths(bw_files): + reference_lengths = {} + with pyBigWig.open(list(bw_files.values())[0]) as bw: + reference_lengths = {chrom: length for chrom, length in bw.chroms().items()} + + # Compare chromosome lengths with other files + for file in list(bw_files.values())[1:]: + with pyBigWig.open(file) as bw: + lengths = {chrom: length for chrom, length in bw.chroms().items()} + if lengths != reference_lengths: + raise Exception( + "Provided .bw files do not have identical chromomosome lengths." + ) + + # return np.array(list(reference_lengths.values()), dtype=np.int64) + return reference_lengths diff --git a/tests/test_main.py b/tests/test_main.py index d9b1c88..78492f2 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -5,14 +5,14 @@ import pytest import momics -from momics import api testdir = os.path.dirname(os.path.realpath(__file__)) + @pytest.mark.parametrize( "file_path", [(os.path.join(testdir, "data", "test.momics"))], ) def test_api(file_path): - clr = momics.api.Momics(file_path) - print(clr) + mom = momics.Momics(file_path) + print(mom)