-
Notifications
You must be signed in to change notification settings - Fork 1
Mccalluc/consistent arrays #66
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
base: main
Are you sure you want to change the base?
Changes from all commits
3f7874c
4d99793
f0c0ebf
ba166ef
a21ef87
0f74cd4
b3f0232
d72b6ec
7d42b8b
9dbe37a
f990839
aafa5c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.0.6 | ||
| 0.1.0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ | |
| import zarr | ||
|
|
||
| from .base_builders import ViewConfBuilder | ||
| from ..utils import get_conf_cells | ||
|
|
||
|
|
||
| class RNASeqAnnDataZarrViewConfBuilder(ViewConfBuilder): | ||
|
|
@@ -18,14 +17,14 @@ class RNASeqAnnDataZarrViewConfBuilder(ViewConfBuilder): | |
| https://portal.hubmapconsortium.org/browse/dataset/e65175561b4b17da5352e3837aa0e497 | ||
| """ | ||
|
|
||
| def __init__(self, entity, groups_token, assets_endpoint, **kwargs): | ||
| super().__init__(entity, groups_token, assets_endpoint, **kwargs) | ||
| def __init__(self, entity, groups_token, assets_endpoint): | ||
| super().__init__(entity, groups_token, assets_endpoint) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| # Spatially resolved RNA-seq assays require some special handling, | ||
| # and others do not. | ||
| self._is_spatial = False | ||
| self._scatterplot_w = 9 | ||
|
|
||
| def get_conf_cells(self, marker=None): | ||
| def get_configs(self, marker=None): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Builder subclasses now define |
||
| zarr_path = 'hubmap_ui/anndata-zarr/secondary_analysis.zarr' | ||
| file_paths_found = [file["rel_path"] for file in self._entity["files"]] | ||
| # Use .zgroup file as proxy for whether or not the zarr store is present. | ||
|
|
@@ -77,7 +76,7 @@ def get_conf_cells(self, marker=None): | |
| )) | ||
|
|
||
| vc = self._setup_anndata_view_config(vc, dataset, marker) | ||
| return get_conf_cells(vc) | ||
| return [vc] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| def _setup_anndata_view_config(self, vc, dataset, marker=None): | ||
| scatterplot = vc.add_view( | ||
|
|
@@ -118,8 +117,8 @@ class SpatialRNASeqAnnDataZarrViewConfBuilder(RNASeqAnnDataZarrViewConfBuilder): | |
| https://portal.hubmapconsortium.org/browse/dataset/2a590db3d7ab1e1512816b165d95cdcf | ||
| """ | ||
|
|
||
| def __init__(self, entity, groups_token, assets_endpoint, **kwargs): | ||
| super().__init__(entity, groups_token, assets_endpoint, **kwargs) | ||
| def __init__(self, entity, groups_token, assets_endpoint): | ||
| super().__init__(entity, groups_token, assets_endpoint) | ||
| # Spatially resolved RNA-seq assays require some special handling, | ||
| # and others do not. | ||
| self._is_spatial = True | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,21 +2,40 @@ | |
| from collections import namedtuple | ||
| from abc import ABC, abstractmethod | ||
|
|
||
| import nbformat | ||
|
|
||
| ConfCells = namedtuple('ConfCells', ['conf', 'cells']) | ||
|
|
||
| ConfigsCells = namedtuple('ConfigsCells', ['configs', 'cells']) | ||
|
|
||
|
|
||
| def _get_cells_from_conf_list(confs): | ||
| cells = [] | ||
| if len(confs) > 1: | ||
| cells.append(nbformat.v4.new_markdown_cell('Multiple visualizations are available.')) | ||
| for conf in confs: | ||
| cells.extend(_get_cells_from_conf(conf)) | ||
| return cells | ||
|
|
||
|
|
||
| def _get_cells_from_conf(conf): | ||
| imports, conf_expression = conf.to_python() | ||
| return [ | ||
| nbformat.v4.new_code_cell(f'from vitessce import {", ".join(imports)}'), | ||
| nbformat.v4.new_code_cell(f'conf = {conf_expression}\nconf.widget()'), | ||
| ] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both of these are moved from utils, since this is the only code that needs them. |
||
|
|
||
|
|
||
| class NullViewConfBuilder(): | ||
| def __init__(self, entity, groups_token, assets_endpoint, **kwargs): | ||
| def __init__(self, entity, groups_token, assets_endpoint): | ||
| # Just so it has the same signature as the other builders | ||
| pass | ||
|
|
||
| def get_conf_cells(self, **kwargs): | ||
| return ConfCells(None, None) | ||
| def get_configs_cells(self, marker=None): | ||
| return ConfigsCells([], []) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, even for the Null case we return lists. (One possibility for the cells would be to generate a message that there is no visualization... Sort of depends on the direction taken by workspaces.) |
||
|
|
||
|
|
||
| class ViewConfBuilder(ABC): | ||
| def __init__(self, entity, groups_token, assets_endpoint, **kwargs): | ||
| def __init__(self, entity, groups_token, assets_endpoint): | ||
| """Object for building the vitessce configuration. | ||
| :param dict entity: Entity response from search index (from the entity API) | ||
| :param str groups_token: Groups token for use in authenticating API | ||
|
|
@@ -29,9 +48,15 @@ def __init__(self, entity, groups_token, assets_endpoint, **kwargs): | |
| self._files = [] | ||
|
|
||
| @abstractmethod | ||
| def get_conf_cells(self, **kwargs): # pragma: no cover | ||
| def get_configs(self): # pragma: no cover | ||
| raise NotImplementedError() | ||
|
|
||
| def get_configs_cells(self, marker=None): | ||
| kwargs = {'marker': marker} if marker is not None else {} | ||
| configs = self.get_configs(**kwargs) | ||
| cells = _get_cells_from_conf_list(configs) | ||
| return ConfigsCells(configs, cells) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the new base class method that constructs the list of cells and returns a tuple. |
||
|
|
||
| def _replace_url_in_file(self, file): | ||
| """Replace url in incoming file object | ||
| :param dict file: File dict which will have its rel_path replaced by url | ||
|
|
@@ -118,5 +143,5 @@ def _get_file_paths(self): | |
| class _DocTestBuilder(ViewConfBuilder): # pragma: no cover | ||
| # The doctests on the methods in this file need a concrete class to instantiate: | ||
| # We need a concrete definition for this method, even if it's never used. | ||
| def get_conf_cells(self, **kwargs): | ||
| pass | ||
| def get_configs(self): | ||
| raise NotImplementedError() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be called... if it were, we want an error. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| Component as cm, | ||
| ) | ||
|
|
||
| from ..utils import get_matches, group_by_file_name, get_conf_cells | ||
| from ..utils import get_matches, group_by_file_name | ||
| from ..paths import IMAGE_PYRAMID_DIR, OFFSETS_DIR, SEQFISH_HYB_CYCLE_REGEX, SEQFISH_FILE_REGEX | ||
| from .base_builders import ViewConfBuilder | ||
|
|
||
|
|
@@ -23,7 +23,7 @@ def _get_img_and_offset_url(self, img_path, img_dir): | |
|
|
||
| >>> from pprint import pprint | ||
| >>> class ConcreteBuilder(AbstractImagingViewConfBuilder): | ||
| ... def get_conf_cells(self, **kwargs): | ||
| ... def get_configs(self): | ||
| ... pass | ||
| >>> builder = ConcreteBuilder( | ||
| ... entity={ "uuid": "uuid" }, | ||
|
|
@@ -56,15 +56,15 @@ def _setup_view_config_raster(self, vc, dataset, disable_3d=[]): | |
|
|
||
|
|
||
| class ImagePyramidViewConfBuilder(AbstractImagingViewConfBuilder): | ||
| def __init__(self, entity, groups_token, assets_endpoint, **kwargs): | ||
| def __init__(self, entity, groups_token, assets_endpoint): | ||
| """Wrapper class for creating a standard view configuration for image pyramids, | ||
| i.e for high resolution viz-lifted imaging datasets like | ||
| https://portal.hubmapconsortium.org/browse/dataset/dc289471333309925e46ceb9bafafaf4 | ||
| """ | ||
| self.image_pyramid_regex = IMAGE_PYRAMID_DIR | ||
| super().__init__(entity, groups_token, assets_endpoint, **kwargs) | ||
| super().__init__(entity, groups_token, assets_endpoint) | ||
|
|
||
| def get_conf_cells(self, **kwargs): | ||
| def get_configs(self): | ||
| file_paths_found = self._get_file_paths() | ||
| found_images = [ | ||
| path for path in get_matches( | ||
|
|
@@ -93,7 +93,7 @@ def get_conf_cells(self, **kwargs): | |
| conf = vc.to_dict() | ||
| # Don't want to render all layers | ||
| del conf["datasets"][0]["files"][0]["options"]["renderLayers"] | ||
| return get_conf_cells(conf) | ||
| return [VitessceConfig.from_dict(conf)] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another change for the sake of consistency: |
||
|
|
||
|
|
||
| class IMSViewConfBuilder(ImagePyramidViewConfBuilder): | ||
|
|
@@ -102,8 +102,8 @@ class IMSViewConfBuilder(ImagePyramidViewConfBuilder): | |
| of all the channels separated out. | ||
| """ | ||
|
|
||
| def __init__(self, entity, groups_token, assets_endpoint, **kwargs): | ||
| super().__init__(entity, groups_token, assets_endpoint, **kwargs) | ||
| def __init__(self, entity, groups_token, assets_endpoint): | ||
| super().__init__(entity, groups_token, assets_endpoint) | ||
| # Do not show the separated mass-spec images. | ||
| self.image_pyramid_regex = ( | ||
| re.escape(IMAGE_PYRAMID_DIR) + r"(?!/ometiffs/separate/)" | ||
|
|
@@ -116,7 +116,7 @@ class SeqFISHViewConfBuilder(AbstractImagingViewConfBuilder): | |
| grouped together per position in a single Vitessce configuration. | ||
| """ | ||
|
|
||
| def get_conf_cells(self, **kwargs): | ||
| def get_configs(self): | ||
| file_paths_found = [file["rel_path"] for file in self._entity["files"]] | ||
| full_seqfish_regex = "/".join( | ||
| [ | ||
|
|
@@ -159,13 +159,11 @@ def get_conf_cells(self, **kwargs): | |
| conf = vc.to_dict() | ||
| # Don't want to render all layers | ||
| del conf["datasets"][0]["files"][0]["options"]["renderLayers"] | ||
| confs.append(conf) | ||
| return get_conf_cells(confs) | ||
| confs.append(VitessceConfig.from_dict(conf)) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto: We're always objects now. |
||
| return confs | ||
|
|
||
| def _get_hybcycle(self, image_path): | ||
| return re.search(SEQFISH_HYB_CYCLE_REGEX, image_path)[0] | ||
|
|
||
| def _get_pos_name(self, image_path): | ||
| return re.search(SEQFISH_FILE_REGEX, image_path)[0].split(".")[ | ||
| 0 | ||
| ] | ||
| return re.search(SEQFISH_FILE_REGEX, image_path)[0].split(".")[0] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change to the interface, so incrementing the minor version number seems appropriate.