Skip to content

Commit

Permalink
Merge branch 'master' into modify-terminalStateFromMarkovChain-
Browse files Browse the repository at this point in the history
  • Loading branch information
zktuong authored Dec 12, 2024
2 parents f389c0c + 748dabb commit 84d7296
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 41 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/R-CMD-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
config:
- { os: ubuntu-latest }
# - { os: macos-latest } # disabling until https://github.com/r-lib/actions/issues/950 is resolved
- { os: macos-latest } # disabling until https://github.com/r-lib/actions/issues/950 is resolved
- { os: windows-latest }
runs-on: ${{ matrix.config.os }}
env:
Expand Down Expand Up @@ -60,7 +60,6 @@ jobs:
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
packages: any::covr

- uses: r-lib/actions/check-r-package@v2

Expand All @@ -80,6 +79,12 @@ jobs:
- name: Debug permissions output
run: |
echo "Has permission: ${{ steps.check_permissions.outputs.has_permission }}"
- name: Setup to test coverage
uses: r-lib/actions/setup-r-dependencies@v2
if: steps.check_permissions.outputs.has_permission == 'true' && matrix.config.os == 'ubuntu-latest'
with:
packages: covr

- name: Test coverage
if: steps.check_permissions.outputs.has_permission == 'true' && matrix.config.os == 'ubuntu-latest'
Expand Down
10 changes: 5 additions & 5 deletions R/markovProbability.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ markovProbability <- function(
diffusiontime = NULL, pseudotime_key = "pseudotime", scale_components = TRUE,
num_waypoints = 500) {
if (is.null(milo[[pseudotime_key]])) {
if (is.null(diffusiontime)) {
if (is.null(diffusiontime)) { # nocov start
abort(paste(
"Missing pseudotime data. This data can be either stored in",
deparse(substitute(milo)), "or provided by parameter diffusiontime"
))
)) # nocov end
} else {
milo[[pseudotime_key]] <- diffusiontime
}
} else {
diffusiontime <- milo[[pseudotime_key]]
diffusiontime <- milo[[pseudotime_key]] # nocov
}

# scale data
Expand All @@ -98,7 +98,7 @@ markovProbability <- function(
colnames(new_coldata) <- c(names(terminal_state))
# prevent same name in colData
idx <- names(colData(milo)) %in% colnames(new_coldata)
if (any(idx)) {
if (any(idx)) { # nocov start
warning(paste(
"Name", paste(names(colData(milo))[idx], collapse = ", "),
"already exists in", as.character(substitute(milo))
Expand All @@ -121,7 +121,7 @@ markovProbability <- function(
message("Invalid response. Please enter 'y' or 'n'.")
}
}
}
} # nocov end
colData(milo) <- cbind(colData(milo), new_coldata)
return(milo)
}
28 changes: 14 additions & 14 deletions R/setupVdjPseudobulk.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ setupVdjPseudobulk <- function(
abort(paste(
"ValueError: length of check_vj_mapping should be 2. But", length(check_vj_mapping),
"was provided."
))
)) # nocov
}
.typeCheck(check_vdj_mapping, "logical")
if (length(check_vdj_mapping) != 3) {
abort(paste(
"ValueError: length of check_vj_mapping should be 3. But", length(check_vdj_mapping),
"was provided."
))
)) # nocov
}
.typeCheck(check_extract_cols_mapping, "character")
.typeCheck(remove_missing, "logical")

