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

Keller mark/spatial data2 #375

Merged
merged 8 commits into from
Oct 7, 2024
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
66 changes: 61 additions & 5 deletions tests/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,69 @@ def test_multivec_zarr_with_base_dir(self):
def test_spatial_data_with_base_dir(self):

spatial_data_path = 'test.spatialdata.zarr'
w = SpatialDataWrapper(sdata_path=spatial_data_path, image_path="images/picture", obs_set_paths=['obs/CellType'], obs_set_names=['Cell Type'], obs_embedding_paths=[
'obsm/X_umap'], obs_embedding_names=['UMAP'])
w = SpatialDataWrapper(
sdata_path=spatial_data_path,
image_path="images/picture",
obs_set_paths=['obs/CellType'],
obs_set_names=['Cell Type'],
obs_embedding_paths=['obsm/X_umap'],
obs_embedding_names=['UMAP']
)
w.base_dir = data_path
w.local_dir_uid = 'spatialdata.zarr'

file_def_creator = w.make_file_def_creator('A', 0)
file_def = file_def_creator('http://localhost:8000')
print(file_def)
self.assertEqual(file_def,
{'fileType': 'spatialdata.zarr', 'url': 'http://localhost:8000/test.spatialdata.zarr', 'options': {'obsSets': {'obsSets': [{'name': 'Cell Type', 'path': 'obs/CellType'}], 'tablePath': 'tables/table'}, 'image': {'path': 'images/picture'}}})
self.assertEqual(file_def, {
'fileType': 'spatialdata.zarr',
'url': 'http://localhost:8000/test.spatialdata.zarr',
'options': {
'obsSets': {
'obsSets': [{'name': 'Cell Type', 'path': 'obs/CellType'}],
'tablePath': 'tables/table'
},
'image': {'path': 'images/picture'}
}})

def test_spatial_data_with_base_dir_2(self):
spatial_data_path = 'test.spatialdata.zarr'
w = SpatialDataWrapper(
sdata_path=spatial_data_path,
image_path='images/CytAssist_FFPE_Human_Breast_Cancer_full_image',
coordinate_system='aligned',
region='CytAssist_FFPE_Human_Breast_Cancer',
obs_feature_matrix_path='tables/table/X',
obs_spots_path='shapes/CytAssist_FFPE_Human_Breast_Cancer',
table_path='tables/table',
coordination_values={
"obsType": "spot"
}
)
w.base_dir = data_path
w.local_dir_uid = 'spatialdata.zarr'

