annotate tools/script.R @ 1:ddde82ae5dea draft

planemo upload
author marpiech
date Sun, 11 Dec 2016 18:57:58 -0500
parents c5a812cdf478
children db5d126bf8d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
1 #!/usr/bin/env Rscript
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
2
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
3 args = commandArgs(TRUE)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
4 countDataPath = args[1]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
5 statsDataPath = args[2]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
6 logFC = args[3]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
7 logCPM = args[4]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
8 pValue = args[5]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
9 fdr = args[6]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
10
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
11 require(preprocessCore)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
12 require(gplots)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
13
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
14 #prepare counts data --------------------------------------------------------
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
15 countData = read.table(countDataPath, comment = "",
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
16 sep = "\t")
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
17
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
18 groups = sapply(as.character(countData[1, -1]), strsplit, ":")
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
19 groups = as.vector(t(countData[1, -1]))
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
20
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
21 names = as.vector(t(countData[2, -1]))
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
22
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
23 countData = countData[-c(1,2), ]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
24 rownames(countData) = countData[, 1]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
25 countData = countData[, -1]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
26 colnames(countData) = names
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
27
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
28 countData = countData[, order(groups, names)]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
29
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
30 # prepare stats data ------------------------------------------------------
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
31
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
32 statsData = read.table(statsDataPath, sep = "\t",
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
33 header = T)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
34
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
35 colnames(statsData)[-1] = sapply(colnames(statsData)[-1], function(x){
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
36 unlist(strsplit(x, ".", fixed = T))[3]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
37 })
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
38
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
39 wh = which(abs(statsData$logFC) >= logFC & statsData$logCPM >= logCPM & statsData$PValue <= pValue & statsData$FDR <= fdr)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
40
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
41 for(i in 1:ncol(countData)){
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
42 countData[,i] = as.numeric(countData[,i])
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
43 }
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
44
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
45 countDataNorm = normalize.quantiles(as.matrix(countData), copy = T)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
46 countDataNormLog = log(countDataNorm + 1, 2)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
47
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
48 colnames(countDataNormLog) = colnames(countData)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
49 rownames(countDataNormLog) = rownames(countData)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
50
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
51 #svg("heatmap.svg", width = 3+length(names), height = 1/2*length(wh))
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
52 pdf("heatmap.pdf")
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
53
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
54 heatmap.2(
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
55 countDataNormLog[wh, ],
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
56 density.info=c("none"),
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
57 hclustfun = function(x) hclust(x, method = "average"),
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
58 distfun = function(x) as.dist(1-cor(t(x))),
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
59 col = bluered(50),
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
60 scale = 'row',
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
61 trace = "none", #lwid = c(1, length(names)), lhei = c(1,1/3*length(wh)),
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
62 # Rowv=NA,
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
63 Colv = NA,
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
64 margins = c(7, 8)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
65 )
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
66
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
67 dev.off()
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
68