aboutsummaryrefslogtreecommitdiff
path: root/scripts/ctl_analysis.R
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/ctl_analysis.R')
-rw-r--r--scripts/ctl_analysis.R36
1 files changed, 25 insertions, 11 deletions
diff --git a/scripts/ctl_analysis.R b/scripts/ctl_analysis.R
index d9a937f..8c831ad 100644
--- a/scripts/ctl_analysis.R
+++ b/scripts/ctl_analysis.R
@@ -1,4 +1,5 @@
library(ctl)
+library(stringi);
library(rjson)
options(stringsAsFactors = FALSE);
@@ -7,6 +8,8 @@ options(stringsAsFactors = FALSE);
args = commandArgs(trailingOnly=TRUE)
+imgDir = Sys.getenv("GENERATED_IMAGE_DIR")
+
if (length(args)==0) {
stop("Argument for the data file", call.=FALSE)
} else {
@@ -14,20 +17,32 @@ if (length(args)==0) {
json_file_path = args[1]
}
+json_file_path
# add validation for the files
input <- fromJSON(file = json_file_path)
+genoData <- input$geno
+phenoData <- input$pheno
+
+formData <- input$form
+# create the matixes
+genoData
+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))
-genotypes <- read.csv(input$geno_file,row.names=1, header=FALSE, sep="\t")
-# The phenotypes.csv file containing individuals (rows) x traits (columns) measurements:
-traits <- read.csv(input$pheno_file,row.names=1, header=FALSE, sep="\t")
+# Use a data frame to store the objects
+pheno = data.frame(pheno_matrix, check.names=FALSE)
+geno = data.frame(geno_matrix, check.names=FALSE)
-ctls <- CTLscan(geno,traits,strategy=input$strategy,
- nperm=input$nperms,parametric =input$parametric,
- nthreads=6,verbose=TRUE)
+ctls <- CTLscan(geno,pheno,verbose=TRUE)
+
# same function used in a different script:refactor
genImageRandStr <- function(prefix){
@@ -38,16 +53,15 @@ genImageRandStr <- function(prefix){
#output matrix significant CTL interactions with 4 columns: trait, marker, trait, lod
-sign <- CTLsignificant(ctls,significance = input$significance)
+sign <- CTLsignificant(ctls,significance = formData$significance)
# Create the lineplot
imageLoc = file.path(imgDir,genImageRandStr("CTLline"))
png(imageLoc,width=1000,height=600,type='cairo-png')
-lineplot(res, significance=input$significance)
-
+ctl.lineplot(ctls, significance=formData$significance)
-json_data <- list(significance=signs,
- images=lists("image_1"=imageLoc),
+json_data <- list(significance=sign,
+ images=list("image_1"=imageLoc),
network_figure_location="/location") \ No newline at end of file