@sjcrh/proteinpaint-server 2.109.1 → 2.110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/utils/edge.R CHANGED
@@ -115,27 +115,42 @@ filter_time <- system.time({
115
115
 
116
116
  normalization_time <- system.time({
117
117
  y <- y[keep, keep.lib.sizes = FALSE]
118
- y <- calcNormFactors(y, method = "TMM")
118
+ y <- normLibSizes(y) # Using TMM method for normalization
119
119
  })
120
120
  #cat("Normalization time: ", normalization_time[3], " seconds\n")
121
121
 
122
+ # Saving MDS plot image
123
+ set.seed(as.integer(Sys.time())) # Set the seed according to current time
124
+ cachedir <- input$cachedir # Importing serverconfig.cachedir
125
+ random_number <- runif(1, min = 0, max = 1) # Generating random number
126
+ mds_image_name <- paste0("edgeR_mds_temp_",random_number,".png") # Generating random image name so that simultaneous server side requests do NOT generate the same edgeR file name
127
+ png(filename = paste0(cachedir,"/",mds_image_name), width = 1000, height = 1000, res = 200) # Opening a png device
128
+ par(oma = c(1, 1, 1, 1)) # Creating a margin
129
+ plotMDS(y) # Plot the edgeR MDS plot
130
+ # dev.off() # Gives a null device message which breaks JSON. Commenting it out for now, will investigate it later
131
+
132
+
122
133
  # Differential expression analysis
123
134
  if (length(input$conf1) == 0) { # No adjustment of confounding factors
124
- dispersion_time <- system.time({
135
+ design <- model.matrix(~conditions) # Based on the protocol defined in section 1.4 of edgeR manual https://bioconductor.org/packages/release/bioc/vignettes/edgeR/inst/doc/edgeRUsersGuide.pdf
136
+ fit_time <- system.time({
125
137
  suppressWarnings({
126
138
  suppressMessages({
127
- y <- estimateDisp(y)
139
+ fit <- glmQLFit(y,design) # The glmQLFit() replaces glmFit() which implements the quasi-likelihood function. This is better able to account for overdispersion as it employs a more lenient approach where variance is not a fixed function of the mean.
128
140
  })
129
141
  })
130
142
  })
131
- #cat("Dispersion time: ", dispersion_time[3], " seconds\n")
143
+ #cat("QL fit time: ", fit_time[3], " seconds\n")
132
144
 
133
- exact_test_time <- system.time({
134
- et <- exactTest(y)
145
+ test_time <- system.time({
146
+ suppressWarnings({
147
+ suppressMessages({
148
+ et <- glmQLFTest(fit)
149
+ })
150
+ })
135
151
  })
136
- #cat("Exact test time: ", exact_test_time[3], " seconds\n")
152
+ #cat("QL test time: ", test_time[3], " seconds\n")
137
153
  } else { # Adjusting for confounding factors
138
-
139
154
  # Check the type of confounding variable
140
155
  if (input$conf1_mode == "continuous") { # If this is float, the input conf1 vector should be converted into a numeric vector
141
156
  conf1 <- as.numeric(input$conf1)
@@ -144,7 +159,7 @@ if (length(input$conf1) == 0) { # No adjustment of confounding factors
144
159
  }
145
160
 
146
161
  if (length(input$conf2) == 0) { # No adjustment of confounding factor 2
147
- y$samples <- data.frame(conditions = conditions, conf1 = conf1)
162
+ y$samples <- data.frame(y$samples, conditions = conditions, conf1 = conf1)
148
163
  model_gen_time <- system.time({
149
164
  design <- model.matrix(~ conditions + conf1, data = y$samples)
150
165
  })
@@ -156,29 +171,41 @@ if (length(input$conf1) == 0) { # No adjustment of confounding factors
156
171
  } else { # When input$conf2_mode == "discrete" keep the vector as string.
157
172
  conf2 <- as.factor(input$conf2)
158
173
  }
159
- y$samples <- data.frame(conditions = conditions, conf1 = conf1, conf2 = conf2)
174
+ y$samples <- data.frame(y$samples, conditions = conditions, conf1 = conf1, conf2 = conf2)
160
175
  model_gen_time <- system.time({
161
176
  design <- model.matrix(~ conditions + conf1 + conf2, data = y$samples)
162
177
  })
163
178
  #cat("Time for making design matrix: ", model_gen_time[3], " seconds\n")
164
179
  }
165
180
 
166
- dispersion_time <- system.time({
167
- y <- estimateDisp(y, design)
168
- })
169
- #cat("Dispersion time: ", dispersion_time[3], " seconds\n")
170
-
171
181
  fit_time <- system.time({
172
- fit <- glmFit(y, design)
182
+ suppressWarnings({
183
+ suppressMessages({
184
+ fit <- glmQLFit(y,design)
185
+ })
186
+ })
173
187
  })
174
- #cat("Fit time: ", fit_time[3], " seconds\n")
175
-
176
- test_statistics_time <- system.time({
177
- et <- glmLRT(fit, coef = "conditionsDiseased")
188
+ #cat("QL fit time: ", fit_time[3], " seconds\n")
189
+ test_time <- system.time({
190
+ suppressWarnings({
191
+ suppressMessages({
192
+ et <- glmQLFTest(fit, coef = "conditionsDiseased")
193
+ })
194
+ })
178
195
  })
179
- #cat("Test statistics time: ", test_statistics_time[3], " seconds\n")
196
+ #cat("QL test time: ", test_time[3], " seconds\n")
180
197
  }
181
198
 
199
+ # Saving QL fit image
200
+ set.seed(as.integer(Sys.time())) # Set the seed according to current time
201
+ cachedir <- input$cachedir # Importing serverconfig.cachedir
202
+ random_number <- runif(1, min = 0, max = 1) # Generating random number
203
+ ql_image_name <- paste0("edgeR_ql_temp_",random_number,".png") # Generating random image name so that simultaneous server side requests do NOT generate the same edgeR file name
204
+ png(filename = paste0(cachedir,"/",ql_image_name), width = 1000, height = 1000, res = 200) # Opening a png device
205
+ par(oma = c(1, 1, 1, 1)) # Creating a margin
206
+ plotQLDisp(fit) # Plot the edgeR fit
207
+ # dev.off() # Gives a null device message which breaks JSON. Commenting it out for now, will investigate it later
208
+
182
209
  # Multiple testing correction
183
210
  multiple_testing_correction_time <- system.time({
184
211
  logfc <- et$table$logFC
@@ -195,10 +222,14 @@ multiple_testing_correction_time <- system.time({
195
222
  names(output)[4] <- "original_p_value"
196
223
  names(output)[5] <- "adjusted_p_value"
197
224
  })
225
+ final_output <- c()
226
+ final_output$gene_data <- output
227
+ final_output$edgeR_ql_image_name <- ql_image_name
228
+ final_output$edgeR_mds_image_name <- mds_image_name
198
229
  #cat("Time for multiple testing correction: ", multiple_testing_correction_time[3], " seconds\n")
199
230
 
200
231
  # Output results
201
- toJSON(output)
232
+ toJSON(final_output)
202
233
 
203
234
  #-----------------------------------#
204
235
  # Will implement this later