annotate tools/script.R @ 3:db5d126bf8d0 draft

planemo upload
author marpiech
date Thu, 22 Dec 2016 18:19:53 -0500
parents c5a812cdf478
children
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
3
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
11 clusterRow = args[7]
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
12 clusterCol = args[8]
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
13 hclustMethod = args[9]
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
14
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
15 mgColumnNm = as.numeric(args[10])
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
16 mgRowNm = as.numeric(args[11])
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
17
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
18 pdfWidth = as.numeric(args[12])
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
19 pdfHeight = as.numeric(args[13])
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
20
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
21
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
22 if(clusterRow == "Yes"){
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
23 clusterRow = TRUE
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
24 } else {
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
25 clusterRow = NA
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
26 }
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
27
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
28 if(clusterCol == "Yes"){
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
29 clusterCol = TRUE
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
30 } else {
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
31 clusterCol = NA
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
32 }
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
33
0
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
34 require(preprocessCore)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
35 require(gplots)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
36
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
37 #prepare counts data --------------------------------------------------------
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
38 countData = read.table(countDataPath, comment = "",
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
39 sep = "\t")
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
40
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
41 groups = sapply(as.character(countData[1, -1]), strsplit, ":")
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
42 groups = as.vector(t(countData[1, -1]))
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
43
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
44 names = as.vector(t(countData[2, -1]))
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
45
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
46 countData = countData[-c(1,2), ]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
47 rownames(countData) = countData[, 1]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
48 countData = countData[, -1]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
49 colnames(countData) = names
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
50
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
51 countData = countData[, order(groups, names)]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
52
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
53 # prepare stats data ------------------------------------------------------
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
54
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
55 statsData = read.table(statsDataPath, sep = "\t",
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
56 header = T)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
57
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
58 colnames(statsData)[-1] = sapply(colnames(statsData)[-1], function(x){
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
59 unlist(strsplit(x, ".", fixed = T))[3]
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
60 })
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
61
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
62 wh = which(abs(statsData$logFC) >= logFC & statsData$logCPM >= logCPM & statsData$PValue <= pValue & statsData$FDR <= fdr)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
63
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
64 for(i in 1:ncol(countData)){
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
65 countData[,i] = as.numeric(countData[,i])
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
66 }
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
67
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
68 countDataNorm = normalize.quantiles(as.matrix(countData), copy = T)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
69 countDataNormLog = log(countDataNorm + 1, 2)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
70
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
71 colnames(countDataNormLog) = colnames(countData)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
72 rownames(countDataNormLog) = rownames(countData)
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
73
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
74 #svg("heatmap.svg", width = 3+length(names), height = 1/2*length(wh))
3
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
75 pdf("heatmap.pdf", width = pdfWidth, height = pdfHeight)
0
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
76
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
77 heatmap.2(
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
78 countDataNormLog[wh, ],
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
79 density.info=c("none"),
3
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
80 hclustfun = function(x) hclust(x, method = hclustMethod),
0
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
81 distfun = function(x) as.dist(1-cor(t(x))),
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
82 col = bluered(50),
3
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
83 scale = "row",
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
84 trace = "none",
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
85 Rowv = clusterRow,
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
86 Colv = clusterCol,
db5d126bf8d0 planemo upload
marpiech
parents: 0
diff changeset
87 margins = c(mgColumnNm, mgRowNm)
0
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
88 )
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
89
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
90 dev.off()
c5a812cdf478 planemo upload
marpiech
parents:
diff changeset
91