-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |