Changeset 1883:8d992429535b in orangebioinformatics for orangecontrib/bio/widgets/OWGOEnrichmentAnalysis.py
Legend:
 Unmodified
 Added
 Removed

orangecontrib/bio/widgets/OWGOEnrichmentAnalysis.py
r1874 r1883 105 105 "filterByNumOfInstances", "minNumOfInstances", 106 106 "filterByPValue", "maxPValue", "selectionDirectAnnotation", 107 "filterByPValue_nofdr", "maxPValue_nofdr", 107 108 "selectionDisjoint", "selectionType", 108 "selectionAddTermAsClass", "useAttrNames", "probFunc", 109 "useFDR" 109 "selectionAddTermAsClass", "useAttrNames", "probFunc" 110 110 ] 111 111 … … 140 140 self.filterByPValue = True 141 141 self.maxPValue = 0.1 142 self.filterByPValue_nofdr = False 143 self.maxPValue_nofdr = 0.1 142 144 self.probFunc = 0 143 self.useFDR = True144 145 self.selectionDirectAnnotation = 0 145 146 self.selectionDisjoint = 0 … … 216 217 tooltip="Min. number of input genes mapped to a term") 217 218 218 OWGUI.checkBox(box, self, "filterByPValue ", "Significance",219 OWGUI.checkBox(box, self, "filterByPValue_nofdr", "pvalue", 219 220 callback=self.FilterAndDisplayGraph, 220 221 tooltip="Filter by term pvalue") 222 OWGUI.doubleSpin(OWGUI.indentedBox(box), self, 'maxPValue_nofdr', 1e8, 1, 223 step=1e8, label='p:', labelWidth=15, 224 callback=self.FilterAndDisplayGraph, 225 callbackOnReturn=True, 226 tooltip="Max term pvalue") 227 228 #use filterByPValue for FDR, as it was the default in prior versions 229 OWGUI.checkBox(box, self, "filterByPValue", "FDR", 230 callback=self.FilterAndDisplayGraph, 231 tooltip="Filter by term FDR") 221 232 OWGUI.doubleSpin(OWGUI.indentedBox(box), self, 'maxPValue', 1e8, 1, 222 233 step=1e8, label='p:', labelWidth=15, … … 224 235 callbackOnReturn=True, 225 236 tooltip="Max term pvalue") 237 226 238 box = OWGUI.widgetBox(box, "Significance test") 239 227 240 OWGUI.radioButtonsInBox(box, self, "probFunc", ["Binomial", "Hypergeometric"], 228 241 tooltips=["Use binomial distribution test", 229 242 "Use hypergeometric distribution test"], 230 243 callback=self.Update) 231 OWGUI.checkBox(box, self, "useFDR", "Use FDR (False Discovery Rate)",232 callback=self.Update,233 tooltip="Use False Discovery Rate correction")234 244 box = OWGUI.widgetBox(self.filterTab, "Evidence codes in annotation", 235 245 addSpace=True) … … 261 271 262 272 # ListView for DAG, and table for significant GOIDs 263 self.DAGcolumns = ['GO term', 'Cluster', 'Reference', 'p value', 'Genes', 'Enrichment']273 self.DAGcolumns = ['GO term', 'Cluster', 'Reference', 'pvalue', 'FDR', 'Genes', 'Enrichment'] 264 274 265 275 self.splitter = QSplitter(Qt.Vertical, self.mainArea) … … 276 286 self.listView.header().setSortIndicatorShown(True) 277 287 self.listView.setSortingEnabled(True) 278 self.listView.setItemDelegateForColumn( 5, EnrichmentColumnItemDelegate(self))288 self.listView.setItemDelegateForColumn(6, EnrichmentColumnItemDelegate(self)) 279 289 self.listView.setRootIsDecorated(True) 280 290 … … 288 298 self.sigTerms.setSortingEnabled(True) 289 299 self.sigTerms.setSelectionMode(QAbstractItemView.ExtendedSelection) 300 self.sigTerms.setItemDelegateForColumn(6, EnrichmentColumnItemDelegate(self)) 290 301 291 302 self.connect(self.sigTerms, SIGNAL("itemSelectionChanged()"), self.TableSelectionChanged) … … 651 662 if clusterGenes: 652 663 self.terms = terms = self.annotations.GetEnrichedTerms(clusterGenes, referenceGenes, evidences, aspect=aspect, 653 prob=self.probFunctions[self.probFunc], useFDR= self.useFDR,664 prob=self.probFunctions[self.probFunc], useFDR=False, 654 665 progressCallback=lambda value:pb.advance() ) 666 ids = [] 667 pvals = [] 668 for i,d in self.terms.items(): 669 ids.append(i) 670 pvals.append(d[1]) 671 for i,fdr in zip(ids, obiProb.FDR(pvals)): #save FDR as the last part of the tuple 672 terms[i] = tuple(list(terms[i]) + [ fdr ]) 673 655 674 else: 656 675 self.terms = terms = {} … … 681 700 682 701 def FilterGraph(self, graph): 683 if self.filterByPValue: 684 graph = obiGO.filterByPValue(graph, self.maxPValue) 702 if self.filterByPValue_nofdr: 703 graph = obiGO.filterByPValue(graph, self.maxPValue_nofdr) 704 if self.filterByPValue: #FDR 705 graph = dict(filter(lambda (k, e): e[3] <= self.maxPValue, graph.items())) 685 706 if self.filterByNumOfInstances: 686 graph = dict(filter(lambda (id,(genes, p, rc )):len(genes)>=self.minNumOfInstances, graph.items()))707 graph = dict(filter(lambda (id,(genes, p, rc, fdr)):len(genes)>=self.minNumOfInstances, graph.items())) 687 708 return graph 688 709 … … 716 737 enrichment = lambda t:float(len(t[0])) / t[2] * (float(len(self.referenceGenes))/len(self.clusterGenes)) 717 738 maxFoldEnrichment = max([enrichment(term) for term in self.graph.values()] or [1]) 739 718 740 719 741 def addNode(term, parent, parentDisplayNode): … … 744 766 745 767 self.sigTerms.clear() 746 for i, (t_id, (genes, p_value, refCount )) in enumerate(terms):768 for i, (t_id, (genes, p_value, refCount, fdr)) in enumerate(terms): 747 769 item = GOTreeWidgetItem(self.ontology[t_id], 748 (genes, p_value, refCount ),770 (genes, p_value, refCount, fdr), 749 771 len(self.clusterGenes), 750 772 len(self.referenceGenes), … … 754 776 755 777 self.listView.expandAll() 756 for i in range( 4):778 for i in range(5): 757 779 self.listView.resizeColumnToContents(i) 758 780 self.sigTerms.resizeColumnToContents(i) 759 self.sigTerms.resizeColumnToContents( 5)781 self.sigTerms.resizeColumnToContents(6) 760 782 width = min(self.listView.columnWidth(0), 350) 761 783 self.listView.setColumnWidth(0, width) … … 768 790 orange.FloatVariable("Cluster Frequency"), 769 791 orange.FloatVariable("Reference Frequency"), 770 orange.FloatVariable("Pvalue"), 792 orange.FloatVariable("pvalue"), 793 orange.FloatVariable("FDR"), 771 794 orange.FloatVariable("Enrichment"), 772 795 orange.StringVariable("Genes") … … 778 801 float(r_count) / len(self.referenceGenes), 779 802 p_value, 803 fdr, 780 804 float(len(genes)) / len(self.clusterGenes) * \ 781 805 float(len(self.referenceGenes)) / r_count, 782 806 ",".join(genes) 783 807 ] 784 for t_id, (genes, p_value, r_count ) in terms]808 for t_id, (genes, p_value, r_count, fdr) in terms] 785 809 786 810 if terms: … … 917 941 def sendReport(self): 918 942 self.reportSettings("Settings", [("Organism", self.annotationCodes[min(self.annotationIndex, len(self.annotationCodes)  1)]), 919 ("Significance test", ("Binomial" if self.probFunc == 0 else "Hypergeometric") + (" with FDR" if self.useFDR else ""))])943 ("Significance test", ("Binomial" if self.probFunc == 0 else "Hypergeometric") )]) 920 944 self.reportSettings("Filter", ([("Min cluster size", self.minNumOfInstances)] if self.filterByNumOfInstances else []) + \ 921 ([("Max pvalue", self.maxPValue)] if self.filterByPValue else [])) 945 ([("Max pvalue", self.maxPValue_nofdr)] if self.filterByPValue_nofdr else []) + \ 946 ([("Max FDR", self.maxPValue)] if self.filterByPValue else [])) 922 947 923 948 def treeDepth(item): … … 927 952 text = '<tr>' + '<td width=16px></td>' * level 928 953 text += '<td colspan="%i">%s: %s</td>' % (treeDepth  level, item.term.id, item.term.name) 929 text += ''.join('<td>%s</td>' % item.text(i) for i in range(1, 4) + [5]) + '</tr>\n'954 text += ''.join('<td>%s</td>' % item.text(i) for i in range(1, 5) + [6]) + '</tr>\n' 930 955 for i in range(item.childCount()): 931 956 text += printTree(item.child(i), level + 1, treeDepth) … … 934 959 treeDepth = max([treeDepth(self.listView.topLevelItem(i)) for i in range(self.listView.topLevelItemCount())] + [0]) 935 960 936 tableText = '<table>\n<tr>' + ''.join('<th>%s</th>' % s for s in ["Term:", "List:", "Reference:", " Pvalue:", "Enrichment:"]) + '</tr>'961 tableText = '<table>\n<tr>' + ''.join('<th>%s</th>' % s for s in ["Term:", "List:", "Reference:", "pvalue:", "FDR", "Enrichment:"]) + '</tr>' 937 962 938 963 treeText = '<table>\n' + '<th colspan="%i">%s</th>' % (treeDepth, "Term:") 939 treeText += ''.join('<th>%s</th>' % s for s in ["List:", "Reference:", " Pvalue:", "Enrichment:"]) + '</tr>'964 treeText += ''.join('<th>%s</th>' % s for s in ["List:", "Reference:", "pvalue:", "FDR", "Enrichment:"]) + '</tr>' 940 965 941 966 for index in range(self.sigTerms.topLevelItemCount()): … … 966 991 gc.collect() # Force collection 967 992 993 994 fmtp = lambda score: "%0.5f" % score if score > 10e4 else "%0.1e" % score 995 fmtpdet = lambda score: "%0.9f" % score if score > 10e4 else "%0.5e" % score 968 996 969 997 class GOTreeWidgetItem(QTreeWidgetItem): … … 981 1009 fmt = "%" + str(int(math.log(nRefGenes))) + "i (%.2f%%)" 982 1010 self.setText(2, fmt % (enrichmentResult[2], 100.0*enrichmentResult[2]/nRefGenes)) 983 self.setText(3, "%.4f" % enrichmentResult[1]) 984 self.setText(4, ", ".join(enrichmentResult[0])) 985 self.setText(5, "%.2f" % (enrichment(enrichmentResult))) 1011 self.setText(3, fmtp(enrichmentResult[1])) 1012 self.setToolTip(3, fmtpdet(enrichmentResult[1])) 1013 self.setText(4, fmtp(enrichmentResult[3])) #FDR 1014 self.setToolTip(4, fmtpdet(enrichmentResult[3])) 1015 self.setText(5, ", ".join(enrichmentResult[0])) 1016 self.setText(6, "%.2f" % (enrichment(enrichmentResult))) 1017 self.setToolTip(6, "%.2f" % (enrichment(enrichmentResult))) 986 1018 self.setToolTip(0, "<p>" + term.__repr__()[6:].strip().replace("\n", "<br>")) 987 self.sortByData = [term.name, len(self.enrichmentResult[0]), enrichmentResult[2], enrichmentResult[1], ", ".join(enrichmentResult[0]), enrichment(enrichmentResult)]1019 self.sortByData = [term.name, len(self.enrichmentResult[0]), enrichmentResult[2], enrichmentResult[1], enrichmentResult[3], ", ".join(enrichmentResult[0]), enrichment(enrichmentResult)] 988 1020 989 1021 def data(self, col, role):
Note: See TracChangeset
for help on using the changeset viewer.