From 4fc6ce16c27afe90c68f0f9f6dd691ee9a4b67e5 Mon Sep 17 00:00:00 2001 From: scverse-bot Date: Tue, 21 May 2024 13:41:54 +0000 Subject: [PATCH 1/5] Update template to v0.4.0 --- .cruft.json | 7 ++-- .github/workflows/release.yaml.rej | 10 ++++++ .github/workflows/test.yaml.rej | 16 +++++++++ .gitignore | 1 + .pre-commit-config.yaml.rej | 34 +++++++++++++++++++ README.md | 2 +- docs/conf.py | 2 +- docs/conf.py.rej | 16 +++++++++ docs/contributing.md | 5 +-- pyproject.toml | 10 +++--- pyproject.toml.rej | 53 ++++++++++++++++++++++++++++++ 11 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/release.yaml.rej create mode 100644 .github/workflows/test.yaml.rej create mode 100644 .pre-commit-config.yaml.rej create mode 100644 docs/conf.py.rej create mode 100644 pyproject.toml.rej diff --git a/.cruft.json b/.cruft.json index 36edd93..e2d3b27 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/scverse/cookiecutter-scverse", - "commit": "8e96abb5c3e2d5078c44713958da672711cf2a48", + "commit": "87a407a65408d75a949c0b54b19fd287475a56f8", "context": { "cookiecutter": { "project_name": "infercnvpy", @@ -12,7 +12,8 @@ "project_repo": "https://github.com/icbi-lab/infercnvpy", "license": "BSD 3-Clause License", "_copy_without_render": [ - ".github/workflows/**.yaml", + ".github/workflows/build.yaml", + ".github/workflows/test.yaml", "docs/_templates/autosummary/**.rst" ], "_render_devdocs": false, @@ -24,5 +25,5 @@ } }, "directory": null, - "checkout": "v0.3.0" + "checkout": "v0.4.0" } diff --git a/.github/workflows/release.yaml.rej b/.github/workflows/release.yaml.rej new file mode 100644 index 0000000..f65d3cd --- /dev/null +++ b/.github/workflows/release.yaml.rej @@ -0,0 +1,10 @@ +diff a/.github/workflows/release.yaml b/.github/workflows/release.yaml (rejected hunks) +@@ -11,7 +11,7 @@ jobs: + runs-on: ubuntu-latest + environment: + name: pypi +- url: https://pypi.org/p/{{ cookiecutter.package_name }} ++ url: https://pypi.org/p/infercnvpy + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + steps: diff --git a/.github/workflows/test.yaml.rej b/.github/workflows/test.yaml.rej new file mode 100644 index 0000000..e165fb8 --- /dev/null +++ b/.github/workflows/test.yaml.rej @@ -0,0 +1,16 @@ +diff a/.github/workflows/test.yaml b/.github/workflows/test.yaml (rejected hunks) +@@ -24,11 +24,11 @@ jobs: + matrix: + include: + - os: ubuntu-latest +- python: "3.9" ++ python: "3.10" + - os: ubuntu-latest +- python: "3.11" ++ python: "3.12" + - os: ubuntu-latest +- python: "3.11" ++ python: "3.12" + pip-flags: "--pre" + name: PRE-RELEASE DEPENDENCIES + diff --git a/.gitignore b/.gitignore index c50520b..7aab72c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ __pycache__/ /.pytest_cache/ /.cache/ /data/ +/node_modules/ # docs /docs/generated/ diff --git a/.pre-commit-config.yaml.rej b/.pre-commit-config.yaml.rej new file mode 100644 index 0000000..5f9ac18 --- /dev/null +++ b/.pre-commit-config.yaml.rej @@ -0,0 +1,34 @@ +diff a/.pre-commit-config.yaml b/.pre-commit-config.yaml (rejected hunks) +@@ -6,29 +6,18 @@ default_stages: + - push + minimum_pre_commit_version: 2.16.0 + repos: +- - repo: https://github.com/psf/black +- rev: "24.4.2" +- hooks: +- - id: black +- - repo: https://github.com/asottile/blacken-docs +- rev: 1.16.0 +- hooks: +- - id: blacken-docs + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 + hooks: + - id: prettier +- # Newer versions of node don't work on systems that have an older version of GLIBC +- # (in particular Ubuntu 18.04 and Centos 7) +- # EOL of Centos 7 is in 2024-06, we can probably get rid of this then. +- # See https://github.com/scverse/cookiecutter-scverse/issues/143 and +- # https://github.com/jupyterlab/jupyterlab/issues/12675 +- language_version: "17.9.1" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.4 + hooks: + - id: ruff ++ types_or: [python, pyi, jupyter] + args: [--fix, --exit-non-zero-on-fix] ++ - id: ruff-format ++ types_or: [python, pyi, jupyter] + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: diff --git a/README.md b/README.md index 4ebb981..e34e4c1 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Please refer to the [documentation][link-docs]. In particular, the ## Installation -You need to have Python 3.9 or newer installed on your system. If you don't have +You need to have Python 3.10 or newer installed on your system. If you don't have Python installed, we recommend installing [Mambaforge](https://github.com/conda-forge/miniforge#mambaforge). There are several alternative options to install infercnvpy: diff --git a/docs/conf.py b/docs/conf.py index 895af36..7c24ab8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,5 @@ # Configuration file for the Sphinx documentation builder. -# + # This file only contains a selection of the most common options. For a full # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html diff --git a/docs/conf.py.rej b/docs/conf.py.rej new file mode 100644 index 0000000..6a707c4 --- /dev/null +++ b/docs/conf.py.rej @@ -0,0 +1,16 @@ +diff a/docs/conf.py b/docs/conf.py (rejected hunks) +@@ -36,10 +36,10 @@ needs_sphinx = "4.0" + + html_context = { + "display_github": True, # Integrate GitHub +- "github_user": "grst", # Username +- "github_repo": project_name, # Repo name +- "github_version": "main", # Version +- "conf_py_path": "/docs/", # Path in the checkout to the docs root ++ "github_user": "grst", ++ "github_repo": "https://github.com/icbi-lab/infercnvpy", ++ "github_version": "main", ++ "conf_py_path": "/docs/", + } + + # -- General configuration --------------------------------------------------- diff --git a/docs/contributing.md b/docs/contributing.md index 4794249..9bbacf1 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -51,7 +51,7 @@ and [prettier][prettier-editors]. ## Writing tests ```{note} -Remember to first install the package with `pip install '-e[dev,test]'` +Remember to first install the package with `pip install -e '.[dev,test]'` ``` This package uses the [pytest][] for automated testing. Please [write tests][scanpy-test-docs] for every function added @@ -93,7 +93,7 @@ Before making a release, you need to update the version number in the `pyproject > Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. Once you are done, commit and push your changes and navigate to the "Releases" page of this project on GitHub. -Specify `vX.X.X` as a tag name and create a release. For more information, see [managing Github releases][]. This will automatically create a git tag and trigger a Github workflow that creates a release on PyPI. +Specify `vX.X.X` as a tag name and create a release. For more information, see [managing GitHub releases][]. This will automatically create a git tag and trigger a Github workflow that creates a release on PyPI. ## Writing documentation @@ -157,3 +157,4 @@ open _build/html/index.html [numpydoc]: https://numpydoc.readthedocs.io/en/latest/format.html [sphinx autodoc typehints]: https://github.com/tox-dev/sphinx-autodoc-typehints [pypi]: https://pypi.org/ +[managing GitHub releases]: https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository diff --git a/pyproject.toml b/pyproject.toml index afd54be..1c86a25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,7 @@ select = [ "RUF100", # Report unused noqa directives ] ignore = [ - # line too long -> we accept long comment lines; black gets rid of long code lines + # line too long -> we accept long comment lines; formatter gets rid of long code lines "E501", # Do not assign a lambda expression, use a def -> lambda expression assignments are convenient "E731", @@ -117,7 +117,7 @@ ignore = [ "D107", # Errors from function calls in argument defaults. These are fine when the result is immutable. "B008", - # __magic__ methods are are often self-explanatory, allow missing docstrings + # __magic__ methods are often self-explanatory, allow missing docstrings "D105", # first line should end with a period [Bug: doesn't work with single-line docstrings] "D400", @@ -130,10 +130,10 @@ ignore = [ "D213", ] -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] convention = "numpy" -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "docs/*" = ["I"] "tests/*" = ["D"] "*/__init__.py" = ["F401"] @@ -147,5 +147,5 @@ skip = [ "docs/changelog.md", "docs/references.bib", "docs/references.md", - "docs/notebooks/example.ipynb" + "docs/notebooks/example.ipynb", ] diff --git a/pyproject.toml.rej b/pyproject.toml.rej new file mode 100644 index 0000000..74b5700 --- /dev/null +++ b/pyproject.toml.rej @@ -0,0 +1,53 @@ +diff a/pyproject.toml b/pyproject.toml (rejected hunks) +@@ -7,7 +7,7 @@ name = "infercnvpy" + version = "0.0.1" + description = "Infer copy number variation (CNV) from scRNA-seq data. Plays nicely with Scanpy. " + readme = "README.md" +-requires-python = ">=3.9" ++requires-python = ">=3.10" + license = {file = "LICENSE"} + authors = [ + {name = "Gregor Sturm"}, +@@ -21,19 +21,19 @@ urls.Home-page = "https://github.com/icbi-lab/infercnvpy" + dependencies = [ + "anndata", + # for debug logging (referenced from the issue template) +- "session-info" ++ "session-info", + ] + + [project.optional-dependencies] + dev = [ + "pre-commit", +- "twine>=4.0.2" ++ "twine>=4.0.2", + ] + doc = [ + "docutils>=0.8,!=0.18.*,!=0.19.*", + "sphinx>=4", + "sphinx-book-theme>=1.0.0", +- "myst-nb", ++ "myst-nb>=1.1.0", + "sphinxcontrib-bibtex>=1.0.0", + "sphinx-autodoc-typehints", + "sphinxext-opengraph", +@@ -61,12 +61,15 @@ addopts = [ + "--import-mode=importlib", # allow using test files with same name + ] + +-[tool.black] +-line-length = 120 +- + [tool.ruff] +-src = ["src"] + line-length = 120 ++src = ["src"] ++extend-include = ["*.ipynb"] ++ ++[tool.ruff.format] ++docstring-code-format = true ++ ++[tool.ruff.lint] + select = [ + "F", # Errors detected by Pyflakes + "E", # Error detected by Pycodestyle From d7233edc75e3ee0f1101879a0f4dcb268243710c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:41:58 +0000 Subject: [PATCH 2/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.3.4 → v0.4.8](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.4...v0.4.8) - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v4.6.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 09806a3..28aa3a8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: # doesn't work in combination with jupytext hook yet. See https://github.com/mwouts/jupytext/issues/580 exclude: "docs/notebooks/.*\\.md" - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.4 + rev: v0.4.8 hooks: - id: ruff types_or: [python, pyi, jupyter] @@ -21,7 +21,7 @@ repos: - id: ruff-format types_or: [python, pyi, jupyter] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: detect-private-key - id: check-ast From 5acc17cc04fbad7a292c9c23953dee9527950432 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Thu, 13 Jun 2024 15:58:38 +0200 Subject: [PATCH 3/5] fix docs --- src/infercnvpy/tl/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/infercnvpy/tl/__init__.py b/src/infercnvpy/tl/__init__.py index 7f7cdcd..66dfa0f 100644 --- a/src/infercnvpy/tl/__init__.py +++ b/src/infercnvpy/tl/__init__.py @@ -41,16 +41,16 @@ def pca( ) -> Union[np.ndarray, None]: """Compute the PCA on the result of :func:`infercnvpy.tl.infercnv`. - Thin wrapper around :func:`scanpy.tl.pca`. + Thin wrapper around :func:`scanpy.pp.pca`. Parameters ---------- adata annotated data matrix svd_solver - See :func:`scanpy.tl.pca`. + See :func:`scanpy.pp.pca`. zero_center - See :func:`scanpy.tl.pca`. + See :func:`scanpy.pp.pca`. inplace If True, store the result in adata.obsm. Otherwise return the PCA matrix. use_rep @@ -58,7 +58,7 @@ def pca( key_added Key under which the result will be stored in adata.obsm if `inplace=True`. **kwargs - Additional arguments passed to :func:`scanpy.tl.pca`. + Additional arguments passed to :func:`scanpy.pp.pca`. """ if f"X_{use_rep}" not in adata.obsm: raise KeyError(f"X_{use_rep} is not in adata.obsm. Did you run `tl.infercnv`?") From 8788642472f4f952e0dbaf45760a8bdec7916889 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Thu, 13 Jun 2024 16:03:03 +0200 Subject: [PATCH 4/5] Fix merge conflicts --- .github/workflows/release.yaml.rej | 10 ------ .github/workflows/test.yaml | 6 ++-- .github/workflows/test.yaml.rej | 16 --------- .pre-commit-config.yaml.rej | 34 ------------------- docs/conf.py.rej | 16 --------- pyproject.toml | 13 +++++--- pyproject.toml.rej | 53 ------------------------------ 7 files changed, 11 insertions(+), 137 deletions(-) delete mode 100644 .github/workflows/release.yaml.rej delete mode 100644 .github/workflows/test.yaml.rej delete mode 100644 .pre-commit-config.yaml.rej delete mode 100644 docs/conf.py.rej delete mode 100644 pyproject.toml.rej diff --git a/.github/workflows/release.yaml.rej b/.github/workflows/release.yaml.rej deleted file mode 100644 index f65d3cd..0000000 --- a/.github/workflows/release.yaml.rej +++ /dev/null @@ -1,10 +0,0 @@ -diff a/.github/workflows/release.yaml b/.github/workflows/release.yaml (rejected hunks) -@@ -11,7 +11,7 @@ jobs: - runs-on: ubuntu-latest - environment: - name: pypi -- url: https://pypi.org/p/{{ cookiecutter.package_name }} -+ url: https://pypi.org/p/infercnvpy - permissions: - id-token: write # IMPORTANT: this permission is mandatory for trusted publishing - steps: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 589655e..d1f87b1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,13 +24,13 @@ jobs: matrix: include: - os: ubuntu-latest - python: "3.9" + python: "3.10" r: release - os: ubuntu-latest - python: "3.11" + python: "3.12" r: release - os: ubuntu-latest - python: "3.11" + python: "3.12" r: release pip-flags: "--pre" diff --git a/.github/workflows/test.yaml.rej b/.github/workflows/test.yaml.rej deleted file mode 100644 index e165fb8..0000000 --- a/.github/workflows/test.yaml.rej +++ /dev/null @@ -1,16 +0,0 @@ -diff a/.github/workflows/test.yaml b/.github/workflows/test.yaml (rejected hunks) -@@ -24,11 +24,11 @@ jobs: - matrix: - include: - - os: ubuntu-latest -- python: "3.9" -+ python: "3.10" - - os: ubuntu-latest -- python: "3.11" -+ python: "3.12" - - os: ubuntu-latest -- python: "3.11" -+ python: "3.12" - pip-flags: "--pre" - name: PRE-RELEASE DEPENDENCIES - diff --git a/.pre-commit-config.yaml.rej b/.pre-commit-config.yaml.rej deleted file mode 100644 index 5f9ac18..0000000 --- a/.pre-commit-config.yaml.rej +++ /dev/null @@ -1,34 +0,0 @@ -diff a/.pre-commit-config.yaml b/.pre-commit-config.yaml (rejected hunks) -@@ -6,29 +6,18 @@ default_stages: - - push - minimum_pre_commit_version: 2.16.0 - repos: -- - repo: https://github.com/psf/black -- rev: "24.4.2" -- hooks: -- - id: black -- - repo: https://github.com/asottile/blacken-docs -- rev: 1.16.0 -- hooks: -- - id: blacken-docs - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v4.0.0-alpha.8 - hooks: - - id: prettier -- # Newer versions of node don't work on systems that have an older version of GLIBC -- # (in particular Ubuntu 18.04 and Centos 7) -- # EOL of Centos 7 is in 2024-06, we can probably get rid of this then. -- # See https://github.com/scverse/cookiecutter-scverse/issues/143 and -- # https://github.com/jupyterlab/jupyterlab/issues/12675 -- language_version: "17.9.1" - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.4 - hooks: - - id: ruff -+ types_or: [python, pyi, jupyter] - args: [--fix, --exit-non-zero-on-fix] -+ - id: ruff-format -+ types_or: [python, pyi, jupyter] - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 - hooks: diff --git a/docs/conf.py.rej b/docs/conf.py.rej deleted file mode 100644 index 6a707c4..0000000 --- a/docs/conf.py.rej +++ /dev/null @@ -1,16 +0,0 @@ -diff a/docs/conf.py b/docs/conf.py (rejected hunks) -@@ -36,10 +36,10 @@ needs_sphinx = "4.0" - - html_context = { - "display_github": True, # Integrate GitHub -- "github_user": "grst", # Username -- "github_repo": project_name, # Repo name -- "github_version": "main", # Version -- "conf_py_path": "/docs/", # Path in the checkout to the docs root -+ "github_user": "grst", -+ "github_repo": "https://github.com/icbi-lab/infercnvpy", -+ "github_version": "main", -+ "conf_py_path": "/docs/", - } - - # -- General configuration --------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 1c86a25..446cf33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ name = "infercnvpy" dynamic = ["version"] description = "Infercnv is a scalable python library to infer copy number variation (CNV) events from single cell transcriptomics data. It is heavliy inspired by InferCNV, but plays nicely with scanpy and is much more scalable." readme = "README.md" -requires-python = ">=3.9" +requires-python = ">=3.10" license = {file = "LICENSE"} authors = [ {name = "Gregor Sturm"}, @@ -47,7 +47,7 @@ doc = [ "docutils>=0.8,!=0.18.*,!=0.19.*", "sphinx>=4.2", "sphinx-book-theme>=1.0.0", - "myst-nb", + "myst-nb>=1.1.0", "sphinxcontrib-bibtex>=1.0.0", "sphinx-autodoc-typehints", "sphinxext-opengraph", @@ -83,12 +83,15 @@ filterwarnings = [ # "ignore:.*U.*mode is deprecated:DeprecationWarning", ] -[tool.black] -line-length = 120 - [tool.ruff] src = ["src"] line-length = 120 +extent-include = ["*.ipynb"] + +[tool.ruff.format] +docstring-code-format = true + +[tool.ruff.lint] select = [ "F", # Errors detected by Pyflakes "E", # Error detected by Pycodestyle diff --git a/pyproject.toml.rej b/pyproject.toml.rej deleted file mode 100644 index 74b5700..0000000 --- a/pyproject.toml.rej +++ /dev/null @@ -1,53 +0,0 @@ -diff a/pyproject.toml b/pyproject.toml (rejected hunks) -@@ -7,7 +7,7 @@ name = "infercnvpy" - version = "0.0.1" - description = "Infer copy number variation (CNV) from scRNA-seq data. Plays nicely with Scanpy. " - readme = "README.md" --requires-python = ">=3.9" -+requires-python = ">=3.10" - license = {file = "LICENSE"} - authors = [ - {name = "Gregor Sturm"}, -@@ -21,19 +21,19 @@ urls.Home-page = "https://github.com/icbi-lab/infercnvpy" - dependencies = [ - "anndata", - # for debug logging (referenced from the issue template) -- "session-info" -+ "session-info", - ] - - [project.optional-dependencies] - dev = [ - "pre-commit", -- "twine>=4.0.2" -+ "twine>=4.0.2", - ] - doc = [ - "docutils>=0.8,!=0.18.*,!=0.19.*", - "sphinx>=4", - "sphinx-book-theme>=1.0.0", -- "myst-nb", -+ "myst-nb>=1.1.0", - "sphinxcontrib-bibtex>=1.0.0", - "sphinx-autodoc-typehints", - "sphinxext-opengraph", -@@ -61,12 +61,15 @@ addopts = [ - "--import-mode=importlib", # allow using test files with same name - ] - --[tool.black] --line-length = 120 -- - [tool.ruff] --src = ["src"] - line-length = 120 -+src = ["src"] -+extend-include = ["*.ipynb"] -+ -+[tool.ruff.format] -+docstring-code-format = true -+ -+[tool.ruff.lint] - select = [ - "F", # Errors detected by Pyflakes - "E", # Error detected by Pycodestyle From acbda4f12e5368fa2d973c4e66977407e1cfe742 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Thu, 13 Jun 2024 16:07:27 +0200 Subject: [PATCH 5/5] Fix pre-commit --- pyproject.toml | 2 +- src/infercnvpy/io/_genepos.py | 10 ++++---- src/infercnvpy/io/_scevan.py | 7 +++--- src/infercnvpy/pl/_chromosome_heatmap.py | 22 ++++++++--------- src/infercnvpy/tl/__init__.py | 2 +- src/infercnvpy/tl/_copykat.py | 7 +++--- src/infercnvpy/tl/_infercnv.py | 30 ++++++++++++------------ src/infercnvpy/tl/_scores.py | 12 +++++----- 8 files changed, 44 insertions(+), 48 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 446cf33..07eae2e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,7 +86,7 @@ filterwarnings = [ [tool.ruff] src = ["src"] line-length = 120 -extent-include = ["*.ipynb"] +extend-include = ["*.ipynb"] [tool.ruff.format] docstring-code-format = true diff --git a/src/infercnvpy/io/_genepos.py b/src/infercnvpy/io/_genepos.py index 4814de3..83ac094 100644 --- a/src/infercnvpy/io/_genepos.py +++ b/src/infercnvpy/io/_genepos.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Literal, Union +from typing import Literal import gtfparse import numpy as np @@ -9,13 +9,13 @@ def genomic_position_from_gtf( - gtf_file: Union[Path, str], - adata: Union[AnnData, None] = None, + gtf_file: Path | str, + adata: AnnData | None = None, *, gtf_gene_id: Literal["gene_id", "gene_name"] = "gene_name", - adata_gene_id: Union[str, None] = None, + adata_gene_id: str | None = None, inplace: bool = True, -) -> Union[pd.DataFrame, None]: +) -> pd.DataFrame | None: """Get genomic gene positions from a GTF file. The GTF file needs to match the genome annotation used for your single cell dataset. diff --git a/src/infercnvpy/io/_scevan.py b/src/infercnvpy/io/_scevan.py index 8547cb5..0539547 100644 --- a/src/infercnvpy/io/_scevan.py +++ b/src/infercnvpy/io/_scevan.py @@ -1,7 +1,6 @@ """Read in result files from scevan.""" from pathlib import Path -from typing import Optional, Union import numpy as np import pandas as pd @@ -26,14 +25,14 @@ def _get_chr_pos_from_array(chr_pos_array): def read_scevan( adata: AnnData, - scevan_res_dir: Union[str, Path], - scevan_res_table: Optional[Union[str, Path]] = None, + scevan_res_dir: str | Path, + scevan_res_table: str | Path | None = None, *, subclones: bool = True, inplace: bool = True, subset: bool = True, key_added: str = "scevan", -) -> Optional[AnnData]: +) -> AnnData | None: """Load results from SCEVAN :cite:`DeFalco2021` for downstream analysis with infercnvpy. Requires that the cell barcodes used for SCEVAN and `adata.obs_names` match, diff --git a/src/infercnvpy/pl/_chromosome_heatmap.py b/src/infercnvpy/pl/_chromosome_heatmap.py index 178e89b..19023f1 100644 --- a/src/infercnvpy/pl/_chromosome_heatmap.py +++ b/src/infercnvpy/pl/_chromosome_heatmap.py @@ -1,5 +1,3 @@ -from typing import Optional, Union - import matplotlib.axes import numpy as np import pandas as pd @@ -15,12 +13,12 @@ def chromosome_heatmap( *, groupby: str = "cnv_leiden", use_rep: str = "cnv", - cmap: Union[str, Colormap] = "bwr", + cmap: str | Colormap = "bwr", figsize: tuple[int, int] = (16, 10), - show: Optional[bool] = None, - save: Union[str, bool, None] = None, + show: bool | None = None, + save: str | bool | None = None, **kwargs, -) -> Optional[dict[str, matplotlib.axes.Axes]]: +) -> dict[str, matplotlib.axes.Axes] | None: """Plot a heatmap of smoothed gene expression by chromosome. Wrapper around :func:`scanpy.pl.heatmap`. @@ -71,7 +69,7 @@ def chromosome_heatmap( kwargs["norm"] = TwoSlopeNorm(0, vmin=vmin, vmax=vmax) # add chromosome annotations - var_group_positions = list(zip(chr_pos, chr_pos[1:] + [tmp_adata.shape[1]])) + var_group_positions = list(zip(chr_pos, chr_pos[1:] + [tmp_adata.shape[1]], strict=False)) return_ax_dic = sc.pl.heatmap( tmp_adata, @@ -99,12 +97,12 @@ def chromosome_heatmap_summary( *, groupby: str = "cnv_leiden", use_rep: str = "cnv", - cmap: Union[str, Colormap] = "bwr", + cmap: str | Colormap = "bwr", figsize: tuple[int, int] = (16, 10), - show: Optional[bool] = None, - save: Union[str, bool, None] = None, + show: bool | None = None, + save: str | bool | None = None, **kwargs, -) -> Optional[dict[str, matplotlib.axes.Axes]]: +) -> dict[str, matplotlib.axes.Axes] | None: """Plot a heatmap of average of the smoothed gene expression by chromosome per category in groupby. Wrapper around :func:`scanpy.pl.heatmap`. @@ -172,7 +170,7 @@ def _get_group_mean(group): kwargs["norm"] = TwoSlopeNorm(0, vmin=vmin, vmax=vmax) # add chromosome annotations - var_group_positions = list(zip(chr_pos, chr_pos[1:] + [tmp_adata.shape[1]])) + var_group_positions = list(zip(chr_pos, chr_pos[1:] + [tmp_adata.shape[1]], strict=False)) return_ax_dic = sc.pl.heatmap( tmp_adata, diff --git a/src/infercnvpy/tl/__init__.py b/src/infercnvpy/tl/__init__.py index 66dfa0f..466989a 100644 --- a/src/infercnvpy/tl/__init__.py +++ b/src/infercnvpy/tl/__init__.py @@ -38,7 +38,7 @@ def pca( use_rep: str = "cnv", key_added: str = "cnv_pca", **kwargs, -) -> Union[np.ndarray, None]: +) -> np.ndarray | None: """Compute the PCA on the result of :func:`infercnvpy.tl.infercnv`. Thin wrapper around :func:`scanpy.pp.pca`. diff --git a/src/infercnvpy/tl/_copykat.py b/src/infercnvpy/tl/_copykat.py index 3b41899..fdec659 100644 --- a/src/infercnvpy/tl/_copykat.py +++ b/src/infercnvpy/tl/_copykat.py @@ -1,6 +1,5 @@ import os from multiprocessing import cpu_count -from typing import Optional import pandas as pd from anndata import AnnData @@ -18,8 +17,8 @@ def copykat( min_genes_chr: int = 5, key_added: str = "cnv", inplace: bool = True, - layer: Optional[str] = None, - n_jobs: Optional[int] = None, + layer: str | None = None, + n_jobs: int | None = None, norm_cell_names: str = "", cell_line="no", window_size=25, @@ -172,7 +171,7 @@ def copykat( if inplace: adata.uns[key_added] = chrom_pos - adata.obsm["X_%s" % key_added] = new_cpkat_trans + adata.obsm[f"X_{key_added}"] = new_cpkat_trans adata.obs[key_added] = copyKAT_pred else: return new_cpkat_trans, copyKAT_pred diff --git a/src/infercnvpy/tl/_infercnv.py b/src/infercnvpy/tl/_infercnv.py index d118aa7..deb0b9d 100644 --- a/src/infercnvpy/tl/_infercnv.py +++ b/src/infercnvpy/tl/_infercnv.py @@ -2,7 +2,6 @@ import re from collections.abc import Sequence from multiprocessing import cpu_count -from typing import Union import numpy as np import scipy.ndimage @@ -18,20 +17,20 @@ def infercnv( adata: AnnData, *, - reference_key: Union[str, None] = None, - reference_cat: Union[None, str, Sequence[str]] = None, - reference: Union[np.ndarray, None] = None, + reference_key: str | None = None, + reference_cat: None | str | Sequence[str] = None, + reference: np.ndarray | None = None, lfc_clip: float = 3, window_size: int = 100, step: int = 10, - dynamic_threshold: Union[float, None] = 1.5, - exclude_chromosomes: Union[Sequence[str], None] = ("chrX", "chrY"), + dynamic_threshold: float | None = 1.5, + exclude_chromosomes: Sequence[str] | None = ("chrX", "chrY"), chunksize: int = 5000, - n_jobs: Union[int, None] = None, + n_jobs: int | None = None, inplace: bool = True, - layer: Union[str, None] = None, + layer: str | None = None, key_added: str = "cnv", -) -> Union[None, tuple[dict, scipy.sparse.csr_matrix]]: +) -> None | tuple[dict, scipy.sparse.csr_matrix]: """Infer Copy Number Variation (CNV) by averaging gene expression over genomic regions. This method is heavily inspired by `infercnv `_ @@ -121,7 +120,8 @@ def infercnv( itertools.repeat(dynamic_threshold), tqdm_class=tqdm, max_workers=cpu_count() if n_jobs is None else n_jobs, - ) + ), + strict=False, ) res = scipy.sparse.vstack(chunks) @@ -148,7 +148,7 @@ def alphanum_key(key): return sorted(l, key=alphanum_key) -def _running_mean(x: Union[np.ndarray, scipy.sparse.spmatrix], n: int = 50, step: int = 10) -> np.ndarray: +def _running_mean(x: np.ndarray | scipy.sparse.spmatrix, n: int = 50, step: int = 10) -> np.ndarray: """Compute a pyramidially weighted running mean. Densifies the matrix. Use `step` and `chunksize` to save memory. @@ -213,16 +213,16 @@ def _running_mean_for_chromosome(chr): running_means = [_running_mean_for_chromosome(chr) for chr in chromosomes] - chr_start_pos = dict(zip(chromosomes, np.cumsum([0] + [x.shape[1] for x in running_means]))) + chr_start_pos = dict(zip(chromosomes, np.cumsum([0] + [x.shape[1] for x in running_means]), strict=False)) return chr_start_pos, np.hstack(running_means) def _get_reference( adata: AnnData, - reference_key: Union[str, None], - reference_cat: Union[None, str, Sequence[str]], - reference: Union[np.ndarray, None], + reference_key: str | None, + reference_cat: None | str | Sequence[str], + reference: np.ndarray | None, ) -> np.ndarray: """Parameter validation extraction of reference gene expression. diff --git a/src/infercnvpy/tl/_scores.py b/src/infercnvpy/tl/_scores.py index 388a89f..3642536 100644 --- a/src/infercnvpy/tl/_scores.py +++ b/src/infercnvpy/tl/_scores.py @@ -2,7 +2,7 @@ import warnings from collections.abc import Mapping -from typing import Any, Optional +from typing import Any import numpy as np import scipy.sparse as sp @@ -19,7 +19,7 @@ def cnv_score( key_added: str = "cnv_score", inplace: bool = True, obs_key=None, -) -> Optional[Mapping[Any, np.number]]: +) -> Mapping[Any, np.number] | None: """Assign each cnv cluster a CNV score. Clusters with a high score are likely affected by copy number abberations. @@ -78,11 +78,11 @@ def ithgex( adata: AnnData, groupby: str, *, - use_raw: Optional[bool] = None, - layer: Optional[str] = None, + use_raw: bool | None = None, + layer: str | None = None, inplace: bool = True, key_added: str = "ithgex", -) -> Optional[Mapping[str, float]]: +) -> Mapping[str, float] | None: """Compute the ITHGEX diversity score based on gene expression cite:`Wu2021`. A high score indicates a high diversity of gene expression profiles of cells @@ -158,7 +158,7 @@ def ithcna( use_rep: str = "X_cnv", key_added: str = "ithcna", inplace: bool = True, -) -> Optional[Mapping[str, float]]: +) -> Mapping[str, float] | None: """Compute the ITHCNA diversity score based on copy number variation :cite:`Wu2021`. A high score indicates a high diversity of CNV profiles of cells