Skip to content

Commit

Permalink
Filters are working!
Browse files Browse the repository at this point in the history
  • Loading branch information
SteampunkIslande committed Oct 8, 2024
1 parent b1a33c4 commit 924561d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 44 deletions.
12 changes: 6 additions & 6 deletions common_widgets/page_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ def setup_layout(self):
self.setLayout(layout)

def goto_first_page(self):
self.query.first_page()
self.query.first_page().commit()

def goto_previous_page(self):
self.query.previous_page()
self.query.previous_page().commit()

def goto_next_page(self):
self.query.next_page()
self.query.next_page().commit()

def goto_last_page(self):
self.query.last_page()
self.query.last_page().commit()

def update_page_selector(self):
# Block signals to avoid infinite loops
Expand All @@ -85,7 +85,7 @@ def update_page_selector(self):
self.rows_lineedit.blockSignals(False)

def set_page(self, page):
self.query.set_page(int(page) if page else 1)
self.query.set_page(int(page) if page else 1).commit()

def set_rows_per_page(self, rows_per_page):
self.query.set_limit(int(rows_per_page or 10))
self.query.set_limit(int(rows_per_page or 10)).commit()
6 changes: 4 additions & 2 deletions config_folder/validation_methods/validation_immuno.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ steps:
query:
select:
fields:
- '"Chrom"'
- '"Position"'
- '"Project.recurrence"'
- '"Recurrence.cosmic"'
- '"Phastcons"'
Expand All @@ -39,7 +41,6 @@ steps:
- '"Variant.effect"'
- '"Clinvar.clinical.significance"'
- '"Glims"'
- '"Position"'
- '"PROVEAN"'
- '"NbrReadAlt"'
- '"MUTATIONTASTER"'
Expand All @@ -55,7 +56,6 @@ steps:
- '"CADD.phred"'
- '"dbscsnv.Rf.score"'
- '"Histo_majoritaire.cosmic"'
- '"Chrom"'
- '''#''||"Background color" AS ''.backgroundcolor'''
- '"Background color"'
tables:
Expand All @@ -69,6 +69,8 @@ steps:
order_by:
- field: main_table.Chrom
order: ASC
- field: main_table.Position
order: ASC
- title: VAF en rouge + SUIVI uniquement
description: Trié par chromosome et par position
query:
Expand Down
11 changes: 2 additions & 9 deletions filters_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def add_child(self, parent: QModelIndex, item: FilterItem):

def add_filter(self, expression: str):
"""Add a filter to the root element of the model"""
index = self.index(0, 0, self.index(0, 0, self.index(0, 0)))
self.add_child(index, FilterItem(FilterType.LEAF, expression=expression))
root_filter = self.index(0, 0, QModelIndex())
self.add_child(root_filter, FilterItem(FilterType.LEAF, expression=expression))

def remove_child(self, index: QModelIndex):
"""Remove a child from the parent index"""
Expand Down Expand Up @@ -281,22 +281,15 @@ def add_child(self):
index = self.view.currentIndex()
if not index.isValid():
return
print("Before", self.model.to_dict())
self.model.add_child(index, FilterItem(FilterType.LEAF, "a=3"))
print("After", self.model.to_dict())

def remove_child(self):
print("Before")
print(self.model.to_dict())
index = self.view.currentIndex()
if not index.isValid():
return

self.model.remove_child(index)

print("After")
print(self.model.to_dict())

def context_menu_requested(self, p: QPoint):
menu = QMenu()
add_child_action = menu.addAction("Add Child")
Expand Down
25 changes: 23 additions & 2 deletions filters_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,23 @@ def add_filter_leaf(self):
index = self.filters_view.currentIndex()
if not index.isValid():
return
expression = qw.QInputDialog.getText(self, "Expression", "Enter expression")
item = FilterItem(FilterType.LEAF, expression, None)
print("Adding LEAF expression to index ", index)
expression, _ = qw.QInputDialog.getText(self, "Expression", "Enter expression")
item = FilterItem(FilterType.LEAF, expression, alias=None, parent=None)
self.model.add_child(index, item)

def add_filter_and(self):
index = self.filters_view.currentIndex()
if not index.isValid():
return
item = FilterItem(FilterType.AND, None, alias=None, parent=None)
self.model.add_child(index, item)

def add_filter_or(self):
index = self.filters_view.currentIndex()
if not index.isValid():
return
item = FilterItem(FilterType.OR, None, alias=None, parent=None)
self.model.add_child(index, item)

