Module Expr Str Import alias Import alias Import alias Import alias identifier Import alias identifier ImportFrom alias identifier ImportFrom alias Import alias identifier Import alias identifier FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults NameLoad Str body Expr Str Expr Call NameLoad Str Assign NameStore Dict Str Str Call NameLoad Call NameLoad For TupleStore NameStore NameStore TupleLoad TupleLoad Str NameLoad TupleLoad Str NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad If NameLoad body Expr Call AttributeLoad NameLoad attr For NameStore NameLoad body Expr Call AttributeLoad SubscriptLoad NameLoad Index NameLoad attr SubscriptLoad NameLoad Slice Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad Assign NameStore BinOpMod Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad keyword NameLoad keyword NameLoad keyword Num For NameStore NameLoad body Assign NameStore NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword Str For TupleStore NameStore NameStore NameLoad body Assign NameStore Call AttributeLoad SubscriptLoad SubscriptLoad NameLoad Index CompareEq SubscriptLoad NameLoad Index Str NameLoad Index Str attr Expr Call AttributeLoad SubscriptLoad NameLoad Index NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Str Expr Call AttributeLoad NameLoad attr Str Assign NameStore SubscriptLoad NameLoad Index Str Assign NameStore SubscriptLoad NameLoad Index Str Assign NameStore ListLoad Assign NameStore ListLoad For NameStore NameLoad body Assign NameStore Call AttributeLoad NameLoad attr TupleLoad Num Num For NameStore Call AttributeLoad NameLoad attr body If CompareIn NameLoad SubscriptLoad NameLoad Index Str body If CompareIn NameLoad SubscriptLoad NameLoad Index NameLoad body AugAssignAdd SubscriptStore NameLoad Index TupleLoad Num Num Num orelse If CompareNotIn NameLoad SubscriptLoad NameLoad Index NameLoad body AugAssignAdd SubscriptStore NameLoad Index TupleLoad Num Num Num orelse If CompareIn NameLoad SubscriptLoad NameLoad Index Str body If CompareIn NameLoad SubscriptLoad NameLoad Index NameLoad body AugAssignAdd SubscriptStore NameLoad Index TupleLoad Num Num Num orelse If CompareNotIn NameLoad SubscriptLoad NameLoad Index NameLoad body AugAssignAdd SubscriptStore NameLoad Index TupleLoad Num Num Num Assign NameStore Call NameLoad Call NameLoad NameLoad keyword NameLoad Assign NameStore SubscriptLoad NameLoad Index TupleLoad Num Num Assign NameStore SubscriptLoad NameLoad Index TupleLoad Num Num Assign NameStore BinOpAdd SubscriptLoad NameLoad Index TupleLoad Num Num SubscriptLoad NameLoad Index TupleLoad Num Num Assign NameStore BinOpAdd SubscriptLoad NameLoad Index TupleLoad Num Num SubscriptLoad NameLoad Index TupleLoad Num Num Assign NameStore ListComp Call NameLoad NameLoad comprehension NameStore Call AttributeLoad NameLoad attr NameLoad Assign TupleStore NameStore NameStore NameStore NameStore TupleLoad SubscriptLoad SubscriptLoad NameLoad Index Num Index Num SubscriptLoad SubscriptLoad NameLoad Index Num Index Num SubscriptLoad SubscriptLoad NameLoad Index Num Index Num SubscriptLoad SubscriptLoad NameLoad Index Num Index Num Expr Call AttributeLoad NameLoad attr NameLoad If BoolOpOr CompareEq BinOpAdd NameLoad NameLoad Num BoolOpAnd CompareEq NameLoad NameLoad CompareEq NameLoad NameLoad body Assign NameStore Num Expr Call AttributeLoad NameLoad attr ListLoad NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad Assign NameStore Call NameLoad NameLoad For NameStore Call NameLoad Call NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr BinOpAdd Call AttributeLoad Str attr Call NameLoad NameLoad BinOpAdd SubscriptLoad NameLoad Index NameLoad ListLoad SubscriptLoad NameLoad Index NameLoad Str Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults NameLoad body Expr Str If CompareIs NameLoad NameLoad body Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr keyword Str keyword SubscriptLoad Call NameLoad Index Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr decorator_list If CompareEq NameLoad Str body Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr
N/A N/A 
tfbs2enrichment.py - template for CGAT scripts
====================================================

:Author: Mike Morgan
:Release: $Id$
:Date: |today|
:Tags: Python

Purpose
-------

.. Runs transcription factor motif enrichment using the
Transfac(R) database.  Signficance testing is currently
carried out by Fisher's Exact test based on a background
gene set matched for %CG content.

Currently only for use in pipeline_transfacmatch.py, this is
not a stand-alone script.

Usage
-----

.. Example use case

Example::

   python tfbs2enrichment.py

Type::

   python tfbs2enrichment.py --help

for command line help.

