Skip to content

Commit

Permalink
Minor fixes of readme and args
Browse files Browse the repository at this point in the history
  • Loading branch information
tkakar committed Sep 16, 2024
1 parent efda4a3 commit 2331472
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`
Expand All @@ -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/).
Expand Down
6 changes: 3 additions & 3 deletions src/portal_visualization/builders/epic_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions src/vis-preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit 2331472

Please sign in to comment.