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)
Rscript = {{args.Rscript | repr}} 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)
def testAddListFromFile(self, genefile, delimit = '\t', skip = 0, col = 0): enrichr = Enrichr() ret = enrichr.addListFromFile(genefile, col = col, delimit = delimit, skip = skip) self.assertIsInstance(ret.userListId, int) self.assertEqual(ret.userListId, enrichr.listid)
def testAddList(self, genes, description): enrichr = Enrichr() ret = enrichr.addList(genes, description) self.assertIsInstance(ret.userListId, int) self.assertEqual(ret.userListId, enrichr.listid)
def testInit(self, library): enrichr = Enrichr(library) self.assertIsInstance(enrichr, Enrichr) self.assertIsNone(enrichr.listid) self.assertEqual(enrichr.library, library) self.assertEqual(enrichr.results, [])
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)
def testGenemap(self, gene, results): enrichr = Enrichr() ret = list(itertools.islice(enrichr.genemap(gene), 3)) self.assertListEqual(ret, results)