source: orange-bioinformatics/orangecontrib/bio/widgets/prototypes/OWArrayExpress.py @ 1886:5a859e2c6ae1

Revision 1886:5a859e2c6ae1, 3.4 KB checked in by Ales Erjavec <ales.erjavec@…>, 6 months ago (diff)

Fixes for Arary Express query response parsing.

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