From 5a650334dfc5fd4e72e78120e508a1d9acc37c80 Mon Sep 17 00:00:00 2001 From: Alok Saldanha Date: Thu, 6 Jul 2023 07:56:43 -0600 Subject: [PATCH] #81 moved gene set check into fileitem_source --- Changelog.md | 4 ++++ cellxgene_gateway/filecrawl.py | 12 ++---------- cellxgene_gateway/items/file/fileitem_source.py | 3 +++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Changelog.md b/Changelog.md index 2a93964..b8d8239 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# 0.3.11 + +* #81 added support for gene sets via GATEWAY_ENABLE_GENE_SETS + # 0.3.10 * #65 Added GATEWAY_EXPIRE_SECONDS to set how long cellxgene servers can remain idle before being terminated. diff --git a/cellxgene_gateway/filecrawl.py b/cellxgene_gateway/filecrawl.py index 582afe8..f812091 100644 --- a/cellxgene_gateway/filecrawl.py +++ b/cellxgene_gateway/filecrawl.py @@ -20,23 +20,15 @@ def render_annotations(item, item_source): item_source.get_annotations_subpath(item), item_source.name ) new_annotation = f"new" - non_gene_set_files = [] - if item.annotations is not None: - # Do not also display files to store gene_sets. These should be loaded - # by clicking on the associated annotations file (i.e. without the - # appended "_gene_sets") - for a in item.annotations: - if (len(a.name) < 10) or (a.name[-10:] != "_gene_sets"): - non_gene_set_files.append(a) annotations = ( ", ".join( [ f"{a.name}" - for a in non_gene_set_files + for a in item.annotations ] ) + ", " - if non_gene_set_files + if item.annotations else "" ) return " | annotations: " + annotations + new_annotation diff --git a/cellxgene_gateway/items/file/fileitem_source.py b/cellxgene_gateway/items/file/fileitem_source.py index 4ade4b9..38d0a8f 100644 --- a/cellxgene_gateway/items/file/fileitem_source.py +++ b/cellxgene_gateway/items/file/fileitem_source.py @@ -35,6 +35,8 @@ class FileItemSource(ItemSource): def name(self): return self._name or f"Files:{self.base_path}" + def is_gene_set(self, path:str) -> bool: + return ('_gene_sets' in path or '-gene-sets' in path) and path.endswith(self.annotation_file_suffix) def is_h5ad_file(self, path: str) -> bool: return path.endswith(self.h5ad_suffix) and os.path.isfile(path) @@ -180,6 +182,7 @@ class FileItemSource(ItemSource): self.make_fileitem_from_path(annotation, annotations_subpath, True) for annotation in sorted(os.listdir(annotations_fullpath)) if annotation.endswith(self.annotation_file_suffix) + and not self.is_gene_set(annotation) and os.path.isfile(os.path.join(annotations_fullpath, annotation)) ] else: