如何计算长度分布和覆盖分布床档

How to calculate length distribution and coverage distribution bed file

我在 bed 文件中有数据集,我想计算并绘制文件的长度和覆盖分布。如何计算 R 中的长度分布。

df1:

chr21 2800 3270
chr21 3600 4152
chr2 3719 5092
chr22 3893 4547 
chr2 339 5092
chr22 3563 3597 
structure(list(df1c = c("chr21", "chr21", "chr2", "chr22","chr2"), df1c2 = c(2800, 
3600, 3719, 3893,339,3563), df1c3 = c(3270, 4152, 5092, 4547,5092,3597)), class = "data.frame", row.names = c(NA, 
-4L))

你可以这样做:

library(tidyverse)

df %>% 
  mutate(id = factor(seq(nrow(.)))) %>%
  ggplot(aes(y = df1c2, x = df1c, xend = df1c, yend = df1c3)) +
  geom_segment(aes(y = 1, yend = max(df1c3)), size = 8, lineend = 'round',
               color = 'gray20') +
  geom_segment(size = 7, aes(color = 'coverage')) +
  coord_flip() + 
  labs(color = '', y = 'Location', x = 'Chromosome') +
  theme_light(base_size = 16)