rtracklayer bigWig import fails with "'ranges' must have the length of the object to construct"
1
0
Entering edit mode
bonob • 0
@4109460e
Last seen 15 months ago
China

-- edit 2022-07-26: put complete session log, add results from other examples and remove speculative bits. (I feel bad for the walls of output, but if I'm not mistaken there's no way to fold code here?)

I can't get bigWig import to work with rtracklayer.

A full session log, using the 3 first lines of ?import.bw examples, with traceback and sessionInfo:

> library("rtracklayer")
Loading required package: GenomicRanges
Loading required package: stats4
Loading required package: BiocGenerics

Attaching package: ‘BiocGenerics’

The following objects are masked from ‘package:stats’:

    IQR, mad, sd, var, xtabs

The following objects are masked from ‘package:base’:

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min

Loading required package: S4Vectors

Attaching package: ‘S4Vectors’

The following objects are masked from ‘package:base’:

    expand.grid, I, unname

Loading required package: IRanges
Loading required package: GenomeInfoDb
>
> test_path <- system.file("tests", package = "rtracklayer")
> test_bw <- file.path(test_path, "test.bw")
> import.bw(test_bw)
Error in stop_if_wrong_length(what, ans_len) :
  'ranges' must have the length of the object to construct (9) or length
  1
>
> traceback()
11: stop(wmsg(what, " must have the length of the object ", "to construct (",
        ans_len, ") or length 1"))
10: stop_if_wrong_length(what, ans_len)
9: new_GRanges("GRanges", seqnames = seqnames, ranges = ranges,
       strand = strand, mcols = mcols, seqinfo = seqinfo)
8: GRanges(rep(seqnames(which), nhits), C_ans[[1L]], seqinfo = si)
7: .local(con, format, text, ...)
6: import(FileForFormat(con, format), ...)
5: import(FileForFormat(con, format), ...)
4: import(con, "BigWig", ...)
3: import(con, "BigWig", ...)
2: import.bw(test_bw)
1: import.bw(test_bw)
>
> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.10.1
LAPACK: /usr/lib/liblapack.so.3.10.1

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods
[8] base

other attached packages:
[1] rtracklayer_1.56.1   GenomicRanges_1.48.0 GenomeInfoDb_1.32.2
[4] IRanges_2.30.0       S4Vectors_0.34.0     BiocGenerics_0.42.0

loaded via a namespace (and not attached):
 [1] XVector_0.36.0              zlibbioc_1.42.0
 [3] GenomicAlignments_1.32.1    BiocParallel_1.30.3
 [5] lattice_0.20-45             rjson_0.2.21
 [7] tools_4.2.0                 grid_4.2.0
 [9] SummarizedExperiment_1.26.1 parallel_4.2.0
[11] Biobase_2.56.0              matrixStats_0.62.0
[13] yaml_2.3.5                  crayon_1.5.1
[15] BiocIO_1.6.0                Matrix_1.4-1
[17] GenomeInfoDbData_1.2.8      restfulr_0.0.15
[19] bitops_1.0-7                codetools_0.2-18
[21] RCurl_1.98-1.7              DelayedArray_0.22.0
[23] compiler_4.2.0              MatrixGenerics_1.8.1
[25] Biostrings_2.64.0           Rsamtools_2.12.0
[27] XML_3.99-0.10

Interestingly, the second example (from ?import.bw) works as expected:

> which <- GRanges(c("chr2", "chr2"), IRanges(c(1, 300), c(400, 1000)))
> import(test_bw, which = which)
GRanges object with 4 ranges and 1 metadata column:
      seqnames    ranges strand |     score
         <Rle> <IRanges>  <Rle> | <numeric>
  [1]     chr2     1-300      * |        -1
  [2]     chr2     1-300      * |        -1
  [3]     chr2     1-300      * |        -1
  [4]     chr2     1-300      * |        -1
  -------
  seqinfo: 2 sequences from an unspecified genome

While the next one raises the same error:

> mini <- narrow(unlist(tile(which, 50)), 2)
> import(test_bw, which = mini, as = "RleList")
Error in stop_if_wrong_length(what, ans_len) :
  'ranges' must have the length of the object to construct (83) or length
  1

The same error occurs when running the package unit tests (with rtracklayer:::.test()) for test_bw.R, the other tests pass:

