rnabioco / valr

Genome Interval Arithmetic in R
http://rnabioco.github.io/valr/
Other
88 stars 25 forks source link

bed_slop failed test "crossover during negative slop" #320

Closed raysinensis closed 6 years ago

raysinensis commented 6 years ago

start and end not reversed when crossover occurs

library(valr)
tiny.genome <- tibble::tribble(
  ~chrom, ~size,
  "chr1", 1000
)
b <- tibble::tribble(
  ~chrom, ~start, ~end, ~name, ~score, ~strand,
  "chr1", 300, 320, "a1", 5, "-"
)
res <- bed_slop(b, tiny.genome, left = -60, right = -60, strand = TRUE)
res
#> # A tibble: 1 x 6
#>   chrom start   end  name score strand
#>   <chr> <dbl> <dbl> <chr> <dbl>  <chr>
#> 1  chr1   360   260    a1     5      -

Created on 2018-01-19 by the reprex package (v0.1.1.9000).

raysinensis commented 6 years ago

adding a step to check at the end of bed_slop() fixes the issue

res <- res %>% mutate(temp.start = start, temp.end = end) %>%
                 mutate(start = ifelse(temp.start - temp.end < 0, temp.start, temp.end),
                        end = ifelse(temp.start - temp.end < 0, temp.end, temp.start)) %>%
            select(-temp.start,-temp.end)