Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #129

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/scverse/cookiecutter-scverse",
"commit": "8e96abb5c3e2d5078c44713958da672711cf2a48",
"commit": "87a407a65408d75a949c0b54b19fd287475a56f8",
"context": {
"cookiecutter": {
"project_name": "infercnvpy",
Expand All @@ -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,
Expand All @@ -24,5 +25,5 @@
}
},
"directory": null,
"checkout": "v0.3.0"
"checkout": "v0.4.0"
}
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ __pycache__/
/.pytest_cache/
/.cache/
/data/
/node_modules/

# docs
/docs/generated/
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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]
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.5.0
rev: v4.6.0
hooks:
- id: detect-private-key
- id: check-ast
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
23 changes: 13 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -83,12 +83,15 @@ filterwarnings = [
# "ignore:.*U.*mode is deprecated:DeprecationWarning",
]

[tool.black]
line-length = 120

[tool.ruff]
src = ["src"]
line-length = 120
extend-include = ["*.ipynb"]

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
select = [
"F", # Errors detected by Pyflakes
"E", # Error detected by Pycodestyle
Expand All @@ -103,7 +106,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",
Expand All @@ -117,7 +120,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",
Expand All @@ -130,10 +133,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"]
Expand All @@ -147,5 +150,5 @@ skip = [
"docs/changelog.md",
"docs/references.bib",
"docs/references.md",
"docs/notebooks/example.ipynb"
"docs/notebooks/example.ipynb",
]
10 changes: 5 additions & 5 deletions src/infercnvpy/io/_genepos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Literal, Union
from typing import Literal

import gtfparse
import numpy as np
Expand All @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions src/infercnvpy/io/_scevan.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
22 changes: 10 additions & 12 deletions src/infercnvpy/pl/_chromosome_heatmap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional, Union

import matplotlib.axes
import numpy as np
import pandas as pd
Expand All @@ -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`.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/infercnvpy/tl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ 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.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
Key under which the result of infercnv is stored in adata
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`?")
Expand Down
7 changes: 3 additions & 4 deletions src/infercnvpy/tl/_copykat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from multiprocessing import cpu_count
from typing import Optional

import pandas as pd
from anndata import AnnData
Expand All @@ -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,
Expand Down Expand Up @@ -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
Loading
Loading