def testExport(self, genes, description, retfile, results): self.maxDiff = None enrichr = Enrichr(cutoff = 1) enrichr.addList(genes, description) enrichr.enrich() enrichr.export(retfile) ret = [] with open(retfile) as f: for line in f: line = line.strip() if not line or line.startswith('Term'): continue ret.append(Enrichr_Term._make(line.split('\t'))) for i, result in enumerate(results): for field in result._fields: rval = getattr(result, field) oval = getattr(ret[i], field) if isinstance(rval, (int, float)): oval = float(oval) self.assertAlmostEqual(rval, oval, places=3) else: self.assertEqual(rval, oval)
def testEnrich(self, genes, description, results): self.maxDiff = None enrichr = Enrichr() enrichr.addList(genes, description) ret = enrichr.enrich() for i, result in enumerate(results): for field in result._fields: rval = getattr(result, field) oval = getattr(ret[i], field) if isinstance(rval, (int, float)): self.assertAlmostEqual(rval, oval) else: self.assertEqual(rval, oval)
if cutoff['by'] == 'p': cutoff['by'] = 'Pval' if cutoff['by'] == 'q': cutoff['by'] = 'AdjPval' reader = TsvReader(infile, **inopts) genes = [r[genecol] for r in reader] en = Enrichr(cutoff = cutoff, top = top, Rscript = Rscript) en.addList(genes, description = path.basename(infile)) para = Parallel(nthread = nthread) runPathview = lambda r, hsa: shell.Shell().Rscript(r, hsa).run() for db in dbs: outfile = path.join(outdir, prefix + '.' + db + '.txt') en.enrich(db) en.export(outfile, top = 100) if plot: plotfile = path.join(outdir, prefix + '.' + db + '.png') en.plot(plotfile, res = devpars.res, width = devpars.width, height = devpars.height) if pathview and 'KEGG' in db: pathviewRDir = path.join(outdir, prefix + '.' + db + '.pathview') pathviewRfile = path.join(pathviewRDir, 'pathview.R') shell.mkdir(pathviewRDir) with open(pathviewRfile, 'w') as f: f.write(""" {rimport}('__init__.r') library(pathview) args = commandArgs(trailingOnly = TRUE) setwd({pathviewRDir!r}) inopts = {{args.inopts | R}}
def testPlot(self, genes, description, plotfile): enrichr = Enrichr(cutoff = 1) enrichr.addList(genes, description) enrichr.enrich() enrichr.plot(plotfile) self.assertGreater(path.getsize(plotfile), 0)