Changeset 1689:f3edbd78dbfd in orange-bioinformatics


Ignore:
Timestamp:
06/28/12 14:04:06 (22 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Check the target selection for a case where there are no labels/values.

Fixes #1208.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • _bioinformatics/widgets/OWFeatureSelection.py

    r1636 r1689  
    287287        self.label_selection_widget.set_labels(targets) 
    288288        self.data_labels = targets 
    289          
     289 
    290290    def set_data(self, data): 
    291291        self.closeContext("Data") 
     
    297297        self.data = data 
    298298        self.init_from_data(data) 
    299          
     299 
    300300        if self.data: 
    301301            self.genes_in_columns = not data_hints.get_hint(data, "genesinrows", False) 
    302302            self.openContext("Data", data) 
    303              
    304             # If only attr. labels or only class values then disable the 'Genes in columns' control 
     303 
     304            # If only attr. labels or only class values then disable 
     305            # the 'Genes in columns' control 
    305306            if not self.attribute_targets or not self.class_targets: 
    306307                self.genes_in_columns_check.setEnabled(False) 
    307308                self.genes_in_columns = bool(self.attribute_targets) 
    308          
     309 
    309310        self.update_targets_widget() 
    310          
    311         # If both attr. labels and classes are missing, show an error 
    312         if not (self.attribute_targets or self.class_targets): 
    313 #        if self.data and not self.data_labels: 
    314             self.error(1, "Cannot compute gene scores! Gene Selection widget requires a data-set with a discrete class variable or attribute labels!") 
     311 
     312        if self.data is not None  and \ 
     313                not (self.attribute_targets or self.class_targets): 
     314            # If both attr. labels and classes are missing, show an error 
     315            self.error(1, "Cannot compute gene scores! Gene Selection widget " 
     316                          "requires a data-set with a discrete class variable " 
     317                          "or attribute labels!") 
    315318            self.data = None 
    316          
     319 
    317320        if self.data: 
    318321            # Load context selection 
    319322            items = [(label, v) for label, values in self.data_labels for v in values] 
    320              
     323 
    321324            self.target_selections = [values[:1] for _, values in self.data_labels] 
    322325            label, values = self.data_labels[0] 
    323326            self.current_target_selection = label, values[:1] # Default selections 
    324              
     327 
    325328            self.openContext("TargetSelection", set(items)) # Load selections from context 
    326329            self.label_selection_widget.set_selection(*self.current_target_selection) 
     
    330333            self.send("Example table with remaining genes", None) 
    331334            self.send("Selected genes", None) 
    332              
     335 
    333336    def set_targets(self, targets): 
    334337        """ Set the target groups for score computation. 
     
    617620            self.send("Selected genes", None) 
    618621        self.data_changed_flag = False 
    619          
     622 
    620623    def on_target_changed(self): 
    621         label, values  = self.label_selection_widget.current_selection() 
     624        label, values = self.label_selection_widget.current_selection() 
     625 
     626        if values is None: 
     627            values = [] 
     628 
    622629        if self.genes_in_columns: 
    623630            targets = [(label, t) for t in values] 
    624631        else: 
    625632            targets = values 
     633 
    626634        self.targets = targets 
    627635        self.current_target_selection = label, values 
     
    631639            label_index = labels.index(label) 
    632640            self.target_selections[label_index] = values 
    633         self.set_targets(targets)  
    634      
     641        self.set_targets(targets) 
     642 
    635643    def on_label_activated(self, index): 
    636644        selection = self.target_selections[index] 
Note: See TracChangeset for help on using the changeset viewer.