【问题标题】:Integer overflow with package `IRanges` in `R`“R”中包“IRanges”的整数溢出
【发布时间】:2016-03-09 00:28:10
【问题描述】:

问题

我正在使用 [IRanges][1] 包,我需要为超过 2^31 约 10 倍的超长序列准确编码。

从下面看来IRanges使用int32

##### INSTALLATION FROM SRC CODE ######
## try http:// if https:// URLs are not supported
source("https://bioconductor.org/biocLite.R")
biocLite("IRanges")

##### CALL PACKAGE #####
require(IRanges)


IRanges(start=1,end=2^31-1) # Works fine

IRanges(start=1,end=2^31)   # Fail
Error in .Call2("solve_user_SEW0", start, end, width, PACKAGE = "IRanges") : 
  solving row 1: range cannot be determined from the supplied arguments (too many NAs)
In addition: Warning message:
In .normargSEW0(end, "end") : NAs introduced by coercion to integer range

由于这个包经常用于 DNA 序列,因此能够处理大于 2^32 (≈ 10^9) 的值将非常有用,因为许多生物的基因组大小都比这长.

问题

  • 我认为这是整数溢出问题是否正确?
  • 您是否遇到过同样的问题?
  • 有没有办法解决这个问题?
    • 是否可以(并且容易)找到源代码并只修改对象类型
    • 您认为该软件包是否存在其他版本?

我找到的唯一解决方案是接受降低我的准确度级别并将每个宽度除以 100...但我对降低我的准确度不太满意。

R 版

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

【问题讨论】:

    标签: r int integer-overflow int32 iranges


    【解决方案1】:

    您已达到可以用 R 表示的整数大小的限制。

    > .Machine$integer.max
    #[1] 2147483647
    > log2(.Machine$integer.max)
    #[1] 31
    

    有一些特殊的库,如 bit64gmp 用于处理例如 64 位有符号整数。但是,不确定此类包表示的整数是否与其他库兼容。

    【讨论】:

    • 调用包bit64 似乎没有在包IRanges 中达到更高的数字。我想我将不得不重写IRanges 的一些功能。谢谢
    • @Remi.b 您是否能够找到解决方法,或者您最终是否不得不编辑 IRanges 源?
    • 我制作了自己的一系列 IRanges 函数,我只是使用 data.frame 而不是创建一个新类。这实际上非常简单(包括调试可能需要 3 个小时)。我没有将这段代码放在 github 上,因为我不使用 github,但我应该而且我很快就会。
    猜你喜欢
    • 2022-01-21
    • 2020-10-24
    • 2022-01-07
    • 2012-04-12
    • 1970-01-01
    • 2014-01-24
    • 2014-06-08
    • 1970-01-01
    相关资源
    最近更新 更多