Skip to content

Commit

Permalink
handles missing data for ADsplit
Browse files Browse the repository at this point in the history
  • Loading branch information
jendelman committed Jan 4, 2024
1 parent a71aed0 commit cb969e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion R/ADsplit.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#'
#' Extract read counts from AD string
#'
#' Only valid for a single ALT allele.
#'
#' @param AD array of AD strings
#' @param ALT TRUE or FALSE (= REF)
#' @param n.core number of cores
Expand All @@ -16,7 +18,14 @@ ADsplit <- function(AD, ALT, n.core=1) {

f <- function(AD,k) {
x <- strsplit(AD,split=",",fixed=T)
as.integer(sapply(x,"[[",k))
m <- length(x)
out <- integer(m)
ok <- which(sapply(x,length)==2)
out[ok] <- as.integer(sapply(x[ok],"[[",k))
missing <- which(is.na(out))
if (length(missing)>0)
out[missing] <- 0
return(out)
}

k <- as.integer(ALT)+1
Expand Down
3 changes: 3 additions & 0 deletions man/ADsplit.Rd

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

0 comments on commit cb969e3

Please sign in to comment.