Changeset 1498:20bf9f96189e in orange-bioinformatics


Ignore:
Timestamp:
10/18/11 17:10:19 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
d3bab21061bc84aad7aa7615a75f55066755efab
Message:

Fixed a broken filters GUI.
Fixed a problem with PyQt4 and sorting in QTreeWidget (when using fink's PyQt4).
Fixed filtering by min. count.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • widgets/OWSetEnrichment.py

    r1478 r1498  
    2121from OWGUI import BarItemDelegate 
    2222 
     23def _toPyObject(variant): 
     24    val = variant.toPyObject() 
     25    if isinstance(val, type(NotImplemented)): # PyQt 4.4 converts python int, floats ... to C types 
     26        qtype = variant.type() 
     27        if qtype == QVariant.Double: 
     28            val, ok = variant.toDouble() 
     29        elif qtype == QVariant.Int: 
     30            val, ok = variant.toInt() 
     31        elif qtype == QVariant.LongLong: 
     32            val, ok = variant.toLongLong() 
     33        elif qtype == QVariant.String: 
     34            val = variant.toString() 
     35    return val 
    2336 
    2437class MyTreeWidget(QTreeWidget): 
     
    3346            painter.end() 
    3447             
     48class MyTreeWidgetItem(QTreeWidgetItem): 
     49    def __lt__(self, other): 
     50        if not self.treeWidget(): 
     51            return id(self) < id(other) 
     52        column = self.treeWidget().sortColumn() 
     53        lhs = _toPyObject(self.data(column, Qt.DisplayRole)) 
     54        rhs = _toPyObject(other.data(column, Qt.DisplayRole)) 
     55        return lhs < rhs 
    3556             
    3657class OWSetEnrichment(OWWidget): 
     
    3859    contextHandlers = {"":DomainContextHandler("", ["speciesIndex", "genesinrows", "geneattr", "categoriesCheckState"])} 
    3960     
    40     def __init__(self, parent=None, signalManager=None, name="Enrichment Analysis", **kwargs): 
     61    def __init__(self, parent=None, signalManager=None, name="Gene Set Enrichment Analysis", **kwargs): 
    4162        OWWidget.__init__(self, parent, signalManager, name, **kwargs) 
    4263        self.inputs = [("Example Table", ExampleTable, self.setData, Default), ("Reference", ExampleTable, self.setReference)] 
     
    100121        hLayout = QHBoxLayout() 
    101122        hLayout.setSpacing(10) 
    102         sb, sbcb = OWGUI.spin(QWidget(self.mainArea), self, "minClusterCount", 
     123        hWidget = OWGUI.widgetBox(self.mainArea, orientation=hLayout) 
     124        sb, sbcb = OWGUI.spin(hWidget, self, "minClusterCount", 
    103125                              0, 100, label="Min. Count", 
    104126                              tooltip="Minimum gene count", 
     
    108130                              checkCallback=self.filterAnnotationsChartView) 
    109131         
    110         dsp, dspcb = OWGUI.doubleSpin(QWidget(self.mainArea), self, 
     132        dsp, dspcb = OWGUI.doubleSpin(hWidget, self, 
    111133                        "maxPValue", 0.0, 1.0, 0.0001, 
    112134                        label="Max. P-Value", 
     
    117139                        checkCallback=self.filterAnnotationsChartView) 
    118140         
    119         hLayout.addWidget(sb) 
    120         hLayout.addWidget(sbcb) 
    121         hLayout.addWidget(dsp) 
    122         hLayout.addWidget(dspcb) 
    123          
    124141        import OWGUIEx 
    125142        self.filterLineEdit = OWGUIEx.QLineEditWithActions(self) 
     
    136153         
    137154        hLayout.addWidget(self.filterLineEdit) 
    138         self.mainArea.layout().addLayout(hLayout) 
     155        self.mainArea.layout().addWidget(hWidget) 
    139156         
    140157        self.connect(self.filterLineEdit, SIGNAL("textChanged(QString)"), 
     
    170187         
    171188        self.connect(self, SIGNAL("widgetStateChanged(QString, int, QString)"), self.onStateChange) 
     189         
     190        self.updatingAnnotationsFlag = False 
    172191         
    173192    def updateHierarchy(self): 
     
    424443        for i, (geneset, (cmapped, rmapped, p_val, enrichment)) in enumerate(results): 
    425444            if len(cmapped) > 0: 
    426                 item = QTreeWidgetItem(self.annotationsChartView, [" ".join(geneset.hierarchy), geneset.name]) 
     445                item = MyTreeWidgetItem(self.annotationsChartView, [" ".join(geneset.hierarchy), geneset.name]) 
    427446                item.setData(2, Qt.DisplayRole, QVariant(countFmt % (len(cmapped), 100.0*len(cmapped)/countAll))) 
     447                item.setData(2, Qt.ToolTipRole, QVariant(len(cmapped))) # For filtering 
    428448                item.setData(3, Qt.DisplayRole, QVariant(refFmt % (len(rmapped), 100.0*len(rmapped)/len(referenceGenes)))) 
    429449                item.setData(4, Qt.DisplayRole, QVariant(p_val)) 
     
    466486        for item in self.treeItems: 
    467487            item_cat = str(item.data(0, Qt.EditRole).toString()) 
    468             (count, _), (pval, _) = item.data(2, Qt.EditRole).toInt(), item.data(4, Qt.EditRole).toDouble() 
     488            count, pval = _toPyObject(item.data(2, Qt.ToolTipRole)), _toPyObject(item.data(4, Qt.DisplayRole)) 
    469489            geneset = item.geneset.name.lower() 
    470490            hidden = item_cat not in categories or (self.useMinCountFilter and count < self.minClusterCount) or \ 
     
    518538         
    519539         
    520          
    521540def reportItemView(view): 
    522541    model = view.model() 
Note: See TracChangeset for help on using the changeset viewer.