@sjcrh/proteinpaint-server 2.37.0 → 2.38.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/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
- B_left <- sum(tsPs <= -abs(tsO))
205
- B_right <- sum(tsPs >= abs(tsO))
206
- B <- B_left + B_right
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
 
@@ -1,5 +1,5 @@
1
1
  # Usage:
2
- # time Rscript fastclust.R in.json
2
+ # time Rscript hclust.R in.json
3
3
 
4
4
  # Image is in Rplots.pdf
5
5
 
@@ -68,7 +68,6 @@ RowDist <- dist(normalized_matrix, method = "euclidean") # Transposing the matri
68
68
 
69
69
 
70
70
  # Hierarchical clustering
71
- print (input$cluster_method)
72
71
  RowDend <- hclust(RowDist, method = tolower(input$cluster_method))
73
72
  #RowDend <- flashClust(RowDist, method = tolower(input$cluster_method))
74
73
  #print (RowDend$order)
@@ -93,8 +92,19 @@ row_node_coordinates <- get_nodes_xy(
93
92
  RowDendro,
94
93
  type = "rectangle"
95
94
  )
96
- print ("RowCoordinates")
97
- print (row_node_coordinates)
95
+
96
+ row_node_df <- as.data.frame(row_node_coordinates)
97
+ colnames(row_node_df) <- c("x","y")
98
+
99
+ #row_node_transform <- apply(row_node_coordinates, 1, function(row){
100
+ # lapply(c(1,2), function(col_index){
101
+ # if (col_index == 1) {
102
+ # list(x=row[col_index])
103
+ # } else if (col_index == 2) {
104
+ # list(y=row[col_index])
105
+ # }
106
+ # })
107
+ #})
98
108
 
99
109
  # For columns (i.e samples)
100
110
  ColumnDist <- dist(t(normalized_matrix), method = "euclidean") # Transposing the matrix
@@ -106,14 +116,15 @@ ColumnDend <- hclust(ColumnDist, method = tolower(input$cluster_method))
106
116
  ColumnDendro <- as.dendrogram(ColumnDend)
107
117
  #plot (ColumnDendro)
108
118
 
119
+ #print ("ColumnCoordinates")
109
120
  col_node_coordinates <- get_nodes_xy(
110
121
  ColumnDendro,
111
122
  type = "rectangle"
112
123
  )
113
- print ("ColumnCoordinates")
114
- print (col_node_coordinates)
115
124
 
116
- print ("Done")
125
+ col_node_df <- as.data.frame(col_node_coordinates)
126
+ colnames(col_node_df) <- c("x","y")
127
+
117
128
  # Sorting the matrix
118
129
 
119
130
  SortedMatrix <- normalized_matrix[RowDend$order, ColumnDend$order]
@@ -123,11 +134,52 @@ SortedColumnNames <- colnames(normalized_matrix)[ColumnDend$order]
123
134
  #m <- matrix(SortedMatrix,length(SortedRowNames),length(SortedColumnNames))
124
135
  #colnames(m) <- SortedColumnNames
125
136
  #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.
137
+
138
+ output_df <- list()
139
+ output_df$method <- input$cluster_method
140
+ output_df$RowNodeJson <- row_node_df
141
+ output_df$ColNodeJson <- col_node_df
142
+ #output_df$RowDendOrder <- {lapply(1:length(RowDend$order), function(y){
143
+ # list(i=RowDend$order[y])
144
+ #})}
145
+ row_dend_order_df <- as.data.frame(RowDend$order)
146
+ colnames(row_dend_order_df) <- c("ind")
147
+ output_df$RowDendOrder <- row_dend_order_df
148
+
149
+ col_dend_order_df <- as.data.frame(ColumnDend$order)
150
+ colnames(col_dend_order_df) <- c("ind")
151
+ output_df$ColumnDendOrder <- col_dend_order_df
152
+
153
+ #output_df$SortedRowNames <- {lapply(1:length(SortedRowNames), function(y){
154
+ # list(gene=SortedRowNames[y])
155
+ #})}
156
+
157
+ sorted_row_names_df <- as.data.frame(SortedRowNames)
158
+ colnames(sorted_row_names_df) <- c("gene")
159
+ output_df$SortedRowNames <- sorted_row_names_df
160
+
161
+ sorted_col_names_df <- as.data.frame(SortedColumnNames)
162
+ colnames(sorted_col_names_df) <- c("sample")
163
+ output_df$SortedColumnNames <- sorted_col_names_df
164
+
165
+ output_df$OutputMatrix <- {lapply(1:length(normalized_matrix), function(y){
166
+ list(elem=normalized_matrix[y])
167
+ })}
168
+
169
+ # Converting to data frame does not work for the raw counts since the key of the json needs to be unique.
170
+
171
+ #output_matrix_df <- as.data.frame(normalized_matrix)
172
+ #colnames(output_matrix_df) <- c(rep("elem",dim(normalized_matrix)[2]))
173
+ #print (output_matrix_df)
174
+ #output_df$OutputMatrix <- output_matrix_df
175
+
176
+ toJSON(output_df)
177
+
178
+ #cat("rowindexes",RowDend$order,"\n",sep="\t") # Prints out row indices
179
+ #cat("colindexes",ColumnDend$order,"\n",sep="\t") # Prints out column indicies
180
+ #cat("rownames",SortedRowNames,"\n",sep="\t") # Prints out row names
181
+ #cat("colnames",SortedColumnNames,"\n",sep="\t") # Prints out column names
182
+ #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
183
 
132
184
 
133
185
  #df <- melt(m)