Changeset 1861:d80f56ee144e in orange-bioinformatics for _bioinformatics/widgets/OWSetEnrichment.py


Ignore:
Timestamp:
10/08/13 17:40:10 (6 months ago)
Author:
markotoplak
Branch:
default
Message:

gene set enrichment widgets corretly uses gene sets without species given

File:
1 edited

Legend:

Unmodified
Added
Removed
  • _bioinformatics/widgets/OWSetEnrichment.py

    r1860 r1861  
    1616 
    1717from .. import obiGene, obiGeneSets, obiProb, obiTaxonomy 
     18 
     19def gsname(geneset): 
     20    return geneset.name if geneset.name else geneset.id 
     21 
    1822 
    1923def _toPyObject(variant): 
     
    248252#            print self.speciesIndex 
    249253 
    250             self.setHierarchy(self.getHierarchy(taxid=self.taxid_list[self.speciesIndex])) 
     254            self.setHierarchy(*self.getHierarchy(taxid=self.taxid_list[self.speciesIndex])) 
    251255 
    252256            self.loadedGenematcher = "None" 
     
    266270                collect(col[hier[0]], hier[1:]) 
    267271 
    268         print "GS", self.genesets 
    269  
    270272        for hierarchy, t_id, _ in self.genesets: 
    271273            collect(collection[t_id], hierarchy) 
    272274 
    273         #TODO add genesets without species identifiers 
    274  
    275         return collection[taxid] 
    276  
    277     def setHierarchy(self, hierarchy): 
     275        return (taxid, collection[taxid]), (None, collection[None]) 
     276 
     277    def setHierarchy(self, hierarchy, hierarchy_noorg): 
    278278        self.groupsWidgetItems = {} 
    279         def fill(col, parent, full=()): 
     279        def fill(col, parent, full=(), org=""): 
    280280            for key, value in sorted(col.items()): 
    281281                full_cat = full + (key,) 
     
    288288                item.setExpanded(True) 
    289289                item.category = full_cat 
     290                item.organism = org 
    290291                self.groupsWidgetItems[full_cat] = item 
    291                 fill(value, item, full_cat) 
    292  
    293         fill(hierarchy, self.groupsWidget) 
     292                fill(value, item, full_cat, org=org) 
     293 
     294        fill(hierarchy[1], self.groupsWidget, org=hierarchy[0]) 
     295        fill(hierarchy_noorg[1], self.groupsWidget, org=hierarchy_noorg[0]) 
    294296 
    295297#    def updateCategoryCounts(self): 
     
    298300 
    299301    def selectedCategories(self): 
    300         taxid = self.taxid_list[self.speciesIndex] 
    301         return [(key, taxid) for key, check in self.getHierarchyCheckState().items() if check == Qt.Checked] 
     302        return [(key, org) for (key, org), check in self.getHierarchyCheckState().items() if check == Qt.Checked] 
    302303 
    303304    def getHierarchyCheckState(self): 
     
    306307            name = str(item.data(0, Qt.DisplayRole).toString()) 
    307308            full_cat = full + (name,) 
    308             result = [(full_cat, checked)] 
     309            result = [((full_cat, item.organism), checked)] 
    309310            for i in range(item.childCount()): 
    310311                result.extend(collect(item.child(i), full_cat)) 
     
    316317 
    317318    def subsetSelectionChanged(self, item, column): 
     319        #FIXME this should also recompute FDR 
    318320        self.categoriesCheckState = self.getHierarchyCheckState() 
    319  
    320321        categories = self.selectedCategories() 
    321322        if not set(categories) <= set(self.currentAnnotatedCategories): 
     
    412413 
    413414        ## Load collections in a worker thread 
    414         print "CAT", categories 
    415415        call = self.asyncCall(obiGeneSets.collections, categories, name="Loading collections", blocking=True, thread=self.thread()) 
    416416        call.connect(call, SIGNAL("progressChanged(float)"), self.progressBarSet) 
     
    466466        for i, (geneset, (cmapped, rmapped, p_val, enrichment)) in enumerate(results): 
    467467            if len(cmapped) > 0: 
    468                 item = MyTreeWidgetItem(self.annotationsChartView, [" ".join(geneset.hierarchy), geneset.name]) 
     468                item = MyTreeWidgetItem(self.annotationsChartView, [" ".join(geneset.hierarchy), gsname(geneset)]) 
    469469                item.setData(2, Qt.DisplayRole, QVariant(countFmt % (len(cmapped), 100.0*len(cmapped)/countAll))) 
    470470                item.setData(2, Qt.ToolTipRole, QVariant(len(cmapped))) # For filtering 
     
    490490 
    491491        replace = lambda s:s.replace(",", " ").replace("(", " ").replace(")", " ") 
    492         self._completerModel = completerModel = QStringListModel(sorted(reduce(set.union, [[geneset.name] + replace(geneset.name).split() for geneset, (c, _, _, _) in results if c], set()))) 
     492        self._completerModel = completerModel = QStringListModel(sorted(reduce(set.union, [[gsname(geneset)] + replace(gsname(geneset)).split() for geneset, (c, _, _, _) in results if c], set()))) 
    493493        self.filterCompleter.setModel(completerModel) 
    494494 
     
    513513            item_cat = str(item.data(0, Qt.EditRole).toString()) 
    514514            count, pval = _toPyObject(item.data(2, Qt.ToolTipRole)), _toPyObject(item.data(4, 42)) 
    515             geneset = item.geneset.name.lower() 
     515            geneset = gsname(item.geneset).lower() 
    516516            hidden = item_cat not in categories or (self.useMinCountFilter and count < self.minClusterCount) or \ 
    517517                     (self.useMaxPValFilter and pval > self.maxPValue) or filterString not in geneset 
Note: See TracChangeset for help on using the changeset viewer.