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

(chore): Clean up AnnDataWrapper API #341

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
15 changes: 10 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ per-file-ignores =
vitessce/__init__.py: F401
vitessce/data_utils/__init__.py: F401
ignore =
E501, # Ignore line too long
W605, # Ignore invalid escape sequence '\*'
W503, # Ignore line break before binary operator: Skim down the left edge to understand intent.
E127 # Ignore continuation line over-indented for visual indent
E128 # Ignore continuation line under-indented for visual indent
# Ignore line too long
E501,
# Ignore invalid escape sequence '\*'
W605,
# Ignore line break before binary operator: Skim down the left edge to understand intent.
W503,
# Ignore continuation line over-indented for visual indent
E127
# Ignore continuation line under-indented for visual indent
E128
Comment on lines +10 to +19
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclude =
./js/node_modules/,
./docs/notebooks/.ipynb_checkpoints/,
Expand Down
52 changes: 27 additions & 25 deletions vitessce/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile
from uuid import uuid4
from pathlib import PurePath, PurePosixPath
import warnings
import zarr

from .constants import (
Expand Down Expand Up @@ -968,9 +969,9 @@ def __init__(self, adata_path=None, adata_url=None, adata_store=None, obs_featur
"""
super().__init__(**kwargs)
self._repr = make_repr(locals())
self._adata_path = adata_path
self._adata_url = adata_url
self._adata_store = adata_store
self._path = adata_path
self._url = adata_url
self._store = adata_store

num_inputs = sum([1 for x in [adata_path, adata_url, adata_store] if x is not None])
if num_inputs > 1:
Expand All @@ -996,24 +997,25 @@ def __init__(self, adata_path=None, adata_url=None, adata_store=None, obs_featur

self.local_dir_uid = make_unique_filename(".adata.zarr")
self._expression_matrix = obs_feature_matrix_path
self._cell_set_obs_names = obs_set_names
self._obs_set_names = obs_set_names
self._mappings_obsm_names = obs_embedding_names
self._gene_var_filter = feature_filter_path
self._matrix_gene_var_filter = initial_feature_filter_path
self._cell_set_obs = obs_set_paths
self._obs_set_elems = obs_set_paths
self._spatial_centroid_obsm = obs_locations_path
self._spatial_polygon_obsm = obs_segmentations_path
self._mappings_obsm = obs_embedding_paths
self._mappings_obsm_dims = obs_embedding_dims
self._spatial_spots_obsm = obs_spots_path
self._spatial_points_obsm = obs_points_path
self._gene_alias = feature_labels_path
self._feature_labels = feature_labels_path
# Support legacy provision of single obs labels path
if (obs_labels_path is not None):
self._obs_labels_paths = [obs_labels_path]
warnings.warn("`obs_labels_path` will be deprecated in a future release.", DeprecationWarning)
self._obs_labels_elems = [obs_labels_path]
self._obs_labels_names = [obs_labels_path.split('/')[-1]]
else:
self._obs_labels_paths = obs_labels_paths
self._obs_labels_elems = obs_labels_paths
self._obs_labels_names = obs_labels_names
self._convert_to_dense = convert_to_dense
self._coordination_values = coordination_values
Expand All @@ -1025,25 +1027,25 @@ def convert_and_save(self, dataset_uid, obj_i, base_dir=None):

file_def_creator = self.make_file_def_creator(
dataset_uid, obj_i)
routes = self.make_anndata_routes(dataset_uid, obj_i)
routes = self.make_routes(dataset_uid, obj_i)

self.file_def_creators.append(file_def_creator)
self.routes += routes

def make_anndata_routes(self, dataset_uid, obj_i):
def make_routes(self, dataset_uid, obj_i):
if self.is_remote:
return []
elif self.is_store:
self.register_zarr_store(dataset_uid, obj_i, self._adata_store, self.local_dir_uid)
self.register_zarr_store(dataset_uid, obj_i, self._store, self.local_dir_uid)
return []
else:
return self.get_local_dir_route(dataset_uid, obj_i, self._adata_path, self.local_dir_uid)
return self.get_local_dir_route(dataset_uid, obj_i, self._path, self.local_dir_uid)

def get_zarr_url(self, base_url="", dataset_uid="", obj_i=""):
if self.is_remote:
return self._adata_url
return self._url
else:
return self.get_local_dir_url(base_url, dataset_uid, obj_i, self._adata_path, self.local_dir_uid)
return self.get_local_dir_url(base_url, dataset_uid, obj_i, self._path, self.local_dir_uid)

def make_file_def_creator(self, dataset_uid, obj_i):
def get_anndata_zarr(base_url):
Expand Down Expand Up @@ -1085,13 +1087,13 @@ def get_anndata_zarr(base_url):
if self._mappings_obsm_dims is not None:
for dim_i, dim in enumerate(self._mappings_obsm_dims):
options["obsEmbedding"][dim_i]['dims'] = dim
if self._cell_set_obs is not None:
if self._obs_set_elems is not None:
options["obsSets"] = []
if self._cell_set_obs_names is not None:
names = self._cell_set_obs_names
if self._obs_set_names is not None:
names = self._obs_set_names
else:
names = [obs.split('/')[-1] for obs in self._cell_set_obs]
for obs, name in zip(self._cell_set_obs, names):
names = [obs.split('/')[-1] for obs in self._obs_set_elems]
for obs, name in zip(self._obs_set_elems, names):
options["obsSets"].append({
"name": name,
"path": obs
Expand All @@ -1104,20 +1106,20 @@ def get_anndata_zarr(base_url):
options["obsFeatureMatrix"]["featureFilterPath"] = self._gene_var_filter
if self._matrix_gene_var_filter is not None:
options["obsFeatureMatrix"]["initialFeatureFilterPath"] = self._matrix_gene_var_filter
if self._gene_alias is not None:
if self._feature_labels is not None:
options["featureLabels"] = {
"path": self._gene_alias
"path": self._feature_labels
}
if self._obs_labels_paths is not None:
if self._obs_labels_names is not None and len(self._obs_labels_paths) == len(self._obs_labels_names):
if self._obs_labels_elems is not None:
if self._obs_labels_names is not None and len(self._obs_labels_elems) == len(self._obs_labels_names):
# A name was provided for each path element, so use those values.
names = self._obs_labels_names
else:
# Names were not provided for each path element,
# so fall back to using the final part of each path for the names.
names = [labels_path.split('/')[-1] for labels_path in self._obs_labels_paths]
names = [labels_path.split('/')[-1] for labels_path in self._obs_labels_elems]
obs_labels = []
for path, name in zip(self._obs_labels_paths, names):
for path, name in zip(self._obs_labels_elems, names):
obs_labels.append({"path": path, "obsLabelsType": name})
options["obsLabels"] = obs_labels
if len(options.keys()) > 0:
Expand Down
Loading