【问题标题】:Downsampling dataset下采样数据集
【发布时间】:2015-02-20 03:33:27
【问题描述】:

我有一个数据集,它是一个大字符向量(1,024,459 个元素),由基因 ID 组成。它看起来像:

> length(allres)
[1] 1024459
>allres[1:10]  
[1] "1"   "1"   "1"   "1"   "1"   "1"   "1"   "10"  "10"  "100"  

每个基因 ID 重复其在 RNA seq 运行中出现的次数(因此这里,基因“1”有 7 个读数,基因“10”有 2 个读数)。我想以 10,000 个读取间隔绘制每个读取次数识别的基因数量,这样我可以看到如果我随机采样 10,000 个读取、20,000、30,0000 等,我可以看到有多少个基因被识别出来。我制作了一个间距向量seq() 函数如下所示:

> gaps <- seq(10000, length(allres), by=10000)  

但我不确定如何将其应用于我的 allres 矢量并绘制它。非常感谢任何帮助。

【问题讨论】:

    标签: r subsampling


    【解决方案1】:

    所以,你可能想要的是这样的:

    gaps <- seq(10000, length(allres), by = 10000)
    
    lapply(gaps, function(x){
    
        #This will give you the number of appearances of each value, within
        #an gaps[x]-sized sample of allres
        aggregated_sample <- table(sample(allres, size = x))
    
        #plotting code for sample goes here. And "x" is the number of reads so
        #you can even use it in the title!
        #Just remember to include code to save it to disc, if you want to save it to disc.
        return(TRUE)
    
    })
    

    如果您使用 ggplot2 进行绘图,当然,您甚至可以将绘图保存为对象,然后用 return(plot) 而不是 return(TRUE),然后再进行进一步的调整/调查。

    【讨论】:

    • 这绝对是我想要的,谢谢!我仍在试图弄清楚如何在一个情节上获得所有内容。我已经尝试了几件事,沿着“plot(x, xlab="reads", ylab="genes")" 的行,但这会为每个数据点生成一个单独的图表。
    • 也就是说,一个“间隙”实例中的每个数据点,还是您想要一个绘图上的所有“间隙”选项?
    • 一张图上的所有空白选项都是最好的。
    • 好,那你要看this
    • 谢谢!仍然花了我一点时间才能正确地将它们组合在一起,但这无疑为我指明了正确的方向。 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 2017-10-28
    • 2021-08-08
    • 2011-09-27
    • 1970-01-01
    • 2022-11-15
    相关资源
    最近更新 更多