From ce8a25d1ac5103e7b749e369035184d304dda40a Mon Sep 17 00:00:00 2001 From: Nikolay Akhmetov Date: Mon, 14 Aug 2023 11:41:55 -0400 Subject: [PATCH] Add `create_coordination_values` helper util --- .../builders/scatterplot_builders.py | 36 +++++-------------- .../builders/sprm_builders.py | 15 +++----- src/portal_visualization/utils.py | 7 ++++ 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/portal_visualization/builders/scatterplot_builders.py b/src/portal_visualization/builders/scatterplot_builders.py index 304f15d..8b6d981 100644 --- a/src/portal_visualization/builders/scatterplot_builders.py +++ b/src/portal_visualization/builders/scatterplot_builders.py @@ -5,7 +5,7 @@ ) -from ..utils import get_conf_cells +from ..utils import create_coordination_values, get_conf_cells from ..paths import SCRNA_SEQ_DIR, SCATAC_SEQ_DIR from .base_builders import ViewConfBuilder @@ -54,31 +54,22 @@ def __init__(self, entity, groups_token, assets_endpoint, **kwargs): { "rel_path": f"{SCRNA_SEQ_DIR}.cells.json", "file_type": ft.OBS_SEGMENTATIONS_CELLS_JSON, - "coordination_values": { - "obsType": "cell", - }, + "coordination_values": create_coordination_values(), }, { "rel_path": f"{SCRNA_SEQ_DIR}.cells.json", "file_type": ft.OBS_LOCATIONS_CELLS_JSON, - "coordination_values": { - "obsType": "cell", - }, + "coordination_values": create_coordination_values() }, { "rel_path": f"{SCRNA_SEQ_DIR}.cells.json", "file_type": ft.OBS_EMBEDDING_CELLS_JSON, - "coordination_values": { - "obsType": "cell", - "embeddingType": "UMAP", - }, + "coordination_values": create_coordination_values(embeddingType="UMAP") }, { "rel_path": f"{SCRNA_SEQ_DIR}.cell-sets.json", "file_type": ft.OBS_SETS_CELL_SETS_JSON, - "coordination_values": { - "obsType": "cell", - }, + "coordination_values": create_coordination_values() }, ] @@ -98,33 +89,24 @@ def __init__(self, entity, groups_token, assets_endpoint, **kwargs): "rel_path": SCATAC_SEQ_DIR + "/umap_coords_clusters.cells.json", "file_type": ft.OBS_SEGMENTATIONS_CELLS_JSON, - "coordination_values": { - "obsType": "cell", - }, + "coordination_values": create_coordination_values() }, { "rel_path": SCATAC_SEQ_DIR + "/umap_coords_clusters.cells.json", "file_type": ft.OBS_LOCATIONS_CELLS_JSON, - "coordination_values": { - "obsType": "cell", - }, + "coordination_values": create_coordination_values() }, { "rel_path": SCATAC_SEQ_DIR + "/umap_coords_clusters.cells.json", "file_type": ft.OBS_EMBEDDING_CELLS_JSON, - "coordination_values": { - "obsType": "cell", - "embeddingType": "UMAP", - }, + "coordination_values": create_coordination_values(embeddingType="UMAP") }, { "rel_path": SCATAC_SEQ_DIR + "/umap_coords_clusters.cell-sets.json", "file_type": ft.OBS_SETS_CELL_SETS_JSON, - "coordination_values": { - "obsType": "cell", - }, + "coordination_values": create_coordination_values() }, ] diff --git a/src/portal_visualization/builders/sprm_builders.py b/src/portal_visualization/builders/sprm_builders.py index e8cd67f..e7df177 100644 --- a/src/portal_visualization/builders/sprm_builders.py +++ b/src/portal_visualization/builders/sprm_builders.py @@ -12,7 +12,7 @@ ) from .base_builders import ViewConfBuilder -from ..utils import get_matches, get_conf_cells +from ..utils import create_coordination_values, get_matches, get_conf_cells from ..paths import ( SPRM_JSON_DIR, STITCHED_REGEX, CODEX_TILE_DIR, TILE_REGEX, STITCHED_IMAGE_DIR, SPRM_PYRAMID_SUBDIR, IMAGE_PYRAMID_DIR @@ -93,25 +93,18 @@ def __init__(self, entity, groups_token, assets_endpoint, **kwargs): { "rel_path": f"{SPRM_JSON_DIR}/" + f"{self._base_name}.cells.json", "file_type": ft.CELLS_JSON, - "coordination_values": { - "obsType": "cell", - }, + "coordination_values": create_coordination_values() }, { "rel_path": f"{SPRM_JSON_DIR}/" + f"{self._base_name}.cell-sets.json", "file_type": ft.CELL_SETS_JSON, - "coordination_values": { - "obsType": "cell", - }, + "coordination_values": create_coordination_values() }, { "rel_path": f"{SPRM_JSON_DIR}/" + f"{self._base_name}.clusters.json", "file_type": "clusters.json", - "coordination_values": { - "obsType": "cell", - }, - + "coordination_values": create_coordination_values() }, ] diff --git a/src/portal_visualization/utils.py b/src/portal_visualization/utils.py index c09fb97..a8261e9 100644 --- a/src/portal_visualization/utils.py +++ b/src/portal_visualization/utils.py @@ -16,6 +16,13 @@ def get_matches(files, regex): ) +def create_coordination_values(obs_type='cell', **kwargs): + return { + 'obsType': obs_type, + **kwargs + } + + def _get_path_name(file): return Path(file).name