Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected behavior when intersecting three tibbles #380

Closed
sheridar opened this issue Oct 15, 2021 · 2 comments
Closed

unexpected behavior when intersecting three tibbles #380

sheridar opened this issue Oct 15, 2021 · 2 comments
Assignees
Labels

Comments

@sheridar
Copy link
Member

sheridar commented Oct 15, 2021

When passing a list of tibbles to bed_intersect an unexpected error is thrown:

x <- tibble::tribble(
  ~chrom, ~start, ~end,
  'chr1', 100,    500,
  'chr2', 200,    400,
  'chr2', 300,    500,
  'chr2', 800,    900
)

y <- tibble::tribble(
  ~chrom, ~start, ~end, ~value,
  'chr1', 150,    400,  100,
  'chr1', 500,    550,  100,
  'chr2', 230,    430,  200,
  'chr2', 350,    430,  300
)

z <- tibble::tribble(
  ~chrom, ~start, ~end, ~value,
  'chr1', 150,    400,  100,
  'chr1', 500,    550,  100,
  'chr2', 230,    430,  200,
  'chr2', 750,    900,  400
)

lst <- list(y, z)

# These variations work:
bed_intersect(x, y, z)
bed_intersect(x, list(y, z))
bed_intersect(x, lst[1:2])

# VARIATION 1: If a list is passed, error is thrown
# this seems to be due to line 91:
# https://github.com/rnabioco/valr/blob/799dd742ebd681bced0ce03f294d55487729aeaf/R/bed_intersect.r#L91
bed_intersect(x, lst)

# this produces different error
bed_intersect(x, lst[1])

# VARIATION 2: This ignores the third tibble
bed_intersect(x, lst[[1]], lst[[2]])
@kriemo
Copy link
Member

kriemo commented Oct 15, 2021

thanks for the detailed reprex. I worried that code might not be robust for detecting certain inputs. I'll work on a solution.

@kriemo kriemo self-assigned this Oct 15, 2021
@kriemo
Copy link
Member

kriemo commented Oct 17, 2021

With the changes introduced by #381 these errors should be resolved. Github actions are not running the build checks for ubuntu for some reason. Once these complete successfully I'll merge the changes and notify you.

library(valr)
library(tibble)
x <- tibble::tribble(
  ~chrom, ~start, ~end,
  'chr1', 100,    500,
  'chr2', 200,    400,
  'chr2', 300,    500,
  'chr2', 800,    900
)

y <- tibble::tribble(
  ~chrom, ~start, ~end, ~value,
  'chr1', 150,    400,  100,
  'chr1', 500,    550,  100,
  'chr2', 230,    430,  200,
  'chr2', 350,    430,  300
)

z <- tibble::tribble(
  ~chrom, ~start, ~end, ~value,
  'chr1', 150,    400,  100,
  'chr1', 500,    550,  100,
  'chr2', 230,    430,  200,
  'chr2', 750,    900,  400
)

lst <- list(y, z)

