def main(): args = get_args() # load genes (accounting for linkage) genes = col2dict( args.genes, value=(1 if args.linked else None), headers=args.skip_headers, ) genes = {g: (g if k is None else k) for g, k in genes.items()} # load background (accounting for linkage) background = None if args.background is not None: background = col2dict( args.background, value=(1 if args.linked else None), headers=args.skip_headers, ) background = { g: (g if k is None else k) for g, k in background.items() } # load gene sets gene_sets = polymap( args.gene_sets, reverse=args.reversed_mapping, ) # run analysis results = fisher_enrich( genes, gene_sets, depletions=not args.exclude_depletions, background=background, intersect_background=args.intersect_background, intersect_annotated=args.intersect_annotated, fdr=args.fdr, min_expected_overlap=args.min_expected_overlap, verbose=False, ) # write results fh = open(args.outfile, "w") if args.outfile is not None else sys.stdout writer = csv.writer(fh, dialect="excel-tab") writer.writerow(c_fisher_fields) for R in results: writer.writerow(R.row()) # wrapup if len(results) == 0: say("# NO SIGNIFICANT ENRICHMENTS") fh.close() return None
def main(): args = get_args() # load key values def make_link(row): key = row[1] if args.linked else row[0] return Link(key, float(row[-1])) values = col2dict( args.values, func=make_link, headers=args.skip_headers, ) # load key sets gene_sets = polymap( args.gene_sets, reverse=args.reversed_mapping, ) # perform analysis results = rank_enrich( values, gene_sets, depletions=not args.exclude_depletions, intersect_annotated=args.intersect_annotated, fdr=args.fdr, min_overlap=args.min_overlap, verbose=True, ) # write results fh = open(args.outfile, "w") if args.outfile is not None else sys.stdout writer = csv.writer(fh, dialect="excel-tab") writer.writerow(c_rank_fields) for R in results: writer.writerow(R.row()) # wrapup if len(results) == 0: say("# NO SIGNIFICANT ENRICHMENTS") fh.close() return None
#! /usr/bin/env python import os, sys, re, glob, argparse from zopy.enrichments import fisher_enrich as fe from zopy.dictation import polymap with open(sys.argv[1]) as fh: x = [k.strip() for k in fh.readlines()] a = polymap(sys.argv[2]) for result in fe(x, a, ranked=True): print result[:-1], len(result[-1]), len(x)
def main(): args = get_args() # load obo / report rel type obo = Ontology(args.obo) warn("Summary of relationship types:") for k in sorted(parentage_types): warn(k, parentage_types[k]) # attach genes if args.mapping is not None: mapping = polymap(args.mapping, reverse=args.flip) if args.allowed_genes is not None: allowed = col2dict(args.allowed_genes) mapping = {k: v for k, v in mapping.items() if k in allowed} obo.attach_genes(mapping) warn("# of attached genes:", len(obo.attached_genes)) # informative cut if args.informative is not None: threshold = float(args.informative) if threshold < 1: warn( "Intepretting informative cutoff as fraction of annotated genes" ) threshold *= len(obo.attached_genes) threshold = int(threshold) obo.set_informative(threshold) for term in obo.iter_terms(): if not term.is_informative: term.is_acceptable = False # pruning cut if args.prune is not None: obo.prune(args.prune) for term in obo.iter_terms(): if not term.is_pruned: term.is_acceptable = False # depth cut if args.depth is not None: for term in obo.iter_terms(): if term.depth != args.depth: term.is_acceptable = False # grep cut if args.grep is not None: for term in obo.iter_terms(): if not re.search(args.grep, term.name): term.is_acceptable = False # namespace cut if args.namespace is not None: for term in obo.iter_terms(): if term.namespace_short not in args.namespace: term.is_acceptable = False # output the new polymap fh = open(args.outfile, "w") if args.outfile is not None else sys.stdout for term in obo.iter_terms(): if term.is_acceptable: outline = [str(term)] if not args.terms_only: outline += list(term.get_progeny_genes( ) if not args.ignore_progeny else term.genes) print >> fh, "\t".join(outline) fh.close()
def attach_genes(self, path): """assigns genes from a polymap to the tree""" for gene, terms_dict in polymap(path).items(): self.attached_genes[gene] = 1 for term in terms_dict: self.nodes[term].add_genes(gene)