【发布时间】:2020-06-03 19:46:34
【问题描述】:
我有 2 个基因数据集,我试图在其中查找基因组(文件 1)中某个位置的变体是否在另一个数据集(文件 2)中我的任何行的范围内匹配/找到,然后提取找到的匹配项文件 2 与文件 1 合并。一个条件是匹配项仅在具有相同染色体的情况下搜索变体。例如:
文件1:
Chromosome Position
1 3
1 47
2 10
3 2
文件2:
Chromosome Start End
1 101 102
1 40 50
2 40 50
3 20 22
预期输出:
Chromosome Start End
1 40 50
#this is the only row from which a variant from file1 fits in its position range and is on the same chromosome
理想情况下,我会合并 file1 变体,以与 file2 中匹配的染色体开始和结束位置在同一行中对齐,但我是 R 新手,并坚持尝试基于如果它的位置编号在第二个文件的范围内。目前我正在努力适应:
dt1[ dt2, match := i.,ID #including a made-up ID column for the sake of trying to adapt this code
on = .(Chromosome, Position > Start, Position < End ) ]
但这似乎不起作用,除此之外我不知道如何开始。任何有关如何解决此问题的帮助将不胜感激
数据:
dput(file1)
structure(list(Chromosome = c(1L, 1L, 2L, 3L), Position = c(3L,
47L, 10L, 2L)), row.names = c(NA, -4L), class = c("data.table",
"data.frame"))
dput(file2)
structure(list(Chromosome = c(1L, 1L, 2L, 3L), Start = c(101L,
40L, 40L, 20L), End = c(102L, 50L, 50L, 22L)), row.names = c(NA,
-4L), class = c("data.table", "data.frame"))
【问题讨论】:
-
bedtools intersect不是你喜欢的?在 R 中,您可以使用 GenomicRanges Bioconductor 包中的findOverlaps。 -
谢谢你,我不知道这些,我会调查它们。
标签: r data.table bioinformatics