Last active
November 26, 2019 16:12
-
-
Save kbroman/383326861f06716be0366edf8edc01bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find large intervals in a map | |
# | |
# | |
# input: map = list of chromosomes that are vectors of marker positions | |
# [can also be a cross object, in which case pull.map() is used] | |
# min_distance = minimum distance between markers to be flagged | |
# | |
# example use: | |
# library(qtl) | |
# data(hyper) | |
# find_large_intervals(hyper, 20) | |
find_large_intervals <- | |
function(map, min_distance=35) | |
{ | |
output <- NULL | |
# if input is a cross, pull out the map | |
if("cross" %in% class(map)) { | |
map <- pull.map(map) | |
} | |
# make sure there are names | |
if(is.null(names(map))) { | |
names(map) <- seq_along(map) | |
} | |
for(i in names(map)) { | |
d <- diff(map[[i]]) | |
big <- which(d > min_distance) | |
n_big <- length(big) | |
mar <- names(map[[i]]) | |
if(n_big > 0) { | |
this <- data.frame(chr=rep(i, n_big), | |
left=mar[big], | |
right=mar[big+1], | |
interval_size=d[big], | |
stringsAsFactors=FALSE) | |
if(is.null(output)) output <- this | |
else output <- rbind(output, this) | |
} | |
} | |
if(!is.null(output)) rownames(output) <- 1:nrow(output) | |
output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment