aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlexander Kabui2022-01-13 15:21:19 +0300
committerBonfaceKilz2022-01-22 09:23:14 +0300
commitdb4cb5b9fa4e574e0c78a8443f9ddf8859b1205b (patch)
tree721ccdb9dc215f43365ac265b10948b8eec089c9 /scripts
parentb6bd968702b21f2cd8ed72be686d77a8666e2877 (diff)
downloadgenenetwork3-db4cb5b9fa4e574e0c78a8443f9ddf8859b1205b.tar.gz
fixes for ctl script:generate ctl ctl_significant json
Diffstat (limited to 'scripts')
-rw-r--r--scripts/ctl_analysis.R51
1 files changed, 33 insertions, 18 deletions
diff --git a/scripts/ctl_analysis.R b/scripts/ctl_analysis.R
index 8c831ad..91fa746 100644
--- a/scripts/ctl_analysis.R
+++ b/scripts/ctl_analysis.R
@@ -1,3 +1,4 @@
+
library(ctl)
library(stringi);
library(rjson)
@@ -21,29 +22,35 @@ json_file_path
# add validation for the files
input <- fromJSON(file = json_file_path)
-genoData <- input$geno
-phenoData <- input$pheno
+cat("The input data is \n")
+
+
+
+genoData <- input$genoData
+phenoData <- input$phenoData
-formData <- input$form
+# formData <- input$form
# create the matixes
-genoData
+
+# genotypes Matrix of genotypes. (individuals x markers)
+# phenotypes Matrix of phenotypes. (individuals x phenotypes)
+
geno_matrix = t(matrix(unlist(genoData$genotypes),
nrow=length(genoData$markernames), ncol=length(genoData$individuals),
dimnames=list(genoData$markernames, genoData$individuals), byrow=TRUE))
+
pheno_matrix = t(matrix(as.numeric(unlist(phenoData$traits)), nrow=length(phenoData$trait_db_list), ncol=length(
phenoData$individuals), dimnames= list(phenoData$trait_db_list, phenoData$individuals), byrow=TRUE))
-# Use a data frame to store the objects
-pheno = data.frame(pheno_matrix, check.names=FALSE)
-geno = data.frame(geno_matrix, check.names=FALSE)
+# # Use a data frame to store the objects
+ctls <- CTLscan(geno_matrix,pheno_matrix,nperm=input$nperm,strategy=input$strategy,parametric=TRUE,nthreads=3,verbose=TRUE)
-ctls <- CTLscan(geno,pheno,verbose=TRUE)
-# same function used in a different script:refactor
+# # same function used in a different script:refactor
genImageRandStr <- function(prefix){
randStr <- paste(prefix,stri_rand_strings(1, 9, pattern = "[A-Za-z0-9]"),sep="_")
@@ -52,16 +59,24 @@ genImageRandStr <- function(prefix){
}
-#output matrix significant CTL interactions with 4 columns: trait, marker, trait, lod
-sign <- CTLsignificant(ctls,significance = formData$significance)
+
+# #output matrix significant CTL interactions with 4 columns: trait, marker, trait, lod
+ctl_significant <- CTLsignificant(ctls,significance = 0.05)
-# Create the lineplot
-imageLoc = file.path(imgDir,genImageRandStr("CTLline"))
+# # Create the lineplot
+# imageLoc = file.path(imgDir,genImageRandStr("CTLline"))
+
+# png(imageLoc,width=1000,height=600,type='cairo-png')
+
+# ctl.lineplot(ctls, significance=formData$significance)
+
+
+# rename coz of duplicate key names
+colnames(sign) = c("trait","marker","trait_2","LOD","dcor")
+
+json_data <- list(significance_table = ctl_significant)
-png(imageLoc,width=1000,height=600,type='cairo-png')
-ctl.lineplot(ctls, significance=formData$significance)
+json_data <- toJSON(json_data)
-json_data <- list(significance=sign,
- images=list("image_1"=imageLoc),
- network_figure_location="/location") \ No newline at end of file
+write(json_data,file= json_file_path) \ No newline at end of file