file_def_creator = w.make_file_def_creator('A', 0)
file_def = file_def_creator('http://localhost:8000')
self.assertDictEqual(file_def, {
'fileType': 'spatialdata.zarr',
'url': 'http://localhost:8000/test.spatialdata.zarr',
'options': {
'image': {
'path': 'images/CytAssist_FFPE_Human_Breast_Cancer_full_image',
'coordinateSystem': 'aligned',
},
'obsFeatureMatrix': {
'path': 'tables/table/X',
'region': 'CytAssist_FFPE_Human_Breast_Cancer'
},
'obsSpots': {
'path': 'shapes/CytAssist_FFPE_Human_Breast_Cancer',
'tablePath': 'tables/table',
'region': 'CytAssist_FFPE_Human_Breast_Cancer',
'coordinateSystem': 'aligned',
}
},
'coordinationValues': {
"obsType": "spot"
}
})
21 changes: 18 additions & 3 deletions vitessce/file_def_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,28 @@ def gen_sdata_labels_schema(options, path: str, table_path: str = "tables/table"
return options


def gen_sdata_obs_spots_schema(options: dict, shapes_path: Optional[str] = None, table_path: str = "tables/table", region: Optional[str] = None, coordinate_system: Optional[str] = None) -> dict:
def gen_sdata_obs_spots_schema(options: dict, shapes_path: str, table_path: str = "tables/table", region: Optional[str] = None, coordinate_system: Optional[str] = None) -> dict:
if shapes_path is not None:
options['obsSpots'] = {
"path": shapes_path,
"tablePath": table_path,
"region": region
"tablePath": table_path
}
if region is not None:
options['obsSpots']['region'] = region
if coordinate_system is not None:
options['obsSpots']['coordinateSystem'] = coordinate_system
return options


def gen_sdata_obs_feature_matrix_schema(options: dict, matrix_path: Optional[str] = None, var_filter_path: Optional[str] = None, init_var_filter_path: Optional[str] = None, region: Optional[str] = None):
if matrix_path is not None:
options["obsFeatureMatrix"] = {
"path": matrix_path
}
if region is not None:
options['obsFeatureMatrix']['region'] = region
if var_filter_path is not None:
options["obsFeatureMatrix"]["featureFilterPath"] = var_filter_path
if init_var_filter_path is not None:
options["obsFeatureMatrix"]["initialFeatureFilterPath"] = init_var_filter_path
return options
6 changes: 3 additions & 3 deletions vitessce/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class VitessceWidget(anywidget.AnyWidget):

next_port = DEFAULT_PORT

js_package_version = Unicode('3.4.12').tag(sync=True)
js_package_version = Unicode('3.4.14').tag(sync=True)
js_dev_mode = Bool(False).tag(sync=True)
custom_js_url = Unicode('').tag(sync=True)
plugin_esm = List(trait=Unicode(''), default_value=[]).tag(sync=True)
Expand All @@ -463,7 +463,7 @@ class VitessceWidget(anywidget.AnyWidget):

store_urls = List(trait=Unicode(''), default_value=[]).tag(sync=True)

def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=False, js_package_version='3.4.12', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, invoke_timeout=30000):
def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=False, js_package_version='3.4.14', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, invoke_timeout=30000):
"""
Construct a new Vitessce widget.

Expand Down Expand Up @@ -576,7 +576,7 @@ def _plugin_command(self, params, buffers):
# Launch Vitessce using plain HTML representation (no ipywidgets)


def ipython_display(config, height=600, theme='auto', base_url=None, host_name=None, uid=None, port=None, proxy=False, js_package_version='3.4.12', js_dev_mode=False, custom_js_url='', plugin_esm=DEFAULT_PLUGIN_ESM, remount_on_uid_change=True):
def ipython_display(config, height=600, theme='auto', base_url=None, host_name=None, uid=None, port=None, proxy=False, js_package_version='3.4.14', js_dev_mode=False, custom_js_url='', plugin_esm=DEFAULT_PLUGIN_ESM, remount_on_uid_change=True):
from IPython.display import display, HTML
uid_str = "vitessce" + get_uid_str(uid)

Expand Down
25 changes: 13 additions & 12 deletions vitessce/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
gen_sdata_image_schema,
gen_sdata_labels_schema,
gen_sdata_obs_spots_schema,
gen_sdata_obs_sets_schema
gen_sdata_obs_sets_schema,
gen_sdata_obs_feature_matrix_schema,
)

from .constants import (
Expand Down Expand Up @@ -1289,7 +1290,7 @@ def auto_view_config(self, vc):

class SpatialDataWrapper(AnnDataWrapper):

def __init__(self, sdata_path: Optional[str] = None, sdata_url: Optional[str] = None, sdata_store: Optional[Union[str, zarr.storage.StoreLike]] = None, sdata_artifact: Optional[ln.Artifact] = None, image_path: Optional[str] = None, region: Optional[str] = None, coordinate_system: Optional[str] = None, affine_transformation: Optional[np.ndarray] = None, spot_shapes_path: Optional[str] = None, labels_path: Optional[str] = None, table_path: str = "tables/table", **kwargs):
def __init__(self, sdata_path: Optional[str] = None, sdata_url: Optional[str] = None, sdata_store: Optional[Union[str, zarr.storage.StoreLike]] = None, sdata_artifact: Optional[ln.Artifact] = None, image_path: Optional[str] = None, region: Optional[str] = None, coordinate_system: Optional[str] = None, affine_transformation: Optional[np.ndarray] = None, obs_spots_path: Optional[str] = None, labels_path: Optional[str] = None, table_path: str = "tables/table", **kwargs):
"""
Wrap a SpatialData object.

