mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-11 07:20:56 +08:00
Merge remote-tracking branch 'ghall/just_gene_sets'
This commit is contained in:
@@ -24,21 +24,21 @@ class FileItemSource(ItemSource):
|
|||||||
h5ad_suffix=dir_util.h5ad_suffix,
|
h5ad_suffix=dir_util.h5ad_suffix,
|
||||||
annotation_dir_suffix=dir_util.annotations_suffix,
|
annotation_dir_suffix=dir_util.annotations_suffix,
|
||||||
annotation_file_suffix=".csv",
|
annotation_file_suffix=".csv",
|
||||||
|
gene_set_file_suffix="_gene_sets.csv",
|
||||||
):
|
):
|
||||||
self._name = name
|
self._name = name
|
||||||
self.base_path = base_path
|
self.base_path = base_path
|
||||||
self.h5ad_suffix = h5ad_suffix
|
self.h5ad_suffix = h5ad_suffix
|
||||||
self.annotation_dir_suffix = annotation_dir_suffix
|
self.annotation_dir_suffix = annotation_dir_suffix
|
||||||
self.annotation_file_suffix = annotation_file_suffix
|
self.annotation_file_suffix = annotation_file_suffix
|
||||||
|
self.gene_set_file_suffix = gene_set_file_suffix
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._name or f"Files:{self.base_path}"
|
return self._name or f"Files:{self.base_path}"
|
||||||
|
|
||||||
def is_gene_set(self, path: str) -> bool:
|
def is_gene_set(self, path: str) -> bool:
|
||||||
return ("_gene_sets" in path or "-gene-sets" in path) and path.endswith(
|
return path.endswith(self.gene_set_file_suffix)
|
||||||
self.annotation_file_suffix
|
|
||||||
)
|
|
||||||
|
|
||||||
def is_h5ad_file(self, path: str) -> bool:
|
def is_h5ad_file(self, path: str) -> bool:
|
||||||
return path.endswith(self.h5ad_suffix) and os.path.isfile(path)
|
return path.endswith(self.h5ad_suffix) and os.path.isfile(path)
|
||||||
@@ -186,12 +186,29 @@ class FileItemSource(ItemSource):
|
|||||||
annotations_subpath = self.get_annotations_subpath(item)
|
annotations_subpath = self.get_annotations_subpath(item)
|
||||||
annotations_fullpath = self.full_path(annotations_subpath)
|
annotations_fullpath = self.full_path(annotations_subpath)
|
||||||
if os.path.isdir(annotations_fullpath):
|
if os.path.isdir(annotations_fullpath):
|
||||||
return [
|
sorted_files = sorted(os.listdir(annotations_fullpath))
|
||||||
|
annotation_files = [
|
||||||
self.make_fileitem_from_path(annotation, annotations_subpath, True)
|
self.make_fileitem_from_path(annotation, annotations_subpath, True)
|
||||||
for annotation in sorted(os.listdir(annotations_fullpath))
|
for annotation in sorted_files
|
||||||
if annotation.endswith(self.annotation_file_suffix)
|
if annotation.endswith(self.annotation_file_suffix)
|
||||||
and not self.is_gene_set(annotation)
|
and not self.is_gene_set(annotation)
|
||||||
and os.path.isfile(os.path.join(annotations_fullpath, annotation))
|
and os.path.isfile(os.path.join(annotations_fullpath, annotation))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Catch gene sets without accompanying [annotations].csv
|
||||||
|
gene_sets_files = [
|
||||||
|
self.make_fileitem_from_path(
|
||||||
|
annotation[: -len(self.gene_set_file_suffix)] + ".csv",
|
||||||
|
annotations_subpath,
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
for annotation in sorted_files
|
||||||
|
if self.is_gene_set(annotation)
|
||||||
|
and annotation[: -len(self.gene_set_file_suffix)]
|
||||||
|
not in [a.name for a in annotation_files]
|
||||||
|
and os.path.isfile(os.path.join(annotations_fullpath, annotation))
|
||||||
|
]
|
||||||
|
|
||||||
|
return sorted(annotation_files + gene_sets_files, key=lambda x: x.name)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user