Skip to content

Commit af32227

Browse files
authored
Merge pull request #23 from YosefLab/destvi_utils_oier
Issues corrected
2 parents eaf9d93 + 213c6b7 commit af32227

9 files changed

Lines changed: 120 additions & 50 deletions

File tree

.github/workflows/test.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: destvi_utils
55

66
on:
77
push:
8-
branches: [main]
8+
branches: [main, "[0-9]+.[0-9]+.x"]
99
pull_request:
1010
branches: [main]
1111

@@ -15,21 +15,17 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: [3.7, 3.8]
18+
python-version: [3.11, 3.12, 3.13]
1919

2020
steps:
21-
- uses: actions/checkout@v2
22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
24-
with:
25-
python-version: ${{ matrix.python-version }}
26-
- name: Cache pip
27-
uses: actions/cache@v2
21+
- uses: actions/checkout@v4
22+
23+
- uses: actions/setup-python@v5
2824
with:
29-
path: ~/.cache/pip
30-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
31-
restore-keys: |
32-
${{ runner.os }}-pip-
25+
python-version: ${{ matrix.python }}
26+
cache: "pip"
27+
cache-dependency-path: "**/pyproject.toml"
28+
3329
- name: Install dependencies
3430
run: |
3531
pip install pytest-cov

.pre-commit-config.yaml

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,69 @@
1+
fail_fast: false
2+
default_language_version:
3+
python: python3
4+
default_stages:
5+
- pre-commit
6+
- pre-push
7+
minimum_pre_commit_version: 2.16.0
18
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 22.3.0
4-
hooks:
5-
- id: black
6-
- repo: https://github.com/PyCQA/flake8
7-
rev: 4.0.1
8-
hooks:
9-
- id: flake8
10-
- repo: https://github.com/pycqa/isort
11-
rev: 5.10.1
12-
hooks:
13-
- id: isort
14-
name: isort (python)
15-
additional_dependencies: [toml]
9+
- repo: https://github.com/asottile/blacken-docs
10+
rev: 1.20.0
11+
hooks:
12+
- id: blacken-docs
13+
14+
- repo: https://github.com/pre-commit/mirrors-prettier
15+
rev: v4.0.0-alpha.8
16+
hooks:
17+
- id: prettier
18+
types: [yaml]
19+
20+
- repo: https://github.com/executablebooks/mdformat
21+
rev: 1.0.0
22+
hooks:
23+
- id: mdformat
24+
additional_dependencies:
25+
- mdformat-mkdocs
26+
- mdformat-admon
27+
exclude: |
28+
(?x)^(
29+
\.github/.*\.md
30+
| docs/.*\.md
31+
)$
32+
33+
- repo: https://github.com/igorshubovych/markdownlint-cli
34+
rev: v0.46.0
35+
hooks:
36+
- id: markdownlint-fix
37+
exclude: |
38+
(?x)^(
39+
\.github/.*\.md
40+
| docs/.*\.md
41+
)$
42+
43+
- repo: https://github.com/astral-sh/ruff-pre-commit
44+
rev: v0.14.6
45+
hooks:
46+
- id: ruff
47+
args: [--fix, --exit-non-zero-on-fix]
48+
- id: ruff-format
49+
50+
- repo: https://github.com/pre-commit/pre-commit-hooks
51+
rev: v6.0.0
52+
hooks:
53+
- id: detect-private-key
54+
- id: check-ast
55+
- id: end-of-file-fixer
56+
- id: mixed-line-ending
57+
args: [--fix=lf]
58+
- id: trailing-whitespace
59+
- id: check-case-conflict
60+
61+
- repo: local
62+
hooks:
63+
- id: forbid-to-commit
64+
name: Don't commit rej files
65+
entry: |
66+
Cannot commit .rej files. These indicate merge conflicts that arise during automated template updates.
67+
Fix the merge conflicts manually and remove the .rej files.
68+
language: fail
69+
files: '.*\.rej$'

