Skip to content

Commit

Permalink
Refactoring: Added helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
mevers committed Nov 4, 2019
1 parent c183789 commit 159db94
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
22 changes: 22 additions & 0 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ CheckClassTxLocConsistency <- function(obj1, obj2) {
}


#' Match `flank` function argument
#'
#' @param flank An \code{integer} scalar or an \code{nteger} vector of length 2.
#'
#' @return An \code{integer} vector of length 2.
#'
#' @author Maurits Evers, \email{maurits.evers@@anu.edu.au}
MatchFlank <- function(flank) {

if (length(flank) == 1) {
if (flank < 0) stop("`flank` cannot be negative!")
return(c(-abs(flank), abs(flank)))
} else if (length(flank) == 2) {
if (any(flank < 0)) stop("`flank` cannot be negative!")
return(c(-abs(flank[1]), abs(flank[2])))
} else {
stop("`flank` needs to be a scalar or a vector of length 2!")
}

}


#' Load reference transcriptome.
#'
#' Load reference transcriptome. See 'Details'.
Expand Down
26 changes: 4 additions & 22 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -965,13 +965,7 @@ PlotRelDistDistribution <- function(txLoc,
CheckClassTxLocConsistency(txLoc, txLocRef)

# Allow for variable window sizes
if (length(flank) == 1) {
flank <- c(-abs(flank), abs(flank))
} else if (length(flank) == 2) {
flank <- c(-abs(flank[1]), abs(flank[2]))
} else {
stop("`flank` needs to be a scalar or vector of length 2!")
}
flank <- MatchFlank(flank)

# Get ids
id <- GetId(txLoc)
Expand Down Expand Up @@ -1073,14 +1067,8 @@ PlotRelDistEnrichment <- function(txLoc1,
CheckClassTxLocConsistency(txLoc2, txLocRef)

# Allow for variable window sizes
if (length(flank) == 1) {
flank <- c(-abs(flank), abs(flank))
} else if (length(flank) == 2) {
flank <- c(-abs(flank[1]), abs(flank[2]))
} else {
stop("`flank` needs to be a scalar or vector of length 2!")
}

flank <- MatchFlank(flank)

# Get ids
id1 <- GetId(txLoc1)
id2 <- GetId(txLoc2)
Expand Down Expand Up @@ -1277,13 +1265,7 @@ PlotRelStartStopEnrichment <- function(txLoc1,
lstDist2 <- GetDistNearestStartStop(txLoc2)

# Allow for variable window sizes
if (length(flank) == 1) {
flank <- c(-abs(flank), abs(flank))
} else if (length(flank) == 2) {
flank <- c(-abs(flank[1]), abs(flank[2]))
} else {
stop("`flank` needs to be a scalar or vector of length 2!")
}
flank <- MatchFlank(flank)

# Determine figure panel layout
par(mfrow = c(1, 2))
Expand Down
20 changes: 20 additions & 0 deletions man/MatchFlank.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 159db94

Please sign in to comment.