Skip to content

Commit

Permalink
Merged main and fixed readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tkakar committed Dec 18, 2024
2 parents 76eb0c3 + e84b829 commit 3a26b2d
Show file tree
Hide file tree
Showing 62 changed files with 292 additions and 267 deletions.
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,25 @@ $ cd portal-visualization
$ 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] [--parent_uuid UUID]
usage: vis-preview.py [-h] (--url URL | --json JSON) [--assets_url URL]
[--token TOKEN] [--marker MARKER] [--to_json]
[--epic_uuid UUID] [--parent_uuid UUID]
Given HuBMAP Dataset JSON, generate a Vitessce viewconf, and load vitessce.io.
options:
-h, --help show this help message and exit
--url URL URL which returns Dataset JSON
--json JSON File containing Dataset JSON
--assaytypes_url URL AssayType service; default: https://ingest-
api.dev.hubmapconsortium.org/assaytype/
--assets_url URL Assets endpoint; default:
https://assets.dev.hubmapconsortium.org
--token TOKEN Globus groups token; Only needed if data is not public
--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.
--parent_uuid UUID Parent uuid - Only needed for an image-pyramid support
dataset.
-h, --help show this help message and exit
--url URL URL which returns Dataset JSON
--json JSON File containing Dataset JSON
--assets_url URL Assets endpoint; default:
https://assets.dev.hubmapconsortium.org
--token TOKEN Globus groups token; Only needed if data is not public
--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.
--parent_uuid UUID Parent uuid - Only needed for an image-pyramid support
dataset.
```


Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.9
0.3.6
1 change: 0 additions & 1 deletion src/defaults.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"assets_url": "https://assets.dev.hubmapconsortium.org",
"assaytypes_url": "https://ingest-api.dev.hubmapconsortium.org/assaytype/",
"dataset_url":"https://portal.dev.hubmapconsortium.org/browse/dataset/"
}
15 changes: 6 additions & 9 deletions src/portal_visualization/builder_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ def process_hints(hints):
# It returns the correct builder for the given entity.
#
# The entity is a dict that contains the entity UUID and metadata.
# `get_assaytype` is a function which takes an entity UUID and returns
# a dict containing the assaytype and vitessce-hints for that entity.
def get_view_config_builder(entity, get_assaytype, parent=None, epic_uuid=None):
def get_view_config_builder(entity, get_entity, parent=None, epic_uuid=None):
if entity.get("uuid") is None:
raise ValueError("Provided entity does not have a uuid")
assay = get_assaytype(entity.get('uuid'))
assay_name = assay.get("assaytype")
hints = assay.get("vitessce-hints", [])
assay_name = entity.get("soft_assaytype")
hints = entity.get("vitessce-hints", [])
(
is_image,
is_rna,
Expand All @@ -79,7 +76,7 @@ def get_view_config_builder(entity, get_assaytype, parent=None, epic_uuid=None):
return SegImagePyramidViewConfBuilder

elif is_support and is_image:
ancestor_assaytype = get_assaytype(parent).get("assaytype")
ancestor_assaytype = get_entity(parent).get("soft_assaytype")
if SEQFISH == ancestor_assaytype:
# e.g. parent = c6a254b2dc2ed46b002500ade163a7cc
# e.g. support = 9db61adfc017670a196ea9b3ca1852a0
Expand Down Expand Up @@ -138,6 +135,6 @@ def get_view_config_builder(entity, get_assaytype, parent=None, epic_uuid=None):
return NullViewConfBuilder


def has_visualization(entity, get_assaytype, parent=None, epic_uuid=None):
builder = get_view_config_builder(entity, get_assaytype, parent, epic_uuid)
def has_visualization(entity, get_entity, parent=None, epic_uuid=None):
builder = get_view_config_builder(entity, get_entity, parent, epic_uuid)
return builder != NullViewConfBuilder
42 changes: 5 additions & 37 deletions src/portal_visualization/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ def get_vitessce_conf_cells_and_lifted_uuid(
# Otherwise, just try to visualize the data for the entity itself:
else: # pragma: no cover # We have separate tests for the builder logic
try:
Builder = get_view_config_builder(entity, self._get_assaytype(), parent, epic_uuid)
def get_entity(entity):
if (type(entity) is str):
return self.get_entity(uuid=entity)
return self.get_entity(uuid=entity.get('uuid'))
Builder = get_view_config_builder(entity, get_entity, parent, epic_uuid)
builder = Builder(entity, self.groups_token, self.assets_endpoint)
vitessce_conf = builder.get_conf_cells(marker=marker)
except Exception as e:
Expand All @@ -272,42 +276,6 @@ def get_vitessce_conf_cells_and_lifted_uuid(
vitessce_conf=vitessce_conf, vis_lifted_uuid=vis_lifted_uuid
)

# Helper to create a function that fetches assaytype from the API with current headers
def _get_assaytype(self): # pragma: no cover
def get_assaytype(param):
if isinstance(param, str):
uuid = param
else:
uuid = param.get("uuid")

url = f"{self.soft_assay_url}/{uuid}"
headers = self._get_headers()
try:
response = requests.get(url, headers=headers)
return response.json()
except Exception as e:
# Redact Authorization header from logs
cleaned_headers = self._clean_headers(headers)
if response:
status = response.status_code
else:
status = None
current_app.logger.error(
{
"source": "get_assaytype",
"url": url,
"headers": cleaned_headers,
"status": status,
"error": str(e),
}
)
current_app.logger.error(
f"Fetching assaytype threw error: {traceback.format_exc()}"
)
raise e

return get_assaytype

def _file_request(self, url):
headers = (
{"Authorization": "Bearer " + self.groups_token}
Expand Down
21 changes: 1 addition & 20 deletions src/vis-preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
def main(): # pragma: no cover
defaults = json.load((Path(__file__).parent / 'defaults.json').open())
assets_default_url = defaults['assets_url']
assaytypes_default_url = defaults['assaytypes_url']

parser = argparse.ArgumentParser(description='''
Given HuBMAP Dataset JSON, generate a Vitessce viewconf, and load vitessce.io.''')
Expand All @@ -26,10 +25,6 @@ def main(): # pragma: no cover
input.add_argument(
'--json', type=Path, help='File containing Dataset JSON')

parser.add_argument(
'--assaytypes_url', metavar='URL',
help=f'AssayType service; default: {assaytypes_default_url}',
default=assaytypes_default_url)
parser.add_argument(
'--assets_url', metavar='URL',
help=f'Assets endpoint; default: {assets_default_url}',
Expand Down Expand Up @@ -60,21 +55,7 @@ def main(): # pragma: no cover
headers = get_headers(args.token)
entity = get_entity(args.url, args.json, headers)

def get_assaytype(uuid):
try:
response = requests.get(f'{defaults["assaytypes_url"]}{uuid}', headers=headers)
if response.status_code != 200:
print(f"Error: Received status code {response.status_code}")
else:
try:
data = response.json()
return data
except Exception as e:
print(f"Error in parsing the response {str(e)}")
except Exception as e:
print(f"Error accessing {defaults['assaytypes_url']}{uuid}: {str(e)}")

Builder = get_view_config_builder(entity, get_assaytype, parent_uuid, epic_uuid)
Builder = get_view_config_builder(entity, get_entity, parent_uuid, epic_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
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "codex_cytokit_v1",
"contains-pii": false,
"description": "CODEX [Cytokit + SPRM]",
"primary": false,
"soft_assaytype": "codex_cytokit_v1",
"vitessce-hints": [
"codex",
"is_image",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "sn_atac_seq",
"contains-pii": false,
"description": "snATAC-seq [SnapATAC]",
"primary": false,
"soft_assaytype": "sn_atac_seq",
"vitessce-hints": [
"is_sc",
"atac"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"assaytype": "multiome-10x",
"contains-pii": false,
"description": "10X Multiome [Salmon + ArchR + Muon]",
"is-multi-assay": true,
"primary": false,
"soft_assaytype": "multiome-10x",
"vitessce-hints": [
"is_sc",
"rna",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "salmon_rnaseq_slideseq",
"contains-pii": false,
"description": "Slide-seq [Salmon]",
"primary": false,
"soft_assaytype": "salmon_rnaseq_slideseq",
"vitessce-hints": [
"is_sc",
"rna"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"assaytype": "bulk-RNA",
"contains-pii": true,
"description": "Bulk RNA-seq",
"dir-schema": "bulkrnaseq-v0",
"primary": true,
"tbl-schema": "bulkrnaseq-v0",
"soft_assaytype": "bulk-RNA",
"vitessce-hints": []
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"assaytype": "MALDI-IMS",
"contains-pii": false,
"description": "MALDI IMS",
"dir-schema": "ims-v0",
"primary": true,
"tbl-schema": "ims-v2",
"soft_assaytype": "MALDI-IMS",
"vitessce-hints": [
"maldi"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "codex_cytokit_v1",
"contains-pii": false,
"description": "CODEX [Cytokit + SPRM]",
"primary": false,
"soft_assaytype": "codex_cytokit_v1",
"vitessce-hints": [
"codex",
"is_image",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"assaytype": "NanoDESI",
"contains-pii": false,
"description": "NanoDESI",
"dir-schema": "ims-v0",
"primary": true,
"tbl-schema": "ims-v2",
"soft_assaytype": "NanoDESI",
"vitessce-hints": []
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"assaytype": "visium-no-probes",
"contains-pii": false,
"description": "Visium (no probes) [Salmon + Scanpy]",
"is-multi-assay": true,
"primary": false,
"soft_assaytype": "visium-no-probes",
"vitessce-hints": [
"rna",
"is_image",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"assaytype": "PAS",
"contains-pii": false,
"dataset-type": "Histology",
"description": "PAS Stained Microscopy",
"dir-schema": "stained-v0",
"primary": true,
"tbl-schema": "stained-v0",
"soft_assaytype": "PAS",
"vitessce-hints": []
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "image_pyramid",
"contains-pii": false,
"description": "Image Pyramid",
"primary": false,
"soft_assaytype": "image_pyramid",
"vitessce-hints": [
"is_image",
"pyramid",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "image_pyramid",
"contains-pii": false,
"description": "Image Pyramid",
"primary": false,
"soft_assaytype": "image_pyramid",
"vitessce-hints": [
"is_image",
"pyramid",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "codex_cytokit_v1",
"contains-pii": false,
"description": "CODEX [Cytokit + SPRM]",
"primary": false,
"soft_assaytype": "codex_cytokit_v1",
"vitessce-hints": [
"codex",
"is_image",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "salmon_sn_rnaseq_10x",
"contains-pii": false,
"description": "snRNA-seq [Salmon]",
"primary": false,
"soft_assaytype": "salmon_sn_rnaseq_10x",
"vitessce-hints": [
"is_sc",
"rna",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "celldive_deepcell",
"contains-pii": false,
"description": "CellDIVE [DeepCell + SPRM]",
"primary": false,
"soft_assaytype": "celldive_deepcell",
"vitessce-hints": [
"sprm",
"anndata",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"assaytype": "seqFish",
"contains-pii": false,
"description": "seqFISH",
"dir-schema": "seqfish-v0",
"primary": true,
"tbl-schema": "seqfish-v0",
"soft_assaytype": "seqFish",
"vitessce-hints": []
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "sc_atac_seq_sci",
"contains-pii": false,
"description": "sciATAC-seq [SnapATAC]",
"primary": false,
"soft_assaytype": "sc_atac_seq_sci",
"vitessce-hints": [
"is_sc",
"atac"
Expand Down
10 changes: 2 additions & 8 deletions test/assaytype-fixtures/df7cac7cb67a822f7007b57c4d8f5e7d.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
{
"contains-pii": false,
"dataset-type": "Histology",
"description": "Segmentation Mask",
"dir-schema": "stained-v0",
"primary": true,
"tbl-schema": "stained-v0",
"vitessce-hints": ["segmentation_mask","is_image","pyramid"]
}
"vitessce-hints": ["segmentation_mask", "is_image", "pyramid"]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"assaytype": "image_pyramid",
"contains-pii": false,
"description": "Image Pyramid",
"primary": false,
"soft_assaytype": "image_pyramid",
"vitessce-hints": [
"is_image",
"pyramid",
Expand Down
Loading

0 comments on commit 3a26b2d

Please sign in to comment.