Skip to content

Commit

Permalink
fix #32 - inconsistent 0/1-based intron handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thackl committed Feb 2, 2021
1 parent 4e378e7 commit ef25576
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion R/geom_gene.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ GeomGene <- ggplot2::ggproto("GeomGene", ggplot2::Geom,
# unnest exons before coord$transform so all x/xend get transformed
data <- mutate(data,
id = row_number(),
introns = ifelse(type %in% params$intron_types, introns, list(NULL)))
introns = ifelse(type %in% params$intron_types, introns, list(NULL)),
introns = map(introns, ~.x - c(1, 0)) # convert 1[s,e] to 0[s,e) for drawing
)

data <- unnest_exons(data)
},
Expand Down Expand Up @@ -264,6 +266,8 @@ exon_spans <- function(x, xend, introns, ...){

introns <- if(x<xend) x + introns else xend + rev(introns)
exons <- c(x, introns, xend)
print(introns)
print(exons)

as_tibble(vec_unzip(exons, c("x", "xend")))
}
Expand Down
3 changes: 2 additions & 1 deletion R/read_gff3.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@ coords2introns <- function(starts, ends){
return(NULL)
i <- 2:n
# introns: start, end, start2, end2, ...
c(rbind(ends[i-1], starts[i])) - starts[1]
# +2 corrects of 1[s,e] coord issues
c(rbind(ends[i-1]+2, starts[i])) - starts[1]
}

0 comments on commit ef25576

Please sign in to comment.