Changeset 1872:5518b82614e3 in orangebioinformatics
 Timestamp:
 10/10/13 12:54:22 (6 months ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

_bioinformatics/widgets/OWSetEnrichment.py
r1863 r1872 20 20 return geneset.name if geneset.name else geneset.id 21 21 22 fmtp = lambda score: "%0.5f" % score if score > 10e4 else "%0.1e" % score 23 fmtpdet = lambda score: "%0.9f" % score if score > 10e4 else "%0.5e" % score 22 24 23 25 def _toPyObject(variant): … … 51 53 return id(self) < id(other) 52 54 column = self.treeWidget().sortColumn() 53 if column == 4:55 if column in [4,5]: 54 56 lhs = _toPyObject(self.data(column, 42)) 55 57 rhs = _toPyObject(other.data(column, 42)) … … 68 70 69 71 class OWSetEnrichment(OWWidget): 70 settingsList = ["speciesIndex", "genesinrows", "geneattr", "categoriesCheckState" ]72 settingsList = ["speciesIndex", "genesinrows", "geneattr", "categoriesCheckState", "useMinCountFilter", "useMaxPValFilter", "useMaxFDRFilter", "minClusterCount", "maxPValue", "maxFDR" ] 71 73 contextHandlers = {"":DomainContextHandler("", ["speciesIndex", "genesinrows", "geneattr", "categoriesCheckState"])} 72 74 … … 86 88 self.useMinCountFilter = True 87 89 self.useMaxPValFilter = True 88 self.minClusterCount = 0 90 self.useMaxFDRFilter = True 91 self.minClusterCount = 3 89 92 self.maxPValue = 0.01 90 91 self.useFDR = True 93 self.maxFDR = 0.01 92 94 93 95 self.categoriesCheckState = {} … … 148 150 dsp, dspcb = OWGUI.doubleSpin(hWidget, self, 149 151 "maxPValue", 0.0, 1.0, 0.0001, 150 label=" FDR adjusted PValue",151 tooltip="Maximum (FDR adjusted) PValue",152 label="pvalue", 153 tooltip="Maximum pvalue", 152 154 callback=self.filterAnnotationsChartView, 153 155 callbackOnReturn=True, 154 156 checked="useMaxPValFilter", 157 checkCallback=self.filterAnnotationsChartView) 158 159 dsfdr, dsfdrcb = OWGUI.doubleSpin(hWidget, self, 160 "maxFDR", 0.0, 1.0, 0.0001, 161 label="FDR", 162 tooltip="Maximum False discovery rate", 163 callback=self.filterAnnotationsChartView, 164 callbackOnReturn=True, 165 checked="useMaxFDRFilter", 155 166 checkCallback=self.filterAnnotationsChartView) 156 167 … … 176 187 self.annotationsChartView = MyTreeWidget(self) 177 188 self.annotationsChartView.setHeaderLabels(["Category", "Term", 178 "Count", "Reference count", " PValue", "Enrichment"])189 "Count", "Reference count", "pvalue", "FDR", "Enrichment"]) 179 190 self.annotationsChartView.setAlternatingRowColors(True) 180 191 self.annotationsChartView.setSortingEnabled(True) … … 319 330 320 331 def subsetSelectionChanged(self, item, column): 321 #FIXME this should also recompute FDR322 332 self.categoriesCheckState = self.getHierarchyCheckState() 323 333 categories = self.selectedCategories() … … 448 458 self.progressBarSet(100.0 * i / len(collections)) 449 459 450 if self.useFDR:451 results = sorted(results, key=lambda a:a[1][2])452 pvals = obiProb.FDR([pval for _, (_, _, pval, _) in results])453 results = [(geneset, (cmapped, rmapped, pvals[i], es)) for i, (geneset, (cmapped, rmapped, _, es)) in enumerate(results)]454 455 fmt = lambda score, max_decimals=10: "%%.%if" % min(int(abs(math.log(max(score, 1e10)))) + 2, max_decimals) if score > math.pow(10, max_decimals) and score < 1 else "%.1f"456 460 self.annotationsChartView.clear() 457 461 … … 459 463 maxRefCount = max([len(rc) for _, (_, rc, _, _) in results] + [1]) 460 464 countSpaces = int(math.ceil(math.log10(maxCount))) 461 #print maxRefCount462 465 refSpaces = int(math.ceil(math.log(maxRefCount))) 463 466 countFmt = "%"+str(countSpaces) + "s (%.2f%%)" … … 474 477 item.setData(2, Qt.ToolTipRole, QVariant(len(cmapped))) # For filtering 475 478 item.setData(3, Qt.DisplayRole, QVariant(refFmt % (len(rmapped), 100.0*len(rmapped)/len(referenceGenes)))) 476 item.setData(4, Qt.DisplayRole, QVariant("%0.6f" % p_val)) if p_val > 0.001 else item.setData(4, Qt.DisplayRole, QVariant("%0.2e" % p_val)) 477 item.setData(4, 42, QVariant(p_val)) #sorting 478 item.setData(4, Qt.ToolTipRole, QVariant("%0.10f" % p_val)) 479 item.setData(5, Qt.DisplayRole, QVariant(enrichment)) 480 item.setData(5, Qt.ToolTipRole, QVariant("%.3f" % enrichment)) 479 item.setData(4, Qt.ToolTipRole, QVariant(fmtpdet(p_val))) 480 item.setData(4, Qt.DisplayRole, QVariant(fmtp(p_val))) 481 item.setData(4, 42, QVariant(p_val)) 482 #column 5, FDR, is computed in filterAnnotationsChartView 483 item.setData(6, Qt.DisplayRole, QVariant(enrichment)) 484 item.setData(6, Qt.ToolTipRole, QVariant("%.3f" % enrichment)) 481 485 item.geneset= geneset 482 486 self.treeItems.append(item) … … 496 500 self.filterCompleter.setModel(completerModel) 497 501 498 self.annotationsChartView.setItemDelegateForColumn( 5, BarItemDelegate(self, scale=(0.0, max(t[1][3] for t in results))))502 self.annotationsChartView.setItemDelegateForColumn(6, BarItemDelegate(self, scale=(0.0, max(t[1][3] for t in results)))) 499 503 self.annotationsChartView.setItemDelegateForColumn(1, LinkStyledItemDelegate(self.annotationsChartView)) 500 504 … … 512 516 categories = set(" ".join(cat) for cat, taxid in self.selectedCategories()) 513 517 514 #compute FDR after selection categories515 518 516 519 filterString = str(self.filterLineEdit.text()).lower() 517 itemsHidden = [] 520 521 #hide categories 522 itemsHiddenCat = [] 518 523 for item in self.treeItems: 519 524 item_cat = str(item.data(0, Qt.EditRole).toString()) 520 count, pval = _toPyObject(item.data(2, Qt.ToolTipRole)), _toPyObject(item.data(4, 42))521 525 geneset = gsname(item.geneset).lower() 522 hidden = item_cat not in categories or (self.useMinCountFilter and count < self.minClusterCount) or \ 523 (self.useMaxPValFilter and pval > self.maxPValue) or filterString not in geneset 526 hidden = item_cat not in categories 527 itemsHiddenCat.append(hidden) 528 529 #compute FDR according the selected categories 530 pvals = [ _toPyObject(item.data(4, 42)) for item, hidden in zip(self.treeItems, itemsHiddenCat) if not hidden ] 531 fdrs = obiProb.FDR(pvals) 532 533 #update FDR for the selected collections and apply filtering rules 534 fdri = 0 535 itemsHidden = [] 536 for item, hidden in zip(self.treeItems, itemsHiddenCat): 537 if not hidden: 538 fdr = fdrs[fdri] 539 fdri += 1 540 541 count, pval = _toPyObject(item.data(2, Qt.ToolTipRole)), _toPyObject(item.data(4, 42)) 542 543 hidden = (self.useMinCountFilter and count < self.minClusterCount) or \ 544 (self.useMaxPValFilter and pval > self.maxPValue) or \ 545 (self.useMaxFDRFilter and fdr > self.maxFDR) 546 547 if not hidden: 548 item.setData(5, Qt.ToolTipRole, QVariant(fmtpdet(fdr))) 549 item.setData(5, Qt.DisplayRole, QVariant(fmtp(fdr))) 550 item.setData(5, 42, QVariant(fdr)) 551 524 552 item.setHidden(hidden) 525 553 itemsHidden.append(hidden) 554 526 555 527 556 if self.treeItems and all(itemsHidden): … … 559 588 self.reportSettings("Settings", [("Organism", obiTaxonomy.name(self.taxid_list[self.speciesIndex]))]) 560 589 self.reportSettings("Filter", [("Min cluster size", self.minClusterCount if self.useMinCountFilter else 0), 561 ("Max pvalue", self.maxPValue if self.useMaxPValFilter else 1.0)]) 590 ("Max pvalue", self.maxPValue if self.useMaxPValFilter else 1.0), 591 ("Max FDR", self.maxFDR if self.useMaxFDRFilter else 1.0)]) 562 592 563 593 self.reportSubsection("Annotations")
Note: See TracChangeset
for help on using the changeset viewer.