aboutsummaryrefslogtreecommitdiff
path: root/scripts/wgcna_analysis.R
diff options
context:
space:
mode:
authorAlexander Kabui2021-09-23 12:22:10 +0300
committerAlexander Kabui2021-09-23 12:22:10 +0300
commit3d36fe96c94cebb6e7ea93b735148b25c4b95f6d (patch)
treec6f25bd191ae16e0637b3b9f5ad6823ef521c308 /scripts/wgcna_analysis.R
parent0f871f49e749eb625f58326adf8f80b3d3b5b932 (diff)
downloadgenenetwork3-3d36fe96c94cebb6e7ea93b735148b25c4b95f6d.tar.gz
load data from json file and and convert to dt
Diffstat (limited to 'scripts/wgcna_analysis.R')
-rw-r--r--scripts/wgcna_analysis.R22
1 files changed, 12 insertions, 10 deletions
diff --git a/scripts/wgcna_analysis.R b/scripts/wgcna_analysis.R
index 267cd86..d0ba91a 100644
--- a/scripts/wgcna_analysis.R
+++ b/scripts/wgcna_analysis.R
@@ -2,26 +2,29 @@
library(WGCNA);
library(stringi);
+library(rjson)
options(stringsAsFactors = FALSE);
imgDir = Sys.getenv("GENERATED_IMAGE_DIR")
-# load expression data **assumes csv format row(traits)(columns info+samples)
+# load expression data **assumes from json files row(traits)(columns info+samples)
# pass the file_path as arg
-inputData <- read.csv(file = "wgcna_data.csv")
+results <- fromJSON(file = "file_path.json")
-# transform expressionData
+# trait_sample_data <- results$trait_sample_data
+trait_sample_data <- do.call(rbind, results$trait_sample_data)
-dataExpr <- as.data.frame(t(inputData));
-## data cleaning
+dataExpr <- data.frame(apply(trait_sample_data, 2, function(x) as.numeric(as.character(x))))
+# trait_sample_data <- as.data.frame(t(results$trait_sample_data))
+# transform expressionData
+dataExpr <- data.frame(t(dataExpr))
gsg = goodSamplesGenes(dataExpr, verbose = 3);
# https://horvath.genetics.ucla.edu/html/CoexpressionNetwork/Rpackages/
-
if (!gsg$allOK)
{
if (sum(!gsg$goodGenes)>0)
@@ -49,7 +52,7 @@ network <- blockwiseModules(dataExpr,
corType = "pearson",
#adjacency matrix options
- power = sft$powerEstimate,
+ power = 5,
networkType = "unsigned",
#TOM options
TOMtype = "unsigned",
@@ -70,14 +73,13 @@ genImageRandStr <- function(prefix){
return(paste(randStr,".png",sep=""))
}
-mergedColors <- labels2colors(net$colors)
+mergedColors <- labels2colors(network$colors)
imageLoc <- file.path(imgDir,genImageRandStr("WGCNAoutput"))
-
png(imageLoc,width=1000,height=600,type='cairo-png')
-plotDendroAndColors(network$dendrograms[[1]],mergedColors[net$blockGenes[[1]]],
+plotDendroAndColors(network$dendrograms[[1]],mergedColors[network$blockGenes[[1]]],
"Module colors",
dendroLabels = FALSE, hang = 0.03,
addGuide = TRUE, guideHang = 0.05)