-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalJob_File.R
More file actions
174 lines (146 loc) · 5.49 KB
/
LocalJob_File.R
File metadata and controls
174 lines (146 loc) · 5.49 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
library(data.table)
library(tidyverse)
library(betAS)
set.seed(1906)
CharmObj_rbp_All <- readRDS("~/Projects/CHARM/data/CharmObj_rbp_All.rds")
CharmObj_rbp_HEPG2 <- readRDS("~/Projects/CHARM/data/CharmObj_rbp_HEPG2.rds")
CharmObj_rbp_K562 <- readRDS("~/Projects/CHARM/data/CharmObj_rbp_K562.rds")
Charm.object <- readRDS("data/Charm.object.RDS")
Charm.object_K562 <- readRDS("data/Charm.object_K562.RDS")
Charm.object_HEPG2 <- readRDS("data/Charm.object_HEPG2.RDS")
#Both Cells
for (rbp in names(CharmObj_rbp_All)) {
dataset_All_filtered <- CharmObj_rbp_All[[rbp]]
psi <- dataset_All_filtered$PSI
qual <- dataset_All_filtered$Qual
# --- Automatically detect control and shRNA columns ---
cols_CTRL_names <- grep("control", colnames(psi), value = TRUE, ignore.case = TRUE)
cols_shRNA_names <- grep("shrna", colnames(psi), value = TRUE, ignore.case = TRUE)
# Skip safely if nothing is found
if (length(cols_CTRL_names) == 0 || length(cols_shRNA_names) == 0) {
message("⚠️ Skipping ", rbp, ": no control or shRNA columns found.")
next
}
# Convert to column indices for betAS
cols_CTRL <- convertCols(psi, cols_CTRL_names)
cols_shRNA <- convertCols(psi, cols_shRNA_names)
# --- Build volcano table ---
volcanoTable_Pdiff_All <- tryCatch({
prepareTableVolcano(
psitable = psi,
qualtable = qual,
npoints = 500,
colsA = cols_CTRL,
colsB = cols_shRNA,
labA = "CTRL",
labB = "shRNA",
basalColor = "#89C0AE",
interestColor = "#E69A9C",
maxDevTable = maxDevSimulationN100,
seed = TRUE,
CoverageWeight = FALSE
)
}, error = function(e) {
message("⚠️ Skipping ", rbp, " due to error: ", e$message)
return(NULL)
})
# Skip if failed
if (is.null(volcanoTable_Pdiff_All)) next
# --- Format output ---
volcanoTable_Pdiff_All <- volcanoTable_Pdiff_All[, c("EVENT", "GENE", "deltapsi", "Pdiff")]
colnames(volcanoTable_Pdiff_All) <- c("Event.ID", "Gene", "dPSI", "Pdiff")
# --- Store result ---
Charm.object[[rbp]]$VulcanTable <- volcanoTable_Pdiff_All
}
# K562
for (rbp in names(CharmObj_rbp_K562)) {
dataset_All_filtered <- CharmObj_rbp_K562[[rbp]]
psi <- dataset_All_filtered$PSI
qual <- dataset_All_filtered$Qual
# --- Automatically detect control and shRNA columns ---
cols_CTRL_names <- grep("control", colnames(psi), value = TRUE, ignore.case = TRUE)
cols_shRNA_names <- grep("shrna", colnames(psi), value = TRUE, ignore.case = TRUE)
# Skip safely if nothing is found
if (length(cols_CTRL_names) == 0 || length(cols_shRNA_names) == 0) {
message("⚠️ Skipping ", rbp, ": no control or shRNA columns found.")
next
}
# Convert to column indices for betAS
cols_CTRL <- convertCols(psi, cols_CTRL_names)
cols_shRNA <- convertCols(psi, cols_shRNA_names)
# --- Build volcano table ---
volcanoTable_Pdiff_All <- tryCatch({
prepareTableVolcano(
psitable = psi,
qualtable = qual,
npoints = 500,
colsA = cols_CTRL,
colsB = cols_shRNA,
labA = "CTRL",
labB = "shRNA",
basalColor = "#89C0AE",
interestColor = "#E69A9C",
maxDevTable = maxDevSimulationN100,
seed = TRUE,
CoverageWeight = FALSE
)
}, error = function(e) {
message("⚠️ Skipping ", rbp, " due to error: ", e$message)
return(NULL)
})
# Skip if failed
if (is.null(volcanoTable_Pdiff_All)) next
# --- Format output ---
volcanoTable_Pdiff_All <- volcanoTable_Pdiff_All[, c("EVENT", "GENE", "deltapsi", "Pdiff")]
colnames(volcanoTable_Pdiff_All) <- c("Event.ID", "Gene", "dPSI", "Pdiff")
# --- Store result ---
Charm.object_K562[[rbp]]$VulcanTable <- volcanoTable_Pdiff_All
}
# HEPG2
for (rbp in names(CharmObj_rbp_HEPG2)) {
dataset_All_filtered <- CharmObj_rbp_HEPG2[[rbp]]
psi <- dataset_All_filtered$PSI
qual <- dataset_All_filtered$Qual
# --- Automatically detect control and shRNA columns ---
cols_CTRL_names <- grep("control", colnames(psi), value = TRUE, ignore.case = TRUE)
cols_shRNA_names <- grep("shrna", colnames(psi), value = TRUE, ignore.case = TRUE)
# Skip safely if nothing is found
if (length(cols_CTRL_names) == 0 || length(cols_shRNA_names) == 0) {
message("⚠️ Skipping ", rbp, ": no control or shRNA columns found.")
next
}
# Convert to column indices for betAS
cols_CTRL <- convertCols(psi, cols_CTRL_names)
cols_shRNA <- convertCols(psi, cols_shRNA_names)
# --- Build volcano table ---
volcanoTable_Pdiff_All <- tryCatch({
prepareTableVolcano(
psitable = psi,
qualtable = qual,
npoints = 500,
colsA = cols_CTRL,
colsB = cols_shRNA,
labA = "CTRL",
labB = "shRNA",
basalColor = "#89C0AE",
interestColor = "#E69A9C",
maxDevTable = maxDevSimulationN100,
seed = TRUE,
CoverageWeight = FALSE
)
}, error = function(e) {
message("⚠️ Skipping ", rbp, " due to error: ", e$message)
return(NULL)
})
# Skip if failed
if (is.null(volcanoTable_Pdiff_All)) next
# --- Format output ---
volcanoTable_Pdiff_All <- volcanoTable_Pdiff_All[, c("EVENT", "GENE", "deltapsi", "Pdiff")]
colnames(volcanoTable_Pdiff_All) <- c("Event.ID", "Gene", "dPSI", "Pdiff")
# --- Store result ---
Charm.object_HEPG2[[rbp]]$VulcanTable <- volcanoTable_Pdiff_All
}
# Save separately
saveRDS(Charm.object, file = "~/Projects/CHARM/data/CharmObj_ALL_DEDS.rds")
saveRDS(Charm.object_HEPG2, file = "~/Projects/CHARM/data/CharmObj_HEPG2_DEDS.rds")
saveRDS(Charm.object_K562, file = "~/Projects/CHARM/data/CharmObj_K562_DEDS.rds")