Skip to content

Commit b12fa24

Browse files
committed
Add pre-commit configuration, fix dependencies, and add CI workflow
1 parent 297ce8c commit b12fa24

8 files changed

Lines changed: 83 additions & 11 deletions

File tree

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.11", "3.12"]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
cache: 'pip'
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install -U pip
29+
pip install -e ".[dev]"
30+
31+
- name: Lint with flake8
32+
run: |
33+
# stop the build if there are Python syntax errors or undefined names
34+
flake8 src tests --count --select=E9,F63,F7,F82 --show-source --statistics
35+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
36+
flake8 src tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37+
38+
- name: Test with pytest
39+
run: |
40+
pytest tests/

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 25.1.0
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pycqa/isort
7+
rev: 6.0.1
8+
hooks:
9+
- id: isort
10+
args: ["--profile", "black"]
11+
- repo: https://github.com/pycqa/flake8
12+
rev: 7.1.1
13+
hooks:
14+
- id: flake8
15+
args: ["--max-line-length=127", "--extend-ignore=E203"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CSDE: Corrected Spatial Differential Expression
22

3+
[![Tests](https://github.com/YosefLab/csde/actions/workflows/test.yml/badge.svg)](https://github.com/YosefLab/csde/actions/workflows/test.yml)
4+
35
`csde` (Corrected Spatial Differential Expression) is a Python package designed to **identify differentially expressed (DE) genes between spatially-resolved cell populations** (e.g., T-cells inside vs. outside a tumor).
46

57
Standard analysis relies on cell population assignments (e.g., "infiltrating" vs. "non-infiltrating") obtained automatically from clustering/ML that are often prone to errors. `csde` corrects for these inaccuracies by leveraging a small subset of validated "ground-truth" data, providing rigorous statistical guarantees for spatially-resolved DE analyses.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ version = "0.1.0"
88
description = "Corrected Spatial Differential Expression analysis package"
99
readme = "README.md"
1010
requires-python = ">=3.10"
11-
license = {text = "MIT"}
11+
license = {text = "BSD-3-Clause"}
1212
authors = [
1313
{name = "Pierre Boyeau"},
1414
]
1515
dependencies = [
1616
"anndata>=0.8.0",
1717
"scanpy>=1.9.0",
18-
"jax>=0.4.0",
18+
"jax>=0.4.0,<0.10.0",
1919
"flax>=0.7.0",
2020
"optax>=0.1.0",
2121
"numpyro>=0.12.0",

src/csde/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Tuple, List
1+
from typing import Optional
22

33
import anndata
44
import numpy as np

src/csde/model.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import os
2-
from typing import Union, Optional, Tuple, List, Dict, Any
1+
from typing import Any, Dict, List, Optional, Tuple, Union
32

43
import flax.linen as nn
54
import jax
6-
7-
jax.config.update("jax_enable_x64", True)
85
import jax.numpy as jnp
96
import numpy as np
107
import pandas as pd
@@ -14,6 +11,8 @@
1411

1512
from csde.optimization import _zstat_generic2, optimize_ppi, optimize_ppi_gd
1613

14+
jax.config.update("jax_enable_x64", True)
15+
1716

1817
class PPIAbstractClass:
1918
"""
@@ -413,14 +412,14 @@ def likelihood(model_params, x, y):
413412

414413
all_grads = np.zeros((n_obs, self.n_params))
415414
for i in tqdm(range(0, n_obs, batch_size), desc="Gradient computation"):
416-
x_batch = x[i : i + batch_size]
417-
y_batch = y[i : i + batch_size]
415+
x_batch = x[i:i+batch_size]
416+
y_batch = y[i:i+batch_size]
418417
n_obs_batch = x_batch.shape[0]
419418
score = self.jit(jax.jacfwd(likelihood))
420419
grads = score(self.model_params, x_batch, y_batch)
421420
grad_mu = np.array(grads["params"]["mu"].reshape(n_obs_batch, -1))
422421
grad_mu0 = np.array(grads["params"]["mu0"].reshape(n_obs_batch, -1))
423-
all_grads[i : i + batch_size] = np.hstack([grad_mu, grad_mu0])
422+
all_grads[i:i+batch_size] = np.hstack([grad_mu, grad_mu0])
424423
return np.array(all_grads)
425424

426425
def _construct_contrast(self, feature_id: int, idx_a: int) -> np.ndarray:

src/csde/optimization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import time
2-
from typing import Optional, Callable, Dict, Any, Tuple
2+
from typing import Any, Optional, Tuple
33

44
import jax
55
import jax.numpy as jnp

tox.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tox]
2+
envlist = py311, py312
3+
isolated_build = True
4+
toxworkdir = /tmp/tox/{env:USER}/{toxinidir:name}
5+
6+
[testenv]
7+
description = Run flake8 and pytest
8+
extras =
9+
dev
10+
commands =
11+
# stop the build if there are Python syntax errors or undefined names
12+
flake8 src tests --count --select=E9,F63,F7,F82 --show-source --statistics
13+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
14+
flake8 src tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
15+
# Test with pytest
16+
pytest {posargs:tests}

0 commit comments

Comments
 (0)