def testView(self, genes, description): self.maxDiff = None enrichr = Enrichr() enrichr.addList(genes, description) ret = enrichr.view() self.assertCountEqual(ret.genes, genes) self.assertEqual(ret.description, description)
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)
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)
cutoff = {{args.cutoff | repr}} devpars = {{args.devpars | repr}} pathview = {{args.pathview | repr}} shell.TOOLS.Rscript = Rscript if isinstance(cutoff, dict): 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:
def testAddList(self, genes, description): enrichr = Enrichr() ret = enrichr.addList(genes, description) self.assertIsInstance(ret.userListId, int) self.assertEqual(ret.userListId, enrichr.listid)
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)