Skip to content

Commit c2f4021

Browse files
author
Zhong Wang
committed
Fix bug in permutation
1 parent d8dd56f commit c2f4021

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

Funmap2/R/fm2.permu.r

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ permu.execute<-function( dat, grp.idx=NULL, permu.loop, filter.ratio=1, scan.ste
1313
{
1414
if( filter.ratio<1 && is.null(dat$obj.phe$pheX) )
1515
dat$clustering <- permu.cluster(dat);
16-
16+
1717
#p0 <- task_start("Execute the permutation, nCount=", permu.loop, "...\n");
1818

1919
cpu.fun <- function(i)
@@ -24,7 +24,7 @@ permu.execute<-function( dat, grp.idx=NULL, permu.loop, filter.ratio=1, scan.ste
2424
dat0$obj.phe$pheX <- dat0$obj.phe$pheX[new_index, ];
2525
dat0$obj.phe$pheT <- dat0$obj.phe$pheT[new_index, ];
2626
dat0$clustering$Q <- dat0$clustering$Q[new_index, ];
27-
27+
2828
qtl_table <- NULL;
2929
if( filter.ratio<1 && is.null(dat$obj.phe$pheX) )
3030
qtl_table <- permu.qtlfilter( dat0, grp.idx, filter.ratio, scan.step );
@@ -124,11 +124,11 @@ permu.plot<-function( object, file.pdf =NULL )
124124

125125
fpt.plot_permutation ( object$pv.table );
126126

127-
if(!is.null(file.pdf))
127+
if(!is.null(file.pdf))
128128
{
129129
dev.off();
130130
cat( "* The permutation cutoff are shown to ", file.pdf, ".\n");
131-
}
131+
}
132132

133133
invisible();
134134
}
@@ -150,7 +150,7 @@ fin.find_cutoff <- function(perm, p=0.05)
150150
warning("pvalue is too small and no exact cutoff in the permutation results.")
151151
idx <- 1;
152152
}
153-
153+
154154
perm.cutoff <- sort(pv.table[,3], decreasing=TRUE)[idx];
155155
}
156156

@@ -339,6 +339,8 @@ permu.cluster <- function( dat )
339339
n.grp <- dat$obj.cross$gen_num;
340340
n.par.cov <- get_param_info( dat$obj.covar, dat$obj.phe$pheT)$count;
341341
n.par.curve <- get_param_info(dat$obj.curve, dat$obj.phe$pheT)$count;
342+
t.range <- range(dat$obj.phe$pheT, na.rm=TRUE);
343+
options <- list(max.time=t.range[2], min.time=t.range[1]);
342344

343345
mle <- function(par, W, pheY, pheT, pheX, obj.curve, obj.covar, obj.cross, optim=T)
344346
{
@@ -356,23 +358,23 @@ permu.cluster <- function( dat )
356358
L <- matrix(NA, ncol=n.grp, nrow=NROW(pheY));
357359
if (obj.cross$gen_QQ)
358360
{
359-
y.delt <- pheY- get_curve( obj.curve, par.m[i,], pheT );
360-
Q[,i] <- dmvnorm_fast( y.delt, rep(0, n.par.cov), cov, log=F);
361+
y.delt <- pheY- get_curve( obj.curve, par.m[i,], pheT, options );
362+
Q[,i] <- dmvnorm_fast( y.delt, rep(0, NCOL(y.delt)), cov, log=F);
361363
L[,i] <- Q[,i]*W[i]
362364
i <- i+1;
363365
}
364366

365367
if (obj.cross$gen_Qq)
366368
{
367-
y.delt <- pheY- get_curve( obj.curve, par.m[i,], pheT );
369+
y.delt <- pheY- get_curve( obj.curve, par.m[i,], pheT, options );
368370
Q[,i] <- dmvnorm_fast( y.delt, rep(0, NCOL(y.delt)), cov, log=F);
369371
L[,i] <- Q[,i]*W[i]
370372
i <- i+1;
371373
}
372374

373375
if (obj.cross$gen_qq)
374376
{
375-
y.delt <- pheY- get_curve( obj.curve, par.m[i,], pheT );
377+
y.delt <- pheY- get_curve( obj.curve, par.m[i,], pheT, options );
376378
Q[,i] <- dmvnorm_fast( y.delt, rep(0, NCOL(y.delt)), cov, log=F);
377379
L[,i] <- Q[,i]*W[i]
378380
i <- i+1;
@@ -390,10 +392,10 @@ permu.cluster <- function( dat )
390392
while( max(abs( c(W.new) - c(W) ) ) > 1e-5 )
391393
{
392394
W <- W.new;
393-
r <- try( optim( par.new, mle, W=W, pheY=dat$obj.phe$pheY, pheT=dat$obj.phe$pheT, pheX=dat$obj.phe$pheX,
394-
obj.curve=dat$obj.curve, obj.covar= dat$obj.covar, obj.cross=dat$obj.cross,
395+
r <- try( optim( par.new, mle, W=W, pheY=dat$obj.phe$pheY, pheT=dat$obj.phe$pheT, pheX=dat$obj.phe$pheX,
396+
obj.curve=dat$obj.curve, obj.covar= dat$obj.covar, obj.cross=dat$obj.cross,
395397
optim=T, control = list(maxit=50000)));
396-
398+
397399
if(class(r)!="try-error" && r$convergence==0)
398400
{
399401
par.new <- r$par;

Funmap2/R/fm2.qtlmodel.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Qtlmle.qtlscan<-function( dat, qtl.table=NULL, grp_idx=NULL, options=list(scan.s
66
# search for all marker for current group(chromosome)
77
if(is.null(qtl.table))
88
qtl.table <- fin.get_qtl( dat$obj.gen$marker.table, scan.step=options$scan.step );
9+
910
if(!is.null(grp_idx))
1011
qtl.table <- qtl.table[which(qtl.table$grp %in% grp_idx), ]
1112

0 commit comments

Comments
 (0)