source: orange-bioinformatics/orangecontrib/bio/widgets/prototypes/OWArrayExpress.py @ 1873:0810c5708cc5

Revision 1873:0810c5708cc5, 3.3 KB checked in by Ales Erjavec <ales.erjavec@…>, 6 months ago (diff)

Moved '_bioinformatics' into orangecontrib namespace.

RevLine 
[1688]1"""
2<name>Array Express</name>
3<description>Access Array Express datasets<description>
4
5"""
6
7import sys
8import os
9from datetime import date
10import Orange
11
12from Orange.bio import obiArrayExpress
13
14from OWWidget import *
15import OWGUI
16
17
18class OWArrayExpress(OWWidget):
19    settingsList = ["current_experiement", "search_string"]
20
21    HEADER_LABELS = ["ID", "Title", "Species", "Assays", "Date"]
22    def __init__(self, parent=None, signalManager=None, title="Array Express"):
23        OWWidget.__init__(self, parent, signalManager, title)
24
25        self.outputs = [("Data Table", Orange.data.Table)]
26        self.current_experiment = None
27        self.search_string = ""
28
29        self.loadSettings()
30
31        #####
32        # GUI
33        #####
34
35        box = OWGUI.widgetBox(self.controlArea, "Info")
36        self.info = OWGUI.widgetLabel(box, "")
37
38        OWGUI.rubber(self.controlArea)
39        OWGUI.button(self.controlArea, self, "Commit", callback=self.commit)
40
41        self.experiments_view = QTreeView(self)
42        self.experiments_view.setSortingEnabled(True)
43        self.experiments_view.viewport().setMouseTracking(True)
44        self.experiments_view.setItemDelegateForColumn(
45            0, OWGUI.LinkStyledItemDelegate(self.experiments_view)
46        )
47
48        model = QStandardItemModel()
49        model.setHorizontalHeaderLabels(self.HEADER_LABELS)
50
51        self.experiments_view.setModel(model)
52
53        self.mainArea.layout().addWidget(self.experiments_view)
54
55        self.setEnabled(False)
56        QTimer.singleShot(50, self.fill_experiments)
57
58    def fill_experiments(self):
59        self.connection = obiArrayExpress.ArrayExpressConnection()
60        self.all_experiments = []
61        res = obiArrayExpress.query_experiments(gxa=True)  # only gxa for now
62        res = res["experiments"]
63        experiments = res["experiment"]
64        model = QStandardItemModel(self)
65        model.setHorizontalHeaderLabels(self.HEADER_LABELS)
66
67        for exp in experiments:
68            accession = str(exp["accession"])
69            species = str(exp.get("species", ""))
70            title = exp.get("name", "")
71            assays = str(exp["assays"])
72            date = exp.get("releasedate", "") or ""
73
74            row = map(PyStandardItem,
75                      [accession, title, species, assays, date])
76            url = "http://www.ebi.ac.uk/arrayexpress/experiments/" + accession
77            row[0].setData(QVariant(url), OWGUI.LinkRole)
78            model.appendRow(row)
79
80        self.experiments_view.setModel(model)
81
82        self.info.setText("%i experiments" % model.rowCount())
83        self.setEnabled(True)
84
85    def commit(self):
86        selected = self.experiments_view.selectionModel().selectedRows()
87
88        if selected:
89            i = selected[0].row()
90            model = self.experiments_view.model()
91            item = model.item(i)
92            accession = str(item.data(Qt.DisplayRole).toPyObject())
93            experiment = obiArrayExpress.ArrayExpressExperiment(accession)
94            table = experiment.fgem_to_table()
95
96            self.send("Data Table", table)
97
98
99class PyStandardItem(QStandardItem):
100    def __lt__(self, other):
101        return self.data(Qt.DisplayRole).toPyObject() < \
102                other.data(Qt.DisplayRole).toPyObject()
103
104
105if __name__ == "__main__":
106    import sys
107    app = QApplication(sys.argv)
108    w = OWArrayExpress()
109    w.show()
110    app.exec_()
Note: See TracBrowser for help on using the repository browser.