@sjcrh/proteinpaint-server 2.29.1 → 2.29.3
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/cards/index.json +3 -3
- package/package.json +2 -2
- package/routes/termdb.categories.ts +3 -3
- package/server.js +1 -1
- package/utils/edge.R +86 -0
package/utils/edge.R
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# json='{"case":"SJMB066856,SJMB069601,SJMB030827,SJMB030838,SJMB031131,SJMB031227,SJMB077221,SJMB077223","control":"SJMB069596,SJMB069587,SJMB074736,SJMB030488,SJMB030825,SJMB031110,SJMB032998,SJMB033002","input_file":"/Users/rpaul1/pp_data/files/hg38/sjmb12/rnaseq/geneCounts.txt"}' && time echo $json | Rscript edge.R
|
|
2
|
+
|
|
3
|
+
# json='{"case":"SJMB030827,SJMB030838,SJMB064540,SJMB064538,SJMB064520,SJMB064535,SJMB031131,SJMB031227","control":"SJMB030488,SJMB030825,SJMB064537,SJMB064510,SJMB064533,SJMB064534,SJMB031110","input_file":"/Users/rpaul1/pp_data/files/hg38/sjmb12/rnaseq/geneCounts.txt"}' && time echo $json | Rscript edge.R
|
|
4
|
+
|
|
5
|
+
# Checking if all R packages are installed or not, if not installing each one of them
|
|
6
|
+
|
|
7
|
+
jsonlite_path <- system.file(package='jsonlite')
|
|
8
|
+
if (nchar(jsonlite_path) == 0) {
|
|
9
|
+
install.packages("jsonlite", repos='https://cran.case.edu/')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
edgeR_path <- system.file(package='edgeR')
|
|
13
|
+
if (nchar(edgeR_path) == 0) {
|
|
14
|
+
BiocManager::install("edgeR")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
readr_path <- system.file(package='readr')
|
|
18
|
+
if (nchar(readr_path) == 0) {
|
|
19
|
+
install.packages("readr", repos='https://cran.case.edu/')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
library(jsonlite)
|
|
24
|
+
library(stringr)
|
|
25
|
+
library(readr)
|
|
26
|
+
suppressWarnings({
|
|
27
|
+
suppressPackageStartupMessages(library(edgeR))
|
|
28
|
+
suppressPackageStartupMessages(library(dplyr))
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
infile <- file("stdin")
|
|
32
|
+
input <- fromJSON(infile)
|
|
33
|
+
print (input$output_path)
|
|
34
|
+
cases <- unlist(strsplit(input$case, ","))
|
|
35
|
+
controls <- unlist(strsplit(input$control, ","))
|
|
36
|
+
combined <- c("geneID","geneSymbol",cases,controls)
|
|
37
|
+
#data %>% select(all_of(combined))
|
|
38
|
+
read_file_time_start <- Sys.time()
|
|
39
|
+
read_counts <- read_tsv(input$input_file, col_names = TRUE, col_select = combined)
|
|
40
|
+
geneIDs <- unlist(read_counts[1])
|
|
41
|
+
geneSymbols <- unlist(read_counts[2])
|
|
42
|
+
read_counts <- select(read_counts, -geneID)
|
|
43
|
+
read_counts <- select(read_counts, -geneSymbol)
|
|
44
|
+
read_file_time_stop <- Sys.time()
|
|
45
|
+
print (read_file_time_stop - read_file_time_start)
|
|
46
|
+
|
|
47
|
+
diseased <- rep("Diseased", length(cases))
|
|
48
|
+
control <- rep("Control", length(controls))
|
|
49
|
+
conditions <- c(diseased, control)
|
|
50
|
+
tabs <- rep("\t",length(geneIDs))
|
|
51
|
+
gene_id_symbols <- paste0(geneIDs,tabs,geneSymbols)
|
|
52
|
+
y <- DGEList(counts = as.matrix(read_counts), group = conditions, genes = gene_id_symbols)
|
|
53
|
+
keep <- filterByExpr(y)
|
|
54
|
+
y <- y[keep, keep.lib.sizes = FALSE]
|
|
55
|
+
y <- calcNormFactors(y, method = "TMM")
|
|
56
|
+
#print (y)
|
|
57
|
+
calculate_DE_time_start <- Sys.time()
|
|
58
|
+
dge <- estimateDisp(y = y)
|
|
59
|
+
et <- exactTest(object = dge)
|
|
60
|
+
calculate_DE_time_stop <- Sys.time()
|
|
61
|
+
print ("Time to calculate DE")
|
|
62
|
+
print (calculate_DE_time_stop - calculate_DE_time_start)
|
|
63
|
+
#print (et)
|
|
64
|
+
logfc <- et$table$logFC
|
|
65
|
+
logcpm <- et$table$logCPM
|
|
66
|
+
pvalues <- et$table$PValue
|
|
67
|
+
genes_matrix <- str_split_fixed(unlist(et$genes),"\t",2)
|
|
68
|
+
geneids <- unlist(genes_matrix[,1])
|
|
69
|
+
genesymbols <- unlist(genes_matrix[,2])
|
|
70
|
+
adjust_p_values <- p.adjust(pvalues, method = "fdr")
|
|
71
|
+
|
|
72
|
+
output <- data.frame(geneids,genesymbols,logfc,-log10(pvalues),-log10(adjust_p_values))
|
|
73
|
+
names(output)[1] <- "gene_name"
|
|
74
|
+
names(output)[2] <- "gene_symbol"
|
|
75
|
+
names(output)[3] <- "fold_change"
|
|
76
|
+
names(output)[4] <- "original_p_value"
|
|
77
|
+
names(output)[5] <- "adjusted_p_value"
|
|
78
|
+
|
|
79
|
+
output_json <- toJSON(output)
|
|
80
|
+
print ("output_json")
|
|
81
|
+
output_file <- paste0(input$output_path,"/r_output.txt")
|
|
82
|
+
print (output_file)
|
|
83
|
+
cat(output_json, file = output_file)
|
|
84
|
+
#top_degs = topTags(object = et, n = "Inf")
|
|
85
|
+
#print ("top_degs")
|
|
86
|
+
#print (top_degs)
|