@transform( OverlappedGeneChromatinIntersectionContingencyTable, regex(r"overlapped_genes/(\S+).stats.contingency_table"), r"overlapped_genes/"+PARAMS["species"]+r"_\1.stats.fisher.test.tsv" )
def OverlappedGeneChromatinIntersectionFisherTest(infile, outfile):
    R('''x <- read.table(file='%(infile)s', header=TRUE, stringsAsFactors=FALSE, row.names=1)''' % locals() )
    R('''res <- fisher.test(x)''')
    R('''fisher_result <- data.frame(res[3]$estimate,res[1]$p.value,res[2]$conf.int[1],res[2]$conf.int[2])''')
    R('''colnames(fisher_result) <- c("odds.ratio","p.value","conf.int.low","conf.int.high") ''')
    R('''write.table(fisher_result, file="%(outfile)s", sep="\t", row.names=F) ''' % locals() )
    
############################################################
## Compare intervals to external bed files using GAT
calculate intersection of chromatin marks and CAPSeq overlapped genes
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_proj007.py/OverlappedGeneChromatinIntersectionFisherTest