Command line options
--------------------

 N/A sys N/A sqlite3 N/A collections N/A pandas.io.sql pdsql N/A numpy np rpy2.robjects r R rpy2.robjects.numpy2ri numpy2ri N/A CGAT.Experiment E N/A CGAT.IOTools IOTools testSignificanceOfMatrices N/A N/A background foreground database match_table outfile header_line direction N/A True two.sided N/A N/A 
    Uses the fishers exact test to estimate the significance of
    transcription factor motifs in a foregound set of intervals
    compared to a background set
     N/A N/A R rm(list = ls()) N/A interval_sets N/A foreground background N/A set N/A set N/A N/A name fn N/A N/A background background N/A foreground foreground N/A N/A inf N/A N/A IOTools openFile fn N/A header_line N/A N/A N/A N/A inf readline N/A line inf N/A N/A N/A N/A N/A interval_sets N/A name add N/A line N/A -1 N/A dbh N/A N/A sqlite3 connect database N/A ids_tfs N/A N/A collections defaultdict set N/A all_tfs N/A set N/A state N/A SELECT seq_id, matrix_id FROM %s match_table N/A sql_df N/A N/A pdsql read_sql sql state con dbh index_col None chunksize 1000000 N/A chunk sql_df N/A N/A _df chunk N/A sql_group N/A N/A _df groupby by seq_id N/A N/A names groups sql_group N/A N/A tfs N/A N/A N/A N/A groups N/A N/A N/A groups N/A seq_id names N/A matrix_id tolist N/A N/A N/A N/A ids_tfs N/A names update tfs N/A N/A N/A all_tfs update tfs N/A outf N/A N/A IOTools openFile outfile w N/A N/A N/A outf write matrix_id	oddsRatio	95CI_low	95_CI_hi	pvalue	nforeground	nbackground	tforeground	tbackground	qvalue
 N/A fisherpy N/A R N/A fisher.test N/A padjpy N/A R N/A p.adjust N/A results N/A N/A pvalues N/A N/A tf all_tfs N/A N/A contingency N/A N/A np zeros N/A 2 2 N/A seq_id N/A N/A ids_tfs keys N/A N/A N/A seq_id N/A interval_sets N/A foreground N/A N/A N/A tf N/A ids_tfs N/A seq_id N/A N/A N/A contingency N/A N/A 0 0 1 N/A N/A N/A tf N/A ids_tfs N/A seq_id N/A N/A N/A contingency N/A N/A 1 0 1 N/A N/A N/A seq_id N/A interval_sets N/A background N/A N/A N/A tf N/A ids_tfs N/A seq_id N/A N/A N/A contingency N/A N/A 0 1 1 N/A N/A N/A tf N/A ids_tfs N/A seq_id N/A N/A N/A contingency N/A N/A 1 1 1 N/A f N/A fisherpy N/A numpy2ri contingency alternative direction N/A nforeground N/A contingency N/A N/A 0 0 N/A nbackground N/A contingency N/A N/A 0 1 N/A tforeground N/A N/A contingency N/A N/A 0 0 N/A contingency N/A N/A 1 0 N/A tbackground N/A N/A contingency N/A N/A 0 1 N/A contingency N/A N/A 1 1 N/A f N/A N/A list x N/A x N/A N/A np array f N/A N/A pvalue ci_low ci_hi OR N/A N/A N/A f N/A 0 N/A 0 N/A N/A f N/A 1 N/A 0 N/A N/A f N/A 1 N/A 1 N/A N/A f N/A 2 N/A 0 N/A N/A N/A pvalues append pvalue N/A N/A N/A N/A nforeground nbackground 0 N/A N/A nforeground tforeground N/A nbackground tbackground N/A N/A OR 1 N/A N/A N/A results append N/A tf OR ci_low ci_hi pvalue nforeground nbackground tforeground tbackground N/A qvalues N/A padjpy pvalues N/A i N/A range N/A len results N/A N/A N/A N/A outf write N/A N/A N/A join N/A map str N/A N/A results N/A i N/A N/A qvalues N/A i N/A N/A N/A outf close N/A main N/A N/A argv N/A None N/A N/A script main.
    parses command line options in sys.argv, unless *argv* is given.
     N/A N/A argv None N/A N/A argv N/A sys argv N/A parser N/A N/A E OptionParser version %prog version: $Id$ usage N/A N/A globals N/A __doc__ N/A N/A N/A parser add_option --foreground dest foreground type string help foreground file N/A N/A N/A parser add_option --background dest background type string help matched background file N/A N/A N/A parser add_option --database dest database type string help PATH to sqlite database containing Transfac Match output. N/A N/A N/A parser add_option --match-table dest match_table type string help tablename containing Transfac Match output N/A N/A N/A parser add_option --outfile dest outfile type string help output file name N/A N/A N/A parser add_option --direction dest direction type string help direction to test for significance in Fisher's exact test. Default=2-tailed N/A N/A N/A parser add_option --geneset-header dest genesets type string help geneset header N/A N/A options args N/A N/A E Start parser argv argv N/A N/A N/A PipelineTFM testSignificanceOfMatrices N/A options background N/A options foreground N/A options database N/A options match_table N/A options outfile N/A options genesets N/A options direction N/A N/A N/A E Stop N/A N/A N/A __name__ __main__ N/A N/A N/A N/A sys exit N/A main N/A sys argv