Created
April 22, 2015 21:42
-
-
Save npjc/89094d38d2b58c96dd6d to your computer and use it in GitHub Desktop.
overlap stats
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
with combined 3-colbed + 4th col. id | |
```r | |
library(data.table) | |
y = data.table(chr=c("Chr1", "Chr1", "Chr1"), start=c(1, 15,1), | |
end=c(4, 18, 55), id=letters[1:3]) | |
setkey(y, chr, start, end) | |
dt <- foverlaps(y, y, type="any") | |
``` | |
then get overlap stats | |
```r | |
comn_df <- . %>% | |
as.data.frame() %>% | |
filter(id != i.id) %>% | |
rowwise() %>% | |
mutate(len_l = end - start, | |
len_r = i.end - i.start, | |
len_i = min(end, i.end) - max(start, i.start), | |
frac_i_l = len_i / len_l, | |
frac_i_r = len_i / len_r) %>% | |
arrange(chr,start,end) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
quick visual parse