-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.meta
executable file
·51 lines (47 loc) · 1.53 KB
/
run.meta
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
#!/usr/bin/env Rscript
library(GMMAT)
library(data.table)
## Expects : a variant set file and a set of directories
argv = commandArgs(trailingOnly = TRUE)
group_file=argv[1]
argv=argv[-1]
cohorts=NULL
files=NULL
for(d in argv){
flist=list.files(d, pattern="*.out$")
cohort=strsplit(flist[1], ".", fixed=T)[[1]][1]
cohorts=c(cohorts,cohort)
filepat=sub(paste0(cohort,"."), "", flist)
cat(paste("[INFO]", length(flist), "files detected for cohort", cohort, "\n"))
if(is.null(files)){
files=filepat
cat(paste("[INFO] init with",length(files), "\n"))
}else{
oldfiles=files
files=intersect(filepat, files)
if(length(oldfiles)!=length(files)){
print(paste("[Warning]: Dropped", length(oldfiles)-length(files), "files not found in this cohort"))
}
}
}
#we now meta-analyse every file separately
cat(paste("[INFO] Meta-analysing",length(files), "files for",length(cohorts),"cohorts.\n"))
flush.console()
for(f in files){
toanalyse=paste(argv, paste(cohorts,f,sep="."), sep="/")
nfiles=sapply(toanalyse, function(x){
scorefiles=Sys.glob(paste0(x, ".score.*"))
return(length(scorefiles))
})
meta=SMMAT.meta(meta.files.prefix=toanalyse, n.files=nfiles,
group.file=group_file,
MAF.range=c(1e-10, 0.05),
MAF.weights.beta = c(1,1),
miss.cutoff=0.01,
tests=c("O", "E"),
rho=(0:10)/10,
use.minor.allele=T
)
print(paste(paste(cohorts, collapse="."), f, sep="."))
fwrite(meta, paste(paste(cohorts, collapse="."), f, sep="."), sep="\t", na=NA, quote=F)
}