From 41cfdf02e3fd55f12ee3eecccff53c961c36f6c4 Mon Sep 17 00:00:00 2001 From: lenatr99 Date: Fri, 31 May 2024 11:13:24 +0200 Subject: [PATCH 1/4] Marker Genes: Add DictyBase --- .../bioinformatics/widgets/OWMarkerGenes.py | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/orangecontrib/bioinformatics/widgets/OWMarkerGenes.py b/orangecontrib/bioinformatics/widgets/OWMarkerGenes.py index 1e669797..bca32784 100644 --- a/orangecontrib/bioinformatics/widgets/OWMarkerGenes.py +++ b/orangecontrib/bioinformatics/widgets/OWMarkerGenes.py @@ -41,10 +41,10 @@ ) SERVER_FILES_DOMAIN = 'marker_genes' -GROUP_BY_ITEMS = ["Cell Type", "Function"] +GROUP_BY_ITEMS = ["Cell Type", "Function", "Milestones", "Regulon cluster"] FILTER_COLUMNS_DEFAULT = ["Name", "Entrez ID"] NUM_LINES_TEXT = 5 -MAP_GROUP_TO_TAX_ID = {'Human': '9606', 'Mouse': '10090'} +MAP_GROUP_TO_TAX_ID = {'Human': '9606', 'Mouse': '10090', "Dictyostelium discoideum": '44689'} class TreeItem(object): @@ -655,10 +655,11 @@ def setup_model_data( names = data_table.get_column("Name") types = data_table.get_column(parent_column) for n, pt, row in zip(names, types, data_table): - if pt not in parents_dict: - parents_dict[pt] = TreeItem(pt, True, None, parent) + if pt != "?": + if pt not in parents_dict: + parents_dict[pt] = TreeItem(pt, True, None, parent) - TreeItem(n, False, row, parents_dict[pt]) + TreeItem(n, False, row, parents_dict[pt]) def set_expanded(self, index: QModelIndex, expanded: bool) -> None: """ @@ -853,9 +854,13 @@ class Outputs: selected_genes = settings.ContextSetting([]) settings_version = 2 + + available_groups = GROUP_BY_ITEMS + _available_groups = None _data = None _available_sources = None + _selected_root_attribute = None def __init__(self) -> None: super().__init__() @@ -937,7 +942,6 @@ def _init_control_area(self) -> None: box, self, 'selected_root_attribute', - items=GROUP_BY_ITEMS, callback=self._setup, ) @@ -1017,6 +1021,12 @@ def data(self, value: Table): self.organism_index = min( max(self.organism_index, 0), len(group_values) - 1 ) + + self.available_groups = [item for item in GROUP_BY_ITEMS if any(meta.name == item for meta in domain.metas)] + + self.group_by_cb.clear() + self.group_by_cb.addItems(self.available_groups) + self.group_by_cb.setCurrentIndex(self.selected_root_attribute) self._set_group_index(self.organism_index) @@ -1068,8 +1078,12 @@ def _setup(self) -> None: self.openContext((self.selected_organism, self.selected_source)) data_not_selected, data_selected = self._filter_data_group(self.data) + if self._available_groups: + if self._available_groups[self._selected_root_attribute] not in self.available_groups: + self.selected_root_attribute = 0 + # add model to available markers view - group_by = GROUP_BY_ITEMS[self.selected_root_attribute] + group_by = self.available_groups[self.selected_root_attribute] tree_model = TreeModel(data_not_selected, group_by) proxy_model = FilterProxyModel(self.filter_line_edit) proxy_model.setSourceModel(tree_model) @@ -1096,6 +1110,8 @@ def _setup(self) -> None: # update output and messages self._selected_markers_changed() + self._selected_root_attribute = self.selected_root_attribute + self._available_groups = self.available_groups def _filter_data_group(self, data: Table) -> Tuple[Table, Tuple]: """ @@ -1126,7 +1142,7 @@ def _filter_data_group(self, data: Table) -> Tuple[Table, Tuple]: # divide data based on selected_genes variable (context) unique_gene_names = np.core.defchararray.add( data.get_column("Entrez ID").astype(str), - data.get_column("Cell Type").astype(str), + data.get_column(self.available_groups[0]).astype(str), ) mask = np.isin(unique_gene_names, self.selected_genes) data_not_selected = data[~mask] @@ -1184,7 +1200,7 @@ def _selected_markers_changed(self) -> None: """ rows = self.selected_markers_view.model().sourceModel().rootItem.get_data_rows() self.selected_genes = [ - row["Entrez ID"].value + row["Cell Type"].value for row in rows + row["Entrez ID"].value + row[self.available_groups[0]].value for row in rows ] self.commit() From 024d2880a4501d371fbb358db4b468a26350a098 Mon Sep 17 00:00:00 2001 From: lenatr99 Date: Fri, 31 May 2024 11:24:20 +0200 Subject: [PATCH 2/4] Fix Marker Genes unit tests --- .../bioinformatics/tests/widgets/test_OWMarkerGenes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/orangecontrib/bioinformatics/tests/widgets/test_OWMarkerGenes.py b/orangecontrib/bioinformatics/tests/widgets/test_OWMarkerGenes.py index 734e0486..0ba2c1b8 100644 --- a/orangecontrib/bioinformatics/tests/widgets/test_OWMarkerGenes.py +++ b/orangecontrib/bioinformatics/tests/widgets/test_OWMarkerGenes.py @@ -306,7 +306,7 @@ def test_available_sources(self): When more available unittest will be changed. """ self.assertListEqual( - ["CellMarker", "Panglao"], list(self.widget.available_sources.keys()) + ["CellMarker", "DictyBase", "Panglao"], list(self.widget.available_sources.keys()) ) def test_source_changed(self): @@ -319,7 +319,7 @@ def test_source_changed(self): self.assertEqual(len(self.panglao), len(self.widget.data)) # Panglao data - simulate.combobox_activate_index(self.widget.controls.source_index, 1) + simulate.combobox_activate_index(self.widget.controls.source_index, 2) self.assertEqual("CellMarker", self.widget.db_source_cb.currentText()) self.assertTrue(isinstance(self.widget.data, Table)) self.assertEqual(len(self.cell_markers), len(self.widget.data)) @@ -363,7 +363,7 @@ def test_organism_changed(self): len(np.unique(cell_types[~human_rows])), len(model.rootItem.childItems) ) - simulate.combobox_activate_index(self.widget.controls.source_index, 1) + simulate.combobox_activate_index(self.widget.controls.source_index, 2) simulate.combobox_activate_index(self.widget.controls.organism_index, 0) self.assertEqual("CellMarker", self.widget.db_source_cb.currentText()) self.assertEqual("Human", self.widget.group_cb.currentText()) @@ -379,7 +379,7 @@ def test_organism_changed(self): len(np.unique(cell_types[human_rows])), len(model.rootItem.childItems) ) - simulate.combobox_activate_index(self.widget.controls.source_index, 1) + simulate.combobox_activate_index(self.widget.controls.source_index, 2) simulate.combobox_activate_index(self.widget.controls.organism_index, 1) self.assertEqual("CellMarker", self.widget.db_source_cb.currentText()) self.assertEqual("Mouse", self.widget.group_cb.currentText()) From cce9899a92242da4e60d21e335687d8d8f4b62d6 Mon Sep 17 00:00:00 2001 From: lenatr99 Date: Fri, 31 May 2024 11:30:19 +0200 Subject: [PATCH 3/4] Update Marker Genes documentation. --- doc/widgets/marker_genes.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/widgets/marker_genes.md b/doc/widgets/marker_genes.md index e0f1af36..89518466 100644 --- a/doc/widgets/marker_genes.md +++ b/doc/widgets/marker_genes.md @@ -19,6 +19,12 @@ Database sources: - CellMarker [CellMarker: a manually curated resource of cell markers in human and mouse.][1] Nucleic Acids Research. 2018. + +
+ + - DictyBase + + Fey, P., Dodson, R., Basu, S., Chisholm, R. L., One Stop Shop for Everything Dictyostelium: dictyBase and the Dicty Stock Center. Dictyostelium discoideum Protocols. Methods Mol. Biol. 983:59-92, edited by Ludwig Eichinger and Francisco Rivero. Data is preprocessed in Orange readable format and it is hosted [here.][2] One can use [Databases update](databases_update.md) From 80033449f2612af98881bba1944a23c5822b1200 Mon Sep 17 00:00:00 2001 From: lenatr99 Date: Fri, 31 May 2024 11:38:32 +0200 Subject: [PATCH 4/4] Marker genes: Pre-commit reformatting --- .../tests/widgets/test_OWMarkerGenes.py | 3 ++- .../bioinformatics/widgets/OWMarkerGenes.py | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/orangecontrib/bioinformatics/tests/widgets/test_OWMarkerGenes.py b/orangecontrib/bioinformatics/tests/widgets/test_OWMarkerGenes.py index 0ba2c1b8..78542aa4 100644 --- a/orangecontrib/bioinformatics/tests/widgets/test_OWMarkerGenes.py +++ b/orangecontrib/bioinformatics/tests/widgets/test_OWMarkerGenes.py @@ -306,7 +306,8 @@ def test_available_sources(self): When more available unittest will be changed. """ self.assertListEqual( - ["CellMarker", "DictyBase", "Panglao"], list(self.widget.available_sources.keys()) + ["CellMarker", "DictyBase", "Panglao"], + list(self.widget.available_sources.keys()), ) def test_source_changed(self): diff --git a/orangecontrib/bioinformatics/widgets/OWMarkerGenes.py b/orangecontrib/bioinformatics/widgets/OWMarkerGenes.py index bca32784..061ee5e2 100644 --- a/orangecontrib/bioinformatics/widgets/OWMarkerGenes.py +++ b/orangecontrib/bioinformatics/widgets/OWMarkerGenes.py @@ -1,4 +1,5 @@ """ OWMarkerGenes """ + from typing import List, Tuple, Iterable, Optional from functools import partial @@ -44,7 +45,11 @@ GROUP_BY_ITEMS = ["Cell Type", "Function", "Milestones", "Regulon cluster"] FILTER_COLUMNS_DEFAULT = ["Name", "Entrez ID"] NUM_LINES_TEXT = 5 -MAP_GROUP_TO_TAX_ID = {'Human': '9606', 'Mouse': '10090', "Dictyostelium discoideum": '44689'} +MAP_GROUP_TO_TAX_ID = { + 'Human': '9606', + 'Mouse': '10090', + "Dictyostelium discoideum": '44689', +} class TreeItem(object): @@ -854,7 +859,7 @@ class Outputs: selected_genes = settings.ContextSetting([]) settings_version = 2 - + available_groups = GROUP_BY_ITEMS _available_groups = None @@ -1021,12 +1026,16 @@ def data(self, value: Table): self.organism_index = min( max(self.organism_index, 0), len(group_values) - 1 ) - - self.available_groups = [item for item in GROUP_BY_ITEMS if any(meta.name == item for meta in domain.metas)] - + + self.available_groups = [ + item + for item in GROUP_BY_ITEMS + if any(meta.name == item for meta in domain.metas) + ] + self.group_by_cb.clear() self.group_by_cb.addItems(self.available_groups) - self.group_by_cb.setCurrentIndex(self.selected_root_attribute) + self.group_by_cb.setCurrentIndex(self.selected_root_attribute) self._set_group_index(self.organism_index) @@ -1079,7 +1088,10 @@ def _setup(self) -> None: data_not_selected, data_selected = self._filter_data_group(self.data) if self._available_groups: - if self._available_groups[self._selected_root_attribute] not in self.available_groups: + if ( + self._available_groups[self._selected_root_attribute] + not in self.available_groups + ): self.selected_root_attribute = 0 # add model to available markers view