Attachment 'Fisher_Enrichment_FDR_13_1.R'
Download 1 f.Fisher_FDR <- function (exp.genes, uni.genes, GS.ls, pval_obs.nv, iter.n = 2000)
2 {
3
4 cat ("\n")
5
6 # 1) PRE-PROCESSING
7
8 # Reduce everything to the universe
9
10 f.int_uni <- function (input.genes)
11 {return (intersect (input.genes, uni.genes))}
12
13 GS.ls <- lapply (GS.ls, f.int_uni)
14
15 exp.genes <- intersect (exp.genes, uni.genes)
16
17 # 2) COMPUTING
18
19 exp.n <- length (exp.genes)
20 uni.n <- length (uni.genes)
21
22 dummy.ls <- as.list (rep (exp.n, iter.n))
23
24 f.sample_Unit <- function (l.n)
25 {return (sample (uni.genes, l.n))}
26
27 exp_r.ls <- lapply (dummy.ls, f.sample_Unit)
28
29 output.nv <- numeric (3)
30
31 f.Fisher_PvalR_Unit <- function (exp.genes)
32 {
33
34 f.Enr_Fisher_Unit <- function (GS.genes)
35 {
36 enr.n <- length (intersect (exp.genes, GS.genes))
37 GS.n <- length (GS.genes)
38
39 table.mx <- matrix (
40 ncol = 2,
41 nrow = 2,
42 data = c (
43 enr.n,
44 GS.n - enr.n,
45 exp.n - enr.n,
46 uni.n - (GS.n + exp.n - enr.n)
47 ),
48 byrow = T
49 )
50
51 pvalue.n <- fisher.test (table.mx, alternative = "greater")$p.value
52 return (pvalue.n)
53 }
54
55 cat ("r")
56
57 pvalues.nv <- sapply (GS.ls, f.Enr_Fisher_Unit)
58 return (pvalues.nv)
59 }
60
61 pval_r.mx <- sapply (exp_r.ls, f.Fisher_PvalR_Unit)
62
63 pval_obs.ls <- as.list (pval_obs.nv)
64
65 f.count_Unit <- function (thr.n)
66 {
67 rand.n <- sum (pval_r.mx <= thr.n) / iter.n
68 obs.n <- sum (pval_obs.nv <= thr.n)
69 return (rand.n / obs.n)
70 }
71
72 fdr.nv <- sapply (pval_obs.ls, f.count_Unit)
73
74 return (fdr.nv)
75
76 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.