@sjcrh/proteinpaint-server 2.98.1-0 → 2.98.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/utils/corr.R ADDED
@@ -0,0 +1,36 @@
1
+ # Test syntax: cat ~/sjpp/test.txt | time Rscript corr.R
2
+
3
+ # Load required packages
4
+ suppressWarnings({
5
+ library(jsonlite)
6
+ })
7
+
8
+ # Read JSON input from stdin
9
+ con <- file("stdin", "r")
10
+ json <- readLines(con, warn=FALSE)
11
+ close(con)
12
+ input <- fromJSON(json)
13
+
14
+ ids <- input$terms$id
15
+ v1 <- input$terms$v1
16
+ v2 <- input$terms$v2
17
+
18
+ coeffs <- c()
19
+ pvalues <- c()
20
+ sample_sizes <- c()
21
+ for (i in 1:length(v1)) {
22
+ cor <- cor.test(as.numeric(unlist(v1[i])), as.numeric(unlist(v2[i])), method = input$method)
23
+ coeffs <- c(coeffs, cor$estimate)
24
+ pvalues <- c(pvalues, cor$p.value)
25
+ sample_sizes <- c(sample_sizes, length(as.numeric(unlist(v1[i]))))
26
+ }
27
+
28
+ # Adjusting for multiple testing correction
29
+ adjust_p_values <- p.adjust(pvalues, method = "fdr")
30
+ output <- data.frame(ids, coeffs, pvalues, adjust_p_values, sample_sizes)
31
+ names(output)[1] <- "id"
32
+ names(output)[2] <- "correlation"
33
+ names(output)[3] <- "original_p_value"
34
+ names(output)[4] <- "adjusted_p_value"
35
+ names(output)[5] <- "sample_size"
36
+ cat(paste0("adjusted_p_values:", toJSON(output)))