aboutsummaryrefslogtreecommitdiff
path: root/scripts/ctl_analysis.R
blob: d9a937f48c2937510ab95e6db3bff7311ca71c91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
library(ctl)
library(rjson)

options(stringsAsFactors = FALSE);

# The genotypes.csv file containing the genotype matrix is stored individuals (rows) x genetic marker (columns):

args = commandArgs(trailingOnly=TRUE)

if (length(args)==0) {
  stop("Argument for the data file", call.=FALSE)
} else {
  # default output file
  json_file_path = args[1]
}

# add validation for the files
input <- fromJSON(file = json_file_path)


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")


ctls <- CTLscan(geno,traits,strategy=input$strategy,
	nperm=input$nperms,parametric =input$parametric,
	nthreads=6,verbose=TRUE)


# 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="_")

	return(paste(randStr,".png",sep=""))
}


#output matrix significant CTL interactions with 4 columns: trait, marker, trait, lod
sign <- CTLsignificant(ctls,significance = input$significance)
 
# Create the lineplot
imageLoc = file.path(imgDir,genImageRandStr("CTLline"))

png(imageLoc,width=1000,height=600,type='cairo-png')

lineplot(res, significance=input$significance)


json_data <- list(significance=signs,
	images=lists("image_1"=imageLoc),
	network_figure_location="/location")