Skip to content

Commit

Permalink
added function to pull knot distribution -- closes #130
Browse files Browse the repository at this point in the history
  • Loading branch information
jr-leary7 committed Oct 10, 2023
1 parent 5d2cf93 commit 82973ab
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
34 changes: 34 additions & 0 deletions R/getKnotDist.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Pull the set of knots for dynamic genes across each lineage.
#'
#' @name getKnotDist
#' @author Jack Leary
#' @import magrittr
#' @importFrom purrr imap reduce
#' @description Pulls knot locations for dynamic genes across each lineage, allowing comparisons of where transcriptional switches occur between lineages.
#' @param test.dyn.res The output from \code{\link{testDynamic}}. Defaults to NULL.
#' @param dyn.genes The set of genes to pull knots for. If unspecified, pulls knots for all modeled genes. Defaults to NULL.
#' @return A data.frame containing gene name, lineage ID, and knot location in pseudotime.
#' @export
#' @examples
#' \dontrun{
#' getKnotDist(gene_stats)
#' }

getKnotDist <- function(test.dyn.res = NULL, dyn.genes = NULL) {
# check inputs
if (is.null(test.dyn.res)) { stop("You forgot one of the arguments to getKnotDist().") }
if (is.null(dyn.genes)) {
dyn.genes <- names(test.dyn.res)
}
# pull knots per-lineage
knot_df <- purrr::imap(test.dyn.res[dyn.genes], \(x, y) {
purrr::imap(x, \(z, w) {
data.frame(gene = y,
lineage = w,
knot = z$MARGE_Slope_Data$Breakpoint)
}) %>%
purrr::reduce(rbind)
}) %>%
purrr::reduce(rbind)
return(knot_df)
}
27 changes: 27 additions & 0 deletions man/getKnotDist.Rd

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

0 comments on commit 82973ab

Please sign in to comment.