@sjcrh/proteinpaint-server 2.37.0 → 2.38.1
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 +2 -2
- package/routes/termdb.getdescrstats.ts +145 -0
- package/routes/termdb.singlecellSamples.ts +1 -0
- package/server.js +1 -1
- package/server.js.map +1 -1
- package/utils/cuminc.R +3 -4
- package/utils/hclust.R +125 -0
- package/utils/fastclust.R +0 -164
package/utils/cuminc.R
CHANGED
|
@@ -201,10 +201,9 @@ runPermutations <- function(M, dat) {
|
|
|
201
201
|
# function to compute p-value for permutation test
|
|
202
202
|
# perform two-tailed test
|
|
203
203
|
getPermutePvalue <- function(tsPs, tsO) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
pvalue <- signif((B+1)/(length(tsPs)+1), 2)
|
|
204
|
+
P_left <- sum(tsPs <= -abs(tsO))/(length(tsPs)+1)
|
|
205
|
+
P_right <- sum(tsPs >= abs(tsO))/(length(tsPs)+1)
|
|
206
|
+
pvalue <- signif(P_left + P_right, 2)
|
|
208
207
|
return(pvalue)
|
|
209
208
|
}
|
|
210
209
|
|
package/utils/hclust.R
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Usage:
|
|
2
|
+
# time Rscript hclust.R in.json
|
|
3
|
+
|
|
4
|
+
# Image is in Rplots.pdf
|
|
5
|
+
|
|
6
|
+
############################
|
|
7
|
+
# !!! NOTE !!! #
|
|
8
|
+
############################
|
|
9
|
+
# must not auto-install missing package in any R script!
|
|
10
|
+
# declare required packages in dockerfile
|
|
11
|
+
# at 2023/12, a problem emerged for pp container running in gdc qa-pink
|
|
12
|
+
# since the docker images lacks the packages, but the auto-install was prevented due to container safety (no internet query)
|
|
13
|
+
# this script will not run, leading to hard to decipher crashing
|
|
14
|
+
|
|
15
|
+
# To plot the heatmap uncomment line `library(ggplot2) and lines after "Visualization" comment
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
suppressPackageStartupMessages(library(dendextend))
|
|
20
|
+
library(jsonlite)
|
|
21
|
+
#library(flashClust)
|
|
22
|
+
library(dendextend)
|
|
23
|
+
library(reshape)
|
|
24
|
+
#library(ggplot2) # Uncomment this line to plot heatmap in R
|
|
25
|
+
|
|
26
|
+
# Distance matrix
|
|
27
|
+
args <- commandArgs(trailingOnly = T)
|
|
28
|
+
if (length(args) != 1) stop("Usage: Rscript test.R in.json > results")
|
|
29
|
+
infile <- args[1]
|
|
30
|
+
input <- fromJSON(infile)
|
|
31
|
+
|
|
32
|
+
#if (length(input$valueIsTransformed) == 0 || input$valueIsTransformed == FALSE) {
|
|
33
|
+
# normalized_matrix <- t(scale(t(input$matrix))) # Applying z-score normalization
|
|
34
|
+
#} else { # No normalization
|
|
35
|
+
# normalized_matrix <- input$matrix
|
|
36
|
+
#}
|
|
37
|
+
|
|
38
|
+
#rownames(normalized_matrix) <- input$row_names
|
|
39
|
+
#colnames(normalized_matrix) <- input$col_names
|
|
40
|
+
#normalized_matrix <- na.omit(normalized_matrix) # Removes rows with NA values
|
|
41
|
+
|
|
42
|
+
#print ("normalized_matrix")
|
|
43
|
+
#print (dim(normalized_matrix))
|
|
44
|
+
|
|
45
|
+
# For columns (i.e samples)
|
|
46
|
+
RowDist <- dist(input$matrix, method = "euclidean") # Transposing the matrix
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Hierarchical clustering
|
|
50
|
+
RowDend <- hclust(RowDist, method = tolower(input$cluster_method))
|
|
51
|
+
#RowDend <- flashClust(RowDist, method = tolower(input$cluster_method))
|
|
52
|
+
RowDendro <- as.dendrogram(RowDend)
|
|
53
|
+
|
|
54
|
+
row_node_coordinates <- get_nodes_xy(
|
|
55
|
+
RowDendro,
|
|
56
|
+
type = "rectangle"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
row_node_df <- as.data.frame(row_node_coordinates)
|
|
60
|
+
colnames(row_node_df) <- c("x","y")
|
|
61
|
+
|
|
62
|
+
# For columns (i.e samples)
|
|
63
|
+
ColumnDist <- dist(t(input$matrix), method = "euclidean") # Transposing the matrix
|
|
64
|
+
|
|
65
|
+
# Hierarchical clustering
|
|
66
|
+
|
|
67
|
+
ColumnDend <- hclust(ColumnDist, method = tolower(input$cluster_method))
|
|
68
|
+
#ColumnDend <- flashClust(ColumnDist,method = tolower(input$cluster_method))
|
|
69
|
+
ColumnDendro <- as.dendrogram(ColumnDend)
|
|
70
|
+
#plot (ColumnDendro)
|
|
71
|
+
|
|
72
|
+
#print ("ColumnCoordinates")
|
|
73
|
+
col_node_coordinates <- get_nodes_xy(
|
|
74
|
+
ColumnDendro,
|
|
75
|
+
type = "rectangle"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
col_node_df <- as.data.frame(col_node_coordinates)
|
|
79
|
+
colnames(col_node_df) <- c("x","y")
|
|
80
|
+
|
|
81
|
+
# Sorting the matrix
|
|
82
|
+
|
|
83
|
+
#SortedMatrix <- normalized_matrix[RowDend$order, ColumnDend$order]
|
|
84
|
+
SortedRowNames <- input$row_names[RowDend$order]
|
|
85
|
+
SortedColumnNames <- input$col_names[ColumnDend$order]
|
|
86
|
+
|
|
87
|
+
#m <- matrix(SortedMatrix,length(SortedRowNames),length(SortedColumnNames))
|
|
88
|
+
#colnames(m) <- SortedColumnNames
|
|
89
|
+
#rownames(m) <- SortedRowNames
|
|
90
|
+
|
|
91
|
+
output_df <- list()
|
|
92
|
+
output_df$method <- input$cluster_method
|
|
93
|
+
output_df$RowNodeJson <- row_node_df
|
|
94
|
+
output_df$ColNodeJson <- col_node_df
|
|
95
|
+
|
|
96
|
+
row_dend_order_df <- as.data.frame(RowDend$order)
|
|
97
|
+
colnames(row_dend_order_df) <- c("ind")
|
|
98
|
+
output_df$RowDendOrder <- row_dend_order_df
|
|
99
|
+
|
|
100
|
+
col_dend_order_df <- as.data.frame(ColumnDend$order)
|
|
101
|
+
colnames(col_dend_order_df) <- c("ind")
|
|
102
|
+
output_df$ColumnDendOrder <- col_dend_order_df
|
|
103
|
+
|
|
104
|
+
sorted_row_names_df <- as.data.frame(SortedRowNames)
|
|
105
|
+
colnames(sorted_row_names_df) <- c("gene")
|
|
106
|
+
output_df$SortedRowNames <- sorted_row_names_df
|
|
107
|
+
|
|
108
|
+
sorted_col_names_df <- as.data.frame(SortedColumnNames)
|
|
109
|
+
colnames(sorted_col_names_df) <- c("sample")
|
|
110
|
+
output_df$SortedColumnNames <- sorted_col_names_df
|
|
111
|
+
toJSON(output_df)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# Visualization of heatmap, uncomment code below to get ggplot2 image of heatmap
|
|
115
|
+
|
|
116
|
+
#SortedMatrix <- input$matrix[RowDend$order, ColumnDend$order]
|
|
117
|
+
#SortedRowNames <- rownames(input$matrix)[RowDend$order]
|
|
118
|
+
#SortedColumnNames <- colnames(input$matrix)[ColumnDend$order]
|
|
119
|
+
#
|
|
120
|
+
#matrix_melt <- melt(SortedMatrix)
|
|
121
|
+
#ggplot(data = matrix_melt, aes(x = X1, y = X2, fill = value)) +
|
|
122
|
+
# geom_tile() + scale_fill_gradient(low="blue", high="red")
|
|
123
|
+
|
|
124
|
+
#ggsave("heatmap.png")
|
|
125
|
+
|
package/utils/fastclust.R
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
# Usage:
|
|
2
|
-
# time Rscript fastclust.R in.json
|
|
3
|
-
|
|
4
|
-
# Image is in Rplots.pdf
|
|
5
|
-
|
|
6
|
-
############################
|
|
7
|
-
# !!! NOTE !!! #
|
|
8
|
-
############################
|
|
9
|
-
# must not auto-install missing package in any R script!
|
|
10
|
-
# declare required packages in dockerfile
|
|
11
|
-
# at 2023/12, a problem emerged for pp container running in gdc qa-pink
|
|
12
|
-
# since the docker images lacks the packages, but the auto-install was prevented due to container safety (no internet query)
|
|
13
|
-
# this script will not run, leading to hard to decipher crashing
|
|
14
|
-
|
|
15
|
-
#ggplot2_path <- system.file(package='ggplot2')
|
|
16
|
-
#if (nchar(ggplot2_path) == 0) {
|
|
17
|
-
# install.packages("ggplot2", repos='https://cran.case.edu/')
|
|
18
|
-
#}
|
|
19
|
-
#
|
|
20
|
-
#jsonlite_path <- system.file(package='jsonlite')
|
|
21
|
-
#if (nchar(jsonlite_path) == 0) {
|
|
22
|
-
# install.packages("jsonlite", repos='https://cran.case.edu/')
|
|
23
|
-
#}
|
|
24
|
-
#
|
|
25
|
-
#dendextend_path <- system.file(package='dendextend')
|
|
26
|
-
#if (nchar(dendextend_path) == 0) {
|
|
27
|
-
# install.packages("dendextend", repos='https://cran.case.edu/')
|
|
28
|
-
#}
|
|
29
|
-
#
|
|
30
|
-
#reshape_path <- system.file(package='reshape')
|
|
31
|
-
#if (nchar(reshape_path) == 0) {
|
|
32
|
-
# install.packages("reshape", repos='https://cran.case.edu/')
|
|
33
|
-
#}
|
|
34
|
-
|
|
35
|
-
#flashClust_path <- system.file(package='flashClust')
|
|
36
|
-
#if (nchar(flashClust_path) == 0) {
|
|
37
|
-
# install.packages("flashClust", repos='https://cran.case.edu/')
|
|
38
|
-
#}
|
|
39
|
-
|
|
40
|
-
suppressPackageStartupMessages(library(dendextend))
|
|
41
|
-
library(jsonlite)
|
|
42
|
-
#library(flashClust)
|
|
43
|
-
library(dendextend)
|
|
44
|
-
library(reshape)
|
|
45
|
-
library(ggplot2)
|
|
46
|
-
|
|
47
|
-
# Distance matrix
|
|
48
|
-
args <- commandArgs(trailingOnly = T)
|
|
49
|
-
if (length(args) != 1) stop("Usage: Rscript test.R in.json > results")
|
|
50
|
-
infile <- args[1]
|
|
51
|
-
input <- fromJSON(infile)
|
|
52
|
-
|
|
53
|
-
if (length(input$valueIsTransformed) == 0 || input$valueIsTransformed == FALSE) {
|
|
54
|
-
normalized_matrix <- t(scale(t(input$matrix))) # Applying z-score normalization
|
|
55
|
-
} else { # No normalization
|
|
56
|
-
normalized_matrix <- input$matrix
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
rownames(normalized_matrix) <- input$row_names
|
|
60
|
-
colnames(normalized_matrix) <- input$col_names
|
|
61
|
-
normalized_matrix <- na.omit(normalized_matrix) # Removes rows with NA values
|
|
62
|
-
|
|
63
|
-
#print ("normalized_matrix")
|
|
64
|
-
#print (dim(normalized_matrix))
|
|
65
|
-
|
|
66
|
-
# For columns (i.e samples)
|
|
67
|
-
RowDist <- dist(normalized_matrix, method = "euclidean") # Transposing the matrix
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# Hierarchical clustering
|
|
71
|
-
print (input$cluster_method)
|
|
72
|
-
RowDend <- hclust(RowDist, method = tolower(input$cluster_method))
|
|
73
|
-
#RowDend <- flashClust(RowDist, method = tolower(input$cluster_method))
|
|
74
|
-
#print (RowDend$order)
|
|
75
|
-
#print ("Merge")
|
|
76
|
-
#print (RowDend$merge)
|
|
77
|
-
#print ("Height")
|
|
78
|
-
#print (RowDend$height)
|
|
79
|
-
#print ("Labels")
|
|
80
|
-
#print (RowDend$labels)
|
|
81
|
-
#print ("Calls")
|
|
82
|
-
#print (RowDend$call)
|
|
83
|
-
#print ("Attributes")
|
|
84
|
-
#attributes(RowDend)
|
|
85
|
-
#print ("methods")
|
|
86
|
-
#methods(class=class(RowDend))
|
|
87
|
-
RowDendro <- as.dendrogram(RowDend)
|
|
88
|
-
#print ("Attributes as.dendrogram")
|
|
89
|
-
#attributes(RowDendro)
|
|
90
|
-
#plot(RowDendro)
|
|
91
|
-
|
|
92
|
-
row_node_coordinates <- get_nodes_xy(
|
|
93
|
-
RowDendro,
|
|
94
|
-
type = "rectangle"
|
|
95
|
-
)
|
|
96
|
-
print ("RowCoordinates")
|
|
97
|
-
print (row_node_coordinates)
|
|
98
|
-
|
|
99
|
-
# For columns (i.e samples)
|
|
100
|
-
ColumnDist <- dist(t(normalized_matrix), method = "euclidean") # Transposing the matrix
|
|
101
|
-
|
|
102
|
-
# Hierarchical clustering
|
|
103
|
-
|
|
104
|
-
ColumnDend <- hclust(ColumnDist, method = tolower(input$cluster_method))
|
|
105
|
-
#ColumnDend <- flashClust(ColumnDist,method = tolower(input$cluster_method))
|
|
106
|
-
ColumnDendro <- as.dendrogram(ColumnDend)
|
|
107
|
-
#plot (ColumnDendro)
|
|
108
|
-
|
|
109
|
-
col_node_coordinates <- get_nodes_xy(
|
|
110
|
-
ColumnDendro,
|
|
111
|
-
type = "rectangle"
|
|
112
|
-
)
|
|
113
|
-
print ("ColumnCoordinates")
|
|
114
|
-
print (col_node_coordinates)
|
|
115
|
-
|
|
116
|
-
print ("Done")
|
|
117
|
-
# Sorting the matrix
|
|
118
|
-
|
|
119
|
-
SortedMatrix <- normalized_matrix[RowDend$order, ColumnDend$order]
|
|
120
|
-
SortedRowNames <- rownames(normalized_matrix)[RowDend$order]
|
|
121
|
-
SortedColumnNames <- colnames(normalized_matrix)[ColumnDend$order]
|
|
122
|
-
|
|
123
|
-
#m <- matrix(SortedMatrix,length(SortedRowNames),length(SortedColumnNames))
|
|
124
|
-
#colnames(m) <- SortedColumnNames
|
|
125
|
-
#rownames(m) <- SortedRowNames
|
|
126
|
-
cat("rowindexes",RowDend$order,"\n",sep="\t") # Prints out row indices
|
|
127
|
-
cat("colindexes",ColumnDend$order,"\n",sep="\t") # Prints out column indicies
|
|
128
|
-
cat("rownames",SortedRowNames,"\n",sep="\t") # Prints out row names
|
|
129
|
-
cat("colnames",SortedColumnNames,"\n",sep="\t") # Prints out column names
|
|
130
|
-
cat ("OutputMatrix",normalized_matrix,"\n",sep="\t") # This outputs the 2D array in 1D column-wise. This is later converted to 2D array in nodejs.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
#df <- melt(m)
|
|
134
|
-
#colnames(df) <- c("Genes", "Samples", "value")
|
|
135
|
-
|
|
136
|
-
#ggplot(df, aes(x = Genes, y = Samples, fill = value)) + geom_tile() + scale_fill_gradient(low="blue", high="red") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
|
|
137
|
-
|
|
138
|
-
#ggsave("heatmap.png")
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
##print (SortedMatrix)
|
|
142
|
-
#df <- as.data.frame(SortedMatrix)
|
|
143
|
-
#rownames(df) <- SortedRowNames
|
|
144
|
-
#colnames(df) <- SortedColumnNames
|
|
145
|
-
#print ("DataFrame")
|
|
146
|
-
#print (df)
|
|
147
|
-
##plt <- ggplot(as.data.frame(SortedMatrix), aes(SortedColumnNames,SortedRowNames)) + geom_tile() + theme_minimal()
|
|
148
|
-
#plt <- ggplot(df,aes(x=colname,y=rownames(df))) + geom_tile() + theme_minimal()
|
|
149
|
-
#
|
|
150
|
-
## setting gradient color as red and white
|
|
151
|
-
#plt <- plt + scale_fill_gradient(low="blue", high="red")
|
|
152
|
-
#
|
|
153
|
-
## setting the title and subtitles using
|
|
154
|
-
## title and subtitle
|
|
155
|
-
#plt <- plt + labs(title = "Heatmap")
|
|
156
|
-
#plt <- plt + labs(subtitle = "A simple heatmap using geom_tile()")
|
|
157
|
-
#
|
|
158
|
-
## setting x and y labels using labs
|
|
159
|
-
#plt <- plt + labs(x ="Samples", y ="Genes")
|
|
160
|
-
#
|
|
161
|
-
## plotting the Heatmap
|
|
162
|
-
#plt
|
|
163
|
-
#png("heatmap.png")
|
|
164
|
-
#dev.off()
|