From 2331472c2a2bdb498b11a780169dac85b4853cd0 Mon Sep 17 00:00:00 2001 From: Tabassum Kakar Date: Mon, 16 Sep 2024 17:05:44 -0400 Subject: [PATCH] Minor fixes of readme and args --- README.md | 17 ++++++------ .../builders/epic_builders.py | 6 ++--- src/vis-preview.py | 27 +++++++++++-------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 5f9aef8..de75c68 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ $ pip install . $ src/vis-preview.py --help usage: vis-preview.py [-h] (--url URL | --json JSON) [--assaytypes_url URL] [--assets_url URL] [--token TOKEN] [--marker MARKER] - [--to_json] [--epic_uuid UUID] + [--to_json] [--epic_uuid UUID] [--parent_uuid UUID] Given HuBMAP Dataset JSON, generate a Vitessce viewconf, and load vitessce.io. @@ -39,20 +39,20 @@ 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 uuid of the EPIC dataset + --epic_uuid UUID uuid of the EPIC dataset. + --parent_uuid UUID Parent uuid - Only needed for an image-pyramid support + dataset. ``` ``` Notes: - 1. To get the token, look for Authorization Bearer {token represented by a long string} under `search-api` network calls under th network tab in developer's tool when browsing a dataset in portal - 2. If you added an argument to the vis-preview.py script, do update the help docs in README, otherwise build will throw error - 3. - + 1. The token can be retrieved by looking for Authorization Bearer {token represented by a long string} under `search-api` network calls under the network tab in developer's tool when browsing a dataset in portal while logged in. The token is necessary to access non-public datasets, such as those in QA. + 2. The documentation for the `vis-preview.py` script must match the contents of the readme. When a script argument is added or modified, the README must be updated to match the output of `./vis-preview.py --help`. + ``` - ## Build & Testing ``` To build: `python -m build` @@ -66,7 +66,8 @@ optional arguments: Data for the Vitessce visualization almost always comes via raw data that is processed by [ingest-pipeline](https://github.com/hubmapconsortium/ingest-pipeline) airflow dags. Harvard often contributes our own custom pipelines to these dags that can be found in [portal-containers](https://github.com/hubmapconsortium/portal-containers). -The outputs of these pipelines are then converted into view configurations for Vitessce by the [portal backend](https://github.com/hubmapconsortium/portal-ui/blob/0b43a468fff0256a466a3bf928a83893321ea1d9/context/app/api/client.py#L165), The `vis-preview.py` mimics the invocation of `get_view_config_builder` for development and testing purposes independently, i.e., without using the [portal backend](https://github.com/hubmapconsortium/portal-ui/blob/0b43a468fff0256a466a3bf928a83893321ea1d9/context/app/api/client.py#L165). + +The outputs of these pipelines are then converted into view configurations for Vitessce by the [portal backend](https://github.com/hubmapconsortium/portal-visualization/blob/main/src/portal_visualization/client.py), The `vis-preview.py` mimics the invocation of `get_view_config_builder` for development and testing purposes independently, i.e., without using the [portal backend](https://github.com/hubmapconsortium/portal-ui/blob/main/context/app/routes_browse.py#L126). using code in this repo, when a `Dataset` that should be visualized is requested in the client. The view configurations are built using the [Vitessce-Python API](https://vitessce.github.io/vitessce-python/). diff --git a/src/portal_visualization/builders/epic_builders.py b/src/portal_visualization/builders/epic_builders.py index dd4dc5b..0668ef6 100644 --- a/src/portal_visualization/builders/epic_builders.py +++ b/src/portal_visualization/builders/epic_builders.py @@ -79,9 +79,9 @@ def _apply(self, conf): seg_path = f'{self.segmentations_url("seg")}/' # print(seg_path) seg_path = ( - 'https://assets.hubmapconsortium.org/c9d9ab5c9ee9642b60dd351024968627/' - 'ometiff-pyramids/VAN0042-RK-3-18-registered-PAS-to-postAF-registered.ome_mask.ome.tif?' - 'token=AgzQXm7nvOW32vWw0EPpKonwbOqjNBzNvvW1p15855NoYglJxyfkC8rlJJWy8V6E8MeyXOwlpKdNBnHb5qnv7f8oeeG' + f"""https://assets.hubmapconsortium.org/c9d9ab5c9ee9642b60dd351024968627/ + ometiff-pyramids/VAN0042-RK-3-18-registered-PAS-to-postAF-registered.ome_mask.ome.tif? + token={self._groups_token}""" ) mask_names = self.read_metadata_from_url() mask_names = ['mask1', 'mask2'] # for testing purposes diff --git a/src/vis-preview.py b/src/vis-preview.py index 58726e8..9c92557 100755 --- a/src/vis-preview.py +++ b/src/vis-preview.py @@ -43,13 +43,13 @@ 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( '--epic_uuid', metavar='UUID', - help='uuid of the EPIC dataset', + help='uuid of the EPIC dataset.', + default=None) + parser.add_argument( + '--parent_uuid', metavar='UUID', + help='Parent uuid - Only needed for an image-pyramid support dataset.', default=None) # @@ -62,10 +62,11 @@ def main(): # pragma: no cover marker = args.marker # 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 + headers = get_headers(args.token) if args.url: - response = requests.get(args.url) + response = requests.get(args.url, headers=headers) if response.status_code == 403: raise Exception('Protected data: Download JSON via browser; Redo with --json') response.raise_for_status() @@ -76,9 +77,6 @@ def main(): # pragma: no cover def get_assaytype(entity): uuid = entity.get("uuid") - headers = {} - if args.token: - headers['Authorization'] = f'Bearer {args.token}' try: response = requests.get(f'{defaults["assaytypes_url"]}{uuid}', headers=headers) if response.status_code != 200: @@ -92,7 +90,7 @@ def get_assaytype(entity): except Exception as e: print(f"Error accessing {defaults['assaytypes_url']}{uuid}: {str(e)}") - Builder = get_view_config_builder(entity, get_assaytype) + Builder = get_view_config_builder(entity, get_assaytype, parent_uuid) builder = Builder(entity, args.token, args.assets_url) print(f'Using: {builder.__class__.__name__}', file=stderr) conf_cells = builder.get_conf_cells(marker=marker) @@ -123,5 +121,12 @@ def get_assaytype(entity): open_new_tab(vitessce_url) +def get_headers(token): # pragma: no cover + headers = {} + if token: + headers['Authorization'] = f'Bearer {token}' + return headers + + if __name__ == "__main__": # pragma: no cover main()