Skip to content

Commit

Permalink
Marker Genes: Add DictyBase
Browse files Browse the repository at this point in the history
  • Loading branch information
lenatr99 committed May 31, 2024
1 parent 01c18df commit 41cfdf0
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions orangecontrib/bioinformatics/widgets/OWMarkerGenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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__()
Expand Down Expand Up @@ -937,7 +942,6 @@ def _init_control_area(self) -> None:
box,
self,
'selected_root_attribute',
items=GROUP_BY_ITEMS,
callback=self._setup,
)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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]:
"""
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 41cfdf0

Please sign in to comment.