def enrich(self): """ check for annotation enrichment for selected sequences (compared to other sequences in this experiment) """ if not self.cexp.cdb: hs.Debug(8,'No cooldb loaded') return selseqs=[] for cid in self.selection: selseqs.append(self.cexp.seqs[cid]) bmd=hs.cooldb.testenrichment(self.cexp.cdb,self.cexp.seqs,selseqs) hs.Debug(6,'found %d items' % len(bmd)) if len(bmd)>0: slistwin = SListWindow(listname='Enrichment') bmd=hs.sortenrichment(bmd) for cbmd in bmd: if cbmd['observed']<cbmd['expected']: ccolor=QtGui.QColor(155,0,0) else: ccolor=QtGui.QColor(0,155,0) item = QtGui.QListWidgetItem() item.setText("%s (p:%f o:%d e:%f)" % (cbmd['description'],cbmd['pval'],cbmd['observed'],cbmd['expected'])) item.setTextColor(ccolor) slistwin.lList.addItem(item) print("%s (p:%f o:%d e:%f)" % (cbmd['description'],cbmd['pval'],cbmd['observed'],cbmd['expected'])) slistwin.exec_()
def bicluster(self): newexp, seqs, samples = hs.bicluster(self.cexp, method="binary", sampkeep=0, bactkeep=0, justcount=True) self.samples = samples[0] self.seqs = seqs[0] self.lNumSamples.setText(str(len(self.samples))) self.lNumBacteria.setText(str(len(self.seqs))) self.lSamples.clear() self.lBacteria.clear() # get the new bacteria and sample order allsamp = np.arange(len(self.cexp.samples)) allbact = np.arange(len(self.cexp.seqs)) x = np.setdiff1d(allsamp, self.samples) sampo = np.concatenate((self.samples, x)) ubact = [] for cseq in self.seqs: ubact.append(self.cexp.seqdict[cseq]) bacto = np.concatenate((ubact, np.setdiff1d(allbact, ubact))) self.cexp.bactorder = bacto self.cexp.samporder = sampo # if we have enough bacteria and samples, update the info list if len(self.seqs) >= 5 and len(self.samples) >= 5: sampmd = hs.testmdenrichmentall(self.cexp, self.samples) for cmd in sampmd: if cmd["observed"] < cmd["expected"]: ccolor = QtGui.QColor(155, 0, 0) else: ccolor = QtGui.QColor(0, 155, 0) item = QtWidgets.QListWidgetItem() item.setText( "%s - %s (p:%f o:%d e:%f)" % (cmd["field"], cmd["val"], cmd["pval"], cmd["observed"], cmd["expected"]) ) item.setForeground(ccolor) self.lSamples.addItem(item) if self.cooldb: bmd = hs.annotationenrichment(self.cexp, self.seqs) # bmd=hs.cooldb.testenrichment(self.cooldb,self.cexp.seqs,self.seqs) bmd = hs.sortenrichment(bmd) for cbmd in bmd: if cbmd["observed"] < cbmd["expected"]: ccolor = QtGui.QColor(155, 0, 0) else: ccolor = QtGui.QColor(0, 155, 0) item = QtWidgets.QListWidgetItem() item.setText( "%s (p:%f o:%d e:%f)" % (cbmd["description"], cbmd["pval"], cbmd["observed"], cbmd["expected"]) ) item.setForeground(ccolor) self.lBacteria.addItem(item)
def enrichment(self): items=self.bMainList.selectedItems() if len(items)!=1: print("Need 1 item") return for citem in items: cname=str(citem.text()) cexp=self.explist[cname] if self.cooldb: evals=hs.cooldb.testenrichment(self.cooldb,[],cexp.seqs,freqs=np.log(1+np.mean(cexp.data,axis=1))) # sevals=hs.sortenrichment(evals,method='val') sevals=hs.sortenrichment(evals,method='single',epsilon=1) for cval in sevals[::-1]: print('%s - obs:%f catfreq:%f' % (cval['description'],cval['observed'],cval['expected']))