> rtracklayer:::.test()

Attaching package: ‘BiocGenerics’

The following objects are masked from ‘package:stats’:

    IQR, mad, sd, var, xtabs

The following objects are masked from ‘package:base’:

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min


Attaching package: ‘S4Vectors’

The following objects are masked from ‘package:base’:

    expand.grid, I, unname


Attaching package: ‘Biostrings’

The following object is masked from ‘package:base’:

    strsplit

Timing stopped at: 0.045 0.003 0.049
Error in stop_if_wrong_length(what, ans_len) :
  'ranges' must have the length of the object to construct (9) or length
  1
In addition: Warning messages:
1: Use BiocIO::FileForFormat
2: Use BiocIO::FileForFormat
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
For efficiency, consider converting this WIG file to a BigWig file;
see ?wigToBigWig


RUNIT TEST PROTOCOL -- Tue Jul 26 02:43:41 2022
***********************************************
Number of test functions: 11
Number of errors: 1
Number of failures: 0


1 Test Suite :
rtracklayer RUnit Tests - 11 test functions, 1 error, 0 failures
ERROR in test_bw: Error in stop_if_wrong_length(what, ans_len) :
  'ranges' must have the length of the object to construct (9) or length
  1

Test files with failing tests

   test_bw.R
     test_bw


Error in BiocGenerics:::testPackage("rtracklayer") :
  unit tests failed for package rtracklayer
In addition: There were 14 warnings (use warnings() to see them)

BiocManager::valid() for this setup returns TRUE (BiocManager::version() is 3.15).

I also have a setup with R 4.2.1 and Bioconductor 3.16 which behaves the same as above.

rtracklayer • 1.8k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 40 minutes ago
United States

Showing the error without the function call is not helpful. Neither is saying that you did something without showing what you did. How can we possibly help? You do say you can't run the example data, but it seems OK to me.

> test_path <- system.file("tests", package = "rtracklayer")
> test_bw <- file.path(test_path, "test.bw")
> gr <- import(test_bw)
> gr
GRanges object with 9 ranges and 1 metadata column:
      seqnames    ranges strand |     score
         <Rle> <IRanges>  <Rle> | <numeric>
  [1]     chr2     1-300      * |     -1.00
  [2]     chr2   301-600      * |     -0.75
  [3]     chr2   601-900      * |     -0.50
  [4]     chr2  901-1200      * |     -0.25
  [5]     chr2 1201-1500      * |      0.00
  [6]    chr19 1501-1800      * |      0.25
  [7]    chr19 1801-2100      * |      0.50
  [8]    chr19 2101-2400      * |      0.75
  [9]    chr19 2401-2700      * |      1.00
  -------
  seqinfo: 2 sequences from an unspecified genome
> which <- GRanges(c("chr2", "chr2"), IRanges(c(1, 300), c(400, 1000)))
> import(test_bw, which = which)
GRanges object with 4 ranges and 1 metadata column:
      seqnames    ranges strand |     score
         <Rle> <IRanges>  <Rle> | <numeric>
  [1]     chr2     1-300      * |     -1.00
  [2]     chr2   301-600      * |     -0.75
  [3]     chr2   601-900      * |     -0.50
  [4]     chr2  901-1000      * |     -0.25
  -------
  seqinfo: 2 sequences from an unspecified genome
> mini <- narrow(unlist(tile(which, 50)), 2)
> rle <- import(test_bw, which = mini, as = "RleList")
>  rle
RleList of length 2
$chr2
numeric-Rle of length 243199373 with 164 runs
  Lengths:         1         7         1 ...         1        14 243198373
  Values :         0        -1         0 ...      0.00     -0.25      0.00

$chr19
numeric-Rle of length 59128983 with 1 run
  Lengths: 59128983
  Values :        0

> bwf <- BigWigFile(test_bw)
> track <- import(bwf)
> seqinfo(bwf)
Seqinfo object with 2 sequences from an unspecified genome:
  seqnames seqlengths isCircular genome
  chr2      243199373         NA   <NA>
  chr19      59128983         NA   <NA>
>

If you provide a self-contained example that doesn't work for you, we may be able to help.

ADD COMMENT
0
Entering edit mode

Yes, the very three first lines (from ?import.bw) you show do fail on my setup:

