Skip to content

Commit

Permalink
Return empty objects when receiving empty objects.
Browse files Browse the repository at this point in the history
Closes #25
  • Loading branch information
charles-plessy committed Jul 7, 2023
1 parent ab69705 commit 48bdf79
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions R/Translocations.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#' @export

flagTranslocations <- function (gb, tol = Inf, both = TRUE) {
if(length(gb) == 0) {
gb$tra <- Rle(logical(0))
return(gb)
}
# Enforce sorting, to guarantee colinearity on the _target_ranges
if (isFALSE(isSorted(gb))) stop ("Can not run on non-sorted objects.")
gb.bak <- gb # save the original object
Expand Down
5 changes: 4 additions & 1 deletion R/flagColinearAlignments.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ flagColinearAlignments <- function(gb, tol = Inf, minwidth = 0, details = FALSE)
gb <- gb[width(gb$query) >= minwidth]

# Handle empty objects
if (length(gb) == 0) return(gb)
if(length(gb) == 0) {
gb$colinear <- logical(0)
return(gb)
}

# Sort the ranges following the target genome. The argument
# ignore.strand = TRUE is set so that alignments on the opposite strand can
Expand Down
9 changes: 9 additions & 0 deletions R/flagInversions.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#' @export

flagInversions <- function (gb, tol = Inf) {
if(length(gb) == 0) {
gb$inv <- Rle(logical(0))
return(gb)
}
if (isFALSE(isSorted(gb))) stop ("Can not run on non-sorted objects.")
gb.bak <- gb # save the original object
gb <- dist2next(gb, ignore.strand = TRUE)
Expand Down Expand Up @@ -113,6 +117,10 @@ flagInversions <- function (gb, tol = Inf) {
#' @export

flagDoubleInversions <- function(gb, details = FALSE) {
if(length(gb) == 0) {
gb$Dbl <- Rle(logical(0))
return(gb)
}
if (isFALSE(isSorted(gb))) stop ("Can not run on non-sorted objects.")

gb.bak <- gb # Backup the object
Expand Down Expand Up @@ -194,6 +202,7 @@ flagDoubleInversions <- function(gb, details = FALSE) {
#' @export

showInversions <- function(gb, rename = TRUE) {
if(length(gb) == 0) return(gb)
if (is.null(gb$inv)) return(gb[0])
if (isTRUE(rename))
names(gb) <- seq_along(gb)
Expand Down
4 changes: 4 additions & 0 deletions R/flagPairs.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ allPossiblePairClasses <- with(allPossiblePairClasses, {
#' @export

flagPairs <- function (gb) {
if(length(gb) == 0) {
gb$pairs <- factor(character(0))
return(gb)
}
if (isFALSE(isSorted(gb))) stop ("Can not run on non-sorted objects.")
gb.bak <- gb # save the original object

Expand Down

0 comments on commit 48bdf79

Please sign in to comment.