# filtering retain only productive entries based on specified mode
if (!already.productive) {
if (is.null(mode_option)) {
if (!is.null(productive_cols)) {
if (!is.null(productive_cols)) { # nocov start
msg <- paste(productive_cols, collapse = ", ")
message(sprintf("Checking productivity from %s ..."), appendLF = FALSE)
cnumber0 <- dim(sce)[2]
Expand All @@ -140,7 +140,7 @@ setupVdjPseudobulk <- function(
message(sprintf("%d of cells filtered", filtered))
} else {
abort("When mode_option is NULL, the productive_cols must be specified.")
}
} # nocov end
} else {
produ_col <- paste("productive", mode_option, c("VDJ", "VJ"), sep = "_")[c(
productive_vdj,
Expand Down Expand Up @@ -195,8 +195,8 @@ setupVdjPseudobulk <- function(
if (is.null(extract_cols)) {
message("Parameter extract_cols do not provided, automatically geneterate colnames for extraction.")
if (!length(grep("_VDJ_main|_VJ_main", names(colData(sce))))) {
v_call <- if ("v_call_genotyped_VDJ" %in% colnames(colData(sce))) {
"v_call_genotyped_"
v_call <- if ("v_call_genotyped_VDJ" %in% colnames(colData(sce))) { # nocov start
"v_call_genotyped_" # nocov end
} else {
"v_call_"
}
Expand All @@ -211,12 +211,12 @@ setupVdjPseudobulk <- function(
"d_call_", mode_option,
"_VJ"
)]
} else {
} else { # nocov start
suffix <- c("VDJ", "VJ")
extr_cols <- as.vector(outer(prefix, suffix, function(x, y) {
paste0(x, y)
}))
extr_cols <- extr_cols[extr_cols != paste0("d_call_", "VJ")]
extr_cols <- extr_cols[extr_cols != paste0("d_call_", "VJ")] # nocov end
}
msg <- paste(extr_cols, collapse = ", ")
message(sprintf("Detect whether colData %s already exist...", msg))
Expand All @@ -228,7 +228,7 @@ setupVdjPseudobulk <- function(
"Keyerror: Automatically generated colnames's length is",
length(extr_cols), ".It must have the same number with the vdj data columns, which is",
length(splitVdj[[1]]), "\nYou could use parameter extract_cols to specify the columns to match the length"
))
)) # nocov
} else {
vdj <- lapply(seq(length(extr_cols)), function(X, sc) {
vapply(X = sc, "[", X, FUN.VALUE = character(1))
Expand All @@ -241,7 +241,7 @@ setupVdjPseudobulk <- function(
"Keyerror: Automatically generated colnames", paste0(extr_cols[!extr_cols %in%
colnames(colData(sce))], collapse = ", "), "must be contained in colData",
"\nYou could use parameter extract_cols to specify the columns to extract TCR"
))
)) # nocov
}
message(sprintf("Extract main TCR from %s ...", msg), appendLF = FALSE)
sce <- Reduce(function(data, ex_col) {
Expand All @@ -255,7 +255,7 @@ setupVdjPseudobulk <- function(
}, extr_cols, init = sce)
message("Complete.")
}
} else {
} else { # nocov start
msg <- paste(extract_cols, collapse = ", ")
if (!any(extract_cols %in% colnames(colData(sce)))) {
message(sprintf(
Expand Down Expand Up @@ -294,7 +294,7 @@ setupVdjPseudobulk <- function(
data
}, extract_cols, init = sce)
message("Complete.")
}
} # nocov end
# remove unclear mapping
if (filter_unmapped) {
filter_pattern <- ",|None|No_contig"
Expand All @@ -315,7 +315,7 @@ setupVdjPseudobulk <- function(
))
}
} else {
if (is.null(extract_cols)) {
if (is.null(extract_cols)) { # nocov start
if (any(check_vdj_mapping)) {
vdj_mapping <- c("v_call", "d_call", "j_call")
extr_cols <- c(extr_cols, paste(vdj_mapping[check_vdj_mapping],
Expand All @@ -333,7 +333,7 @@ setupVdjPseudobulk <- function(
if (!is.null(check_extract_cols_mapping)) {
extr_cols <- check_extract_cols_mapping
}
}
} # nocov end
}
if (!is.null(extr_cols)) {
msg <- paste(extr_cols, collapse = ", ")
Expand Down
10 changes: 5 additions & 5 deletions R/splitCTgene.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ formatVdj <- function(gene_list) {
chainAssign <- function(vec, num) {
if (length(vec) == (num + 1)) {
chains <- vec[seq_len(num)]
} else if (all(vec == "NA")) {
} else if (all(vec == "NA")) { # nocov start
chains <- rep("None", num)
} else {
abort
abort # nocov end
}
return(chains)
}
Expand All @@ -64,16 +64,16 @@ chainAssign <- function(vec, num) {
# Check if all elements are also lists
all_are_lists <- TRUE
for (item in sublist) {
if (!is.list(item)) {
if (!is.list(item)) { # nocov start
all_are_lists <- FALSE
break
}
} # nocov end
}
# If all elements are lists, unlist one level
if (all_are_lists) {
return(unlist(sublist, recursive = FALSE))
}
}
return(sublist)
return(sublist) # nocov
})
}
8 changes: 4 additions & 4 deletions R/terminalStateFromMarkovChain.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' .terminalStateFromMarkovChain
#' Determine terminal states using Markov chain if terminal states are not provided.
#'
#' @param Transmat Transition matrix
#' @param wp_data Multi scale data of the waypoints
Expand All @@ -11,8 +11,8 @@
#' @importFrom spam nearest.dist
#' @return terminal_state
.terminalStateFromMarkovChain <- function(Transmat, wp_data, pseudotime, waypoints) {
message("No terminal state provided, indentification of terminal states....")
# Identify terminal states dm_boudaries
message("No terminal state provided, identification of terminal states....")
# Identify terminal states dm_boundaries
n <- min(dim(Transmat))
ei <- eigen(t(Transmat))
idx <- order(Re(ei$values), decreasing = TRUE)[seq_len(10)]
Expand All @@ -26,7 +26,7 @@
stats::median(ranks))))
# connect components of cells beyond cutoff
cells <- which(ranks > cutoff)
# Find connected componets
# Find connected components
graph <- graph_from_adjacency_matrix(Transmat[cells, cells],
weighted = TRUE,
mode = "directed"
Expand Down
18 changes: 9 additions & 9 deletions R/vdjPseudobulk.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ vdjPseudobulk <- function(milo, pbs = NULL, col_to_bulk = NULL, extract_cols = c
), col_to_take = NULL, normalise = TRUE, renormalise = FALSE, min_count = 1L) {
# type check
if (!is(milo, "Milo") && !is(milo, "SingleCellExperiment")) {
abort("Uncompatible data type, \nmilo msut be either Milo or SingleCellExperiment object")
abort("Uncompatible data type, \nmilo msut be either Milo or SingleCellExperiment object") # nocov
}
.classCheck(pbs, "Matrix")
if (!all(col_to_bulk %in% names(colData(milo)))) {
abort("Inappropriate argument value: \nocol_to_bulk should within the name of coldata of milo")
abort("Inappropriate argument value: \nocol_to_bulk should within the name of coldata of milo") # nocov
}
if (!all(col_to_take %in% names(colData(milo)))) {
abort("Inappropriate argument value: \ncol_to_take should within the name of coldata of milo")
abort("Inappropriate argument value: \ncol_to_take should within the name of coldata of milo") # nocov
}
.typeCheck(normalise, "logical")
.typeCheck(renormalise, "logical")
Expand All @@ -88,9 +88,9 @@ vdjPseudobulk <- function(milo, pbs = NULL, col_to_bulk = NULL, extract_cols = c
} else {
pbs <- .getPbs(pbs, col_to_bulk, milo)
}
# set the column used in caculation
# set the column used in calculation
if (is.null(extract_cols)) {
if (is.null(mode_option)) {
if (is.null(mode_option)) { # nocov start
all.col.n <- colnames(colData(milo))
extract_cols <- all.col.n[grep("_call_VDJ_main|_call_VJ_main", all.col.n)]
} else {
Expand All @@ -99,7 +99,7 @@ vdjPseudobulk <- function(milo, pbs = NULL, col_to_bulk = NULL, extract_cols = c
mode_option, "_VDJ_main|", mode_option,
"_call_VJ_main"
), all.col.n)]
}
} # nocov end
}
# perform matrix multiplication of pseudobulks by cell matrix by a cells by
# VJs matrix strat off by creating the cell by VJs matix skip the prefix
Expand All @@ -110,7 +110,7 @@ vdjPseudobulk <- function(milo, pbs = NULL, col_to_bulk = NULL, extract_cols = c
if (!is.factor(x)) {
as.factor(x)
} else {
x
x # nocov
}
})
requireNamespace("stats")
Expand Down Expand Up @@ -139,7 +139,7 @@ vdjPseudobulk <- function(milo, pbs = NULL, col_to_bulk = NULL, extract_cols = c
defined.min.counts <- define.count >= min_count
# normalise the pseudobulks
pseudo_vdj_feature[, group.define.mask] <- pseudo_vdj_feature[, group.define.mask] / define.count
if (renormalise) {
if (renormalise) { # nocov start
redefine.count <- apply(
pseudo_vdj_feature[defined.min.counts, group.define.mask],
1, sum
Expand All @@ -148,7 +148,7 @@ vdjPseudobulk <- function(milo, pbs = NULL, col_to_bulk = NULL, extract_cols = c
defined.min.counts,
group.define.mask
] / define.count
}
} # nocov end
pseudo_vdj_feature[!defined.min.counts, group.define.mask] <- 0
}
}
Expand Down
4 changes: 2 additions & 2 deletions man/dot-terminalStateFromMarkovChain.Rd

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

0 comments on commit 84d7296

Please sign in to comment.