-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_static.R
executable file
·93 lines (81 loc) · 2.83 KB
/
load_static.R
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/home/nwk2/R-2.15.2/bin/Rscript
##Script to read in static data and save it to two Rdata files
#nifty, as it reads from the command line
library(MatrixEQTL)
library(sqldf)
annolist <- list()
snp.exp <- list()
#Usage <SNPEXP|ANNO> (If Using arg SNPEXP) <Use_MatrixEQTL_FileReader(T|F)> <SNP_File> <Expression_File> <Output_Rdata_Path>
#Returns a list in that order
args <- list()
oargs <- commandArgs(trailingOnly=TRUE)
print(oargs)
args$EXPANNO <- oargs[1]
if(args$EXPANNO=="ANNO"){
args$SNP <- oargs[2]
args$EXP <- oargs[3]
args$dpath <- oargs[4]
}else if(args$EXPANNO=="SNPEXP"){
args$MEQTL <- oargs[2]
args$SNP <- oargs[3]
args$EXP <- oargs[4]
args$dpath <- oargs[5]
}else{
stop(args)
}
#Helper Functions
load.data.matrix <- function(filepath){
#Reads in data matrices
rawdat <- read.csv.sql(filepath,sep="\t",header=T,eol="\n")
rawdat <- rawdat[!duplicated(rawdat[,1]),]
rownames(rawdat)<- rawdat[,1]
rawdat <- rawdat[,-1]
rawdat <- data.matrix(rawdat)
colnames(rawdat)<- gsub("_","-",colnames(rawdat))
return(data.matrix(rawdat))
}
load.anno <- function(filepath){
#Reads in Annotations
expargs <- scan(filepath,what="character",nlines=1,sep="\n")
expargs <- strsplit(expargs,split="\t")[[1]]
expargs <- expargs[-1]
tf <- read.csv.sql(filepath,sep="\t",header=T,eol="\n")
colnames(tf)<-expargs
return(tf)
}
if(args$EXPANNO=="ANNO"){
annolist$snp.anno <- load.anno(args$SNP)
annolist$exp.anno <- load.anno(args$EXP)
save(annolist,file=args$dpath)
}else {
if(args$MEQTL=="T"){
snp.exp[["snps"]] <- SlicedData$new()
snp.exp[["snps"]]$fileDelimiter <- "\t"
snp.exp[["snps"]]$fileOmitCharacters <- "-1"
snp.exp[["snps"]]$fileSkipRows <- 1
snp.exp[["snps"]]$fileSkipColumns <- 1
snp.exp[["snps"]]$LoadFile(args$SNP)
snp.exp[["gene"]] <- SlicedData$new(load.data.matrix(args$EXP))
sargs <- scan(args$SNP,what="character",nlines=1,sep="\n")
sargs <- strsplit(sargs,split="\t")[[1]]
sargs <- substr(sargs,1,16)
sargs <- sargs[-1]
expargs <- scan(args$EXP,what="character",nlines=1,sep="\n")
expargs <- strsplit(expargs,split="\t")[[1]]
expargs <- substr(expargs,1,16)
expargs <- expargs[-1]
snp.exp[["snps"]]$ColumnSubsample(match(expargs,sargs,nomatch=0))
}else{
snp.exp[["snps"]] <- SlicedData$new(load.data.matrix(args$SNP))
snp.exp[["gene"]] <- SlicedData$new(load.data.matrix(args$EXP))
sargs <- scan(args$SNP,what="character",nlines=1,sep="\n")
sargs <- strsplit(sargs,split="\t")[[1]]
sargs <- sargs[-1]
expargs <- scan(args$EXP,what="character",nlines=1,sep="\n")
expargs <- strsplit(expargs,split="\t")[[1]]
expargs <- expargs[-1]
snp.exp[["snps"]]$ColumnSubsample(match(expargs,sargs,nomatch=0))
snp.exp[["snps"]]$RowReorder(which(!duplicated(snp.exp[["snps"]]$GetAllRowNames())))
}
save(snp.exp,file=args$dpath)
}