Skip to content

Commit

Permalink
NickAkhmetov/CAT-775 - EPIC builders boilerplate, migrate API client (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAkhmetov authored Jul 22, 2024
1 parent 8d8e16e commit 40c7be6
Show file tree
Hide file tree
Showing 12 changed files with 1,287 additions and 99 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.5
0.2.6
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ package_dir =
packages = find:
python_requires = >=3.7
install_requires =
vitessce>=3.2.6
hubmap-commons>=2.0.12
vitessce>=3.2.8
hubmap-commons>=2.0.15
requests>=2.27.1
nbformat==5.1.3
zarr>=2.17.2
aiohttp>=3.8.1
fsspec>=2022.1.0
python-datauri>=2.2.0

[options.packages.find]
where = src
Expand Down
57 changes: 35 additions & 22 deletions src/portal_visualization/builder_factory.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
from .builders.base_builders import NullViewConfBuilder
from .builders.sprm_builders import (
StitchedCytokitSPRMViewConfBuilder, TiledSPRMViewConfBuilder,
MultiImageSPRMAnndataViewConfBuilder
StitchedCytokitSPRMViewConfBuilder,
TiledSPRMViewConfBuilder,
MultiImageSPRMAnndataViewConfBuilder,
)
from .builders.imaging_builders import (
SeqFISHViewConfBuilder,
IMSViewConfBuilder,
ImagePyramidViewConfBuilder,
NanoDESIViewConfBuilder
NanoDESIViewConfBuilder,
)
from .builders.anndata_builders import (
MultiomicAnndataZarrViewConfBuilder,
SpatialRNASeqAnnDataZarrViewConfBuilder,
RNASeqAnnDataZarrViewConfBuilder,
SpatialMultiomicAnnDataZarrViewConfBuilder
)
from .builders.scatterplot_builders import (
RNASeqViewConfBuilder, ATACSeqViewConfBuilder
)
from .assays import (
SEQFISH,
MALDI_IMS,
NANODESI,
SALMON_RNASSEQ_SLIDE
SpatialMultiomicAnnDataZarrViewConfBuilder,
)
from .builders.scatterplot_builders import RNASeqViewConfBuilder, ATACSeqViewConfBuilder
from .assays import SEQFISH, MALDI_IMS, NANODESI, SALMON_RNASSEQ_SLIDE


# This function processes the hints and returns a tuple of booleans
Expand All @@ -40,7 +34,17 @@ def process_hints(hints):
is_spatial = "spatial" in hints
is_support = "is_support" in hints

return is_image, is_rna, is_atac, is_sprm, is_codex, is_anndata, is_json, is_spatial, is_support
return (
is_image,
is_rna,
is_atac,
is_sprm,
is_codex,
is_anndata,
is_json,
is_spatial,
is_support,
)


# This function is the main entrypoint for the builder factory.
Expand All @@ -50,18 +54,27 @@ def process_hints(hints):
# `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):
if (entity.get('uuid') is None):
if entity.get("uuid") is None:
raise ValueError("Provided entity does not have a uuid")
assay = get_assaytype(entity)
assay_name = assay.get('assaytype')
hints = assay.get('vitessce-hints', [])
is_image, is_rna, is_atac, is_sprm, is_codex, is_anndata, is_json, is_spatial, is_support = process_hints(
hints)
assay_name = assay.get("assaytype")
hints = assay.get("vitessce-hints", [])
(
is_image,
is_rna,
is_atac,
is_sprm,
is_codex,
is_anndata,
is_json,
is_spatial,
is_support,
) = process_hints(hints)

# vis-lifted image pyramids
if (parent is not None):
if (is_support and is_image):
ancestor_assaytype = get_assaytype(parent).get('assaytype')
if parent is not None:
if is_support and is_image:
ancestor_assaytype = get_assaytype(parent).get("assaytype")
if SEQFISH == ancestor_assaytype:
# e.g. parent = c6a254b2dc2ed46b002500ade163a7cc
# e.g. support = 9db61adfc017670a196ea9b3ca1852a0
Expand Down
59 changes: 59 additions & 0 deletions src/portal_visualization/builders/epic_builders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from abc import ABC, abstractmethod
from vitessce import VitessceConfig
from .base_builders import ConfCells
from ..utils import get_conf_cells


# EPIC builders take in a vitessce conf output by a previous builder and modify it
# accordingly to add the EPIC-specific configuration.
class EPICConfBuilder(ABC):
def __init__(self, base_conf: ConfCells, epic_uuid) -> None:

conf, cells = base_conf

if conf is None:
raise ValueError("ConfCells object must have a conf attribute")

self._is_plural = isinstance(conf, list)

if self._is_plural:
self._base_conf = [
VitessceConfig.from_dict(conf) for conf in conf
]
else:
self._base_conf: VitessceConfig = VitessceConfig.from_dict(base_conf.conf)

self._epic_uuid = epic_uuid
pass

def get_conf_cells(self):
self.apply()
if (self._is_plural):
return get_conf_cells([conf.to_dict() for conf in self._base_conf])
return get_conf_cells(self._base_conf)

def apply(self):
if self._is_plural:
for conf in self._base_conf:
self._apply(conf)
else:
self._apply(self._base_conf)

@abstractmethod
def _apply(self, conf): # pragma: no cover
pass


class SegmentationMaskBuilder(EPICConfBuilder):

def _apply(self, conf):
datasets = conf.get_datasets()
print(f"Found {len(datasets)} datasets")
# Proof of concept using one of the kaggle segmentation masks for now
# segmentations = ObsSegmentationsOmeTiffWrapper(
# img_url='https://assets.hubmapconsortium.org/c9d9ab5c9ee9642b60dd351024968627/ometiff-pyramids/VAN0042-RK-3-18-registered-PAS-to-postAF-registered.ome_mask.ome.tif?token=AgndN7NVbn83wwDXjpnY1Y0lDoJj2j7zOGmn1WN6qr9pqdkjKmt9C1XYm4KrlWrOXE9rVJvpnEKrPjIXrlKd1hmDGjV',
# # offsets_path=f'./{name}/{name}/offsets/{name}.segmentations.offsets.json',
# obs_types_from_channel_names=True,
# )
# dataset.add_object(segmentations)
pass
1 change: 1 addition & 0 deletions src/portal_visualization/builders/imaging_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def get_conf_cells(self, **kwargs):
)
if 'separate/' not in path # Exclude separate/* in MALDI-IMS
]
found_images = sorted(found_images)
if len(found_images) == 0:
message = f"Image pyramid assay with uuid {self._uuid} has no matching files"
raise FileNotFoundError(message)
Expand Down
Loading

0 comments on commit 40c7be6

Please sign in to comment.