Expand All @@ -1301,16 +1302,16 @@ def __init__(self, sdata_path: Optional[str] = None, sdata_url: Optional[str] =
:type sdata_store: Optional[Union[str, zarr.storage.StoreLike]]
:param sdata_artifact: Artifact that corresponds to a SpatialData object.
:type sdata_artifact: Optional[ln.Artifact]
:param image_elem: Name of the image element of interest. By default, None.
:type image_elem: Optional[str]
:param image_path: Path to the image element of interest. By default, None.
:type image_path: Optional[str]
:param coordinate_system: Name of a target coordinate system.
:type coordinate_system: Optional[str]
:param affine_transformation: Transformation to be applied to the image. By default, None. Prefer coordinate_system.
:type affine_transformation: Optional[np.ndarray]
:param shapes_elem: location of the shapes, by default None
:type shapes_elem: Optional[str]
:param labels_elem: location of the labels, by default None
:type labels_elem: Optional[str]
:param obs_spots_path: Location of shapes that should be interpreted as spot observations, by default None
:type obs_spots_path: Optional[str]
:param labels_path: Location of the labels (segmentation bitmask image), by default None
:type labels_path: Optional[str]
"""
raise_error_if_zero_or_more_than_one([
sdata_path,
Expand All @@ -1331,7 +1332,7 @@ def __init__(self, sdata_path: Optional[str] = None, sdata_url: Optional[str] =
self._coordinate_system = coordinate_system
self._affine_transformation = affine_transformation
self._kwargs = kwargs
self._spot_shapes_path = spot_shapes_path
self._obs_spots_path = obs_spots_path
self._labels_path = labels_path
if self._adata_path is not None:
self.zarr_folder = 'spatialdata.zarr'
Expand Down Expand Up @@ -1402,7 +1403,7 @@ def from_object(cls: Type[SpatialDataWrapperType], sdata: SpatialData, table_key
image_path=str(image_elem) if image_elem is not None else None,
labels_path=str(labels_elem) if labels_elem is not None else None,
obs_feature_matrix_path=str(obs_feature_matrix_elem),
spot_shapes_path=str(spot_shapes_elem) if spot_shapes_elem is not None else None,
obs_spots_path=str(spot_shapes_elem) if spot_shapes_elem is not None else None,
initial_feature_filter_path=initial_feature_filter_elem,
obs_set_paths=obs_set_elems,
coordination_values={"obsType": "spot"} # TODO: should we remove?
Expand All @@ -1414,9 +1415,9 @@ def make_file_def_creator(self, dataset_uid: str, obj_i: str) -> Optional[Callab
def generator(base_url):
options = {}
options = gen_obs_labels_schema(options, self._obs_labels_elems, self._obs_labels_names)
options = gen_obs_feature_matrix_schema(options, self._expression_matrix, self._gene_var_filter, self._matrix_gene_var_filter)
options = gen_sdata_obs_feature_matrix_schema(options, self._expression_matrix, self._gene_var_filter, self._matrix_gene_var_filter, self._region)
options = gen_sdata_obs_sets_schema(options, self._obs_set_elems, self._obs_set_names, self._table_path, self._region)
options = gen_sdata_obs_spots_schema(options, self._spot_shapes_path, self._table_path, self._region, self._coordinate_system)
options = gen_sdata_obs_spots_schema(options, self._obs_spots_path, self._table_path, self._region, self._coordinate_system)
options = gen_sdata_image_schema(options, self._image_path, self._coordinate_system, self._affine_transformation)
options = gen_sdata_labels_schema(options, self._labels_path, self._table_path, self._coordinate_system, self._affine_transformation)
options = gen_feature_labels_schema(self._feature_labels, options)
Expand Down
Loading