dir("foo")
if ("package:multicore" %in% search()) {
 time.mclapply = unix.time(e2 <- eqtlTests(hm, ~male, targdir="bar", runname="bar",
      geneApply = mclapply ) )
 print(time.lapply)
 print(time.mclapply)
 }
mm = meqtlTests( list(hm, hm), list(~male, ~male))
mm
td = tempdir()
setwd(td)
save(hm, file="hm.rda")
pa = getwd()
obpaths = rep(paste(pa, "hm.rda", sep="/"),2)
mm2 = meqtlTests2( obpaths, list(~male, ~male), targdir="mm2")
mm@fflist[[1]][1:4,1:4]
mm2@fflist[[1]][1:4,1:4]
e1@fflist[[1]][1:4,1:4]  # for nonmissing tests, mm = 2xe1
e4 = eqtlTests(hm[1:5,], ~male, runname="abc")
e5 = eqtlTests(hm[6:10,], ~male, runname="def")
#
# create and illustrate use of the director concept 
#  here we take the managers for two gene sets (1:5, 6:10)
#  and create the director that allows queries across them
#
cd = mkCisTransDirector(list(e4,e5), "demo2x5.sqlite", 
	snptabname="snpnames", probetabname="probenames", 
	probeanno=hm@annotation, commonSNPs=TRUE)
#
# first we have specific snp-gene queries
#
rs2 = GGtools:::snpIdList(cd@mgrs[[1]])[[1]][1:2]
cd[rs2, g20[1]]
#
# now we want values for two SNP over all genes 
#  there were only a few genes so we can look at all
#
cd[rs2,]
#
# now get all SNP for a given gene -- this is a large request
#
dem2 = cd[, g20[1]]
sapply(dem2[[1]], length)
#
# now illustrate regression-based imputation
#
hmi = hm[ chrnum("chr20"), ]
#
# here are stored imputation rules built to impute from hapmap phase 3
# panel to 1KG
#
data(imphm3_1KG_20_mA2)
e1i = ieqtlTests(hmi, ~male, rules=imphm3_1KG_20_mA2 )
e1i
topFeats( sym = "CPNE1", mgr=e1i, ffind=1, anno="illuminaHumanv1.db" )
topFeats(probeid="GI_23397697-A", mgr=cd)  
topFeats(rsid="rs6060632", mgr=cd)
#
# now illustrate how scores can be obtained after permuting samples
# the permEx function must be used because snpMatrix testing facilities
# try hard to match sampleIds of phenotype and genotype; the X[,S] idiom
# does not work
#
#if ("package:multicore" %in% search()) {
# library(ceu1kg)
# data(ceu1kgMeta_20)
# cc = cisScores( e1i, 1, "chr20", ceu1kgMeta_20, applier=mclapply, radius=5e5)
# lapply(cc, function(x) sort(x,decreasing=TRUE)[1:3]) # now check scores obtained under permutation
# e1ip = ieqtlTests(permEx(hmi), ~male, rules=imphm3_1KG_20_mA2, targdir="p1", runname="p1" )
# cc2 = cisScores( e1ip, 1, "chr20", ceu1kgMeta_20, applier=mclapply, radius=5e5)
# lapply(cc2, function(x) sort(x,decreasing=TRUE)[1:3])
# }
