mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-09-27 22:48:12 +08:00
removed .csv suffix from annotation name
This commit is contained in:
@@ -18,10 +18,11 @@ class FileItem(Item):
|
||||
The Item superclass expects a 'name' and 'type'.
|
||||
"""
|
||||
|
||||
def __init__(self, subpath: str, *args, **kwargs):
|
||||
def __init__(self, subpath: str, ext: str = "", *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.subpath = subpath
|
||||
self.ext = ext
|
||||
|
||||
@property
|
||||
def descriptor(self) -> str:
|
||||
return os.path.join(self.subpath, self.name).strip("/")
|
||||
return os.path.join(self.subpath, self.name + self.ext).strip("/")
|
||||
|
||||
@@ -150,9 +150,16 @@ class FileItemSource(ItemSource):
|
||||
def make_fileitem_from_path(
|
||||
self, filename, subpath, is_annotation=False, is_shallow=False
|
||||
) -> FileItem:
|
||||
if is_annotation and filename.endswith(self.annotation_file_suffix):
|
||||
name = filename[: -len(self.annotation_file_suffix)]
|
||||
ext = self.annotation_file_suffix
|
||||
else:
|
||||
name = filename
|
||||
ext = ""
|
||||
item = FileItem(
|
||||
subpath=subpath,
|
||||
name=filename,
|
||||
name=name,
|
||||
ext=ext,
|
||||
type=ItemType.annotation if is_annotation else ItemType.h5ad,
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from cellxgene_gateway.items.file.fileitem_source import FileItemSource
|
||||
|
||||
|
||||
class TestFileItemSource(unittest.TestCase):
|
||||
def test_make_fileitem_from_path_GIVEN_annotation_file_THEN_name_lacks_csv(self):
|
||||
source = FileItemSource(tempfile.gettempdir(), "local")
|
||||
item = source.make_fileitem_from_path(
|
||||
"customanno.csv", "someh5ad_annotations", True
|
||||
)
|
||||
self.assertEqual(item.name, "customanno")
|
||||
self.assertEqual(item.descriptor, "someh5ad_annotations/customanno.csv")
|
||||
|
||||
def test_make_fileitem_from_path_GIVEN_h5ad_file_THEN_returns_name(self):
|
||||
source = FileItemSource(tempfile.gettempdir(), "local")
|
||||
item = source.make_fileitem_from_path("someanalysis.h5ad", "studydir")
|
||||
self.assertEqual(item.name, "someanalysis.h5ad")
|
||||
self.assertEqual(item.descriptor, "studydir/someanalysis.h5ad")
|
||||
@@ -10,7 +10,7 @@ from cellxgene_gateway.items.file.fileitem_source import FileItemSource
|
||||
from cellxgene_gateway.items.item import ItemType
|
||||
|
||||
key = CacheKey(
|
||||
FileItem("/czi/", "pbmc3k.h5ad", ItemType.h5ad),
|
||||
FileItem("/czi/", name="pbmc3k.h5ad", type=ItemType.h5ad),
|
||||
FileItemSource("/tmp", "local"),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user