这个问题是here发现的问题的变体。
我也想评估基因重叠的百分比,但我不想在一个列表中对所有基因进行成对的比较,我想比较一个列表和一个不同的列表集。最初的帖子回答给出了一个优雅的嵌套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)})发布于 2019-09-04 13:34:07
你可以试试,
round(sapply(listOfGenes1, function(i)
100 * length(intersect(i, myCellLine[[1]])) / length(myCellLine[[1]])), 0)
#cellLine1 cellLine2 cellLine3
# 100 33 0 注意:您的myCellLine对象是一个列表,因此length(myCellLine)不能工作
发布于 2019-09-04 13:36:02
我们可以使用sapply
sapply(listOfGenes1, function(x) mean(myCellLine[[1]] %in% x) * 100)
#cellLine1 cellLine2 cellLine3
#100.00000 33.33333 0.00000 https://stackoverflow.com/questions/57789480
复制相似问题