Skip to content

Commit

Permalink
iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Feb 6, 2025
1 parent ce007bd commit 8725ec9
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 9 deletions.
9 changes: 0 additions & 9 deletions apis/python/remote_tests/x

This file was deleted.

116 changes: 116 additions & 0 deletions apis/python/test_03_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# These are test that need to run first to check basic functionality, before we go on to test other,
# more complex things.
from __future__ import annotations

import os

import pandas as pd
import pytest

import tiledbsoma
import tiledbsoma.io
import tiledbsoma.logging

if os.getenv("TILEDB_REST_TOKEN") is None:
pytest.skip(reason="$TILEDB_REST_TOKEN is not set", allow_module_level=True)


@pytest.mark.parametrize(
"uri",
[
"tiledb://unittest/pbmc3k_unprocessed_1_7_3",
"tiledb://unittest/pbmc3k_unprocessed_1_12_3",
"tiledb://unittest/pbmc3k_unprocessed_1_14_5",
"tiledb://unittest/pbmc3k_unprocessed_1_15_0",
"tiledb://unittest/pbmc3k_unprocessed_1.15.7",
],
)
def test_basic_readback(uri):
with tiledbsoma.Experiment.open(uri) as exp:

md = dict(exp.metadata)
assert md["dataset_type"] == "soma"
assert md["soma_object_type"] == "SOMAExperiment"

md = dict(exp.obs.metadata)
assert md["soma_object_type"] == "SOMADataFrame"

md = dict(exp.ms["RNA"].var.metadata)
assert md["soma_object_type"] == "SOMADataFrame"

md = dict(exp.ms["RNA"].X["data"].metadata)
assert md["soma_object_type"] == "SOMASparseNDArray"

obs_df = exp.obs.read().concat()
# XXX asserts
var_df = exp.ms["RNA"].var.read().concat()
# XXX asserts
X = exp.ms["RNA"].X["data"].read().tables().concat()
# XXX asserts

adata = tiledbsoma.io.to_anndata(exp, "RNA")
assert adata.obs.shape == (2700, 4)
assert adata.var.shape == (13714, 0)
assert adata.X.shape == (2700, 13714)

# ----------------------------------------------------------------
## Slicing and filtering objects
#exp.obs.read(
# coords=[slice(0, 99)],
# value_filter="total_counts > 4000",
# column_names=["soma_joinid", "obs_id", "total_counts"],
#).concat().to_pandas()
#exp.obs.read(
# coords=[slice(0, 99)],
# value_filter='parity == "even" and total_counts > 4000',
# column_names=["soma_joinid", "obs_id", "total_counts", "parity"],
#).concat().to_pandas()
#exp.ms["RNA"].var.read(
# value_filter="var_id in ['ANXA1', 'IFI44', 'IFI44L', 'OAS1']",
# column_names=["var_id", "gene_ids", "mean_counts"],
#).concat().to_pandas()

# ----------------------------------------------------------------
## Slicing and filtering experiments
#exp.uri
#query = tiledbsoma.ExperimentAxisQuery(
# experiment=exp,
# measurement_name="RNA",
# obs_query=tiledbsoma.AxisQuery(
# value_filter="n_genes_by_counts > 1000",
# ),
# var_query=tiledbsoma.AxisQuery(
# value_filter="n_cells_by_counts > 100",
# ),
#)
#
#(query.n_obs, query.n_vars)

# ----------------------------------------------------------------
#query.obs().concat().to_pandas()
#query.X(layer_name="data").tables().concat().to_pandas()
#query.to_anndata(X_name="data")
#query.close()
#with tiledbsoma.ExperimentAxisQuery(
# experiment=exp,
# measurement_name="RNA",
# obs_query=tiledbsoma.AxisQuery(
# value_filter="n_genes_by_counts > 1000",
# ),
# var_query=tiledbsoma.AxisQuery(
# value_filter="n_cells_by_counts > 100",
# ),
#) as query:
# print(query.to_anndata(X_name="data"))

#with tiledbsoma.ExperimentAxisQuery(
# experiment=exp,
# measurement_name="RNA",
# obs_query=tiledbsoma.AxisQuery(
# value_filter='n_genes_by_counts > 1000 and parity == "even"',
# ),
# var_query=tiledbsoma.AxisQuery(
# value_filter="n_cells_by_counts > 100",
# ),
#) as query:
# print(query.to_anndata(X_name="data"))

0 comments on commit 8725ec9

Please sign in to comment.