bed_intersect(x, y, z)
#> # A tibble: 11 × 8
#>    chrom start.x end.x start.y end.y value.y .source .overlap
#>    <chr>   <dbl> <dbl>   <dbl> <dbl>   <dbl> <chr>      <int>
#>  1 chr1      100   500     150   400     100 y            250
#>  2 chr1      100   500     150   400     100 z            250
#>  3 chr1      100   500     500   550     100 y              0
#>  4 chr1      100   500     500   550     100 z              0
#>  5 chr2      200   400     230   430     200 y            170
#>  6 chr2      200   400     230   430     200 z            170
#>  7 chr2      200   400     350   430     300 y             50
#>  8 chr2      300   500     230   430     200 y            130
#>  9 chr2      300   500     230   430     200 z            130
#> 10 chr2      300   500     350   430     300 y             80
#> 11 chr2      800   900     750   900     400 z            100
bed_intersect(x, list(y, z))
#> # A tibble: 11 × 8
#>    chrom start.x end.x start.y end.y value.y .source .overlap
#>    <chr>   <dbl> <dbl>   <dbl> <dbl>   <dbl> <chr>      <int>
#>  1 chr1      100   500     150   400     100 y            250
#>  2 chr1      100   500     150   400     100 z            250
#>  3 chr1      100   500     500   550     100 y              0
#>  4 chr1      100   500     500   550     100 z              0
#>  5 chr2      200   400     230   430     200 y            170
#>  6 chr2      200   400     230   430     200 z            170
#>  7 chr2      200   400     350   430     300 y             50
#>  8 chr2      300   500     230   430     200 y            130
#>  9 chr2      300   500     230   430     200 z            130
#> 10 chr2      300   500     350   430     300 y             80
#> 11 chr2      800   900     750   900     400 z            100
bed_intersect(x, lst[1:2])
#> # A tibble: 11 × 8
#>    chrom start.x end.x start.y end.y value.y .source .overlap
#>    <chr>   <dbl> <dbl>   <dbl> <dbl>   <dbl> <chr>      <int>
#>  1 chr1      100   500     150   400     100 1            250
#>  2 chr1      100   500     150   400     100 2            250
#>  3 chr1      100   500     500   550     100 1              0
#>  4 chr1      100   500     500   550     100 2              0
#>  5 chr2      200   400     230   430     200 1            170
#>  6 chr2      200   400     230   430     200 2            170
#>  7 chr2      200   400     350   430     300 1             50
#>  8 chr2      300   500     230   430     200 1            130
#>  9 chr2      300   500     230   430     200 2            130
#> 10 chr2      300   500     350   430     300 1             80
#> 11 chr2      800   900     750   900     400 2            100

bed_intersect(x, lst)
#> # A tibble: 11 × 8
#>    chrom start.x end.x start.y end.y value.y .source .overlap
#>    <chr>   <dbl> <dbl>   <dbl> <dbl>   <dbl> <chr>      <int>
#>  1 chr1      100   500     150   400     100 1            250
#>  2 chr1      100   500     150   400     100 2            250
#>  3 chr1      100   500     500   550     100 1              0
#>  4 chr1      100   500     500   550     100 2              0
#>  5 chr2      200   400     230   430     200 1            170
#>  6 chr2      200   400     230   430     200 2            170
#>  7 chr2      200   400     350   430     300 1             50
#>  8 chr2      300   500     230   430     200 1            130
#>  9 chr2      300   500     230   430     200 2            130
#> 10 chr2      300   500     350   430     300 1             80
#> 11 chr2      800   900     750   900     400 2            100

bed_intersect(x, lst[1])
#> # A tibble: 6 × 7
#>   chrom start.x end.x start.y end.y value.y .overlap
#>   <chr>   <dbl> <dbl>   <dbl> <dbl>   <dbl>    <int>
#> 1 chr1      100   500     150   400     100      250
#> 2 chr1      100   500     500   550     100        0
#> 3 chr2      200   400     230   430     200      170
#> 4 chr2      200   400     350   430     300       50
#> 5 chr2      300   500     230   430     200      130
#> 6 chr2      300   500     350   430     300       80

bed_intersect(x, lst[[1]], lst[[2]])
#> # A tibble: 11 × 8
#>    chrom start.x end.x start.y end.y value.y .source .overlap
#>    <chr>   <dbl> <dbl>   <dbl> <dbl>   <dbl> <chr>      <int>
#>  1 chr1      100   500     150   400     100 1            250
#>  2 chr1      100   500     150   400     100 2            250
#>  3 chr1      100   500     500   550     100 1              0
#>  4 chr1      100   500     500   550     100 2              0
#>  5 chr2      200   400     230   430     200 1            170
#>  6 chr2      200   400     230   430     200 2            170
#>  7 chr2      200   400     350   430     300 1             50
#>  8 chr2      300   500     230   430     200 1            130
#>  9 chr2      300   500     230   430     200 2            130
#> 10 chr2      300   500     350   430     300 1             80
#> 11 chr2      800   900     750   900     400 2            100

Created on 2021-10-17 by the reprex package (v2.0.0)

@kriemo kriemo closed this as completed in 7f0672e Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants