Commits

Aleš Erjavec committed 7fa187e

Removed 'GeneMANIA' widget.

  • Participants
  • Parent commits 8ae4268

Comments (0)

Files changed (2)

File orangecontrib/bio/widgets/OWGeneMania.py

-"""<name>GeneMANIA</name>
-<icon>icons/GeneMANIA.svg</icon>
-"""
-
-from __future__ import absolute_import
-
-import os, sys
-import multiprocessing
-import random
-
-import Orange
-from Orange.OrangeWidgets import OWGUI
-from Orange.OrangeWidgets.OWWidget import *
-
-from .. import obiGeneMania
-
-NAME = "GeneMANIA"
-DESCRIPTION = ""
-ICON = "icons/GeneMANIA.svg"
-
-INPUTS = [("Input Genes", Orange.data.Table, "setData")]
-OUTPUTS = [("Network", Orange.network.Graph, Default),
-           ("Items", Orange.data.Table)]
-
-REPLACES = ["_bioinformatics.widgets.OWGeneMania.OWGeneMania"]
-
-
-class BarItemDelegate(QStyledItemDelegate):
-    BarRole = OWGUI.OrangeUserRole.next() 
-    BarForegroundRole = OWGUI.OrangeUserRole.next()
-    
-    def __init__(self, parent, brush=QBrush(QColor(255, 170, 127)), scale=(0.0, 1.0)):
-        QStyledItemDelegate.__init__(self, parent) 
-        self.brush = brush
-        self.scale = scale
-        
-        
-    def paint(self, painter, option, index):
-        painter.save()
-        qApp.style().drawPrimitive(QStyle.PE_PanelItemViewRow, option, painter)
-        qApp.style().drawPrimitive(QStyle.PE_PanelItemViewItem, option, painter)
-        rect = option.rect
-        try:
-            val, ok = index.data(self.BarRole).toDouble()
-            if ok:
-                color = index.data(self.BarForegroundRole)
-                if color.isValid() and color.type() == QVariant.Color:
-                    brush = QBrush(color)
-                else:
-                    brush = self.brush
-                    
-                minval, maxval = self.scale
-                val = (val - minval) / (maxval - minval)
-                painter.save()
-                if option.state & QStyle.State_Selected:
-                    painter.setOpacity(0.75)
-                painter.setBrush(brush)
-                painter.drawRect(rect.adjusted(1, 1, max(-rect.width() * (1.0 - val) - 2, - rect.width() + 2), -2))
-                painter.restore()
-        except Exception, ex:
-            print >> sys.stderr, ex
-            
-        text = index.data(Qt.DisplayRole).toString()
-        if text:
-            align, ok = index.data(Qt.TextAlignmentRole).toInt()
-            if not ok:
-                align = Qt.AlignVCenter | Qt.AlignLeft
-                
-            painter.drawText(option.rect, align, text)
-        painter.restore()
-        
-        
-    def sizeHint(self, option, index):
-        size = QStyledItemDelegate.sizeHint(self, option, index)
-        metrics = QFontMetrics(option.font)
-        height = metrics.lineSpacing() + 2
-        return QSize(size.width(), height)
-    
-
-class OWGeneMania(OWWidget):
-    contextHandlers = {"": DomainContextHandler("", ["selectedOrganismIndex", "selectedGeneAttrIndex", "genesInColumns"])}
-    settingsList = ["serverAddress", "selectedOrganismIndex", "selectedGeneAttrIndex", "genesInColumns", "selectedMethodIndex", "resultCount"]
-    def __init__(self, parent=None, signalManager=None, name="GeneMANIA"):
-        OWWidget.__init__(self, parent, signalManager, name, wantMainArea=True)
-        
-        self.inputs = [("Input Genes", ExampleTable, self.setData)]
-        self.outputs = [("Network", Orange.network.Graph, Default), ("Items", ExampleTable)]
-        
-        self.serverAddress = obiGeneMania.DEFAULT_SERVER
-        self.selectedOrganismIndex = 0
-        self.selectedGeneAttrIndex = 0
-        self.genesInColumns = False
-        self.selectedMethodIndex = 1
-        self.resultCount = 10
-        
-        self.data = None
-        
-        self.loadSettings()
-        
-        #####
-        # GUI
-        #####
-        
-        self.organisms = [("H. sapiens", "9606"),
-                          ("A. thaliana", "3702"),
-                          ("C. elegans", "6239"),
-                          ("D. melanogaster", "7227"),
-                          ("M. musculus", "10090"),
-                          ("S. cerevisiae", "4932")]
-        
-        box = OWGUI.widgetBox(self.controlArea, "Info", addSpace=True)
-        self.info = OWGUI.widgetLabel(box, "No genes on input.")
-        self.infoState = OWGUI.widgetLabel(box, "")
-        self.infoState.setWordWrap(True)
-        
-        box = OWGUI.widgetBox(self.controlArea, "GeneMANIA server address", addSpace=True)
-        OWGUI.lineEdit(box, self, "serverAddress")
-        
-        self.organismCombo = OWGUI.comboBox(self.controlArea, self, "selectedOrganismIndex", "Organims",
-                                            items=[t[0] for t in self.organisms],
-                                            tooltip="Select the organism",
-                                            callback=self.updateInfo)
-        
-        box = OWGUI.widgetBox(self.controlArea, "Genes", addSpace=True)
-        self.geneAttrCombo = OWGUI.comboBox(box, self, "selectedGeneAttrIndex",
-                                            tooltip="Select the attribute with gene names",
-                                            callback=self.updateInfo)
-        
-        cb = OWGUI.checkBox(box, self, "genesInColumns", "Use attribute names",
-                            tooltip="Use attribute names as gene names instead.",
-                            callback=self.updateInfo,
-                            disables=[(-1, self.geneAttrCombo)])
-        cb.makeConsistent()
-        self.methodItems = [("Automatic relevance", "automatic_relevance"),
-                            ("Automatic", "automatic"),
-                            ("Biological process", "bp"),
-                            ("Molecular function", "mf"),
-                            ("Cellular component", "cc"),
-                            ("Average", "average"),
-                            ("Average category", "average_category")]
-        
-        toolTips = ["Assigned based on query genes",
-                    "Automatically selected weighting method",
-                    "Biological process based",
-                    "Molecular function based",
-                    "Cellular component based",
-                    "Equal by data type",
-                    "Equal by network"]
-        
-        OWGUI.comboBox(self.controlArea, self, "selectedMethodIndex", 
-                       box="Net combining method",
-                       items=[t[0] for t in self.methodItems],
-                       callback=self.updateInfo
-                       )
-        
-        OWGUI.spin(self.controlArea, self, "resultCount", 1, 100, 
-                   box="Number of gene results",
-                   callback=self.updateInfo
-                   )
-        
-        self.geneManiaLinkLabel = OWGUI.widgetLabel(self.controlArea, "")
-        self.geneManiaLinkLabel.setOpenExternalLinks(True)
-        OWGUI.button(self.controlArea, self, "Retrieve", callback=self.retrieve)
-        OWGUI.rubber(self.controlArea)
-        
-        self.networksReport = QTreeView()
-        self.networksReport.setEditTriggers(QTreeView.NoEditTriggers)
-        box = OWGUI.widgetBox(self.mainArea, "Networks")
-        box.layout().addWidget(self.networksReport)
-        
-        self.resize(100, 200)
-        
-        self.connect(self, SIGNAL("widgetStateChanged(QString, int, QString)"), self.updateInfo)
-
-
-    def setData(self, data=None):
-        self.error([0,1,2])
-        self.warning([0])
-        self.data = data
-        self.closeContext("")
-        self.geneAttrCombo.clear()
-        self.candidateGeneAttrs = []
-        self.selectedGeneAttrIndex = 0
-        
-        if data is not None:
-            self.candidateGeneAttrs = data.domain.variables + data.domain.getmetas().values()
-            self.candidateGeneAttrs = [attr for attr in self.candidateGeneAttrs if attr.varType != orange.VarTypes.Continuous]
-            self.geneAttrCombo.addItems([attr.name for attr in self.candidateGeneAttrs])
-            self.openContext("", data)
-        else:
-            self.send("Network", None)
-            self.send("Items", None)
-            
-        self.updateInfo()
-            
-    def onGeneSourceSelection(self):
-        genes = self.getSelectedGenes()
-        self.info.setText("")
-        
-    def updateInfo(self, *args):
-        if self.data is not None:
-            genes = self.getSelectedGenes()
-            htmlState = self.widgetStateToHtml()
-            self.info.setText("%i genes on input." % len(genes))
-            self.infoState.setText(htmlState)
-        else:
-            self.info.setText("No data on input.")
-            self.infoState.setText("")
-        
-        if self.data:
-            org = self.organisms[self.selectedOrganismIndex][1]
-            genes = self.getSelectedGenes()
-            method = self.methodItems[self.selectedMethodIndex][1]
-            conn = obiGeneMania.Connection(self.serverAddress)
-            self.geneManiaLinkLabel.setText('<a href="%s">View network in external browser</a>' % conn._queryPage(org, genes, method, self.resultCount))
-        else:
-            self.geneManiaLinkLabel.setText('')
-        
-    def getSelectedGenes(self):
-        if self.data is not None:
-            if self.genesInColumns:
-                names = [attr.name for attr in self.data.domain.attributes]
-            else:
-                attr = self.candidateGeneAttrs[self.selectedGeneAttrIndex]
-                names = set([str(ex[attr]) for ex in self.data if not ex[attr].isSpecial()])
-            return names
-        else:
-            return []
-        
-        
-    def retrieve(self):
-        org = self.organisms[self.selectedOrganismIndex][1]
-        genes = self.getSelectedGenes()
-        method = self.methodItems[self.selectedMethodIndex][1]
-        self.error([0, 1, 2])
-        self.warning([0])
-        
-        conn = obiGeneMania.Connection(self.serverAddress)
-        errorCode, invalid, genes = conn.validate(org, genes)
-        if not genes:
-            self.error(2, "No valid gene names!")
-            self.net, self.netTab = None, None
-            self.updateNetworksReport()
-            return
-        elif invalid:
-            self.warning(0, "There are invalid gene names on input:\n%s" % (",".join(invalid[:5])) + (" ..." if len(invalid) > 5 else ""))
-            
-#        print conn._queryPage(org, genes, method, self.resultCount)
-        call = self.asyncCall(conn.retrieveXML, (org, genes), {"m": method, "r": self.resultCount})
-        call()
-        
-        self.progressBarInit()
-        self.setEnabled(False)
-        try:
-#            net = conn.retrieve(org, genes, m=method, r=self.resultCount)
-            xml = call.get_result(processEvents=True)
-            # Parse the xml in the main thread (pyexpat frequently crashes in 
-            # Qt's threading model)
-            dom = obiGeneMania.minidom.parseString(xml)
-            net = obiGeneMania.parse(dom)
-            items = net.items()
-        except Exception, ex:
-            self.error(0, "Failed to retrieve network from server!\n" + str(ex))
-            sys.excepthook(*sys.exc_info())
-            net = None
-            items = None
-        
-        if net:
-            try:
-                self.netTab = obiGeneMania.parsePage(conn._page)
-            except Exception:
-                self.error(1, "Failed to parse network tabs!\n" + str(ex))
-                self.netTab = None
-        else:
-            self.netTab = None
-        self.setEnabled(True)
-        self.progressBarFinished()
-        
-        self.net = net
-        
-        self.send("Network", net)
-        self.send("Items", items)
-        
-        self.updateNetworksReport()
-        
-    def updateNetworksReport(self):
-        model = QStandardItemModel(self)
-        model.setHorizontalHeaderLabels(["Networks", "Weight"])
-        root = model.invisibleRootItem()
-        def toFloat(s):
-            if s.strip().endswith("%"):
-                return float(s.strip()[:-1])
-            else:
-                return float(s)
-            
-        if self.netTab and self.net and self.net.links:
-            for group in self.netTab:
-                groupItem = QStandardItem(group.name)
-                groupWeightItem = QStandardItem("%.2f %%" % toFloat(group.weight))
-                groupWeightItem.setData(QVariant(toFloat(group.weight) / 100.0), BarItemDelegate.BarRole)
-                root.appendRow([groupItem, groupWeightItem])
-                for net in group.networks:
-                    netItem = QStandardItem(net.name)
-                    netItem.setData(QVariant(net.description), Qt.ToolTipRole)
-                    
-                    netWeightItem = QStandardItem("%.2f %%" % toFloat(net.weight))
-                    netWeightItem.setData(QVariant(toFloat(net.weight) / 100.0), BarItemDelegate.BarRole)
-                    netWeightItem.setData(QVariant(net.description), Qt.ToolTipRole)
-                    groupItem.appendRow([netItem, netWeightItem])
-                
-        self.networksReport.setModel(model)
-        self.networksReport.setItemDelegateForColumn(1, BarItemDelegate(self))
-        self.networksReport.resizeColumnToContents(0)
-            
-        
-if __name__ == "__main__":
-    app = QApplication(sys.argv)
-    w = OWGeneMania()
-    w.show()
-    data = orange.ExampleTable("../../../doc/datasets/brown-selected.tab")
-    w.setData(orange.ExampleTable(data[:3]))
-    app.exec_()
-    w.saveSettings()
-        
-        

File orangecontrib/bio/widgets/icons/GeneMANIA.svg

-<?xml version="1.0" encoding="utf-8"?>
-<!-- Generator: Adobe Illustrator 16.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
-<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
-	 width="48px" height="48px" viewBox="0 0 48 48" enable-background="new 0 0 48 48" xml:space="preserve">
-<g>
-	<path fill-rule="evenodd" clip-rule="evenodd" fill="#333333" d="M22.324,13.354c0.184-0.998,0.799-1.406,1.809-1.315
-		c1.017,0.092,1.49,0.751,1.566,1.67c0.132,1.587,0.181,3.182,0.266,4.796c1.34,0,2.689,0,4.165,0c0-1.508,0.126-2.934-0.022-4.329
-		c-0.541-5.053-3.541-6.907-8.138-5.92c-1.665,0.357-2.86,1.416-3.384,3.013c-0.396,1.207-0.691,2.507-0.707,3.769
-		c-0.072,5.871-0.09,11.746,0.013,17.617c0.026,1.508,0.325,3.103,0.904,4.488c0.614,1.47,2.022,2.441,3.554,2.689
-		c1.34,0.216,3.1,0.296,4.387-0.197c0.775-0.297,1.564-0.931,2.066-1.592c0.678-0.893,0.753-1.979,0.854-3.077
-		c0.223-2.439,0.09-4.975,0.115-7.424c0.004-0.274,0.027-3.778,0-3.778c-2.064,0-3.767,0-5.812,0c0,1.2,0,2.345,0,3.55
-		c0.599,0.001,1.16,0.001,1.731,0.001c0,2.316,0.001,4.68-0.014,6.929c-0.008,1.21-0.59,1.561-1.728,1.627
-		c-0.689,0.041-1.265-0.299-1.471-0.985c-0.173-0.574-0.274-1.192-0.276-1.792c-0.02-5.937-0.015-11.875-0.006-17.811
-		C22.199,14.638,22.209,13.984,22.324,13.354z"/>
-</g>
-</svg>