Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marker Genes: Add DictyBase #348

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/widgets/marker_genes.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Database sources:
- CellMarker

<cite>[CellMarker: a manually curated resource of cell markers in human and mouse.][1] Nucleic Acids Research. 2018.</cite>

</br>

- DictyBase

<cite>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.</cite>


Data is preprocessed in Orange readable format and it is hosted [here.][2] One can use [Databases update](databases_update.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ 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):
Expand All @@ -319,7 +320,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))
Expand Down Expand Up @@ -363,7 +364,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())
Expand All @@ -379,7 +380,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())
Expand Down
46 changes: 37 additions & 9 deletions orangecontrib/bioinformatics/widgets/OWMarkerGenes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" OWMarkerGenes """

from typing import List, Tuple, Iterable, Optional
from functools import partial

Expand Down Expand Up @@ -41,10 +42,14 @@
)

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):
Expand Down Expand Up @@ -655,10 +660,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:
"""
Expand Down Expand Up @@ -854,8 +860,12 @@ class Outputs:

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__()
Expand Down Expand Up @@ -937,7 +947,6 @@ def _init_control_area(self) -> None:
box,
self,
'selected_root_attribute',
items=GROUP_BY_ITEMS,
callback=self._setup,
)

Expand Down Expand Up @@ -1018,6 +1027,16 @@ def data(self, value: Table):
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)

def _load_data(self) -> None:
Expand Down Expand Up @@ -1068,8 +1087,15 @@ 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)
Expand All @@ -1096,6 +1122,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]:
"""
Expand Down Expand Up @@ -1126,7 +1154,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]
Expand Down Expand Up @@ -1184,7 +1212,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()

Expand Down
Loading