Mercurial > repos > cristian > rbgoa
annotate gomwu.functions.R @ 2:5acf9dfdfa27 draft default tip
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
author | cristian |
---|---|
date | Wed, 09 Nov 2022 08:57:54 +0000 |
parents | f7287f82602f |
children |
rev | line source |
---|---|
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
1 clusteringGOs <- function(gen2go, div, cutHeight) { |
1
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
2 nn <- strsplit(gen2go, "[/.]") |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
3 if (length(nn[[1]]) == 3) { |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
4 dir <- nn[[1]][1] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
5 name <- nn[[1]][2] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
6 ext <- nn[[1]][3] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
7 } else if (length(nn[[1]]) == 2) { |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
8 dir <- "." |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
9 name <- nn[[1]][1] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
10 ext <- nn[[1]][2] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
11 } |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
12 inname <- paste(dir, "/", "dissim0_", div, "_", name, ".", ext, sep = "") |
1
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
13 |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
14 outname <- paste(dir, "/", "cl_dissim0_", div, "_", name, ".", ext, sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
15 if (!file.exists(outname)) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
16 diss <- read.table(inname, sep = "\t", header = T, check.names = F) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
17 row.names(diss) <- names(diss) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
18 hc <- hclust(as.dist(diss), method = "complete") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
19 cc <- cutree(hc, h = cutHeight) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
20 write.csv(cc, file = outname, quote = F) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
21 } |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
22 } |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
23 |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
24 |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
25 |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
26 #--------------- |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
27 gomwuStats <- function(input, goDatabase, goAnnotations, goDivision, scriptdir, Module = FALSE, Alternative = "t", adjust.multcomp = "BH", clusterCutHeight = 0.25, largest = 0.1, smallest = 5, perlPath = "perl", shuffle.reps = 20) { |
1
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
28 nn <- strsplit(input, "[/.]") |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
29 if (length(nn[[1]]) == 3) { |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
30 dir <- nn[[1]][1] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
31 name <- nn[[1]][2] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
32 ext <- nn[[1]][3] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
33 } else if (length(nn[[1]]) == 2) { |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
34 dir <- "." |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
35 name <- nn[[1]][1] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
36 ext <- nn[[1]][2] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
37 } |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
38 |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
39 extraOptions <- paste("largest=", largest, " smallest=", smallest, " cutHeight=", clusterCutHeight, sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
40 if (Module == TRUE) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
41 adjust.multcomp <- "shuffle" |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
42 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
43 gomwu_a <- paste(scriptdir, "gomwu_a.pl", sep = "/") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
44 gomwu_b <- paste(scriptdir, "gomwu_b.pl", sep = "/") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
45 system(paste(perlPath, gomwu_a, goDatabase, goAnnotations, input, goDivision, extraOptions)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
46 clusteringGOs(goAnnotations, goDivision, clusterCutHeight) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
47 system(paste(perlPath, gomwu_b, goAnnotations, input, goDivision)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
48 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
49 inname <- paste(dir, "/", name, "_", goDivision, ".tsv", sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
50 rsq <- read.table(inname, sep = "\t", header = T) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
51 rsq$term <- as.factor(rsq$term) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
52 |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
53 mwut.t <- TRUE |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
54 if (length(levels(as.factor(rsq$value))) == 2) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
55 cat("Binary classification detected; will perform Fisher's test\n") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
56 mwut.t <- F |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
57 rr <- fisherTest(rsq) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
58 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
59 if (Module == TRUE) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
60 rsq.f <- rsq |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
61 rsq.f$value <- as.numeric(rsq.f$value > 0) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
62 rf <- fisherTest(rsq.f) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
63 rsq.m <- rsq[rsq$value > 0, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
64 rsq.m$term <- factor(rsq.m$term, levels = unique(rsq.m$term)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
65 rrm <- mwuTest(rsq.m, "g") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
66 rr0 <- rf[rf$term %in% rrm$term, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
67 rr1 <- rf[!(rf$term %in% rrm$term), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
68 rr0 <- rr0[order(rr0$term), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
69 rrm <- rrm[order(rrm$term), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
70 rr0$pval <- rr0$pval * rrm$pval |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
71 rr <- rbind(rr0, rr1) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
72 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
73 cat("Continuous measure of interest: will perform MWU test\n") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
74 rr <- mwuTest(rsq, Alternative) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
75 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
76 } |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
77 |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
78 if (adjust.multcomp == "shuffle") { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
79 message("shuffling values to calculate FDR, ", shuffle.reps, " reps") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
80 reps <- shuffle.reps |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
81 spv <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
82 for (i in 1:reps) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
83 message("replicate ", i) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
84 rsqq <- rsq |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
85 rsqq$value <- sample(rsq$value) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
86 if (Module == TRUE) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
87 rsq.f <- rsqq |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
88 rsq.f$value <- as.numeric(rsq.f$value > 0) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
89 rf <- fisherTest(rsq.f) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
90 rsq.m <- rsqq[rsqq$value > 0, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
91 rsq.m$term <- factor(rsq.m$term, levels = unique(rsq.m$term)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
92 rrm <- mwuTest(rsq.m, "g") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
93 rr0 <- rf[rf$term %in% rrm$term, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
94 rr1 <- rf[!(rf$term %in% rrm$term), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
95 rr0 <- rr0[order(rr0$term), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
96 rrm <- rrm[order(rrm$term), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
97 rr0$pval <- rr0$pval * rrm$pval |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
98 rs <- rbind(rr0, rr1) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
99 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
100 if (mwut.t == TRUE) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
101 rs <- mwuTest(rsqq, Alternative) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
102 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
103 rs <- fisherTest(rsqq) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
104 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
105 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
106 spv <- append(spv, rs$pval) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
107 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
108 fdr <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
109 for (p in rr$pval) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
110 fdr <- append(fdr, (sum(spv <= p) / reps) / sum(rr$pval <= p)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
111 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
112 fdr[fdr > 1] <- 1 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
113 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
114 fdr <- p.adjust(rr$pval, method = adjust.multcomp) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
115 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
116 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
117 message(sum(fdr < 0.1), " GO terms at 10% FDR") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
118 rr$p.adj <- fdr |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
119 fname <- paste(dir, "/", "MWU_", goDivision, "_", name, ".", ext, sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
120 write.table(rr, fname, sep = "\t", row.names = F) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
121 } |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
122 |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
123 #--------------------- |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
124 mwuTest <- function(gotable, Alternative) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
125 gos <- gotable |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
126 terms <- levels(gos$term) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
127 gos$seq <- as.character(gos$seq) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
128 nrg <- gos[!duplicated(gos$seq), 5] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
129 names(nrg) <- gos[!duplicated(gos$seq), 4] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
130 # nrg=nrg+rnorm(nrg,sd=0.01) # to be able to do exact wilcox test |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
131 rnk <- rank(nrg) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
132 names(rnk) <- names(nrg) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
133 pvals <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
134 drs <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
135 nams <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
136 levs <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
137 nseqs <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
138 for (t in terms) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
139 got <- gos[gos$term == t, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
140 got <- got[!duplicated(got$seq), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
141 ngot <- gos[gos$term != t, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
142 ngot <- ngot[!duplicated(ngot$seq), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
143 ngot <- ngot[!(ngot$seq %in% got$seq), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
144 sgo.yes <- got$seq |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
145 n1 <- length(sgo.yes) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
146 sgo.no <- ngot$seq |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
147 n2 <- length(sgo.no) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
148 # message(t," wilcox:",n1," ",n2) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
149 wi <- wilcox.test(nrg[sgo.yes], nrg[sgo.no], alternative = Alternative) # removed correct=FALSE |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
150 r1 <- sum(rnk[sgo.yes]) / n1 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
151 r0 <- sum(rnk[sgo.no]) / n2 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
152 dr <- r1 - r0 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
153 drs <- append(drs, round(dr, 0)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
154 levs <- append(levs, got$lev[1]) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
155 nams <- append(nams, as.character(got$name[1])) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
156 pvals <- append(pvals, wi$p.value) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
157 nseqs <- append(nseqs, n1) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
158 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
159 res <- data.frame(cbind("delta.rank" = drs, "pval" = pvals, "level" = levs, nseqs)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
160 res <- cbind(res, "term" = as.character(terms), "name" = nams) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
161 res$pval <- as.numeric(as.character(res$pval)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
162 res$delta.rank <- as.numeric(as.character(res$delta.rank)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
163 res$level <- as.numeric(as.character(res$level)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
164 res$nseqs <- as.numeric(as.character(res$nseqs)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
165 return(res) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
166 } |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
167 #------------------------ |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
168 fisherTest <- function(gotable) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
169 gos <- gotable |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
170 terms <- levels(gos$term) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
171 gos$seq <- as.character(gos$seq) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
172 pft <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
173 nam <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
174 lev <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
175 nseqs <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
176 for (t in terms) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
177 got <- gos[gos$term == t, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
178 got <- got[!duplicated(got$seq), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
179 ngot <- gos[gos$term != t, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
180 ngot <- ngot[!duplicated(ngot$seq), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
181 ngot <- ngot[!(ngot$seq %in% got$seq), ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
182 go.sig <- sum(got$value) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
183 go.ns <- length(got[, 1]) - go.sig |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
184 ngo.sig <- sum(ngot$value) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
185 ngo.ns <- length(ngot[, 1]) - ngo.sig |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
186 sig <- c(go.sig, ngo.sig) # number of significant genes belonging and not belonging to the tested GO category |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
187 ns <- c(go.ns, ngo.ns) # number of not-significant genes belonging and not belonging to the tested GO category |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
188 mm <- matrix(c(sig, ns), nrow = 2, dimnames = list(ns = c("go", "notgo"), sig = c("go", "notgo"))) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
189 ff <- fisher.test(mm, alternative = "greater") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
190 pft <- append(pft, ff$p.value) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
191 nam <- append(nam, as.character(got$name[1])) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
192 lev <- append(lev, got$lev[1]) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
193 nseqs <- append(nseqs, length(got[, 1])) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
194 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
195 res <- data.frame(cbind("delta.rank" = rep(0), "pval" = pft, "level" = lev, nseqs, "term" = terms, "name" = nam)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
196 res[, 1] <- as.numeric(as.character(res[, 1])) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
197 res[, 2] <- as.numeric(as.character(res[, 2])) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
198 res[, 3] <- as.numeric(as.character(res[, 3])) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
199 res$nseqs <- as.numeric(as.character(res$nseqs)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
200 return(res) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
201 } |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
202 |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
203 #------------------------- |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
204 gomwuPlot <- function(inFile, goAnnotations, goDivision, level1 = 0.1, level2 = 0.05, level3 = 0.01, absValue = -log(0.05, 10), adjusted = TRUE, txtsize = 1, font.family = "sans", treeHeight = 0.5, colors = NULL) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
205 require(ape) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
206 |
1
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
207 nn <- strsplit(inFile, "[/.]") |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
208 if (length(nn[[1]]) == 3) { |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
209 dir <- nn[[1]][1] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
210 name <- nn[[1]][2] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
211 ext <- nn[[1]][3] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
212 } else if (length(nn[[1]]) == 2) { |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
213 dir <- "." |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
214 name <- nn[[1]][1] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
215 ext <- nn[[1]][2] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
216 } |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
217 aa <- strsplit(goAnnotations, "[/.]") |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
218 if (length(aa[[1]]) == 3) { |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
219 adir <- aa[[1]][1] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
220 aname <- aa[[1]][2] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
221 aext <- aa[[1]][3] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
222 } else if (length(aa[[1]]) == 2) { |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
223 adir <- "." |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
224 aname <- aa[[1]][1] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
225 aext <- aa[[1]][2] |
f7287f82602f
"planemo upload commit 486235d6560c9e95bd42152ad19bf7c3941cdc1b"
cristian
parents:
0
diff
changeset
|
226 } |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
227 # input=inFile |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
228 in.mwu <- paste(dir, "/", paste("MWU", goDivision, name, sep = "_"), ".", ext, sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
229 in.dissim <- paste(dir, "/", paste("dissim", goDivision, name, aname, sep = "_"), ".", aext, sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
230 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
231 cutoff <- -log(level1, 10) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
232 pv <- read.table(in.mwu, header = T) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
233 row.names(pv) <- pv$term |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
234 in.raw <- paste(dir, "/", paste(name, goDivision, sep = "_"), ".tsv", sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
235 rsq <- read.table(in.raw, sep = "\t", header = T) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
236 rsq$term <- as.factor(rsq$term) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
237 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
238 if (adjusted == TRUE) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
239 pvals <- pv$p.adj |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
240 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
241 pvals <- pv$pval |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
242 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
243 heat <- data.frame(cbind("pval" = pvals)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
244 row.names(heat) <- pv$term |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
245 heat$pval <- -log(heat$pval + 1e-15, 10) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
246 heat$direction <- 0 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
247 heat$direction[pv$delta.rank > 0] <- 1 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
248 if (cutoff > 0) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
249 goods <- subset(heat, pval >= cutoff) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
250 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
251 goods.names <- unique(rsq$term[abs(rsq$value) >= absValue]) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
252 goods <- heat[row.names(heat) %in% goods.names, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
253 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
254 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
255 if (is.null(colors) | length(colors) < 4) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
256 colors <- c("dodgerblue2", "firebrick1", "skyblue2", "lightcoral") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
257 if (sum(goods$direction) == nrow(goods) | sum(goods$direction) == 0) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
258 colors <- c("black", "black", "grey50", "grey50") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
259 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
260 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
261 goods.names <- row.names(goods) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
262 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
263 # reading and subsetting dissimilarity matrix |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
264 diss <- read.table(in.dissim, sep = "\t", header = T, check.names = F) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
265 row.names(diss) <- names(diss) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
266 diss.goods <- diss[goods.names, goods.names] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
267 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
268 # how many genes out of what we started with we account for with our best categories? |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
269 good.len <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
270 good.genes <- c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
271 for (g in goods.names) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
272 sel <- rsq[rsq$term == g, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
273 pass <- abs(sel$value) >= absValue |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
274 sel <- sel[pass, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
275 good.genes <- append(good.genes, as.character(sel$seq)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
276 good.len <- append(good.len, nrow(sel)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
277 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
278 ngenes <- length(unique(good.genes)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
279 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
280 # hist(rsq$value) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
281 totSum <- length(unique(rsq$seq[abs(rsq$value) >= absValue])) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
282 row.names(goods) <- paste(good.len, "/", pv[pv$term %in% goods.names, ]$nseqs, " ", pv[pv$term %in% goods.names, ]$name, sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
283 row.names(heat) <- paste(good.len, "/", pv$nseqs, " ", pv$name, sep = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
284 row.names(diss.goods) <- paste(good.len, "/", pv[pv$term %in% goods.names, ]$nseqs, " ", pv[pv$term %in% goods.names, ]$name, sep = "") |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
285 |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
286 # clustering terms better than cutoff |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
287 GO.categories <- as.dist(diss.goods) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
288 cl.goods <- hclust(GO.categories, method = "average") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
289 labs <- cl.goods$labels[cl.goods$order] # saving the labels to order the plot |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
290 goods <- goods[labs, ] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
291 labs <- sub(" activity", "", labs) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
292 |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
293 old.par <- par(no.readonly = TRUE) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
294 |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
295 plots <- layout(matrix(c(1, 2, 3), 1, 3, byrow = T), c(treeHeight, 3, 1), TRUE) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
296 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
297 par(mar = c(2, 2, 0.85, 0)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
298 plot(as.phylo(cl.goods), show.tip.label = FALSE, cex = 0.0000001) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
299 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
300 par(mar = c(2, 0, 1, 0)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
301 step <- dev.size("px")[2] / (length(goods.names) - 1) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
302 left <- 1 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
303 top <- step * (length(labs) - 1) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
304 # print(paste("Size:", dev.size("px"))) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
305 # print(paste("Good:", length(goods.names), "Step:", step, "Top:", top)) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
306 |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
307 plot(c(1:top), c(1:top), type = "n", axes = F, xlab = "", ylab = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
308 ii <- 0 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
309 goods$color <- 1 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
310 goods$color[goods$direction == 1 & goods$pval > cutoff] <- colors[4] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
311 goods$color[goods$direction == 0 & goods$pval > cutoff] <- colors[3] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
312 goods$color[goods$direction == 1 & goods$pval > (-log(level2, 10))] <- colors[2] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
313 goods$color[goods$direction == 0 & goods$pval > (-log(level2, 10))] <- colors[1] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
314 goods$color[goods$direction == 1 & goods$pval > (-log(level3, 10))] <- colors[2] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
315 goods$color[goods$direction == 0 & goods$pval > (-log(level3, 10))] <- colors[1] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
316 for (i in length(labs):1) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
317 ypos <- round(top - step * ii) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
318 # print(paste("Ypos:", ypos)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
319 ii <- ii + 1 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
320 if (goods$pval[i] > -log(level3, 10)) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
321 text(left, ypos, labs[i], font = 2, cex = 1 * txtsize, col = goods$color[i], adj = c(0, 0), family = font.family) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
322 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
323 if (goods$pval[i] > -log(level2, 10)) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
324 text(left, ypos, labs[i], font = 1, cex = 0.8 * txtsize, col = goods$color[i], adj = c(0, 0), family = font.family) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
325 } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
326 # if (goods$pval[i]>cutoff) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
327 # text(left,ypos,labs[i],font=3,cex=0.8* txtsize,col=goods$color[i],adj=c(0,0),family=font.family) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
328 # } else { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
329 text(left, ypos, labs[i], font = 3, cex = 0.8 * txtsize, col = goods$color[i], adj = c(0, 0), family = font.family) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
330 # } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
331 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
332 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
333 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
334 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
335 par(mar = c(3, 1, 1, 0)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
336 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
337 plot(c(1:top), c(1:top), type = "n", axes = F, xlab = "", ylab = "") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
338 text(left, top - step * 2, paste("p < ", level3, sep = ""), font = 2, cex = 1 * txtsize, adj = c(0, 0), family = font.family) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
339 text(left, top - step * 3, paste("p < ", level2, sep = ""), font = 1, cex = 0.8 * txtsize, adj = c(0, 0), family = font.family) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
340 text(left, top - step * 4, paste("p < ", 10^(-cutoff), sep = ""), font = 3, col = "grey50", cex = 0.8 * txtsize, adj = c(0, 0), family = font.family) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
341 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
342 message("GO terms dispayed: ", length(goods.names)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
343 message("\"Good genes\" accounted for: ", ngenes, " out of ", totSum, " ( ", round(100 * ngenes / totSum, 0), "% )") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
344 par(old.par) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
345 goods$pval <- 10^(-1 * goods$pval) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
346 return(list(goods, cl.goods)) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
347 } |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
348 |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
349 #------------------ |
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
350 # returns non-overlapping GO categories based on dissimilarity table |
2
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
351 indepGO <- function(dissim.table, min.similarity = 1) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
352 tt <- read.table(dissim.table, sep = "\t", header = TRUE) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
353 tt <- as.matrix(tt) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
354 diag(tt) <- 1 |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
355 for (i in 1:ncol(tt)) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
356 mins <- apply(tt, 2, min) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
357 if (min(mins) >= min.similarity) { |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
358 break |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
359 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
360 sums <- apply(tt, 2, sum) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
361 worst <- which(sums == min(sums))[1] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
362 # cat("\n",worsts,"\n") |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
363 # gw=c() |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
364 # for(w in worsts) { gw=append(gw,sum(tt[,w]==1)) } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
365 # cat(gw) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
366 # worst=worsts[gw==min(gw)] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
367 # cat("\n",i," removing",worst,"; sum =",sums[worst]) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
368 tt <- tt[-worst, -worst] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
369 mins <- mins[-worst] |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
370 # cat(" new min =",min(mins)) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
371 } |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
372 goods <- colnames(tt) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
373 goods <- gsub("GO\\.", "GO:", goods) |
5acf9dfdfa27
planemo upload commit 66a856bcce69986d9a6f1a39820dd9b3f4f6b0db
cristian
parents:
1
diff
changeset
|
374 goods <- gsub("\\.GO", ";GO", goods) |
0
91261b42c07e
"planemo upload commit 25eebba0c98dd7a5a703412be90e97f13f66b5bc"
cristian
parents:
diff
changeset
|
375 } |