mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-08 09:28:12 +08:00
rebased "Introduction of ItemSource interface" patch
This commit is contained in:
@@ -9,15 +9,72 @@
|
||||
|
||||
# There are three kinds of CacheKey:
|
||||
# 1) somedir/dataset.h5ad: a dataset
|
||||
# in this case, pathpart == dataset == 'somedir/dataset.h5ad'
|
||||
# 2) somedir/dataset_annotations/my_annotations.csv : an actual annotaitons file.
|
||||
# in this case, pathpart == 'dataset_annotations/my_annotations.csv', dataset == 'somedir/dataset.h5ad'
|
||||
# in this case, descriptor == dataset == 'somedir/dataset.h5ad'
|
||||
# 2) somedir/dataset_annotations/my_annotations.csv : an actual annotations file.
|
||||
# in this case, descriptor == 'somedir/dataset_annotations/my_annotations.csv', dataset == 'somedir/dataset.h5ad'
|
||||
# 3) somedir/dataset_annotations: an annotation directory. The corresponding h5ad must exist, but the directory may not.
|
||||
# in this case, pathpart == 'dataset_annotations', dataset == 'somedir/dataset.h5ad'
|
||||
# in this case, descriptor == 'somedir/dataset_annotations', dataset == 'somedir/dataset.h5ad'
|
||||
|
||||
from flask.helpers import url_for
|
||||
|
||||
from cellxgene_gateway.items.item import Item
|
||||
from cellxgene_gateway.items.item_source import ItemSource, LookupResult
|
||||
|
||||
|
||||
class CacheKey:
|
||||
def __init__(self, pathpart, dataset, annotation_file):
|
||||
self.pathpart = pathpart
|
||||
self.dataset = dataset
|
||||
self.annotation_file = annotation_file
|
||||
@property
|
||||
def descriptor(self):
|
||||
if self.annotation_item is None:
|
||||
return self.h5ad_item.descriptor
|
||||
else:
|
||||
return self.annotation_item.descriptor
|
||||
|
||||
@property
|
||||
def file_path(self):
|
||||
return self.source.get_local_path(self.h5ad_item)
|
||||
|
||||
@property
|
||||
def annotation_file_path(self):
|
||||
if self.annotation_item is None:
|
||||
return None
|
||||
else:
|
||||
return self.source.get_local_path(self.annotation_item)
|
||||
|
||||
def relaunch_url(self):
|
||||
return url_for("do_relaunch", source=self.source_name, path=self.descriptor)
|
||||
|
||||
def gateway_basepath(self):
|
||||
return (
|
||||
url_for("do_view", source_name=self.source_name, path=self.descriptor) + "/"
|
||||
)
|
||||
|
||||
@property
|
||||
def source_name(self):
|
||||
return self.source.name
|
||||
|
||||
@property
|
||||
def annotation_descriptor(self):
|
||||
if self.annotation_item is None:
|
||||
return None
|
||||
else:
|
||||
return self.annotation_item.descriptor
|
||||
|
||||
def equals(self, other):
|
||||
return (
|
||||
(self.source.name == other.source.name)
|
||||
and (self.h5ad_item.descriptor == other.h5ad_item.descriptor)
|
||||
and (self.annotation_descriptor == other.annotation_descriptor)
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self, h5ad_item: Item, source: ItemSource, annotation_item: Item = None
|
||||
):
|
||||
assert h5ad_item is not None
|
||||
assert source is not None
|
||||
self.h5ad_item = h5ad_item
|
||||
self.annotation_item = annotation_item
|
||||
self.source = source
|
||||
|
||||
@classmethod
|
||||
def for_lookup(cls, source: ItemSource, lookup: LookupResult):
|
||||
return CacheKey(lookup.h5ad_item, source, lookup.annotation_item)
|
||||
|
||||
Reference in New Issue
Block a user