Find point-to-range overlaps

后端 未结 3 1321
你的背包
你的背包 2021-01-22 19:18

I have a dataframe df1:

df1 <- read.table(text=\" Chr06  79641   
Chr06   82862   
Chr06   387314  
Chr06   656098  
Chr06   678491  
Chr06   1018696\", heade         


        
3条回答
  •  执笔经年
    2021-01-22 20:18

    Here is a data.table solution as an alternative to GenomicRanges:

    library(data.table)
    dt1 <- data.table(df1)[, V3 := V2]
    dt2 <- data.table(df2, key = c("V2", "V3"))
    foverlaps(dt1, dt2)[V1 == i.V1][, -c(4, 6), with = F]
    #       V1      V2      V3    i.V3
    # 1: Chr06   79720   87043   82862
    # 2: Chr06  387314  387371  387314
    # 3: Chr06 1018676 1018736 1018696
    

提交回复
热议问题