【问题标题】:Find gene overlap as a percentage between lists查找列表之间的基因重叠百分比
【发布时间】:2019-09-04 21:36:02
【问题描述】:

这个问题是发现的问题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)})

【问题讨论】:

    标签: r overlap


    【解决方案1】:

    你可以试试,

    round(sapply(listOfGenes1, function(i)
                    100 * length(intersect(i, myCellLine[[1]])) / length(myCellLine[[1]])), 0)
    
    #cellLine1 cellLine2 cellLine3 
    #      100        33         0 
    

    注意:您的myCellLine 对象是一个列表,因此length(myCellLine) 将不起作用

    【讨论】:

      【解决方案2】:

      我们可以使用sapply

      sapply(listOfGenes1, function(x) mean(myCellLine[[1]] %in% x) * 100)
      
      #cellLine1 cellLine2 cellLine3 
      #100.00000  33.33333   0.00000 
      

      【讨论】:

      • 这行得通,但取平均值的目的是什么?
      • @strugglebus 我们正在采用mean 的逻辑值,这将直接为您提供比率。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-24
      • 2019-12-05
      • 1970-01-01
      相关资源
      最近更新 更多