-
Notifications
You must be signed in to change notification settings - Fork 20
/
log_reg_case.R
120 lines (76 loc) · 1.66 KB
/
log_reg_case.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
library(foreach)
library(doParallel)
cl<-makeCluster(16)
registerDoParallel(cl)
con = file("case_out_w_bonf_top.kmerDiff", "r")
Z <- read.table("pcs.evec",header=FALSE);
input <- read.table("gwas_eigenstratX.ind");
Y <- matrix(nrow=nrow(Z),ncol=1);
cov <- matrix(nrow=nrow(Z),ncol=1);
case_counts <- read.table("case_total_kmers.txt", header=FALSE)
control_counts <- read.table("control_total_kmers.txt", header=FALSE)
totals <- rbind(case_counts, control_counts)
counts<- vector(length=length(Y));
for(i in 1:length(Y))
{
if(input[i,3]=="Case")
{
Y[i,1]=1;
}
else if(input[i,3]=="Control")
{
Y[i,1]=0;
}
else
{
Y[i,1]=input[i,3];
}
}
print(Y);
if (FALSE) {
input <- read.table("covariates.txt");
for(i in 1:length(cov))
{
if(input[i,1]=="M")
{
cov[i,1]=0;
}
else
{
cov[i,1]=1;
}
}
}
totalKmers <- read.table("total_kmers.txt",header=FALSE);
n<-nrow(Z);
cat("", file = "pvals_case_top.txt")
CHUNK_SIZE=10000;
ptm <- proc.time()
while(TRUE)
{
kmercounts <- read.table(con,nrow=CHUNK_SIZE);
nr=nrow(kmercounts);
ls<-foreach(j=icount(nr), .combine=cbind) %dopar%
{
for(i in 1:length(Y))
{
counts[i]=kmercounts[j,4+i]/totals[i,1];
}
# model1<-glm(formula = Y ~ counts, family = binomial(link = "logit"));
model2<-glm(formula = Y ~ Z[,1]+Z[,2]+totals[,1]+counts, family = binomial(link = "logit"));
#summary(model1);
# v1<-anova(model1, test="Chisq");
#summary(model2);
v2<-anova(model2, test="Chisq");
# rbind(v1$'Pr(>Chi)'[2],v2$'Pr(>Chi)'[13]);
v2$'Pr(>Chi)'[5];
}
write(ls,file='pvals_case_top.txt',ncolumns=1,append=TRUE,sep='\t');
if(nr<CHUNK_SIZE)
{
break;
}
}
close(con);
print(proc.time() - ptm)
stopCluster(cl)