-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRFkit_plot.r
More file actions
140 lines (116 loc) · 3.33 KB
/
Copy pathRFkit_plot.r
File metadata and controls
140 lines (116 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Configuration -------------------------------------------------------------
misc_dir <- "misc"
plot_files <- Sys.glob(file.path(misc_dir, "plot_*.bin"))
plot_colors <- c(
"#4e79a7", "#f28e2b", "#e15759", "#76b7b2", "#59a14f",
"#edc948", "#b07aa1", "#ff9da7", "#9c755f", "#bab0ac"
)
plot_colors_alpha20 <- paste0(plot_colors, "33")
plot_colors_alpha50 <- paste0(plot_colors, "80")
# Plot files ----------------------------------------------------------------
.PlotRfkitFile <- function(plot_file) {
pdf_file <- basename(paste0(
substr(plot_file, 1, nchar(plot_file) - 8),
"pdf"
))
pdf(pdf_file, paper = "a4r", width = 0, height = 0)
on.exit(dev.off(), add = TRUE)
par(
mfrow = c(5, 2),
oma = c(0, 0, 0, 0),
mar = c(2, 2, 1.5, 0)
)
print(pdf_file)
plot_connection <- file(plot_file, "rb")
on.exit(close(plot_connection), add = TRUE)
n_compounds <- readBin(
plot_connection,
integer(),
size = 1,
signed = FALSE,
endian = "little"
)
for (compound_index in seq_len(n_compounds)) {
color_index <- ((compound_index - 1) %% length(plot_colors_alpha50)) + 1
compound_name <- readBin(plot_connection, character())
xic_length <- readBin(
plot_connection,
integer(),
size = 2,
signed = FALSE,
endian = "little"
)
xic_matrix <- matrix(
readBin(
plot_connection,
numeric(),
size = 4,
n = xic_length * 2,
endian = "little"
),
ncol = xic_length
)
rt_xic <- xic_matrix[1, ]
intensity_xic <- xic_matrix[2, ]
n_wells <- readBin(
plot_connection,
integer(),
size = 1,
signed = FALSE,
endian = "little"
)
for (well_index in seq_len(n_wells)) {
well_label <- readBin(plot_connection, character())
rt_left <- readBin(
plot_connection,
integer(),
size = 2,
signed = FALSE,
endian = "little"
)
rt_right <- readBin(
plot_connection,
integer(),
size = 2,
signed = FALSE,
endian = "little"
)
rt_length <- (rt_xic[rt_right] - rt_xic[rt_left]) / 2
rt_start <- rt_xic[rt_left] - rt_length
rt_end <- rt_xic[rt_right] + rt_length
plot_left <- findInterval(rt_start, rt_xic)
plot_right <- findInterval(rt_end, rt_xic)
plot(
x = rt_xic[plot_left:plot_right],
y = intensity_xic[plot_left:plot_right],
pch = ".",
cex = 4,
main = paste(compound_name, well_label),
col.main = plot_colors[color_index],
xlab = "",
ylab = "",
ylim = c(0, max(intensity_xic[rt_left:rt_right])),
yaxt = "n"
)
y_axis_ticks <- axTicks(2)
axis(2, at = c(0, y_axis_ticks[length(y_axis_ticks) - 1]))
rect(
rt_xic[rt_left],
par("usr")[3],
rt_xic[rt_right],
par("usr")[4],
col = plot_colors_alpha20[color_index],
border = NA
)
polygon(
x = c(rt_xic[rt_left:rt_right], rt_xic[rt_right], rt_xic[rt_left]),
y = c(intensity_xic[rt_left:rt_right], 0, 0),
col = plot_colors_alpha50[color_index],
border = NA
)
}
}
return(invisible(pdf_file))
}
# Main ----------------------------------------------------------------------
pdf_files <- lapply(plot_files, .PlotRfkitFile)