-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_nei.R
62 lines (57 loc) · 2.3 KB
/
plot_nei.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
#' Plot LOD score for self or neighbor QTL effects
#'
#' Plot LOD curves for a genome scan of self and neighbor QTL effects.
#' @param res Output results of \code{scan_neighbor()}.
#' @param type Plot \code{"self"}, \code{"neighbor"} or \code{"int"} effects. Default is \code{"neighbor"} effects.
#' @param chr An optional vector to select chromosome numbers to be plotted. If \code{NULL}, shown are all chromosomes.
#' @param th Add genome-wide threshold by user-defined vectors or Bonferroni correction. Default is no thresholds added.
#' @param ... Arguments to be passed to \code{plot()}.
#' @author Yasuhiro Sato (\email{sato.yasuhiro.36c@kyoto-u.jp})
#' @details
#' For the \code{type} argument, \code{"int"} can be selected to draw the results of \code{int_neighbor()}.
#' In this case, the \code{res} object and \code{type} must match, otherwise it returns an error message.
#' @seealso \code{\link{scan_neighbor}} \code{\link{int_neighbor}} \code{\link{perm_neighbor}}
#' @export
plot_nei = function(res, type=c("neighbor","self","int"), chr=NULL, th=NULL, ...) {
type <- match.arg(type)
if(is.null(chr)==FALSE) {
res <- res[res$chr==chr,]
}
pos <- res$pos
chr <- as.factor(res$chr)
coord <- 0
M <- 0
tic <- numeric(nlevels(chr))
for (i in 1:nlevels(chr)) {
w <- (chr == levels(chr)[i])
pos.c <- pos[w]
coord[w] <- M + pos.c
mx <- max(pos.c)
tic[i] <- M + mx/2
M <- M + mx + max(pos)*0.2
}
x <- coord/M
tic <- tic/M
switch(type,
"self" = y <- res$LOD_self,
"neighbor" = y <- res$LOD_nei,
"int" = y <- res$LOD_int,
stop("error: type must be 'self', 'neighbor', or 'int'")
)
if(is.null(y)) {
stop("error: the output results and type does not match")
}
args <- list(...)
args$type <- "n"; args$main <- type
args$x <- x; args$y <- y
args$xlab <- ""; args$ylab <- "LOD score"
args$xaxt <- "n"; args$yaxt <- "s"
do.call(graphics::plot, args)
for(i in levels(factor(res$chr))) {
graphics::points(x[res$chr==i], y[res$chr==i], type="l", col=i)
}
unobs = grep("_loc", rownames(res))
graphics::points(x[-unobs], y[-unobs], pch=16, cex=0.75)
graphics::abline(h=th, col=grDevices::grey(0.5,0.5), lty=2)
graphics::axis(side=1, at=tic, labels=levels(chr))
}