Skip to contents

Columns are automatically typed based on the autoSql schema embedded in the bigBed file. Integer types (uint, int) become R integers, floating point types (float, double) become R doubles, and all other types (including array types like int[blockCount]) remain as character strings.

Usage

read_bigbed(bbfile, chrom = NULL, start = NULL, end = NULL)

Arguments

bbfile

path or URL for a bigBed file. Remote files (http://, https://, ftp://) are supported when the package was installed with libcurl available.

chrom

chromosome(s) to read. Either a character vector of chromosome names, or a GenomicRanges::GRanges of query regions (in which case start/end are ignored). As with read_bigwig(), GRanges 1-based coordinates are converted to bigBed's 0-based half-open coordinates.

start

start position(s) for data. May be a vector describing several ranges, recycled against chrom/end.

end

end position(s) for data. May be a vector describing several ranges, recycled against chrom/start.

Value

tibble

Details

When a bigBed file has no embedded autoSql schema (for example one produced by bedToBigBed without -as), columns are still recovered using the standard BED field names (name, score, strand, thickStart, thickEnd, itemRgb, blockCount, blockSizes, blockStarts) derived from the file's field counts. Any additional (bedN+) fields beyond the standard BED columns are returned as generic fieldN character columns. Because those names are inferred rather than declared by the file, a message() is emitted in this case; silence it with base::suppressMessages().

Examples

bb <- system.file("extdata", "test.bb", package = "cpp11bigwig")

read_bigbed(bb)
#> # A tibble: 3 × 12
#>   chrom  start    end name  score strand thickStart thickEnd reserved blockCount
#>   <chr>  <int>  <int> <chr> <int> <chr>       <int>    <int>    <int>      <int>
#> 1 chr1  4.80e6 4.84e6 test…     1 +         4797973  4836816        1          9
#> 2 chr10 4.85e6 4.88e6 diff…     1 +         4848118  4880877        1          6
#> 3 chr20 5.07e6 5.15e6 negs…     1 -         5073253  5152630        1         14
#> # ℹ 2 more variables: blockSizes <chr>, chromStarts <chr>

read_bigbed(bb, chrom = "chr10")
#> # A tibble: 1 × 12
#>   chrom  start    end name  score strand thickStart thickEnd reserved blockCount
#>   <chr>  <int>  <int> <chr> <int> <chr>       <int>    <int>    <int>      <int>
#> 1 chr10 4.85e6 4.88e6 diff…     1 +         4848118  4880877        1          6
#> # ℹ 2 more variables: blockSizes <chr>, chromStarts <chr>

# query several chromosomes in one call
read_bigbed(bb, chrom = c("chr1", "chr10"))
#> # A tibble: 2 × 12
#>   chrom  start    end name  score strand thickStart thickEnd reserved blockCount
#>   <chr>  <int>  <int> <chr> <int> <chr>       <int>    <int>    <int>      <int>
#> 1 chr1  4.80e6 4.84e6 test…     1 +         4797973  4836816        1          9
#> 2 chr10 4.85e6 4.88e6 diff…     1 +         4848118  4880877        1          6
#> # ℹ 2 more variables: blockSizes <chr>, chromStarts <chr>

# restrict each query to a window
read_bigbed(bb, chrom = c("chr1", "chr10"), start = c(0, 0), end = c(5e6, 5e6))
#> # A tibble: 2 × 12
#>   chrom  start    end name  score strand thickStart thickEnd reserved blockCount
#>   <chr>  <int>  <int> <chr> <int> <chr>       <int>    <int>    <int>      <int>
#> 1 chr1  4.80e6 4.84e6 test…     1 +         4797973  4836816        1          9
#> 2 chr10 4.85e6 4.88e6 diff…     1 +         4848118  4880877        1          6
#> # ℹ 2 more variables: blockSizes <chr>, chromStarts <chr>

# pass a GRanges of regions; 1-based coords are converted automatically
gr <- GenomicRanges::GRanges(
  c("chr1", "chr10"),
  IRanges::IRanges(start = 1, width = 1e7)
)
read_bigbed(bb, chrom = gr)
#> # A tibble: 2 × 12
#>   chrom  start    end name  score strand thickStart thickEnd reserved blockCount
#>   <chr>  <int>  <int> <chr> <int> <chr>       <int>    <int>    <int>      <int>
#> 1 chr1  4.80e6 4.84e6 test…     1 +         4797973  4836816        1          9
#> 2 chr10 4.85e6 4.88e6 diff…     1 +         4848118  4880877        1          6
#> # ℹ 2 more variables: blockSizes <chr>, chromStarts <chr>