@sjcrh/proteinpaint-server 2.110.0 → 2.112.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/package.json +4 -4
- package/routes/correlationVolcano.js +2 -2
- package/routes/gdc.mafBuild.js +49 -12
- package/routes/termdb.DE.js +57 -14
- package/routes/termdb.boxplot.js +4 -8
- package/routes/termdb.config.js +15 -1
- package/routes/termdb.descrstats.js +2 -2
- package/routes/termdb.violin.js +50 -10
- package/routes/tileserver.js +36 -4
- package/routes/wsimages.js +34 -37
- package/src/app.js +11122 -10677
- package/utils/density.R +36 -0
- package/utils/edge.R +25 -36
- package/routes/clearwsisession.js +0 -51
package/utils/density.R
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
library(jsonlite)
|
|
2
|
+
# This script reads in a json string from stdin with the parameters,
|
|
3
|
+
# calculates the densities of each plot and returns the densities as a json string
|
|
4
|
+
# The input json string contains plot2Values, a dictionary where each field maps to an array of numbers and the
|
|
5
|
+
# global min and max values of the x axis.
|
|
6
|
+
# The output json string is a dictionary with the density for each plot. The density is represented
|
|
7
|
+
# by a an object where {x: [x density values], y: [y density values]}
|
|
8
|
+
# In order to test it you can run the following command from the command line replacing plot2Values and min and max
|
|
9
|
+
# with your values:
|
|
10
|
+
# echo '{plot2Values: {"plotA": [1.2, 2, 3], "plotB": [4.5, 5, 6]}, min: 1.2, max:6}' | Rscript ./density.R
|
|
11
|
+
|
|
12
|
+
con <- file("stdin", "r")
|
|
13
|
+
json <- readLines(con)
|
|
14
|
+
close(con)
|
|
15
|
+
data <- fromJSON(json)
|
|
16
|
+
plot2Values <- data$plot2Values
|
|
17
|
+
min <- data$min
|
|
18
|
+
max <- data$max
|
|
19
|
+
densities <- list()
|
|
20
|
+
for(plot in names(plot2Values)){
|
|
21
|
+
values = plot2Values[[plot]]
|
|
22
|
+
# If the plot has less than 5 values or all the values are the same, we will return a flat line
|
|
23
|
+
if(length(values) <= 5 | length(unique(values)) == 1){
|
|
24
|
+
y = rep(0, length(values))
|
|
25
|
+
densities[[plot]] <- list(x=values, y=y)
|
|
26
|
+
next
|
|
27
|
+
}
|
|
28
|
+
den = density(x = values, from=min, to=max)
|
|
29
|
+
x = den$x
|
|
30
|
+
y = den$y
|
|
31
|
+
result = list(x=x, y=y) #This is an object with two keys x and y that are number arrays
|
|
32
|
+
densities[[plot]] <- result
|
|
33
|
+
}
|
|
34
|
+
toJSON(densities, digits = NA, na = "string") # will return a json like { plotA: {x:[...], y: [...]}}
|
|
35
|
+
|
|
36
|
+
|
package/utils/edge.R
CHANGED
|
@@ -10,24 +10,11 @@ suppressWarnings({
|
|
|
10
10
|
suppressPackageStartupMessages(library(dplyr))
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# Add the gene_id_symbols as a new column to the dataframe
|
|
19
|
-
read_counts$gene_id_symbols <- gene_id_symbols
|
|
20
|
-
# Sort the dataframe based on the standard deviation column
|
|
21
|
-
read_counts <- read_counts[order(read_counts$Row_SD, decreasing = TRUE), ]
|
|
22
|
-
# Select top 3000 rows
|
|
23
|
-
read_counts <- head(read_counts,num_variable_genes) # Currently hardcoded 3000 genes
|
|
24
|
-
# Get gene id symbols corresponding to the reordered read count matrix
|
|
25
|
-
gene_id_symbols <- read_counts$gene_id_symbols
|
|
26
|
-
# Remove column Row_SD from read_counts dataframe
|
|
27
|
-
read_counts <- read_counts[, !names(read_counts) %in% "Row_SD"]
|
|
28
|
-
# Remove column gene_id_symbols from read_counts dataframe
|
|
29
|
-
read_counts <- read_counts[, !names(read_counts) %in% "gene_id_symbols"]
|
|
30
|
-
return(list(read_counts = read_counts, gene_id_symbols = gene_id_symbols))
|
|
13
|
+
# Filter based on CPM
|
|
14
|
+
filter_using_cpm <- function(y, gene_cpm_cutoff, sample_cpm_cutoff, count_cpm_cutoff) {
|
|
15
|
+
selr <- rowSums(cpm(y$counts)>gene_cpm_cutoff)>=sample_cpm_cutoff
|
|
16
|
+
selc <- colSums(cpm(y$counts))>=count_cpm_cutoff
|
|
17
|
+
y <- y[selr, selc]
|
|
31
18
|
}
|
|
32
19
|
|
|
33
20
|
# Read JSON input from stdin
|
|
@@ -86,21 +73,6 @@ read_counts_time <- system.time({
|
|
|
86
73
|
conditions <- c(rep("Diseased", length(cases)), rep("Control", length(controls)))
|
|
87
74
|
gene_id_symbols <- paste0(geneIDs, "\t", geneSymbols)
|
|
88
75
|
|
|
89
|
-
filter_genes_time <- system.time({
|
|
90
|
-
if (length(input$VarGenes) != 0) { # Filter out variable genes for DE analysis
|
|
91
|
-
filtered_read_counts <- filter_genes_by_global_variance(read_counts, gene_id_symbols, input$VarGenes)
|
|
92
|
-
read_counts <- filtered_read_counts$read_counts
|
|
93
|
-
gene_id_symbols <- filtered_read_counts$gene_id_symbols
|
|
94
|
-
|
|
95
|
-
#### Will implement filtering by per group variance later
|
|
96
|
-
#filtered_read_counts <- filter_genes_by_group_variance(read_counts, gene_id_symbols, num_variable_genes, cases, controls)
|
|
97
|
-
#read_counts <- filtered_read_counts$read_counts
|
|
98
|
-
#gene_id_symbols <- filtered_read_counts$gene_id_symbols
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
#cat("Time to filter genes: ", filter_genes_time[3], " seconds\n")
|
|
103
|
-
|
|
104
76
|
# Create DGEList object
|
|
105
77
|
dge_list_time <- system.time({
|
|
106
78
|
y <- DGEList(counts = read_counts, group = conditions, genes = gene_id_symbols)
|
|
@@ -119,14 +91,31 @@ normalization_time <- system.time({
|
|
|
119
91
|
})
|
|
120
92
|
#cat("Normalization time: ", normalization_time[3], " seconds\n")
|
|
121
93
|
|
|
94
|
+
# Cutoffs for cpm, will add them as UI options later
|
|
95
|
+
if (length(samples_indices) > 100) {
|
|
96
|
+
gene_cpm_cutoff <- 15
|
|
97
|
+
sample_cpm_cutoff <- 30
|
|
98
|
+
count_cpm_cutoff <- 100000
|
|
99
|
+
} else {
|
|
100
|
+
gene_cpm_cutoff <- 5
|
|
101
|
+
sample_cpm_cutoff <- 15
|
|
102
|
+
count_cpm_cutoff <- 100000
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
filter_using_cpm_time <- system.time({
|
|
106
|
+
y <- filter_using_cpm(y, gene_cpm_cutoff, sample_cpm_cutoff, count_cpm_cutoff) # Filtering counts matrix based on gene_cpm_cutoff, sample_cpm_cutoff and count_cpm_cutoff
|
|
107
|
+
})
|
|
108
|
+
#cat("Filter using cpm time: ", filter_using_cpm_time[3], " seconds\n")
|
|
109
|
+
|
|
122
110
|
# Saving MDS plot image
|
|
123
111
|
set.seed(as.integer(Sys.time())) # Set the seed according to current time
|
|
124
112
|
cachedir <- input$cachedir # Importing serverconfig.cachedir
|
|
125
113
|
random_number <- runif(1, min = 0, max = 1) # Generating random number
|
|
126
114
|
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
115
|
png(filename = paste0(cachedir,"/",mds_image_name), width = 1000, height = 1000, res = 200) # Opening a png device
|
|
128
|
-
par(oma = c(
|
|
129
|
-
|
|
116
|
+
par(oma = c(0, 0, 0, 0)) # Creating a margin
|
|
117
|
+
mds_conditions <- c(rep("T", length(cases)), rep("C", length(controls))) # Case samples are labelled "T" and control samples are labelled "C". Single-letter labelling added because otherwise labels get overwritten on each other.
|
|
118
|
+
plotMDS(y, labels = mds_conditions) # Plot the edgeR MDS plot
|
|
130
119
|
# dev.off() # Gives a null device message which breaks JSON. Commenting it out for now, will investigate it later
|
|
131
120
|
|
|
132
121
|
|
|
@@ -202,7 +191,7 @@ cachedir <- input$cachedir # Importing serverconfig.cachedir
|
|
|
202
191
|
random_number <- runif(1, min = 0, max = 1) # Generating random number
|
|
203
192
|
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
193
|
png(filename = paste0(cachedir,"/",ql_image_name), width = 1000, height = 1000, res = 200) # Opening a png device
|
|
205
|
-
par(oma = c(
|
|
194
|
+
par(oma = c(0, 0, 0, 0)) # Creating a margin
|
|
206
195
|
plotQLDisp(fit) # Plot the edgeR fit
|
|
207
196
|
# dev.off() # Gives a null device message which breaks JSON. Commenting it out for now, will investigate it later
|
|
208
197
|
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { clearWSImagesSessionsPayload } from "#types/checkers";
|
|
2
|
-
import SessionManager from "#src/wsisessions/SessionManager.js";
|
|
3
|
-
import ky from "ky";
|
|
4
|
-
import serverconfig from "#src/serverconfig.js";
|
|
5
|
-
const api = {
|
|
6
|
-
endpoint: "clearwsisession",
|
|
7
|
-
methods: {
|
|
8
|
-
delete: {
|
|
9
|
-
...clearWSImagesSessionsPayload,
|
|
10
|
-
init
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
function init() {
|
|
15
|
-
return async (req, res) => {
|
|
16
|
-
try {
|
|
17
|
-
if (serverconfig.redis) {
|
|
18
|
-
const sessionsString = req.query.sessions;
|
|
19
|
-
const sessionsArray = JSON.parse(sessionsString);
|
|
20
|
-
const sessions = new Map(sessionsArray);
|
|
21
|
-
const sessionManager = SessionManager.getInstance(serverconfig.redis.url);
|
|
22
|
-
for (const [key, value] of sessions.entries()) {
|
|
23
|
-
const sessionData = await sessionManager.getSession(key);
|
|
24
|
-
if (sessionData) {
|
|
25
|
-
const userSessionIds = sessionData.userSessionIds;
|
|
26
|
-
if (!userSessionIds.some((sessionId) => sessionId === value)) {
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
const newSessions = userSessionIds.filter((sessionId) => sessionId !== value);
|
|
30
|
-
if (newSessions.length === 0) {
|
|
31
|
-
await ky.put(`${serverconfig.tileServerURL}/tileserver/reset/${sessionData.imageSessionId}`);
|
|
32
|
-
await sessionManager.deleteSession(key);
|
|
33
|
-
} else {
|
|
34
|
-
sessionData.userSessionIds = newSessions;
|
|
35
|
-
await sessionManager.setSession(key, sessionData);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
res.send({ message: "Sessions cleared" });
|
|
40
|
-
} else {
|
|
41
|
-
res.status(404).send("Redis not configured");
|
|
42
|
-
}
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.log(e);
|
|
45
|
-
res.status(404).send("Error clearing sessions");
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
api
|
|
51
|
-
};
|