来自 VennDiagram 包的函数 calculate.overlap
function calculate.overlap from VennDiagram package
编辑:我有以下两个列表。它们完全按照呈现的方式编写:
x1 <- list()
x1$A <- as.character(c("Per_36","Cent","CeM","vDG","LAVL","RSGd"))
x1$B <- as.character(c("vCA1","DLE","Per_36","vDG","DIE","Per_35"))
x1$C <- as.character(c("vCA1","Cg1","LAVL", "RSGc", "RSGd","Per_35","Per_36"))
x1$D <- as.character(c("Por","Cg1","RSGc","LAVL","Per_35","RSGd","Per_36"))
x2 <- list()
x2$A <- as.character(c("Per_36","Per_35","Por","vCA1","BLV","Cent","PrL"))
x2$B <- as.character(c("BLA","VIE","BLV","Por","Cent","Ment","dCA1"))
x2$C <- as.character(c("dDG","Per_36","CeM","Per_35","BLV","dCA1","PrL","IL"))
x2$D <- as.character(c("CeC","RSGb","CeL","dDG","CeM","dCA1","PrL","IL"))
它们的生成方式完全相同。当我 运行 x1 中 VennDiagram
包中的函数 calculate.overlap
时,我得到了一个很好的绘图和函数 运行s 完美。但是当我在 x2 中 运行 时,我得到一个空列表,这显然是错误的。我只是看不出它有什么问题。有帮助吗??
overlapx1
$a6
[1] "Per_36"
$a12
character(0)
$a11
character(0)
$a5
[1] "LAVL" "RSGd"
$a7
[1] "Per_35"
$a15
[1] "vDG"
$a4
character(0)
$a10
character(0)
$a13
[1] "vCA1"
$a8
character(0)
$a2
[1] "Cg1" "RSGc"
$a9
[1] "Cent" "CeM"
$a14
[1] "DLE" "DIE"
$a1
character(0)
$a3
[1] "Por"
当我 运行 overlapx2 <- calculate.overlap(x2)
我得到一个相等的列表,其中包含列表的所有向量 = character(0)
编辑 2:包的 link 如下
https://cran.r-project.org/web/packages/VennDiagram/index.html
和手册
https://cran.r-project.org/web/packages/VennDiagram/VennDiagram.pdf
作者是 Hambo Chen,但由 Paul Boutros 维护
我挖掘了函数中的代码,发现了错误。
我将 post 只是一个代码示例,可以作为我自己问题的答案和解决方案。
calculate.overlap
function (x)
{
if (1 == length(x)) {
overlap <- x
}
else if (2 == length(x)) {
overlap <- list(a1 = x[[1]], a2 = x[[2]], a3 = intersect(x[[1]],
x[[2]]))
}
else if (3 == length(x)) {
A <- x[[1]]
B <- x[[2]]
C <- x[[3]]
nab <- intersect(A, B)
nbc <- intersect(B, C)
nac <- intersect(A, C)
nabc <- intersect(nab, C)
a5 = nabc
a2 = nab[-which(nab %in% a5)]
a4 = nac[-which(nac %in% a5)]
a6 = nbc[-which(nbc %in% a5)]
a1 = A[-which(A %in% c(a2, a4, a5))]
a3 = B[-which(B %in% c(a2, a5, a6))]
a7 = C[-which(C %in% c(a4, a5, a6))]
overlap <- list(a5 = a5, a2 = a2, a4 = a4, a6 = a6, a1 = a1,
a3 = a3, a7 = a7)
}
#. Purposely took the length(x) == 4 and 5 to shorten it.
#. rationale is the same ans is simple
#.
else {
flog.error("Invalid size of input object", name = "VennDiagramLogger")
stop("Invalid size of input object")
}
}
<environment: namespace:VennDiagram>
错误操作是下面突出显示的命令:
a2 = nab[**-which(**nab %in% a5)]
将其替换为
a2 = nab[! nab %in% a5]
这个技巧做得很好。但是在函数中的所有操作中都要完成。
我会尝试联系包的作者,看他以后能不能更新
编辑:我有以下两个列表。它们完全按照呈现的方式编写:
x1 <- list()
x1$A <- as.character(c("Per_36","Cent","CeM","vDG","LAVL","RSGd"))
x1$B <- as.character(c("vCA1","DLE","Per_36","vDG","DIE","Per_35"))
x1$C <- as.character(c("vCA1","Cg1","LAVL", "RSGc", "RSGd","Per_35","Per_36"))
x1$D <- as.character(c("Por","Cg1","RSGc","LAVL","Per_35","RSGd","Per_36"))
x2 <- list()
x2$A <- as.character(c("Per_36","Per_35","Por","vCA1","BLV","Cent","PrL"))
x2$B <- as.character(c("BLA","VIE","BLV","Por","Cent","Ment","dCA1"))
x2$C <- as.character(c("dDG","Per_36","CeM","Per_35","BLV","dCA1","PrL","IL"))
x2$D <- as.character(c("CeC","RSGb","CeL","dDG","CeM","dCA1","PrL","IL"))
它们的生成方式完全相同。当我 运行 x1 中 VennDiagram
包中的函数 calculate.overlap
时,我得到了一个很好的绘图和函数 运行s 完美。但是当我在 x2 中 运行 时,我得到一个空列表,这显然是错误的。我只是看不出它有什么问题。有帮助吗??
overlapx1
$a6
[1] "Per_36"
$a12
character(0)
$a11
character(0)
$a5
[1] "LAVL" "RSGd"
$a7
[1] "Per_35"
$a15
[1] "vDG"
$a4
character(0)
$a10
character(0)
$a13
[1] "vCA1"
$a8
character(0)
$a2
[1] "Cg1" "RSGc"
$a9
[1] "Cent" "CeM"
$a14
[1] "DLE" "DIE"
$a1
character(0)
$a3
[1] "Por"
当我 运行 overlapx2 <- calculate.overlap(x2)
我得到一个相等的列表,其中包含列表的所有向量 = character(0)
编辑 2:包的 link 如下 https://cran.r-project.org/web/packages/VennDiagram/index.html
和手册 https://cran.r-project.org/web/packages/VennDiagram/VennDiagram.pdf
作者是 Hambo Chen,但由 Paul Boutros 维护
我挖掘了函数中的代码,发现了错误。
我将 post 只是一个代码示例,可以作为我自己问题的答案和解决方案。
calculate.overlap
function (x)
{
if (1 == length(x)) {
overlap <- x
}
else if (2 == length(x)) {
overlap <- list(a1 = x[[1]], a2 = x[[2]], a3 = intersect(x[[1]],
x[[2]]))
}
else if (3 == length(x)) {
A <- x[[1]]
B <- x[[2]]
C <- x[[3]]
nab <- intersect(A, B)
nbc <- intersect(B, C)
nac <- intersect(A, C)
nabc <- intersect(nab, C)
a5 = nabc
a2 = nab[-which(nab %in% a5)]
a4 = nac[-which(nac %in% a5)]
a6 = nbc[-which(nbc %in% a5)]
a1 = A[-which(A %in% c(a2, a4, a5))]
a3 = B[-which(B %in% c(a2, a5, a6))]
a7 = C[-which(C %in% c(a4, a5, a6))]
overlap <- list(a5 = a5, a2 = a2, a4 = a4, a6 = a6, a1 = a1,
a3 = a3, a7 = a7)
}
#. Purposely took the length(x) == 4 and 5 to shorten it.
#. rationale is the same ans is simple
#.
else {
flog.error("Invalid size of input object", name = "VennDiagramLogger")
stop("Invalid size of input object")
}
}
<environment: namespace:VennDiagram>
错误操作是下面突出显示的命令:
a2 = nab[**-which(**nab %in% a5)]
将其替换为
a2 = nab[! nab %in% a5]
这个技巧做得很好。但是在函数中的所有操作中都要完成。
我会尝试联系包的作者,看他以后能不能更新