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

Python API name changes #339

Merged
merged 8 commits into from
Mar 31, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/py-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:

- name: Build
run: python -m build
working-directory: api/python/cell_census/
working-directory: api/python/cellxgene_census/

- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
path: api/python/cell_census/dist/*
path: api/python/cellxgene_census/dist/*

build_docker_container:
name: Build Docker image for Census Builder
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/py-unittests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python cell_census package unit tests
name: Python cellxgene_census package unit tests

on:
pull_request:
Expand All @@ -25,11 +25,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip setuptools wheel
pip install -r ./api/python/cell_census/scripts/requirements-dev.txt
pip install -e ./api/python/cell_census/
pip install -r ./api/python/cellxgene_census/scripts/requirements-dev.txt
pip install -e ./api/python/cellxgene_census/
- name: Test with pytest (API)
run: |
PYTHONPATH=. coverage run --parallel-mode -m pytest --durations=20 ./api/python/cell_census/tests/
PYTHONPATH=. coverage run --parallel-mode -m pytest --durations=20 ./api/python/cellxgene_census/tests/
- uses: actions/upload-artifact@v3
with:
name: coverage
Expand Down
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ repos:
files: ^api/python/notebooks
args: ["--config", "./api/python/notebooks/pyproject.toml"]
- id: black
name: black-cell-census
files: ^api/python/cell_census
args: ["--config", "./api/python/cell_census/pyproject.toml"]
name: black-cellxgene-census
files: ^api/python/cellxgene_census
args: ["--config", "./api/python/cellxgene_census/pyproject.toml"]
- id: black
name: black-tools
files: ^tools
Expand All @@ -21,9 +21,9 @@ repos:
rev: v0.0.249
hooks:
- id: ruff
name: ruff-cell-census
files: ^api/python/cell_census
args: ["--config=./api/python/cell_census/pyproject.toml", "--fix"]
name: ruff-cellxgene-census
files: ^api/python/cellxgene_census
args: ["--config=./api/python/cellxgene_census/pyproject.toml", "--fix"]
- id: ruff
name: ruff-tools
files: ^tools
Expand All @@ -33,9 +33,9 @@ repos:
rev: v1.0.1
hooks:
- id: mypy
name: mypy-cell-census
files: ^api/python/cell_census
args: ["--config-file=./api/python/cell_census/pyproject.toml"]
name: mypy-cellxgene-census
files: ^api/python/cellxgene_census
args: ["--config-file=./api/python/cellxgene_census/pyproject.toml"]
additional_dependencies:
- types-requests
- pytest
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "cell_census"
name = "cellxgene_census"
dynamic = ["version"]
description = "API to facilitate the use of the CZ CELLxGENE Discover Cell Census. For more information about the API and the project visit https://github.com/chanzuckerberg/cell-census/"
description = "API to facilitate the use of the CZ CELLxGENE Discover Census. For more information about the API and the project visit https://github.com/chanzuckerberg/cellxgene-census/"
authors = [
{ name = "Chan Zuckerberg Initiative", email = "[email protected]" }
]
Expand Down Expand Up @@ -41,12 +41,12 @@ dependencies= [
]

[project.urls]
homepage = "https://github.com/chanzuckerberg/cell-census"
repository = "https://github.com/chanzuckerberg/cell-census"
homepage = "https://github.com/chanzuckerberg/cellxgene-census"
repository = "https://github.com/chanzuckerberg/cellxgene-census"

[tool.setuptools.packages.find]
where = ["src"]
include = ["cell_census*"] # package names should match these glob patterns (["*"] by default)
include = ["cellxgene_census*"] # package names should match these glob patterns (["*"] by default)
exclude = ["tests*"] # exclude packages matching these glob patterns (empty by default)

[tool.setuptools_scm]
Expand All @@ -65,7 +65,7 @@ plugins = "numpy.typing.mypy_plugin"

[tool.pytest.ini_options]
markers = [
"live_corpus: runs on the live Cell Census data corpus and small enough to run in CI",
"live_corpus: runs on the live CELLxGENE Census data corpus and small enough to run in CI",
"expensive: too expensive to run regularly or in CI",
]

Expand All @@ -76,4 +76,4 @@ line-length = 120
target-version = "py39"

[tool.ruff.isort]
known-first-party =["cell_census"]
known-first-party =["cellxgene_census"]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# cell_census Python package release process
# cellxgene_census Python package release process

The following approach is used to manage releases of the Python cell_census package:
The following approach is used to manage releases of the Python cellxgene_census package:

1. The cell_census package is automatically built (sdist and wheels) in a GitHub action, and build artifacts are uploaded to GitHub.
1. The cellxgene_census package is automatically built (sdist and wheels) in a GitHub action, and build artifacts are uploaded to GitHub.
2. Release candidate testing is done by installing built assets from Github.
3. Build versions are managed via [`setuptools_scm`](https://github.com/pypa/setuptools_scm) and the version is automatically determined from git tags.
4. Releases are created and managed via GitHub Releases, leaving a tag in place from which future branches (eg, emergency fixes) can be created.
Expand All @@ -12,8 +12,8 @@ The following approach is used to manage releases of the Python cell_census pack

While not strictly required, this process assumes you have met the following prerequisites:

- You have write access to the chanzuckerberg/cell_census repo
- You have an account on pypi.org and test.pypi.org, both with access to the cell_census project
- You have write access to the `chanzuckerberg/cellxgene-census` repo
- You have an account on pypi.org and test.pypi.org, both with access to the cellxgene_census project
- You have the Github CLI tool (`gh`) installed. See [documentation](https://cli.github.com/).
- You have the `pipx` CLI tool installed. See [documentation](https://pypa.github.io/pipx/).

Expand Down Expand Up @@ -43,14 +43,14 @@ Any pre-built asset on Github can be installed and tested from the Github URL. F
```shell
$ unzip artifact.zip -d ./artifact/
Archive: artifact.zip
inflating: ./artifact/cell_census-0.0.1.dev0-py3-none-any.whl
inflating: ./artifact/cell_census-0.0.1.dev0.tar.gz
inflating: ./artifact/cellxgene_census-0.0.1.dev0-py3-none-any.whl
inflating: ./artifact/cellxgene_census-0.0.1.dev0.tar.gz
```

3. Install and test the downloaded build, e.g.,
```shell
$ pip uninstall cell_census
$ pip install ./artifact/cell_census-*-any.whl
$ pip uninstall cellxgene-census
$ pip install ./artifact/cellxgene_census-*-any.whl
```

To test a release candidate:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
"""
Cell Census convience API

An API to facilitate use of the CZI Science Cell Census. The Cell Census is a versioned container of single-cell data hosted at [CELLxGENE Discover](https://cellxgene.cziscience.com/).
An API to facilitate use of the CZI Science CELLxGENE Census. The Census is a versioned container of single-cell data hosted at [CELLxGENE Discover](https://cellxgene.cziscience.com/).

The API is built on the `tiledbsoma` SOMA API, and provides a number of helper functions including:

* Open a named version of the Cell Census, for use with the SOMA API
* Get a list of available Cell Census versions, and for each version, a description
* Get a slice of the Cell Census as an AnnData, for use with ScanPy
* Open a named version of the Census, for use with the SOMA API
* Get a list of available Census versions, and for each version, a description
* Get a slice of the Census as an AnnData, for use with ScanPy
* Get the URI for, or directly download, underlying data in H5AD format

For more information on the API, visit the [cell_census repo](https://github.com/chanzuckerberg/cell-census/). For more information on SOMA, see the [tiledbsoma repo](https://github.com/single-cell-data/TileDB-SOMA).
For more information on the API, visit the [cellxgene_census repo](https://github.com/chanzuckerberg/cellxgene-census/). For more information on SOMA, see the [tiledbsoma repo](https://github.com/single-cell-data/TileDB-SOMA).
"""

try:
Expand All @@ -25,7 +23,7 @@
from ._release_directory import get_census_version_description, get_census_version_directory

try:
__version__ = metadata.version("cell_census")
__version__ = metadata.version("cellxgene_census")
except metadata.PackageNotFoundError:
# package is not installed
__version__ = "0.0.0-unknown"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Acceptance tests for the Census.
Acceptance tests for the CELLxGENE Census.

NOTE: those marked `expensive` are not run in the CI as they are, well, expensive...

Expand All @@ -17,13 +17,13 @@
import tiledb
import tiledbsoma as soma

import cell_census
from cell_census._open import DEFAULT_TILEDB_CONFIGURATION
import cellxgene_census
from cellxgene_census._open import DEFAULT_TILEDB_CONFIGURATION


def make_context(census_version: str, config: Optional[Dict[str, Any]] = None) -> soma.SOMATileDBContext:
config = config or {}
version = cell_census.get_census_version_description(census_version)
version = cellxgene_census.get_census_version_description(census_version)
s3_region = version["soma"].get("s3_region", "us-west-2")
config.update({"vfs.s3.region": s3_region})
return soma.options.SOMATileDBContext(tiledb_ctx=tiledb.Ctx(config))
Expand All @@ -33,7 +33,7 @@ def make_context(census_version: str, config: Optional[Dict[str, Any]] = None) -
@pytest.mark.parametrize("organism", ["homo_sapiens", "mus_musculus"])
def test_load_axes(organism: str) -> None:
"""Verify axes can be loaded into a Pandas DataFrame"""
census = cell_census.open_soma(census_version="latest")
census = cellxgene_census.open_soma(census_version="latest")

# use subset of columns for speed
obs_df = (
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_incremental_read(organism: str) -> None:
# open census with a small (default) TileDB buffer size, which reduces
# memory use, and makes it feasible to run in a GHA.
context = make_context("latest")
with cell_census.open_soma(census_version="latest", context=context) as census:
with cellxgene_census.open_soma(census_version="latest", context=context) as census:
assert table_iter_is_ok(census["census_data"][organism].obs.read(column_names=["soma_joinid", "tissue"]))
assert table_iter_is_ok(
census["census_data"][organism].ms["RNA"].var.read(column_names=["soma_joinid", "feature_id"])
Expand All @@ -93,7 +93,7 @@ def test_incremental_read(organism: str) -> None:
def test_incremental_query(organism: str, obs_value_filter: str, stop_after: Optional[int]) -> None:
"""Verify incremental read of query result."""
# use default TileDB configuration
with cell_census.open_soma(census_version="latest") as census:
with cellxgene_census.open_soma(census_version="latest") as census:
with census["census_data"][organism].axis_query(
measurement_name="RNA", obs_query=soma.AxisQuery(value_filter=obs_value_filter)
) as query:
Expand Down Expand Up @@ -140,6 +140,6 @@ def test_get_anndata(
"""Verify query and read into AnnData"""
ctx_config = ctx_config or {}
context = make_context("latest", ctx_config)
with cell_census.open_soma(census_version="latest", context=context) as census:
ad = cell_census.get_anndata(census, organism, obs_value_filter=obs_value_filter, obs_coords=obs_coords)
with cellxgene_census.open_soma(census_version="latest", context=context) as census:
ad = cellxgene_census.get_anndata(census, organism, obs_value_filter=obs_value_filter, obs_coords=obs_coords)
assert ad is not None
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import requests_mock as rm
import s3fs

import cell_census
from cell_census._release_directory import CELL_CENSUS_RELEASE_DIRECTORY_URL
import cellxgene_census
from cellxgene_census._release_directory import CELL_CENSUS_RELEASE_DIRECTORY_URL

DIRECTORY_JSON = {
"latest": "2022-11-01",
Expand Down Expand Up @@ -45,7 +45,7 @@ def directory_mock(requests_mock: rm.Mocker) -> Any:


def test_get_census_version_directory(directory_mock: Any) -> None:
directory = cell_census.get_census_version_directory()
directory = cellxgene_census.get_census_version_directory()

assert isinstance(directory, dict)
assert len(directory) > 0
Expand All @@ -60,12 +60,12 @@ def test_get_census_version_directory(directory_mock: Any) -> None:
assert directory["latest"] == directory["2022-11-01"]

for tag in directory:
assert directory[tag] == cell_census.get_census_version_description(tag)
assert directory[tag] == cellxgene_census.get_census_version_description(tag)


def test_get_census_version_description_errors() -> None:
with pytest.raises(KeyError):
cell_census.get_census_version_description(census_version="no/such/version/exists")
cellxgene_census.get_census_version_description(census_version="no/such/version/exists")


@pytest.mark.live_corpus
Expand All @@ -78,11 +78,11 @@ def test_live_directory_contents() -> None:

fs = s3fs.S3FileSystem(anon=True, cache_regions=True)

directory = cell_census.get_census_version_directory()
directory = cellxgene_census.get_census_version_directory()
assert "latest" in directory

for version, version_description in directory.items():
with cell_census.open_soma(census_version=version) as census:
with cellxgene_census.open_soma(census_version=version) as census:
assert census is not None

assert fs.exists(version_description["soma"]["uri"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import pytest
import tiledbsoma as soma

import cell_census
import cellxgene_census


@pytest.fixture
def census() -> soma.Collection:
return cell_census.open_soma(census_version="latest")
return cellxgene_census.open_soma(census_version="latest")


@pytest.mark.live_corpus
def test_get_anndata_value_filter(census: soma.Collection) -> None:
with census:
ad = cell_census.get_anndata(
ad = cellxgene_census.get_anndata(
census,
organism="Mus musculus",
obs_value_filter="tissue_general == 'vasculature'",
Expand All @@ -33,7 +33,9 @@ def test_get_anndata_value_filter(census: soma.Collection) -> None:
@pytest.mark.live_corpus
def test_get_anndata_coords(census: soma.Collection) -> None:
with census:
ad = cell_census.get_anndata(census, organism="Mus musculus", obs_coords=slice(1000), var_coords=slice(2000))
ad = cellxgene_census.get_anndata(
census, organism="Mus musculus", obs_coords=slice(1000), var_coords=slice(2000)
)

assert ad is not None
assert ad.n_vars == 2001
Expand All @@ -47,13 +49,13 @@ def test_get_anndata_allows_missing_obs_or_var_filter(census: soma.Collection) -
with census:
mouse = census["census_data"]["mus_musculus"]

adata = cell_census.get_anndata(census, organism="Mus musculus", obs_value_filter="tissue == 'aorta'")
adata = cellxgene_census.get_anndata(census, organism="Mus musculus", obs_value_filter="tissue == 'aorta'")
assert adata.n_obs == len(
mouse.obs.read(value_filter="tissue == 'aorta'", column_names=["soma_joinid"]).concat()
)
assert adata.n_vars == len(mouse.ms["RNA"].var.read(column_names=["soma_joinid"]).concat())

adata = cell_census.get_anndata(
adata = cellxgene_census.get_anndata(
census,
organism="Mus musculus",
obs_coords=slice(10000),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytest
import scipy.sparse

import cell_census
from cell_census._experiment import _get_experiment
import cellxgene_census
from cellxgene_census._experiment import _get_experiment


@pytest.mark.live_corpus
def test_get_experiment() -> None:
with cell_census.open_soma(census_version="latest") as census:
with cellxgene_census.open_soma(census_version="latest") as census:
mouse_uri = census["census_data"]["mus_musculus"].uri
human_uri = census["census_data"]["homo_sapiens"].uri

Expand All @@ -26,11 +26,11 @@ def test_get_experiment() -> None:
@pytest.mark.live_corpus
@pytest.mark.parametrize("organism", ["homo_sapiens", "mus_musculus"])
def test_get_presence_matrix(organism: str) -> None:
census = cell_census.open_soma(census_version="latest")
census = cellxgene_census.open_soma(census_version="latest")

census_datasets = census["census_info"]["datasets"].read().concat().to_pandas()

pm = cell_census.get_presence_matrix(census, organism)
pm = cellxgene_census.get_presence_matrix(census, organism)
assert isinstance(pm, scipy.sparse.csr_matrix)
assert pm.shape[0] == len(census_datasets)
assert pm.shape[1] == len(
Expand Down
Loading