-
-
Save tbrittoborges/b68f5d961daf29fae2f4a539a79b6f07 to your computer and use it in GitHub Desktop.
New approach to computing correlations between pairs of overlapping features in terms of data matrices
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
library(plyranges) | |
set.seed(1) | |
x <- data.frame(seqnames=1, start=0:9 * 100 + 1, | |
width=20, id=1:10) %>% | |
as_granges() | |
y <- data.frame(seqnames=1, start=round(runif(4,100,900)), | |
width=10, id=letters[1:4]) %>% | |
as_granges() %>% | |
sort() | |
tile <- data.frame(seqnames=1, start=c(1,401,801), | |
end=c(400,800,1000), tile_id=1:3) %>% | |
as_granges() | |
set.seed(1) | |
dat_x <- matrix(rnorm(10*100),nrow=10,dimnames=list(1:10,1:100)) | |
dat_y <- matrix(rnorm(4*100),nrow=4,dimnames=list(letters[1:4],1:100)) | |
x <- x %>% join_overlap_left(tile) | |
y <- y %>% join_overlap_left(tile) | |
x_overlaps <- x %>% | |
join_overlap_inner(y, maxgap=100) %>% | |
filter(tile_id.x == tile_id.y) %>% | |
select(tile_id = tile_id.x, id.x, id.y) | |
library(purrr) | |
x_overlaps %>% | |
mutate( | |
rho = map2_dbl(id.x, id.y, \(.x,.y) { | |
cor(dat_x[.x,], dat_y[.y,]) | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment