以列表之间的百分比形式查找基因重叠
Find gene overlap as a percentage between lists
此问题是找到的问题 here 的变体。
我还想评估基因重叠的百分比,但我不想在单个列表中对所有项进行成对比较,而是想将一个列表与不同的列表集进行比较。最初的 post 答案给出了一个优雅的嵌套 sapply,我认为这对我的情况不起作用。
以下是一些示例数据。
>listOfGenes1 <- list("cellLine1" = c("ENSG001", "ENSG002", "ENSG003"), "cellLine2" = c("ENSG003", "ENSG004"), "cellLine3" = c("ENSG004", "ENSG005"))
>myCellLine <- list("myCellLine" = c("ENSG001", "ENSG002", "ENSG003"))
我想将 listOfGenes1 中的每个细胞系与 myCellLine 中的单个组进行比较,输出类似于:
>overlaps
cellLine1 cellLine2 cellLine3
100 33 0
明确地说,我想要百分比重叠,"myCellLine" 作为分母。以下是我到目前为止一直在尝试但没有成功的方法。
overlaps <- sapply(listOfGenes1, function(g1) {round(length(intersect(g1, myCellLine)) / length(myCellLine) * 100)})
你可以试试,
round(sapply(listOfGenes1, function(i)
100 * length(intersect(i, myCellLine[[1]])) / length(myCellLine[[1]])), 0)
#cellLine1 cellLine2 cellLine3
# 100 33 0
注意:您的 myCellLine
对象是一个列表,因此 length(myCellLine)
将不起作用
我们可以使用sapply
sapply(listOfGenes1, function(x) mean(myCellLine[[1]] %in% x) * 100)
#cellLine1 cellLine2 cellLine3
#100.00000 33.33333 0.00000
此问题是找到的问题 here 的变体。
我还想评估基因重叠的百分比,但我不想在单个列表中对所有项进行成对比较,而是想将一个列表与不同的列表集进行比较。最初的 post 答案给出了一个优雅的嵌套 sapply,我认为这对我的情况不起作用。
以下是一些示例数据。
>listOfGenes1 <- list("cellLine1" = c("ENSG001", "ENSG002", "ENSG003"), "cellLine2" = c("ENSG003", "ENSG004"), "cellLine3" = c("ENSG004", "ENSG005"))
>myCellLine <- list("myCellLine" = c("ENSG001", "ENSG002", "ENSG003"))
我想将 listOfGenes1 中的每个细胞系与 myCellLine 中的单个组进行比较,输出类似于:
>overlaps
cellLine1 cellLine2 cellLine3
100 33 0
明确地说,我想要百分比重叠,"myCellLine" 作为分母。以下是我到目前为止一直在尝试但没有成功的方法。
overlaps <- sapply(listOfGenes1, function(g1) {round(length(intersect(g1, myCellLine)) / length(myCellLine) * 100)})
你可以试试,
round(sapply(listOfGenes1, function(i)
100 * length(intersect(i, myCellLine[[1]])) / length(myCellLine[[1]])), 0)
#cellLine1 cellLine2 cellLine3
# 100 33 0
注意:您的 myCellLine
对象是一个列表,因此 length(myCellLine)
将不起作用
我们可以使用sapply
sapply(listOfGenes1, function(x) mean(myCellLine[[1]] %in% x) * 100)
#cellLine1 cellLine2 cellLine3
#100.00000 33.33333 0.00000