Skip to content

Commit

Permalink
Use rowData(altExp(x)) for spike concs, work towards #175 and #169
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Sep 9, 2020
1 parent 517aad3 commit 0d7558c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
10 changes: 5 additions & 5 deletions R/newBASiCS_Data.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ newBASiCS_Data <- function(Counts,
SpikeInfo = NULL,
BatchInfo = NULL,
SpikeType = "ERCC") {

.Deprecated()
if (!inherits(Counts, "matrix")) {
stop("Counts must be a matrix.")
}
Expand Down Expand Up @@ -115,19 +115,19 @@ newBASiCS_Data <- function(Counts,
)
}
# Extracting spike-in input molecules in the correct order
if (sum(!(GeneName[Tech] %in% SpikeInfo[, 1])) > 0) {
if (any(!(GeneName[Tech] %in% SpikeInfo[, 1]))) {
stop("'SpikeInfo' is missing information for some of the spikes")
}
if (sum(!(SpikeInfo[, 1] %in% GeneName[Tech])) > 0) {
if (any(!(SpikeInfo[, 1] %in% GeneName[Tech]))) {
stop("'SpikeInfo' includes spikes that are not in 'Counts'")
}
if (any(GeneName[Tech] != SpikeInfo[, 1])) {
# Re-order spike-ins in SpikeInfo if required
matching <- match(GeneName[Tech], SpikeInfo[, 1])
SpikeInfo <- SpikeInfo[matching, ]
}
metadata(Data)$SpikeInput <- SpikeInfo
altExp(Data, "spike-ins") <- SummarizedExperiment(CountsTech)
altExp(Data, "spike-ins") <- SummarizedExperiment(CountsTech,
rowData = SpikeInfo)
WithSpikes <- TRUE
} else {
message("The data does not contain spike-in genes")
Expand Down
20 changes: 6 additions & 14 deletions R/utils_Data.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,15 @@
errors <- c(errors, "spike-in counts must be provided as 'altExp'. \n")
}
} else {
if (!("SpikeInput" %in% names(metadata(Data)))) {
errors <- c(errors, "'SpikeInput' was not provided as metadata.\n")
if (is.null(colnames(rowData(altExp(Data))))) {
errors <- c(errors, "rowData of altExp is missing!\n")
}
# Extract spike-ins
CountsTech <- assay(altExp(Data))
SpikeInput <- metadata(Data)$SpikeInput
SpikeInput <- rowData(altExp(Data))
# Validity checks for SpikeInput
if (!is.data.frame(SpikeInput)) {
errors <- c(errors, "'SpikeInput' must be a 'data.frame'.\n")
}
if (ncol(SpikeInput) != 2) {
errors <- c(errors, "'SpikeInput' must have two columns only.\n")
}
if (nrow(SpikeInput) != nrow(CountsTech)) {
errors <- c(errors,
"'SpikeInput' dimensions not compatible with 'altExp'. \n"
)
errors <- c(errors, "rowData of altExp must have two columns only.\n")
}
# Validity checks for input concentrations
if (!(is.numeric(SpikeInput[, 2]) & all(SpikeInput[, 2] > 0) &
Expand All @@ -79,14 +71,14 @@
errors <- c(errors, "'SpikeInput' row order does not match 'altExp'.\n")
}
# Check all cells have non-zero total count
if (sum(Matrix::colSums(CountsTech) == 0) > 0) {
if (any(Matrix::colSums(CountsTech) == 0)) {
errors <- c(errors,
"Some cells have zero reads mapping back to the
spike-in genes. Please remove these before running the MCMC.\n"
)
}
# Check all genes have non-zero total count
if (sum(Matrix::rowSums(CountsTech) == 0) > 0) {
if (any(Matrix::rowSums(CountsTech) == 0)) {
errors <- c(errors,
"Some spike-in genes have zero total reads
across all cells. Please remove these before running the MCMC.\n"
Expand Down

0 comments on commit 0d7558c

Please sign in to comment.