比较不同长度的多个向量,计算相同的元素,并打印出相同和不同的元素

时间:2018-05-16 22:07:38

标签: r bioinformatics

我有五个具有以下格式的矢量,并且长度各不相同。是单核苷酸多态性(SNP)的载体

DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

mDatabase.child("locations").child(user.getUid()).child("currentLatitude").setValue("xxxxxx");
     mDatabase.child("locations").child(user.getUid()).child("currentLongitude").setValue("yyyyyy");

在R中,我想: 确定哪些SNP在不同载体之间匹配 计算匹配的SNP数量 打印出哪些SNP不匹配 计算不匹配的SNP数量

我发现下面的脚本打印出矢量匹配的位置,但我已经尝试了一堆打印和长度函数,我似乎无法得到我真正想要的东西。它。如果可能的话,我也想迭代我的五个载体(即A对B,A对C,A对D,A对E等......)。

A <- c("2179_39","2764_47","4521_24","9056_66")
B <- c("2478_39","2734_47","4531_24","2178_39","2734_47","4521_24")

任何建议,即使只是一个可以帮助我整合打印和长度功能的网站,都会很棒。

艾拉

1 个答案:

答案 0 :(得分:1)

compare.SNPs <- function(A, B) {
  # consider only unique names
  A.u <- unique(A)
  B.u <- unique(B)
  common.A.B <- intersect(A.u, B.u)
  diff.A.B <- setdiff(A.u, B.u)
  diff.B.A <- setdiff(B.u, A.u)
  uncommon.A.B <- union(diff.A.B, diff.B.A)
  cat(paste0("The sets have ", length(common.A.B), " SNPs in common:"))
  print(common.A.B)
  print(paste0("The sets have ", length(uncommon.A.B), " SNPs not in common:"))
  print(paste0("In the first set, but not in the second set:"))
  print(diff.A.B)
  print(paste0("Not in the first set, but in the second set:"))
  print(diff.B.A)

}

compare.SNPs(A, B)

The sets have 1 SNPs in common:[1] "4521_24"
[1] "The sets have 7 SNPs not in common:"
[1] "In the first set, but not in the second set:"
[1] "2179_39" "2764_47" "9056_66"
[1] "Not in the first set, but in the second set:"
[1] "2478_39" "2734_47" "4531_24" "2178_39"