Skip to content

Commit

Permalink
Adjusted arguments and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tkakar committed Sep 13, 2024
1 parent e25f2f0 commit 52293d3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```

```
Expand Down
66 changes: 31 additions & 35 deletions src/portal_visualization/builders/epic_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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):
Expand Down
22 changes: 12 additions & 10 deletions src/vis-preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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=(',', ': '))
Expand Down

0 comments on commit 52293d3

Please sign in to comment.