> test_path <- system.file("tests", package = "rtracklayer")
> test_bw <- file.path(test_path, "test.bw")
> import(test_bw)
Error in stop_if_wrong_length(what, ans_len) : 
  'ranges' must have the length of the object to construct (9) or length 1

As do the unit tests (only test_bw fails, the other 10 tests pass):

> rtracklayer:::.test()
Error in stop_if_wrong_length(what, ans_len) : 
  'ranges' must have the length of the object to construct (9) or length 1
In addition: Warning messages:
1: Use BiocIO::FileForFormat 
2: Use BiocIO::FileForFormat 
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
For efficiency, consider converting this WIG file to a BigWig file;
see ?wigToBigWig

RUNIT TEST PROTOCOL -- Thu Jul 21 05:13:04 2022 
*********************************************** 
Number of test functions: 11 
Number of errors: 1 
Number of failures: 0 


1 Test Suite : 
rtracklayer RUnit Tests - 11 test functions, 1 error, 0 failures
ERROR in test_bw: Error in stop_if_wrong_length(what, ans_len) : 
  'ranges' must have the length of the object to construct (9) or length 1

Test files with failing tests

   test_bw.R 
     test_bw 


Error in BiocGenerics:::testPackage("rtracklayer") : 
  unit tests failed for package rtracklayer

Ah, that's interesting, if I go with the next two lines of ?import.bw, which provide a which argument, it works:

> which <- GRanges(c("chr2", "chr2"), IRanges(c(1, 300), c(400, 1000)))
> import(test_bw, which = which)
GRanges object with 4 ranges and 1 metadata column:
      seqnames    ranges strand |     score
         <Rle> <IRanges>  <Rle> | <numeric>
  [1]     chr2     1-300      * |        -1
  [2]     chr2     1-300      * |        -1
  [3]     chr2     1-300      * |        -1
  [4]     chr2     1-300      * |        -1
  -------
  seqinfo: 2 sequences from an unspecified genome
ADD REPLY
0
Entering edit mode

What do you get if you do

> test_path <- system.file("tests", package = "rtracklayer")
>
> test_bw <- file.path(test_path, "test.bw")
> file.info(test_bw)$size
[1] 74326
ADD REPLY
0
Entering edit mode

Same as you get:

> test_path <- system.file("tests", package = "rtracklayer")
> test_bw <- file.path(test_path, "test.bw")
> file.info(test_bw)$size
[1] 74326
ADD REPLY
0
Entering edit mode

The unit tests work for me.

> rtracklayer:::.test()

Attaching package: ‘Biostrings’

The following object is masked from ‘package:base’:

    strsplit

Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
For efficiency, consider converting this WIG file to a BigWig file;
see ?wigToBigWig


RUNIT TEST PROTOCOL -- Thu Jul 21 05:34:06 2022
***********************************************
Number of test functions: 11
Number of errors: 0
Number of failures: 0


1 Test Suite :
rtracklayer RUnit Tests - 11 test functions, 0 errors, 0 failures
Number of test functions: 11
Number of errors: 0
Number of failures: 0
There were 25 warnings (use warnings() to see them)

And here's my sessionInfo(). What you presented above was not after loading rtracklayer, so please provide the results after loading relevant packages.


> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /share/apps/MKL/mkl-2019.3/compilers_and_libraries_2019.3.199/linux/mkl/lib/intel64_lin/libmkl_gf_lp64.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods
[8] base

other attached packages:
[1] rtracklayer_1.56.1   GenomicRanges_1.48.0 GenomeInfoDb_1.32.2
[4] IRanges_2.30.0       S4Vectors_0.34.0     BiocGenerics_0.42.0

loaded via a namespace (and not attached):
 [1] XVector_0.36.0              zlibbioc_1.42.0
 [3] GenomicAlignments_1.32.0    BiocParallel_1.30.3
 [5] lattice_0.20-45             rjson_0.2.21
 [7] tools_4.2.0                 grid_4.2.0
 [9] SummarizedExperiment_1.26.1 parallel_4.2.0
