From 6407cbd6b63a7c45c9e8a79c81aba5b82f4bd868 Mon Sep 17 00:00:00 2001 From: Lena Trnovec <115463806+lenatr99@users.noreply.github.com> Date: Wed, 29 May 2024 14:20:29 +0200 Subject: [PATCH] [FIX] LoadData - Bugs with gene and cell annotations (#403) * Load Data bugfix * Add Spatial Autocorrelation Scorer to documentation json, index.rst --- doc/index.rst | 1 + doc/widgets.json | 7 ++++ .../single_cell/widgets/load_data.py | 32 +++++++++++++------ .../single_cell/widgets/owloaddata.py | 2 ++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index 300acaa4..df62a863 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -16,3 +16,4 @@ Widgets widgets/score_genes widgets/score_cells widgets/dot_matrix + widgets/spatial_autocorrelation diff --git a/doc/widgets.json b/doc/widgets.json index 83731152..1869815e 100644 --- a/doc/widgets.json +++ b/doc/widgets.json @@ -75,6 +75,13 @@ "icon": "../orangecontrib/single_cell/widgets/icons/DotMatrix.svg", "background": "light-blue", "keywords": [] + }, + { + "text": "Spatial Autocorrelation Scorer", + "doc": "widgets/spatial_autocorrelation.md", + "icon": "../orangecontrib/single_cell/widgets/icons/SpatialAutocorrelation.svg", + "background": "light-blue", + "keywords": [] } ] ] diff --git a/orangecontrib/single_cell/widgets/load_data.py b/orangecontrib/single_cell/widgets/load_data.py index 60183822..80a642d2 100644 --- a/orangecontrib/single_cell/widgets/load_data.py +++ b/orangecontrib/single_cell/widgets/load_data.py @@ -488,12 +488,18 @@ def leading_cols(self, value): def _set_annotation_files(self): dir_name, _ = os.path.split(self._file_name) - genes_path = os.path.join(dir_name, "genes.tsv") - if os.path.isfile(genes_path): - self.col_annotation_file = RecentPath.create(genes_path, []) - barcodes_path = os.path.join(dir_name, "barcodes.tsv") - if os.path.isfile(barcodes_path): - self.row_annotation_file = RecentPath.create(barcodes_path, []) + genes_paths = ['genes.tsv', 'features.tsv', 'genes.tsv.gz', 'features.tsv.gz'] + for genes_path in genes_paths: + genes_path = os.path.join(dir_name, genes_path) + if os.path.isfile(genes_path): + self.col_annotation_file = RecentPath.create(genes_path, []) + break + barcodes_paths = ['barcodes.tsv', 'barcodes.tsv.gz'] + for barcodes_path in barcodes_paths: + barcodes_path = os.path.join(dir_name, barcodes_path) + if os.path.isfile(barcodes_path): + self.row_annotation_file = RecentPath.create(barcodes_path, []) + break def _set_enable_annotations(self): # 10x gene-barcode matrix @@ -756,13 +762,21 @@ def key(var): metas=sorted(metas, key=key)) concat_data_t = concat_data.transform(domain) data_t = data.transform(domain) - source_var.values + (source_name, ) + + new_values = source_var.values + (source_name,) + new_source_var = DiscreteVariable(source_var.name, values=new_values) + new_metas = tuple(var if var.name != source_var.name else new_source_var for var in domain.metas) + new_domain = Domain(domain.attributes, metas=new_metas) + concat_data_t = concat_data_t.transform(new_domain) + data_t = data_t.transform(new_domain) + source_var_index = new_source_var.values.index(source_name) # metas can be unlocked, source_var added to metas by append_source_name with data_t.unlocked(data_t.metas): - data_t[:, source_var] = np.full( - (len(data), 1), len(source_var.values) - 1, dtype=object + data_t[:, new_source_var] = np.full( + (len(data_t), 1), source_var_index, dtype=object ) concat_data = Table.concatenate((concat_data_t, data_t), axis=0) + source_var = new_source_var # Update source_var for the next iteration return concat_data @staticmethod diff --git a/orangecontrib/single_cell/widgets/owloaddata.py b/orangecontrib/single_cell/widgets/owloaddata.py index db82f205..ab38d6a3 100644 --- a/orangecontrib/single_cell/widgets/owloaddata.py +++ b/orangecontrib/single_cell/widgets/owloaddata.py @@ -613,6 +613,7 @@ def browse_row_annotations(self): pathitem = RecentPath.create(filename, []) index = insert_recent_path(m, pathitem) self.row_annotations_combo.setCurrentIndex(index) + self._row_annotations_combo_changed() self._invalidate() @Slot() @@ -632,6 +633,7 @@ def browse_col_annotations(self): pathitem = RecentPath.create(filename, []) index = insert_recent_path(m, pathitem) self.col_annotations_combo.setCurrentIndex(index) + self._col_annotations_combo_changed() self._invalidate() def _invalidate(self):