def remove_filter(self):
Expand All @@ -51,6 +66,12 @@ def context_menu_requested(self, pos):
add_filter_action = menu.addAction("Add filter")
add_filter_action.triggered.connect(self.add_filter_leaf)

add_filter_and_action = menu.addAction("Add AND filter")
add_filter_and_action.triggered.connect(self.add_filter_and)

add_filter_or_action = menu.addAction("Add OR filter")
add_filter_or_action.triggered.connect(self.add_filter_or)

remove_filter_action = menu.addAction("Remove filter")
remove_filter_action.triggered.connect(self.remove_filter)

Expand Down
23 changes: 2 additions & 21 deletions query.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ class Query(qc.QObject):
# Signal for external use (tell the UI to update)
query_changed = qc.Signal()

# Signal for internal use (tell the model to update)
internal_changed = qc.Signal()

def __init__(self, datalake: "dl.DataLake", parent=None):
super().__init__(parent)
self.datalake = datalake
Expand All @@ -103,8 +100,6 @@ def __init__(self, datalake: "dl.DataLake", parent=None):
)
self.filter_model.model_changed.connect(self.update_data)

self.internal_changed.connect(self.update_data)

def init_state(self):
# When we create a new Query, we want to reset everything, except for the datalake path...
self.query_template = None
Expand All @@ -127,15 +122,12 @@ def init_state(self):

self.variables = dict()

self.internal_changed.emit()

return self

def add_variable(self, key: str, value: str):
if key in Query.RESERVED_VARIABLES:
raise ValueError(f"Variable name {key} is reserved")
self.variables[key] = value
self.internal_changed.emit()
return self

def get_variable(self, key: str) -> str:
Expand All @@ -149,7 +141,6 @@ def get_limit(self) -> int:

def set_limit(self, limit: int):
self.limit = limit
self.internal_changed.emit()
return self

def get_offset(self) -> int:
Expand All @@ -165,7 +156,6 @@ def get_page(self) -> int:
def set_page(self, page: int):
self.current_page = page
self.set_offset((page - 1) * self.limit)
self.internal_changed.emit()
return self

def previous_page(self):
Expand Down Expand Up @@ -228,20 +218,17 @@ def get_editable_table_name(self) -> str:

def set_editable_table_name(self, name: str):
self.editable_table_name = name
self.internal_changed.emit()
return self

def set_selected_samples(self, samples: List[str]):
self.selected_samples = samples
self.internal_changed.emit()
return self

def get_selected_samples(self) -> List[str]:
return self.selected_samples

def set_selected_genes(self, genes: List[str]):
self.selected_genes = genes
self.internal_changed.emit()
return self

def get_selected_genes(self) -> List[str]:
Expand All @@ -255,7 +242,6 @@ def generate_query_template_from_json(self, data: dict) -> "Query":
data (dict): The json object to build the query template from
"""
self.query_template = build_query_template(data)
self.internal_changed.emit()
return self

def select_query(self, paginated=True):
Expand Down Expand Up @@ -342,13 +328,8 @@ def update_data(self):
self.offset = 0
self.query_changed.emit()

def mute(self):
self.blockSignals(True)
return self

def unmute(self):
self.blockSignals(False)
return self
def commit(self):
self.update_data()

def to_json(self):
return {
Expand Down
4 changes: 3 additions & 1 deletion query_table_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def show_table_context_menu(self, pos):
def show_row_userdata(self, index: qc.QModelIndex):
row_data = index.data(qc.Qt.ItemDataRole.UserRole)
dialog = qw.QMessageBox(self)
dialog.setText(str(row_data))
dialog.setText(
"".join(f"<br><b>{k}</b>: {v}</br>" for k, v in row_data.items())
)
dialog.setWindowTitle(qc.QCoreApplication.tr("Données sous-jacentes"))
dialog.exec()

Expand Down
6 changes: 3 additions & 3 deletions validation_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ def setup_step(self, step_definition: dict):
):
return

self.query.mute().set_readonly_table(
self.query.set_readonly_table(
self.validation_parquet_files
).set_editable_table_name(self.validation_table_uuid).set_selected_genes(
self.validation_gene_names
).set_selected_samples(
self.validation_sample_names
).unmute().generate_query_template_from_json(
).generate_query_template_from_json(
step_definition
)
).commit()

def start_validation(self, selected_validation: dict):
if not self.datalake:
Expand Down

0 comments on commit 924561d

Please sign in to comment.