From 52293d3bcf15865e69f2ae53196f71fcbe2de831 Mon Sep 17 00:00:00 2001 From: Tabassum Kakar Date: Fri, 13 Sep 2024 11:37:42 -0400 Subject: [PATCH] Adjusted arguments and minor fixes --- README.md | 1 + .../builders/epic_builders.py | 66 +++++++++---------- src/vis-preview.py | 22 ++++--- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 2527fa0..55475bd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ optional arguments: --marker MARKER Marker to highlight in visualization; Only used in some visualizations. --to_json Output viewconf, rather than open in browser. + --epic_uuid uuid for EPIC dataset, if available. ``` ``` diff --git a/src/portal_visualization/builders/epic_builders.py b/src/portal_visualization/builders/epic_builders.py index 6510efa..96c1de2 100644 --- a/src/portal_visualization/builders/epic_builders.py +++ b/src/portal_visualization/builders/epic_builders.py @@ -60,11 +60,11 @@ class SegmentationMaskBuilder(EPICConfBuilder): def _apply(self, conf): zarr_url = self.zarr_store_url() datasets = conf.get_datasets() - # TODO: add the correct path to the segmentation mask ome-tiff + # TODO: add the correct path to the segmentation mask ome-tiff (image-pyramid)? seg_path = f'{self.segmentations_url}/' seg_path = 'https://assets.hubmapconsortium.org/c9d9ab5c9ee9642b60dd351024968627/ometiff-pyramids/VAN0042-RK-3-18-registered-PAS-to-postAF-registered.ome_mask.ome.tif?token=AgzQXm7nvOW32vWw0EPpKonwbOqjNBzNvvW1p15855NoYglJxyfkC8rlJJWy8V6E8MeyXOwlpKdNBnHb5qnv7f8oeeG', mask_names = self.read_metadata_from_url() - mask_names = ['mask1', 'mask2'] + mask_names = ['mask1', 'mask2'] #for testing purposes if(mask_names is not None): segmentation_objects = create_segmentation_objects(zarr_url, mask_names) segmentations = ObsSegmentationsOmeTiffWrapper ( @@ -75,50 +75,46 @@ def _apply(self, conf): } ) - for dataset in datasets: + for dataset in datasets: dataset.add_object(segmentations) for obj in segmentation_objects: dataset.add_object(obj) - # TODO: what happens if these views already exist , and if there are other views, how to place these? - spatial_view = conf.add_view("spatialBeta", dataset=dataset, w=8, h=12) - lc_view = conf.add_view("layerControllerBeta", dataset=dataset, w=4, h=12, x=8, y=0) + # TODO: what happens if these views already exist , and if there are other views, how to place these? + spatial_view = conf.add_view("spatialBeta", dataset=dataset, w=8, h=12) + lc_view = conf.add_view("layerControllerBeta", dataset=dataset, w=4, h=12, x=8, y=0) + # without add_view can't access the metaCoordincatinSpace + # (e.g. get_coordination_scope() https://python-docs.vitessce.io/api_config.html?highlight=coordination#vitessce.config.VitessceChainableConfig.get_coordination_scope) + conf.link_views_by_dict([spatial_view, lc_view], { + "segmentationLayer":CL([ + { + "fileUid": "segmentation-mask", + "spatialLayerVisible": True, + "spatialLayerOpacity": 1, + } + ]) - conf.link_views_by_dict([spatial_view, lc_view], { - "segmentationLayer":CL([ - { - "fileUid": "segmentation-mask", - "spatialLayerVisible": True, - "spatialLayerOpacity": 1, - } - ]) - - }, meta=True, scope_prefix=get_initial_coordination_scope_prefix("A", "obsSegmentations")) + }, meta=True, scope_prefix=get_initial_coordination_scope_prefix("A", "obsSegmentations")) def read_metadata_from_url(self): url = f'{self.zarr_store_url()}/metadata.json' - print(url) - url ='https://portal.hubmapconsortium.org/browse/dataset/004d4f157df4ba07356cd805131dfc04.json' + print(f"metadata.json URL: {url}") + # url ='https://portal.hubmapconsortium.org/browse/dataset/004d4f157df4ba07356cd805131dfc04.json' request_init = self._get_request_init() or {} - print("req", request_init) - try: - response = get(url, **request_init) - if response.status_code == 200: - data = response.json() - if isinstance(data, dict) and "mask_name" in data: - mask_name = data["mask_name"] - print(f"Mask name found: {mask_name}") - return mask_name - else: - print("'mask_name' key not found in the response.") - return None + response = get(url, **request_init) + if response.status_code == 200: + data = response.json() + if isinstance(data, dict) and "mask_name" in data: + mask_name = data["mask_name"] + print(f"Mask name found: {mask_name}") + return mask_name else: - # Handle errors (e.g., URL not found, server issues) - raise Exception(f"Failed to retrieve data: {response.status_code} - {response.reason}") - - except Exception as e: - raise Exception(f"Failed to connect to the url: {url} - {str(e)}") + print("'mask_name' key not found in the response.") + return None + else: + # raise Exception(f"Failed to retrieve data: {response.status_code} - {response.reason}") + pass # for testing purposes def create_segmentation_objects(base_url, mask_names): diff --git a/src/vis-preview.py b/src/vis-preview.py index f0c8c09..463d075 100755 --- a/src/vis-preview.py +++ b/src/vis-preview.py @@ -42,26 +42,27 @@ def main(): # pragma: no cover parser.add_argument( '--to_json', action='store_true', help='Output viewconf, rather than open in browser.') - parser.add_argument( - '--parent_uuid', action='store_true', - help='Parent uuid for the dataset', - default=None) + # parser.add_argument( + # '--parent_uuid', action='store_true', + # help='Parent uuid for the dataset', + # default=None) parser.add_argument( '--epic_uuid', metavar='URL', help='Epic dataset"s uuid', default=None) - parser.add_argument( - '--epic_builder', action='store_true', - help='Whether to use the epic_builder or not', - default=None) + # + # parser.add_argument( + # '--epic_builder', action='store_true', + # help='Whether to use the epic_builder or not', + # default=None) args = parser.parse_args() marker = args.marker - epic_builder = args.epic_builder + # epic_builder = args.epic_builder epic_uuid = args.epic_uuid - parent_uuid = args.parent_uuid # this may not be needed, as the --url provides the parent dataset json? + # parent_uuid = args.parent_uuid # this may not be needed, as the --url provides the parent dataset json? if args.url: response = requests.get(args.url) @@ -111,6 +112,7 @@ def get_assaytype(uuid): if args.to_json: print(conf_as_json) + ## For testing # with open ('epic.json','w') as file: # if isinstance(conf_cells.conf, list): # json.dump( conf_cells.conf[0], file, indent=4, separators=(',', ': '))