如何将线段边界映射到R中参考文件中最近的位置
如何将段文件中的坐标位置(起点和终点位置)映射到参考文件中最近的位置如何将线段边界映射到R中参考文件中最近的位置,r,bioinformatics,R,Bioinformatics,如何将段文件中的坐标位置(起点和终点位置)映射到参考文件中最近的位置 seg <- Sample Chromosome Start End Num_markers LogRatio Nf1 1 3020000.5 195340000.5 4732 0.2981 Nf2 2 3100000.5 181980000.5 4091 0.29
seg <- Sample Chromosome Start End Num_markers LogRatio
Nf1 1 3020000.5 195340000.5 4732 0.2981
Nf2 2 3100000.5 181980000.5 4091 0.2986
Ref <- Name Chromosome Position
1:3010000.5 1 3010000.5
1:195330000.5 1 195330000.5
2:3090000.5 2 3090000.5
2:181970000.5 2 181970000.5
seg使用data.table
,您可以在指定roll=“nearest”
的同时执行两个滚动联接。您将需要两倍于您每次需要连接到不同的列,但这应该是非常有效的。这里有一个可能的实现
library(data.table)
setDT(seg)
setDT(Ref)
StartInd <- Ref[seg, on = c(Chromosome = "Chromosome", Position = "Start"), which = TRUE, roll = "nearest"]
EndInd <- Ref[seg, on = c(Chromosome = "Chromosome", Position = "End"), which = TRUE, roll = "nearest"]
seg[, `:=`(Start = Ref[StartInd, Position], End = Ref[EndInd, Position])]
print(seg, digits = 10)
# Sample Chromosome Start End Num_markers LogRatio
# 1: Nf1 1 3010000.5 195330000.5 4732 0.2981
# 2: Nf2 2 3090000.5 181970000.5 4091 0.2986
库(data.table)
setDT(seg)
setDT(参考)
StartInd im在[.data.table`(Ref,seg,on=c(Position=“Start”)中获取错误,其中=TRUE,:未使用的参数(on=c(Position=“Start”))您有一个旧版本的数据。table
。请从CRANI安装1.9.6版。我在一个更大的数据集上尝试使用上面示例中给出的前几列脚本。我收到警告消息:1:in[.data.table
(seg,:=
(Start=ref[StartInd,Position],End=ref[EndInd,:提供10795个项目分配给“开始”列的741个项目(10054个未使用)2:In[.data.table
(seg,:=
)(开始=参考[StartInd,Position],结束=参考[EndInd,:提供9637个项目分配给“结束”列的741个项目(8896个未使用)我无法复制这个。我在不同的数据大小上尝试过它,效果很好。可能你做得不正确。StartInd
和EndInd
的大小应该与seg
的定义相同-因此你的错误消息对meSo没有多大意义,只需将染色体
添加到连接中。我已经升级了回答了为什么我们在基因组位置上有小数点,.5
?Ref中1号染色体的309000.5位置如何与2号染色体的3100000.5位置匹配?@zx8754 i更新了这个问题
library(data.table)
setDT(seg)
setDT(Ref)
StartInd <- Ref[seg, on = c(Chromosome = "Chromosome", Position = "Start"), which = TRUE, roll = "nearest"]
EndInd <- Ref[seg, on = c(Chromosome = "Chromosome", Position = "End"), which = TRUE, roll = "nearest"]
seg[, `:=`(Start = Ref[StartInd, Position], End = Ref[EndInd, Position])]
print(seg, digits = 10)
# Sample Chromosome Start End Num_markers LogRatio
# 1: Nf1 1 3010000.5 195330000.5 4732 0.2981
# 2: Nf2 2 3090000.5 181970000.5 4091 0.2986