annotate chromeister/bin/plot_diags.R @ 0:7fdf47a0bae8 draft

Uploaded
author alvarofaure
date Wed, 12 Dec 2018 07:18:40 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
1 #!/usr/bin/env Rscript
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
2 args = commandArgs(trailingOnly=TRUE)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
3
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
4 if(length(args) < 1){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
5 stop("USE: Rscript --vanilla plot.R <matrix>")
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
6 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
7
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
8
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
9 path_mat = args[1]
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
10
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
11
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
12
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
13
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
14 data <- as.matrix(read.csv(path_mat, sep = " "))
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
15 percentage <- 0.1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
16
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
17
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
18
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
19
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
20 d <- col(data) - row(data)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
21 groups <- split(data, d)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
22 acum <- c()
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
23 for(i in 1:length(groups)){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
24 acum <- c(acum, sum(unlist(groups[i])))
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
25 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
26
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
27
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
28 # reverse
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
29 data_r <- data
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
30 for(i in 1:length(data_r[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
31 data_r[i,] <- rev(data_r[i,])
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
32 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
33 d <- col(data_r) - row(data_r)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
34 groups <- split(data_r, d)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
35 acum_r <- c()
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
36 for(i in 1:length(groups)){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
37 acum_r <- c(acum, sum(unlist(groups[i]))/length(unlist(groups[i])) )
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
38 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
39
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
40 indexes <- matrix(0, nrow=length(acum), ncol = 3)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
41 indexes[,1] <- c(1:length(acum))
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
42 indexes[,2] <- acum
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
43
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
44 #sort
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
45 indexes[order(indexes[,2], decreasing=TRUE),]
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
46
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
47 #crop by percentage
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
48 n_percent <- percentage * length(acum)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
49
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
50 for(i in 1:n_percent){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
51 indexes[i,3] <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
52 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
53
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
54 # Now resort based on first column to have them again in order
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
55 indexes[order(indexes[,1], decreasing=FALSE),]
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
56
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
57
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
58 # same in reverse
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
59 #put into indexes to sort
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
60 indexes_r <- matrix(0, nrow=length(acum_r), ncol = 3)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
61 indexes_r[,1] <- c(1:length(acum_r))
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
62 indexes_r[,2] <- acum_r
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
63
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
64 #sort
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
65 indexes_r[order(indexes_r[,2], decreasing=TRUE),]
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
66
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
67 #crop by percentage
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
68 n_percent <- percentage * length(acum_r)
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
69
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
70 for(i in 1:n_percent){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
71 indexes_r[i,3] <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
72 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
73
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
74 # Now resort based on first column to have them again in order
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
75 indexes_r[order(indexes_r[,1], decreasing=FALSE),]
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
76
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
77
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
78
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
79
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
80 finalmat <- matrix(0, nrow=length(data[,1]), ncol=length(data[1,]))
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
81
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
82
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
83 for(i in length(data[1,]):1){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
84 x <- i
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
85 y <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
86
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
87 if(indexes[i,3] == 1){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
88 while(x < length(data[1,]) && y <= length(data[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
89
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
90
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
91 if(x < length(data[1,]) && y <= length(data[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
92 finalmat[x,y] <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
93 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
94
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
95 y <- y + 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
96 x <- x + 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
97
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
98
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
99 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
100 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
101
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
102 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
103
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
104 for(i in 2:length(data[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
105 x <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
106 y <- i
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
107
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
108 if(indexes[i,3] == 1){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
109
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
110 while(x < length(data[1,]) && y <= length(data[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
111
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
112 if(x < length(data[1,]) && y <= length(data[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
113 finalmat[x,y] <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
114 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
115 y <- y + 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
116 x <- x + 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
117
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
118 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
119 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
120 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
121
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
122
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
123 #same for reverse
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
124 for(i in length(data_r[1,]):1){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
125 x <- i
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
126 y <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
127
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
128 if(indexes[i,3] == 1){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
129 while(x < length(data_r[1,]) && y <= length(data_r[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
130
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
131
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
132 if(x < length(data_r[1,]) && y <= length(data_r[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
133 finalmat[x,length(data_r[,1])-y] <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
134 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
135
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
136 y <- y + 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
137 x <- x + 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
138
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
139
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
140 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
141 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
142
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
143 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
144
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
145 for(i in 2:length(data_r[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
146 x <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
147 y <- i
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
148
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
149 if(indexes[i,3] == 1){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
150
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
151 while(x < length(data_r[1,]) && y <= length(data_r[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
152
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
153 if(x < length(data_r[1,]) && y <= length(data_r[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
154 finalmat[x,length(data_r[,1])-y] <- 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
155 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
156 y <- y + 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
157 x <- x + 1
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
158
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
159 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
160 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
161 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
162
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
163 # fully write last
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
164
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
165 for(i in 1:length(data[,1])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
166 for(j in 1:length(data[1,])){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
167 if(finalmat[i,j] == 0){
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
168
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
169 data[i,j] <- 0
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
170 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
171 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
172 }
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
173
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
174 png(paste(path_mat, ".png", sep=""), width = length(data[,1]), height = length(data[,1]))
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
175 image((data), col = grey(seq(1, 0, length = 256)), xaxt='n', yaxt='n')
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
176 dev.off()
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
177
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
178
7fdf47a0bae8 Uploaded
alvarofaure
parents:
diff changeset
179