[11] Biobase_2.56.0              matrixStats_0.62.0
[13] yaml_2.3.5                  crayon_1.5.1
[15] BiocIO_1.6.0                Matrix_1.4-1
[17] GenomeInfoDbData_1.2.8      restfulr_0.0.15
[19] bitops_1.0-7                codetools_0.2-18
[21] RCurl_1.98-1.7              DelayedArray_0.22.0
[23] compiler_4.2.0              MatrixGenerics_1.8.1
[25] Biostrings_2.64.0           Rsamtools_2.12.0
[27] XML_3.99-0.10
ADD REPLY
0
Entering edit mode

Sorry for not having been careful with the guidelines, I've been behaving like a newbie here, and thanks for your patience!

I've edited the initial post so as to put (hopefully) the proper relevant elements.

ADD REPLY
0
Entering edit mode

Hi I have got the exact problem. Mine worked under R4.0 but has the same as yours under R 4.2. How did you end up dealing with this?

ADD REPLY
0
Entering edit mode

Hi, I have the exact same problem on R 4.2. However, everything works under R 4.0. I posted my code below.

> rtracklayer:::.test()

Attaching package: ‘Biostrings’

The following object is masked from ‘package:base’:

    strsplit

Timing stopped at: 0.03 0 0.029
Error in stop_if_wrong_length(what, ans_len) : 
  'ranges' must have the length of the object to construct (9) or length 1
In addition: Warning messages:
1: Use BiocIO::FileForFormat 
2: Use BiocIO::FileForFormat 
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
Warning in readGFF(filepath, version = version, filter = filter) :
  connection is not positioned at the start of the file, rewinding it
For efficiency, consider converting this WIG file to a BigWig file;
see ?wigToBigWig


RUNIT TEST PROTOCOL -- Wed Oct 19 05:42:44 2022 
*********************************************** 
Number of test functions: 11 
Number of errors: 1 
Number of failures: 0 


1 Test Suite : 
rtracklayer RUnit Tests - 11 test functions, 1 error, 0 failures
ERROR in test_bw: Error in stop_if_wrong_length(what, ans_len) : 
  'ranges' must have the length of the object to construct (9) or length 1

Test files with failing tests

   test_bw.R 
     test_bw 


Error in BiocGenerics:::testPackage("rtracklayer") : 
  unit tests failed for package rtracklayer
In addition: There were 14 warnings (use warnings() to see them)`

And my sessionInfo()

R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] BSgenome.Hsapiens.UCSC.hg19_1.4.3 BSgenome_1.64.0                   Biostrings_2.64.1                 XVector_0.36.0                   
 [5] RUnit_0.4.32                      rtracklayer_1.56.1                GenomicRanges_1.48.0              GenomeInfoDb_1.32.3              
 [9] IRanges_2.30.1                    S4Vectors_0.34.0                  BiocGenerics_0.42.0              

loaded via a namespace (and not attached):
 [1] SummarizedExperiment_1.26.1 tidyselect_1.1.2            xfun_0.32                   purrr_0.3.4                
 [5] lattice_0.20-45             vctrs_0.4.1                 generics_0.1.3              htmltools_0.5.3            
 [9] yaml_2.3.5                  utf8_1.2.2                  XML_3.99-0.10               rlang_1.0.5                
[13] pillar_1.8.1                glue_1.6.2                  DBI_1.1.3                   BiocParallel_1.30.3        
[17] matrixStats_0.62.0          GenomeInfoDbData_1.2.8      lifecycle_1.0.1             zlibbioc_1.42.0            
[21] MatrixGenerics_1.8.1        codetools_0.2-18            evaluate_0.16               restfulr_0.0.15            
[25] Biobase_2.56.0              knitr_1.40                  fastmap_1.1.0               parallel_4.2.1             
[29] fansi_1.0.3                 DelayedArray_0.22.0         Rsamtools_2.12.0            rjson_0.2.21               
[33] digest_0.6.29               dplyr_1.0.10                BiocIO_1.6.0                grid_4.2.1                 
[37] cli_3.3.0                   tools_4.2.1                 bitops_1.0-7                magrittr_2.0.3             
[41] RCurl_1.98-1.8              tibble_3.1.8                crayon_1.5.1                pkgconfig_2.0.3            
[45] Matrix_1.5-1                assertthat_0.2.1            rmarkdown_2.16              rstudioapi_0.14            
[49] R6_2.5.1                    GenomicAlignments_1.32.1    compiler_4.2.1
ADD REPLY

Login before adding your answer.

Traffic: 864 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6