destvi_utils/__init__.py

100644100755
File mode changed.

destvi_utils/_destvi_utils.py

100644100755
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ def explore_gamma_space(
292292
sc_adata.obs[sc_model.registry_["setup_args"]["labels_key"]] == name_ct
293293
].copy()
294294
is_sparse = issparse(sc_adata_slice.X)
295-
normalized_counts = sc_adata_slice.X.A if is_sparse else sc_adata_slice.X
295+
normalized_counts = (
296+
sc_adata_slice.X.toarray() if is_sparse else sc_adata_slice.X
297+
)
296298
indices_ct = np.where(
297299
sc_adata.obs[sc_model.registry_["setup_args"]["labels_key"]] == name_ct
298300
)[0]
@@ -328,7 +330,7 @@ def explore_gamma_space(
328330
# (A) display top 50 genes + AND - (B) for each gene set, get GSEA
329331
for d in [0, 1]:
330332
if output_file is not None:
331-
html += f"<h4>Genes associated with SpatialPC{d+1}</h4>"
333+
html += f"<h4>Genes associated with SpatialPC{d + 1}</h4>"
332334
else:
333335
print("[bold]Genes associated with SpatialPC{}[/bold]".format(d + 1))
334336
r = _utils._vcorrcoef(normalized_counts.T, sc_projection[:, d])
@@ -339,9 +341,9 @@ def explore_gamma_space(
339341
gl = list(st_adata.var.index[ranking[:50]])
340342
enr = gseapy.enrichr(
341343
gene_list=gl,
342-
description="pathway",
343344
gene_sets="BioPlanet_2019",
344345
outdir="test",
346+
organism="Human",
345347
no_plot=True,
346348
)
347349
text_signatures = enr.results.head(10)["Term"].values
@@ -449,12 +451,12 @@ def de_genes(
449451
mask2 = np.logical_and(mask2, st_adata.obsm[key_proportions][ct] > threshold)
450452

451453
avg_library_size = np.mean(np.sum(expression, axis=1).flatten())
452-
exp_px_o = st_model.module.px_o.detach().exp().cpu().numpy()
454+
exp_px_r = st_model.module.px_r.detach().exp().cpu().numpy()
453455
imputations = st_model.get_scale_for_ct(ct).values
454456
mean = avg_library_size * imputations
455457

456-
concentration = torch.tensor(avg_library_size * imputations / exp_px_o)
457-
rate = torch.tensor(1.0 / exp_px_o)
458+
concentration = torch.tensor(avg_library_size * imputations / exp_px_r)
459+
rate = torch.tensor(1.0 / exp_px_r)
458460

459461
# slice conditions
460462
N_mask = N_unmask = N_sample

destvi_utils/_utils.py

100644100755
File mode changed.

docs/installation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ destvi_utils can be installed via PyPI.
99
conda prerequisites
1010
###################
1111

12-
1. Install Conda. We typically use the Miniconda_ Python distribution. Use Python version >=3.7.
12+
1. Install Conda. We typically use the Miniconda_ Python distribution. Use Python version >=3.11.
1313

1414
2. Create a new conda environment::
1515

16-
conda create -n destvi-env python=3.7
16+
conda create -n destvi-env python=3.11
1717

1818
3. Activate your environment::
1919

pyproject.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ classifiers = [
1010
"Development Status :: 5 - Production/Stable",
1111
"Intended Audience :: Science/Research",
1212
"Natural Language :: English",
13-
"Programming Language :: Python :: 3.6",
14-
"Programming Language :: Python :: 3.7",
13+
"Programming Language :: Python :: 3.11",
14+
"Programming Language :: Python :: 3.12",
15+
"Programming Language :: Python :: 3.13",
1516
"Operating System :: MacOS :: MacOS X",
1617
"Operating System :: Microsoft :: Windows",
1718
"Operating System :: POSIX :: Linux",
@@ -26,7 +27,7 @@ packages = [
2627
{include = "destvi_utils"},
2728
]
2829
readme = "README.md"
29-
version = "0.1.0"
30+
version = "0.2.0"
3031

3132
[tool.poetry.dependencies]
3233
adjustText = ">=0.7.1"
@@ -35,7 +36,7 @@ black = {version = ">=20.8b1", optional = true}
3536
cmap2d = {git = "https://github.com/cane11/cmap2d", tag = "v1.0"}
3637
codecov = {version = ">=2.0.8", optional = true}
3738
flake8 = {version = ">=3.7.7", optional = true}
38-
gseapy = {version = "0.10.2"}
39+
gseapy = {version = ">=0.10.2"}
3940
hotspot = {git = "https://github.com/YosefLab/Hotspot", tag = "v1.0"}
4041
importlib-metadata = {version = "^1.0", python = "<3.8"}
4142
ipython = ">=7.1.1"
@@ -50,11 +51,11 @@ nbsphinx-link = {version = "*", optional = true}
5051
pre-commit = {version = ">=2.7.1", optional = true}
5152
pydata-sphinx-theme = {version = ">=0.4.0", optional = true}
5253
pytest = {version = ">=4.4", optional = true}
53-
python = ">=3.7.2,<4.0"
54+
python = ">=3.11.0,<4.0"
5455
igraph = {version = "*"}
5556
scanpy = ">=1.6,<2.0"
5657
scanpydoc = {version = ">=0.5", optional = true}
57-
scvi-tools = ">=0.15.0"
58+
scvi-tools = {git = "https://github.com/scverse/scvi-tools", tag = "Ori-destvi_v2_2"}
5859
sphinx = {version = ">=4.1,<4.4", optional = true}
5960
sphinx-autodoc-typehints = {version = "*", optional = true}
6061
sphinx-rtd-theme = {version = "*", optional = true}

readthedocs.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
version: 2
22
build:
3-
image: latest
3+
os: ubuntu-20.04
4+
tools:
5+
python: "3.11"
46
sphinx:
57
configuration: docs/conf.py
68
python:
7-
version: 3.7
89
install:
9-
- method: pip
10-
path: .
11-
extra_requirements:
12-
- docs
10+
- method: pip
11+
path: .
12+
extra_requirements:
13+
- docsbuild

tests/test_destvi_utils.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
import numpy as np
22
from scvi.data import synthetic_iid
33
from scvi.model import CondSCVI, DestVI
4-
4+
from unittest.mock import patch, MagicMock
5+
import pandas as pd
56
import destvi_utils
67

78

8-
def test_destvi():
9+
@patch("gseapy.enrichr")
10+
def test_destvi(mock_enrichr):
11+
# mock enrichr results
12+
fake_df = pd.DataFrame(
13+
{
14+
"Term": ["fake_pathway"],
15+
"Overlap": ["5/100"],
16+
"Adjusted P-value": [0.05],
17+
"Genes": ["gene_1;gene_2"],
18+
}
19+
)
20+
21+
mock_instance = MagicMock()
22+
mock_instance.results = fake_df
23+
mock_enrichr.return_value = mock_instance
24+
925
# Step1 learn CondSCVI
1026
n_latent = 2
1127
n_labels = 5
@@ -14,7 +30,7 @@ def test_destvi():
1430
dataset.obsm["spatial"] = np.random.randn(dataset.n_obs, 2)
1531
dataset.obs["overclustering_vamp"] = list(range(dataset.n_obs))
1632
CondSCVI.setup_anndata(dataset, labels_key="labels")
17-
sc_model = CondSCVI(dataset, n_latent=n_latent, n_layers=n_layers)
33+
sc_model = CondSCVI(dataset, n_latent=n_latent, n_layers=n_layers, prior="mog")
1834
sc_model.train(1, train_size=1)
1935

2036
DestVI.setup_anndata(dataset, layer=None)

0 commit comments

Comments
 (0)