Changeset 429:7d507bcd0c8f in orange-bioinformatics


Ignore:
Timestamp:
07/22/08 14:12:36 (6 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
df7929e9e9550be38ac32f448618b4fe5c67d1bb
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • prototypes/OWDicty.py

    r425 r429  
    33<description>Widget interface to dicty experaments</description> 
    44""" 
     5from __future__ import with_statement 
    56 
    67from OWWidget import * 
    78import obiDicty 
    89import OWGUI 
     10 
     11from functools import partial 
     12from collections import defaultdict 
     13from threading import Lock, Thread 
     14from traceback import print_exception 
    915import sys 
    1016 
     
    1319        self.drawBackground(painter, option, index) 
    1420        value, ok = index.data(Qt.DisplayRole).toString() 
     21 
     22class MyQThread(QThread): 
     23    def __init__(self, parent, func=None): 
     24        QThread.__init__(self, parent) 
     25        self.func = func 
     26         
     27    def run(self): 
     28        try: 
     29            self.returnValue = self.func() 
     30        except Exception, ex: 
     31            pass 
     32##            print_exception(*sys.exc_info()) 
     33         
    1534class OWDicty(OWWidget): 
    16     settingsList = ["typeIndex", "joinSelected", "separateSelected"] 
     35    settingsList = ["serverToken", "platform", "tables", "selectedTables"] 
    1736    def __init__(self, parent=None, signalManager=None, name="Dicty database"): 
    1837        OWWidget.__init__(self, parent, signalManager, name) 
     38        self.outputs = [("Example tables", ExampleTable, Multiple)] 
    1939        self.serverToken = "" 
    20         self.typeIndex = 0 
    21         self.typesList = [n for n, long in obiDicty.DatabaseConnection.obidPairs] 
     40##        self.type = None 
     41##        self.typesList = ["norms", "chips"] #[n for n, long in obiDicty.DatabaseConnection.obidPairs] 
    2242 
    23         self.platformIndex = 0 
     43        self.platform = None 
    2444        self.platformList = [] 
    2545         
    2646        self.sampleList = [] 
    2747        self.sampleSelected = [] 
     48 
     49        self.treatmentList = [] 
     50        self.treatmentSelected = [] 
     51 
     52        self.growthCondList = [] 
     53        self.growthCondSelected = [] 
    2854         
    2955        self.joinList = [n for n, long in obiDicty.DatabaseConnection.aoidPairs] 
     
    3359        self.separateSelected = [] 
    3460         
    35         self.loadSettings()         
     61        self.loadSettings() 
    3662         
    37         OWGUI.lineEdit(self.controlArea, self, "serverToken", box="Server Token", callback=self.UpdateControls) 
    38         self.typeCombo = OWGUI.comboBox(self.controlArea, self, "typeIndex", box="Type", items=self.typesList, sendSelectedValue=True, callback=self.UpdateControls) 
    39         self.platformCombo = OWGUI.comboBox(self.controlArea, self, "platformIndex", box="Platform", items=self.platformList, sendSelectedValue=True, callback=self.UpdateControls) 
    40         self.sampleListBox = OWGUI.listBox(self.controlArea, self, "sampleSelected", "sampleList", box="Samples", selectionMode=QListWidget.ExtendedSelection, callback=self.UpdateControls) 
    41         self.joinListBox = OWGUI.listBox(self.mainArea, self, "joinSelected", "joinList", box="Join", selectionMode=QListWidget.ExtendedSelection, callback=self.UpdateControls) 
    42         self.separateListBox = OWGUI.listBox(self.mainArea, self, "separateSelected", "separateList", box="Separate", selectionMode=QListWidget.ExtendedSelection, callback=self.UpdateControls) 
     63        OWGUI.lineEdit(self.controlArea, self, "serverToken", box="Server Token", callback=self.Connect) 
     64##        self.typeCombo = OWGUI.comboBox(self.controlArea, self, "type", box="Type", items=self.typesList, sendSelectedValue=True, callback=self.UpdateControls) 
     65        self.platformCombo = OWGUI.comboBox(self.controlArea, self, "platform", box="Platform", items=self.platformList, sendSelectedValue=True, callback=partial(self.UpdateControls, ["sample", "treatment", "growthCond"])) 
     66        self.sampleListBox = OWGUI.listBox(self.controlArea, self, "sampleSelected", "sampleList", box="Samples", selectionMode=QListWidget.ExtendedSelection, callback=partial(self.UpdateControls, ["treatment", "growthCond"])) 
     67        self.treatmentListBox = OWGUI.listBox(self.controlArea, self, "treatmentSelected", "treatmentList", box="Treatment", selectionMode=QListWidget.ExtendedSelection, callback=partial(self.UpdateControls, ["growthCond"])) 
     68        self.growthCondListBox = OWGUI.listBox(self.controlArea, self, "growthCondSelected", "growthCondList", box="Growth Condition", selectionMode=QListWidget.ExtendedSelection, callback=partial(self.UpdateControls, [])) 
     69        self.joinListBox = OWGUI.listBox(self.mainArea, self, "joinSelected", "joinList", box="Join", selectionMode=QListWidget.ExtendedSelection) 
     70        self.separateListBox = OWGUI.listBox(self.mainArea, self, "separateSelected", "separateList", box="Separate", selectionMode=QListWidget.ExtendedSelection) 
    4371         
    44         OWGUI.button(self.controlArea, self, "&Preview", callback=self.ShowPreview) 
     72##        OWGUI.button(self.controlArea, self, "&Preview", callback=self.ShowPreview) 
    4573        OWGUI.button(self.controlArea, self, "&Commit", callback=self.Commit) 
    4674        OWGUI.rubber(self.controlArea) 
    4775 
    4876        self.dbc = None 
    49 ##        self.UpdateControls() 
     77        self.locks = defaultdict(Lock) 
     78        self.InitControls() 
    5079 
    5180    def __updateSelectionList(self, oldList, oldSelection, newList): 
     
    5483 
    5584    def GetOptions(self): 
    56         print self.typeIndex, self.platformIndex, self.sampleSelected, self.joinSelected, self.separateSelected 
    57         return self.typeIndex, self.platformIndex, self.sampleSelected, self.joinSelected, self.separateSelected 
     85        print self.platform, [self.sampleList[i] for i in self.sampleSelected], [self.joinList[i] for i in self.joinSelected], [self.separateList[i] for i in self.separateSelected] 
     86        return self.platform, [self.sampleList[i] for i in self.sampleSelected], [self.joinList[i] for i in self.joinSelected], [self.separateList[i] for i in self.separateSelected] 
    5887 
    59     def UpdateControls(self): 
    60         if not self.dbc: 
    61             try: 
    62                 self.dbc = obiDicty.DatabaseConnection("http://purple.bioch.bcm.tmc.edu/~anup/index.php?token="+self.serverToken+"&") 
    63             except Exception, ex: 
    64                 from traceback import print_exception 
    65                 print_exception(*sys.exc_info()) 
    66                 self.error(0, "Error connecting to server") 
    67                 return 
    68         else: 
    69             self.error(0) 
    70         type, platform, sample, join, separate = self.GetOptions() 
     88    def GetQuery(self): 
     89        query = {} 
     90        if self.platform: 
     91            query["platform"] = self.platform 
     92        if self.sampleSelected: 
     93            query["sample"] = [self.sampleList[i] for i in self.sampleSelected] 
     94        if self.treatmentSelected: 
     95            query["treatment"] = [self.treatmentList[i] for i in self.treatmentSelected] 
     96        if self.growthCondSelected: 
     97            query["growthCond"] = [self.growthCondList[i] for i in self.growthCondSelected] 
     98        return {} #query 
     99     
     100    def Connect(self): 
     101        address = "http://www.ailab.si/dictyexpress/api/index.php?" 
     102        if self.serverToken: 
     103            address += "token="+self.serverToken+"&" 
    71104        try: 
    72             opt = self.dbc.annotationOptions(type=type, platform=platform) #, sample=list(sample), join=list(join), separate=list(separate)) 
     105            self.dbc = obiDicty.DatabaseConnection(address) 
    73106        except Exception, ex: 
    74107            from traceback import print_exception 
    75108            print_exception(*sys.exc_info()) 
    76             self.error(1, "Error retrieving data from server") 
     109            self.error(0, "Error connecting to server" + str(ex)) 
    77110            return 
    78         else: 
    79             self.error(1) 
    80         self.platformCombo.clear() 
    81         self.platformCombo.addItems(opt.get("platform", [])) 
    82         self.sampleList = opt.get("sample", []) 
     111        self.error(0) 
    83112 
     113    def InitControls(self): 
     114        if not self.dbc: 
     115            self.Connect() 
     116        self.platformThread = MyQThread(self, partial(self.dbc.annotationOptions, self.dbc.aoidt("platform"))) 
     117        self.platformCombo.setDisabled(True) 
     118        def _set(): 
     119            self.platformCombo.clear() 
     120            self.platformCombo.addItems(self.platformThread.returnValue["platform"]) 
     121            self.platformCombo.setDisabled(False) 
     122        self.connect(self.platformThread, SIGNAL("finished()"), partial(_set)) 
     123        self.platformThread.start() 
     124             
     125    def UpdateControls(self, controls=()): 
     126        if not self.dbc: 
     127            self.Connect() 
     128        query = self.GetQuery() 
     129        for control in controls: 
     130            thread = MyQThread(self, partial(self.dbc.annotationOptions, self.dbc.aoidt(control), **query)) 
     131            setattr(self, control+"Thread", thread) 
     132            listBox = getattr(self, control+"ListBox") 
     133            listBox.setDisabled(True) 
     134            def _set(control): 
     135                setattr(self, control+"List", getattr(self, control+"Thread").returnValue[control]) 
     136                getattr(self, control+"ListBox").setDisabled(False) 
     137            self.connect(thread, SIGNAL("finished()"), partial(_set, control)) 
     138            thread.start() 
    84139 
    85140    def ShowPreview(self): 
     
    87142 
    88143    def Commit(self): 
    89         pass 
     144        platform, sample, join, separate = self.GetOptions() 
     145        tables = self.dbc.getData(platform=platform, sample=sample, join=join, separate=separate) 
     146        self.send("Example tables", None) 
     147        for i, table in enumerate(tables): 
     148            self.send("Example tables", table, i) 
    90149 
    91150if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.