From 9a8631822b6db4401e84fcd99d18001645b6bd95 Mon Sep 17 00:00:00 2001 From: Nida Pervaiz Date: Mon, 16 Oct 2023 21:03:11 +0200 Subject: [PATCH] Solved warnings and notes from BiocCheck --- R/celda_decontX.R | 4 ++-- R/data.R | 8 ++++++++ R/dropletUtils_barcodeRank.R | 3 ++- R/exportSCEtoAnndata.R | 3 ++- R/exportSCEtoTXT.R | 6 ++++-- R/getTopHVG.R | 5 +++-- R/ggPlotting.R | 33 +++++++++++++++++++++----------- R/htmlReports.R | 27 +++++++++++++++++--------- R/importExampleData.R | 6 ++++-- R/importGeneSets.R | 18 ++++++++++------- R/importOptimus.R | 5 +++-- R/plotDEAnalysis.R | 6 ++++-- R/reticulate_setup.R | 12 ++++++++---- R/runBatchCorrection.R | 9 ++++++--- R/runDimReduce.R | 24 +++++++++++++++-------- R/runPerCellQC.R | 10 ++++++---- R/runQCUtils.R | 12 ++++++++---- R/runSoupX.R | 14 +++++++++----- R/runTSNE.R | 3 ++- R/runUMAP.R | 5 +++-- R/sampleSummaryStats.R | 10 ++++++---- R/scDblFinder_doubletDetection.R | 2 +- R/scater_PCA.R | 3 ++- R/scrublet_doubletDetection.R | 6 ++++-- R/sctkQCUtils.R | 9 ++++++--- R/seuratFunctions.R | 10 ++++++---- man/MitoGenes.Rd | 3 +++ man/SEG.Rd | 3 +++ man/mouseBrainSubsetSCE.Rd | 3 +++ man/msigdb_table.Rd | 3 +++ man/sce.Rd | 4 ++++ man/sceBatches.Rd | 4 ++++ 32 files changed, 186 insertions(+), 87 deletions(-) diff --git a/R/celda_decontX.R b/R/celda_decontX.R index 7f7508716..7a442909d 100644 --- a/R/celda_decontX.R +++ b/R/celda_decontX.R @@ -151,8 +151,8 @@ runDecontX <- function(inSCE, } - - message(paste0(date(), " ... Running 'DecontX'")) + p <- paste0(date(), " ... Running 'DecontX'") + message(p) ## keep a copy of original decontX result, if there's any oldColData <- NULL diff --git a/R/data.R b/R/data.R index f8121516b..2bc7eb80c 100644 --- a/R/data.R +++ b/R/data.R @@ -13,6 +13,7 @@ #' @source DOI: 10.1126/science.aaa1934 #' @keywords datasets #' @usage data("mouseBrainSubsetSCE") +#' @return A subset of 30 cells from a single cell RNA-Seq experiment #' @examples #' data("mouseBrainSubsetSCE") "mouseBrainSubsetSCE" @@ -33,6 +34,8 @@ #' @format A \link[SingleCellExperiment]{SingleCellExperiment} object. #' @keywords datasets #' @usage data("scExample") +#' @return Example Single Cell RNA-Seq data in SingleCellExperiment Object, +#' subset of 10x public dataset #' @examples #' data("scExample") "sce" @@ -47,6 +50,8 @@ #' `'beta'`, that could be found in both original studies with relatively #' large population were kept for cleaner demonstration. #' @usage data('sceBatches') +#' @return Example Single Cell RNA-Seq data in SingleCellExperiment object, with +#' different batches annotated "sceBatches" #' Stably Expressed Gene (SEG) list obect, with SEG sets for human and mouse. @@ -59,6 +64,7 @@ #' @source \code{data('segList', package='scMerge')} #' @keywords datasets #' @usage data('SEG') +#' @return Stably Expressed Gene (SEG) list obect, with SEG sets for human and mouse. #' @examples #' data('SEG') #' humanSEG <- SEG$human @@ -77,6 +83,7 @@ #' @format A data.frame. #' @keywords datasets #' @usage data("msigdb_table") +#' @return A table of gene set categories #' @examples #' data("msigdb_table") "msigdb_table" @@ -93,6 +100,7 @@ #' @format A list #' @keywords datasets #' @usage data("MitoGenes") +#' @return List of mitochondrial genes of multiple reference #' @examples #' data("MitoGenes") "MitoGenes" \ No newline at end of file diff --git a/R/dropletUtils_barcodeRank.R b/R/dropletUtils_barcodeRank.R index 5f748cb38..7f10ab27e 100644 --- a/R/dropletUtils_barcodeRank.R +++ b/R/dropletUtils_barcodeRank.R @@ -69,7 +69,8 @@ runBarcodeRankDrops <- function(inSCE, df = 20 ) { - message(paste0(date(), " ... Running 'barcodeRanks'")) + p <- paste0(date(), " ... Running 'barcodeRanks'") + message(p) ## Getting current arguments values argsList <- mget(names(formals()),sys.frame(sys.nframe())) diff --git a/R/exportSCEtoAnndata.R b/R/exportSCEtoAnndata.R index b650c0c75..7f98ba2bd 100644 --- a/R/exportSCEtoAnndata.R +++ b/R/exportSCEtoAnndata.R @@ -54,7 +54,8 @@ exportSCEtoAnnData <- function(sce, fileName <- paste0(prefix,".h5ad") filePath <- file.path(outputDir,fileName) if (file.exists(filePath) && !isTRUE(overwrite)) { - stop(paste0(path, " already exists. Change 'outputDir' or set 'overwrite' to TRUE.")) + p <- paste0(path, " already exists. Change 'outputDir' or set 'overwrite' to TRUE.") + stop(p) } if (isFALSE(forceDense)) { forceDense <- NULL diff --git a/R/exportSCEtoTXT.R b/R/exportSCEtoTXT.R index b32644d96..5c437c1a4 100644 --- a/R/exportSCEtoTXT.R +++ b/R/exportSCEtoTXT.R @@ -40,7 +40,8 @@ exportSCEtoFlatFile <- function(sce, .checkOverwrite <- function(path, overwrite) { if (file.exists(path) && !isTRUE(overwrite)) { - stop(paste0(path, " already exists. Change 'outputDir' or set 'overwrite' to TRUE.")) + p <- paste0(path, " already exists. Change 'outputDir' or set 'overwrite' to TRUE.") + stop(p) } } @@ -86,7 +87,8 @@ exportSCEtoFlatFile <- function(sce, if(isTRUE(gzipped)) { .checkOverwrite(paste0(assaypath, ".gz"), overwrite) - message(date(), " .. Compressing into ", paste0(assaypath, ".gz")) + p <- paste0(assaypath, ".gz") + message(date(), " .. Compressing into ", p) R.utils::gzip(filename = assaypath, overwrite = overwrite) } } diff --git a/R/getTopHVG.R b/R/getTopHVG.R index 1023cbffc..ebb52951e 100644 --- a/R/getTopHVG.R +++ b/R/getTopHVG.R @@ -126,8 +126,9 @@ setTopHVG <- function(inSCE, } } rowSubset(inSCE, featureSubsetName) <- features - message(paste0(date(), " ... Feature subset variable '", featureSubsetName, - "' created.")) + p <- paste0(date(), " ... Feature subset variable '", featureSubsetName, + "' created.") + message(p) metadata(inSCE)$sctk$featureSubsets[[featureSubsetName]] <- list(method = method, number = nFeature, diff --git a/R/ggPlotting.R b/R/ggPlotting.R index dc576daa2..a2e9afb3c 100644 --- a/R/ggPlotting.R +++ b/R/ggPlotting.R @@ -1089,7 +1089,8 @@ plotSCEViolinColData <- function(inSCE, if (!is.null(coldata)) { if (!coldata %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(coldata), "' is not found in ColData.") + p <- paste(coldata) + stop("'", p, "' is not found in ColData.") } coldata <- SummarizedExperiment::colData(inSCE)[, coldata] } else { @@ -1105,7 +1106,8 @@ plotSCEViolinColData <- function(inSCE, } } else { if (!groupBy %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(groupBy), "' is not found in ColData.") + p <- paste(groupBy) + stop("'", p, "' is not found in ColData.") } groupBy <- as.character(SummarizedExperiment::colData(inSCE)[, groupBy]) } @@ -1314,7 +1316,8 @@ plotSCEViolinAssayData <- function(inSCE, } } else { if (!groupBy %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(groupBy), "' is not found in ColData.") + p <- paste(groupBy) + stop("'", p , "' is not found in ColData.") } groupBy <- as.character(SummarizedExperiment::colData(inSCE)[, groupBy]) } @@ -1547,7 +1550,8 @@ plotSCEViolin <- function(inSCE, } } else { if (!groupBy %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(groupBy), "' is not found in ColData.") + p <- paste(groupBy) + stop("'", p , "' is not found in ColData.") } groupBy <- SummarizedExperiment::colData(inSCE)[, groupBy] } @@ -1768,7 +1772,8 @@ plotSCEDensityColData <- function(inSCE, if (!is.null(coldata)) { if (!coldata %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(coldata), "' is not found in ColData.") + p <- paste(coldata) + stop("'", p , "' is not found in ColData.") } coldata <- SummarizedExperiment::colData(inSCE)[, coldata] } else { @@ -1784,7 +1789,8 @@ plotSCEDensityColData <- function(inSCE, } } else { if (!groupBy %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(groupBy), "' is not found in ColData.") + p <- paste(groupBy) + stop("'", p , "' is not found in ColData.") } groupBy <- as.character(SummarizedExperiment::colData(inSCE)[, groupBy]) } @@ -1939,7 +1945,8 @@ plotSCEDensityAssayData <- function(inSCE, } } else { if (!groupBy %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(groupBy), "' is not found in ColData.") + p <- paste(groupBy) + stop("'", p , "' is not found in ColData.") } groupBy <- as.character(SummarizedExperiment::colData(inSCE)[, groupBy]) } @@ -2103,7 +2110,8 @@ plotSCEDensity <- function(inSCE, } } else { if (!groupBy %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(groupBy), "' is not found in ColData.") + p <- paste(groupBy) + stop("'", p , "' is not found in ColData.") } groupBy <- as.character(SummarizedExperiment::colData(inSCE)[, groupBy]) } @@ -2640,7 +2648,8 @@ plotSCEBarColData <- function(inSCE, combinePlot = TRUE) { if (!is.null(coldata)) { if (!coldata %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(coldata), "' is not found in ColData.") + p <- paste(coldata) + stop("'", p , "' is not found in ColData.") } coldata <- SummarizedExperiment::colData(inSCE)[, coldata] } else { @@ -2656,7 +2665,8 @@ plotSCEBarColData <- function(inSCE, } } else { if (!groupBy %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(groupBy), "' is not found in ColData.") + p <- paste(groupBy) + stop("'", p , "' is not found in ColData.") } groupBy <- as.character(SummarizedExperiment::colData(inSCE)[, groupBy]) } @@ -2775,7 +2785,8 @@ plotSCEBarAssayData <- function(inSCE, } } else { if (!groupBy %in% names(SummarizedExperiment::colData(inSCE))) { - stop("'", paste(groupBy), "' is not found in ColData.") + p <- paste(groupBy) + stop("'", p , "' is not found in ColData.") } groupBy <- as.character(SummarizedExperiment::colData(inSCE)[, groupBy]) } diff --git a/R/htmlReports.R b/R/htmlReports.R index f4e22744c..e767e244e 100644 --- a/R/htmlReports.R +++ b/R/htmlReports.R @@ -374,7 +374,8 @@ reportSeuratRun <- function(inSCE, path <- paste0(outputPath, "SCE_SeuratRun", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratRun", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratRun", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) @@ -506,7 +507,8 @@ reportSeuratResults <- function(inSCE, path <- paste0(outputPath, "SCE_SeuratResults", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratResults", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratResults", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) @@ -593,7 +595,8 @@ reportSeuratDimRed <- function(inSCE, path <- paste0(outputPath, "SCE_SeuratDimRed", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratDimRed", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratDimRed", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) @@ -660,7 +663,8 @@ reportSeuratNormalization <- function(inSCE, path <- paste0(outputPath, "SCE_SeuratNormalization", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratNormalization", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratNormalization", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) @@ -735,7 +739,8 @@ reportSeuratFeatureSelection <- function(inSCE, path <- paste0(outputPath, "SCE_SeuratFeatureSelection", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratFeatureSelection", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratFeatureSelection", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) @@ -802,7 +807,8 @@ reportSeuratScaling <- function(inSCE, path <- paste0(outputPath, "SCE_SeuratScaleData", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratScaleData", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratScaleData", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) @@ -914,7 +920,8 @@ reportSeuratClustering <- function(inSCE, path <- paste0(outputPath, "SCE_SeuratClustering", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratClustering", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratClustering", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) @@ -1018,7 +1025,8 @@ reportSeuratMarkerSelection <- function(inSCE, path <- paste0(outputPath, "SCE_SeuratResults", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratResults", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratResults", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) @@ -1184,7 +1192,8 @@ reportSeurat <- function( path <- paste0(outputPath, "SCE_SeuratReport", "-", gsub(" ", "_", Sys.Date()), ".rds") saveRDS(data, path) - message("Output SCE object stored as ", paste0("SCE_SeuratReport", "-", gsub(" ", "_", Sys.Date()), ".rds"), " in ", outputPath, ".") + p <- paste0("SCE_SeuratReport", "-", gsub(" ", "_", Sys.Date()), ".rds") + message("Output SCE object stored as ", p , " in ", outputPath, ".") message("Output HTML file stored as ", outputFile, " in ", outputPath, ".") return(data) diff --git a/R/importExampleData.R b/R/importExampleData.R index 95d3c420d..bde6fcad4 100644 --- a/R/importExampleData.R +++ b/R/importExampleData.R @@ -58,7 +58,8 @@ importExampleData <- function(dataset, class = c("Matrix", "matrix"), if(dataset %in% scRNAseqDatasets) { if(!("scRNAseq" %in% rownames(utils::installed.packages()))) { - stop(paste0("Package 'scRNAseq' is not installed. Please install to load dataset '", dataset, "'.")) + p <- paste0("Package 'scRNAseq' is not installed. Please install to load dataset '", dataset, "'.") + stop(p) } if (dataset == "fluidigm_pollen") { temp <- scRNAseq::ReprocessedFluidigmData() @@ -84,7 +85,8 @@ importExampleData <- function(dataset, class = c("Matrix", "matrix"), } } else if (dataset %in% tenxPbmcDatasets) { if(!("TENxPBMCData" %in% rownames(utils::installed.packages()))) { - stop(paste0("Package 'TENxPBMCData' is not installed. Please install to load dataset '", dataset, "'.")) + p <- paste0("Package 'TENxPBMCData' is not installed. Please install to load dataset '", dataset, "'.") + stop(p) } temp <- TENxPBMCData::TENxPBMCData(dataset = dataset) colnames(temp) <- paste(temp$Sample, temp$Barcode, sep="_") diff --git a/R/importGeneSets.R b/R/importGeneSets.R index eab92f409..25137f75f 100644 --- a/R/importGeneSets.R +++ b/R/importGeneSets.R @@ -411,8 +411,9 @@ importGeneSetsFromMSigDB <- function(inSCE, categoryIDs, gs.names <- unique(gs$gs_name) num.gs.names <- length(gs.names) if(isTRUE(verbose)){ - message(paste0(date(), " .. Importing '", categoryIDs[i], - "' gene sets (n = ", num.gs.names, ")")) + p <- paste0(date(), " .. Importing '", categoryIDs[i], + "' gene sets (n = ", num.gs.names, ")") + message(p) } for(j in seq_along(gs.names)) { @@ -424,19 +425,22 @@ importGeneSetsFromMSigDB <- function(inSCE, categoryIDs, subCategory = subcat)) if(j %% 1000 == 0) { if(isTRUE(verbose)) { - message(paste0(date(), " .... Completed ", j, " out of ", - num.gs.names, " gene sets")) + p <- paste0(date(), " .... Completed ", j, " out of ", + num.gs.names, " gene sets") + message(p) } } } if(isTRUE(verbose)) { - message(paste0(date(), " .... Completed ", num.gs.names, " gene sets ", - "for ", i)) + p <- paste0(date(), " .... Completed ", num.gs.names, " gene sets ", + "for ", i) + message(p) } # Add to SCE if(isTRUE(verbose)) { - message(paste0(date(), " .. Matching gene sets to '", by, "'")) + p <- paste0(date(), " .. Matching gene sets to '", by, "'") + message(p) } gsc <- GSEABase::GeneSetCollection(gs.list) inSCE <- importGeneSetsFromCollection(inSCE = inSCE, diff --git a/R/importOptimus.R b/R/importOptimus.R index 1940fa690..dc4183e84 100644 --- a/R/importOptimus.R +++ b/R/importOptimus.R @@ -62,9 +62,10 @@ }, silent = TRUE) if(inherits(error, "try-error")) { - stop(paste0("importOptimus did not complete successfully. SCE could not be", + p <- paste0("importOptimus did not complete successfully. SCE could not be", "generated. Error given during the import process: \n\n", - error)) + error) + stop(p) } if (class == "matrix") { diff --git a/R/plotDEAnalysis.R b/R/plotDEAnalysis.R index 60983bf4e..4abafa717 100644 --- a/R/plotDEAnalysis.R +++ b/R/plotDEAnalysis.R @@ -16,12 +16,14 @@ stop('"diffExp" not in metadata, please run runMAST() first.') } if(!useResult %in% names(S4Vectors::metadata(inSCE)$diffExp)){ - stop(paste0('"', useResult, '"', ' not in metadata(inSCE)$diffExp. '), + p <- paste0('"', useResult, '"', ' not in metadata(inSCE)$diffExp. ') + stop(p, 'Please check.') } result <- S4Vectors::metadata(inSCE)$diffExp[[useResult]] if(!all(c('groupNames', 'select', 'result', 'useAssay') %in% names(result))){ - stop(paste0('"', useResult, '"', ' result is not complete. '), + p <- paste0('"', useResult, '"', ' result is not complete. ') + stop(p, 'You might need to rerun it.') } if(!is.null(labelBy)){ diff --git a/R/reticulate_setup.R b/R/reticulate_setup.R index 624b36b26..f22a01e3e 100644 --- a/R/reticulate_setup.R +++ b/R/reticulate_setup.R @@ -144,11 +144,13 @@ selectSCTKConda <- function(envname = "sctk-reticulate") { ix <- condaList$name == envname if(!any(ix)) { - stop(paste0("Environment '", envname, "', not found. Run sctkPythonInstallConda(envname = '", envname, "') to install Python packages into a conda environmanet with this name.")) + p <- paste0("Environment '", envname, "', not found. Run sctkPythonInstallConda(envname = '", envname, "') to install Python packages into a conda environmanet with this name.") + stop(p) } if(sum(ix) > 1) { envs <- paste(condaList[ix,"python"], collapse="\n") - warning(paste0("More than one Conda environment detected with the name '", envname, "'. Selecting the first one in the list:\n", envs)) + p <- paste0("More than one Conda environment detected with the name '", envname, "'. Selecting the first one in the list:\n", envs) + warning(p) } reticulate::use_condaenv(condaenv = envname, required = TRUE) @@ -175,10 +177,12 @@ selectSCTKVirtualEnvironment <- function(envname = "sctk-reticulate") { ix <- res == envname if(!any(ix)) { - stop(paste0("Environmnet '", envname, "', not found. Run selectSCTKVirtualEnvironment(envname = '", envname, "') to install Python packages into a virtual environmanet with this name.")) + p <- paste0("Environmnet '", envname, "', not found. Run selectSCTKVirtualEnvironment(envname = '", envname, "') to install Python packages into a virtual environmanet with this name.") + stop(p) } if(sum(ix) > 1) { - warning(paste0("More than one virtual environment detected with the name '", envname, "'. Selecting the first one in the list.")) + p <- paste0("More than one virtual environment detected with the name '", envname, "'. Selecting the first one in the list.") + warning(p) } reticulate::use_virtualenv(res[which(ix)[1]], required = TRUE) diff --git a/R/runBatchCorrection.R b/R/runBatchCorrection.R index 5633afadd..ed9a71c10 100644 --- a/R/runBatchCorrection.R +++ b/R/runBatchCorrection.R @@ -129,7 +129,8 @@ runComBatSeq <- function(inSCE, useAssay = "counts", batch = 'batch', stop("\"inSCE\" should be a SingleCellExperiment Object.") } if(!useAssay %in% SummarizedExperiment::assayNames(inSCE)) { - stop(paste("\"useAssay\" (assay) name: ", useAssay, " not found.")) + p <- paste("\"useAssay\" (assay) name: ", useAssay, " not found.") + stop(p) } if(any(!c(batch, covariates, bioCond) %in% names(SummarizedExperiment::colData(inSCE)))){ @@ -778,10 +779,12 @@ runZINBWaVE <- function(inSCE, useAssay = 'counts', batch = 'batch', stop("\"inSCE\" should be a SingleCellExperiment Object.") } if(!useAssay %in% SummarizedExperiment::assayNames(inSCE)) { - stop(paste("\"useAssay\" (assay) name: ", useAssay, " not found")) + p <- paste("\"useAssay\" (assay) name: ", useAssay, " not found") + stop(p) } if(!batch %in% names(SummarizedExperiment::colData(inSCE))){ - stop(paste("\"batch name:", batch, "not found.")) + p <- paste("\"batch name:", batch, "not found.") + stop(p) } reducedDimName <- gsub(' ', '_', reducedDimName) nHVG <- as.integer(nHVG) diff --git a/R/runDimReduce.R b/R/runDimReduce.R index ed3dca9cd..a34b85d18 100644 --- a/R/runDimReduce.R +++ b/R/runDimReduce.R @@ -115,14 +115,16 @@ runDimReduce <- function(inSCE, if (method %in% c("seuratPCA", "seuratICA")) { ## SeuratPCA/ICA if (method == "seuratPCA") { - message(paste0(date(), " ... Computing Seurat PCA.")) + p <- paste0(date(), " ... Computing Seurat PCA.") + message(p) tempSCE <- runSeuratPCA(tempSCE, useAssay = useAssay, reducedDimName = reducedDimName, nPCs = nComponents, useFeatureSubset = useFeatureSubset, scale = scale, seed = seed, ...) } else if (method == "seuratICA") { - message(paste0(date(), " ... Computing Seurat ICA.")) + p <- paste0(date(), " ... Computing Seurat ICA.") + message(p) tempSCE <- runSeuratICA(tempSCE, useAssay = useAssay, reducedDimName = reducedDimName, nics = nComponents, @@ -143,25 +145,29 @@ runDimReduce <- function(inSCE, stop("Must specify `useReduction` when using `useAssay` in seuratUMAP/TSNE") } if (args$useReduction == "pca") { - message(paste0(date(), " ... Computing Seurat PCA.")) + p <- paste0(date(), " ... Computing Seurat PCA.") + message(p) tempSCE <- runSeuratPCA(inSCE = tempSCE, useAssay = useAssay, reducedDimName = paste0(useAssay, "_seuratPCA"), useFeatureSubset = useFeatureSubset, seed = seed) } else if (args$useReduction == "ica") { - message(paste0(date(), " ... Computing Seurat ICA.")) + p <- paste0(date(), " ... Computing Seurat ICA.") + message(p) tempSCE <- runSeuratICA(inSCE = tempSCE, useAssay = useAssay, reducedDimName = paste0(useAssay, "_seuratICA"), useFeatureSubset = useFeatureSubset, seed = seed) } if (method == "seuratUMAP") { - message(paste0(date(), " ... Computing Seurat UMAP.")) + p <- paste0(date(), " ... Computing Seurat UMAP.") + message(p) tempSCE <- runSeuratUMAP(inSCE = tempSCE, reducedDimName = reducedDimName, seed = seed, ...) } else { - message(paste0(date(), " ... Computing Seurat tSNE.")) + p <- paste0(date(), " ... Computing Seurat tSNE.") + message(p) tempSCE <- runSeuratTSNE(inSCE = tempSCE, reducedDimName = reducedDimName, seed = seed, ...) @@ -184,13 +190,15 @@ runDimReduce <- function(inSCE, key = paste0(key, "_"), assay = "RNA") if (method == "seuratUMAP") { # hard-code useReduction="pca" - message(paste0(date(), " ... Computing Seurat UMAP.")) + p <- paste0(date(), " ... Computing Seurat UMAP.") + message(p) tempSCE <- runSeuratUMAP(inSCE = tempSCE, useReduction = "pca", reducedDimName = reducedDimName, seed = seed, ...) } else { # hard-code useReduction="pca" - message(paste0(date(), " ... Computing Seurat tSNE.")) + p <- paste0(date(), " ... Computing Seurat tSNE.") + message(p) tempSCE <- runSeuratTSNE(inSCE = tempSCE, useReduction = "pca", reducedDimName = reducedDimName, seed = seed, ...) diff --git a/R/runPerCellQC.R b/R/runPerCellQC.R index f9925f059..89b7d877e 100644 --- a/R/runPerCellQC.R +++ b/R/runPerCellQC.R @@ -118,7 +118,8 @@ runPerCellQC <- function(inSCE, BPPARAM = BiocParallel::SerialParam() ) { - message(paste0(date(), " ... Running 'perCellQCMetrics'")) + p <- paste0(date(), " ... Running 'perCellQCMetrics'") + message(p) argsList <- mget(names(formals()),sys.frame(sys.nframe())) mitoRef <- match.arg(mitoRef) mitoIDType <- match.arg(mitoIDType) @@ -272,9 +273,10 @@ runPerCellQC <- function(inSCE, gs.index <- which(rowData(inSCE)[,temp.location] %in% gs.i) geneSets[[names(geneSetList)[i]]] <- rownames(inSCE)[gs.index] } else { - warning(paste0("No features for gene set '", names(geneSetList)[i], - "' were found in 'rowData(inSCE)' under column '", - temp.location, "'. Excluding this gene set.", sep="")) + p <- paste0("No features for gene set '", names(geneSetList)[i], + "' were found in 'rowData(inSCE)' under column '", + temp.location, "'. Excluding this gene set.", sep="") + warning(p) } if(length(gs.diff) > 0 & length(gs.i) > 0) { diff --git a/R/runQCUtils.R b/R/runQCUtils.R index 9929ac097..dbc53e2bf 100644 --- a/R/runQCUtils.R +++ b/R/runQCUtils.R @@ -136,7 +136,8 @@ } .cellQC <- function(cellSCE, geneSetCollection, Params, cellQCAlgos, mitoInfo, dropletSCE = NULL) { - message(paste0(date(), " .. Running cell QC")) + p <- paste0(date(), " .. Running cell QC") + message(p) cellSCE <- runCellQC(inSCE = cellSCE, geneSetCollection = geneSetCollection, paramsList=Params, algorithms = cellQCAlgos, background = dropletSCE, mitoRef = mitoInfo[['reference']], mitoIDType = mitoInfo[['id']], @@ -150,7 +151,8 @@ ix <- !is.na(dropletSCE$dropletUtils_emptyDrops_fdr) & (dropletSCE$dropletUtils_emptyDrops_fdr < 0.01) cellSCE <- dropletSCE[,ix] } - message(paste0(date(), " .. Running cell QC")) + p <- paste0(date(), " .. Running cell QC") + message(p) cellSCE <- runCellQC(inSCE = cellSCE, geneSetCollection = geneSetCollection, paramsList=Params, algorithms = cellQCAlgos, background = dropletSCE, mitoRef = mitoInfo[['reference']], mitoIDType = mitoInfo[['id']], @@ -158,7 +160,8 @@ } .runDroplet <- function(dropletSCE, geneSetCollection, Params, mitoInfo, cellQCAlgos, detectCell, cellCalling) { - message(paste0(date(), " .. Running droplet QC")) + p <- paste0(date(), " .. Running droplet QC") + message(p) dropletSCE <- runDropletQC(inSCE = dropletSCE, paramsList=Params) if (isTRUE(detectCell)) { if (cellCalling == "EmptyDrops") { @@ -169,7 +172,8 @@ ix <- dropletSCE$dropletUtils_BarcodeRank_Inflection == 1 } cellSCE <- dropletSCE[,ix] - message(paste0(date(), " .. Running cell QC")) + p <- paste0(date(), " .. Running cell QC") + message(p) cellSCE <- runCellQC(inSCE = cellSCE, geneSetCollection = geneSetCollection, paramsList=Params, algorithms = cellQCAlgos, background = dropletSCE, mitoRef = mitoInfo[['reference']], mitoIDType = mitoInfo[['id']], diff --git a/R/runSoupX.R b/R/runSoupX.R index 83b876f28..bfbd0555e 100644 --- a/R/runSoupX.R +++ b/R/runSoupX.R @@ -153,8 +153,9 @@ runSoupX <- function(inSCE, } uniqSample <- "all_cells" } - - message(paste0(date(), " ... Running 'SoupX'")) + + p <- paste0(date(), " ... Running 'SoupX'") + message(p) # try/catch block in case SoupX finds no marker genes result <- tryCatch( @@ -162,7 +163,8 @@ runSoupX <- function(inSCE, results <- list() sampleIdx <- list() for (s in uniqSample) { - message(paste0(date(), " ... Running 'SoupX' on sample: ", s)) + p <- paste0(date(), " ... Running 'SoupX' on sample: ", s) + message(p) cellIdx <- sample == s sampleIdx[[s]] <- cellIdx tempSCE <- inSCE[,cellIdx] @@ -289,7 +291,8 @@ runSoupX <- function(inSCE, SummarizedExperiment::rowData(inSCE) <- newRowData }, error=function(cond) { - message(paste0(date(), " ... Error occured in 'SoupX'; skipping 'SoupX'. Details as follows:")) + p <- paste0(date(), " ... Error occured in 'SoupX'; skipping 'SoupX'. Details as follows:") + message(p) message(cond) } ) @@ -477,7 +480,8 @@ runSoupX <- function(inSCE, stop("Invalid cluster specification") } } else { - message(paste0(date(), " ... Cluster info not supplied. Generating clusters with Scran SNN")) + p <- paste0(date(), " ... Cluster info not supplied. Generating clusters with Scran SNN") + message(p) suppressMessages({ c <- scran::quickCluster(inSCE, assay.type = useAssay, method = "igraph") diff --git a/R/runTSNE.R b/R/runTSNE.R index 70624a133..dd7f4103a 100644 --- a/R/runTSNE.R +++ b/R/runTSNE.R @@ -133,7 +133,8 @@ runTSNE <- function(inSCE, useReducedDim = "PCA", useAssay = NULL, } # Rtsne requires a matrix input mat <- as.matrix(mat) - message(paste0(date(), " ... Computing Rtsne.")) + p <- paste0(date(), " ... Computing Rtsne.") + message(p) withr::with_seed(seed, { tsneOut <- Rtsne::Rtsne(mat, pca_scale = scale, pca_center = center, pca = pca, partial_pca = partialPCA, diff --git a/R/runUMAP.R b/R/runUMAP.R index c6bda67e0..165f778b5 100644 --- a/R/runUMAP.R +++ b/R/runUMAP.R @@ -123,8 +123,9 @@ runUMAP <- function(inSCE, useReducedDim = "PCA", useAssay = NULL, nNeighbors <- min(ncol(sceSample), nNeighbors) if(isTRUE(verbose)) { - message(paste0(date(), " ... Computing Scater UMAP for sample '", - samples[i], "'.")) + p <- paste0(date(), " ... Computing Scater UMAP for sample '", + samples[i], "'.") + message(p) } umapRes <- withr::with_seed(seed, { diff --git a/R/sampleSummaryStats.R b/R/sampleSummaryStats.R index e61f388c7..d872ceef8 100644 --- a/R/sampleSummaryStats.R +++ b/R/sampleSummaryStats.R @@ -22,13 +22,15 @@ setReplaceMethod("setSampleSummaryStatsTable", c("SingleCellExperiment", "ANY"), #' @importFrom S4Vectors metadata setMethod("listSampleSummaryStatsTables", "SingleCellExperiment", function(inSCE, ...){ if(is.null(metadata(inSCE)$sctk$sample_summary)){ - stop(paste("No sample-level QC tables are available.", - "Please try executing functions such as sampleSummaryStats first.")) + p <- paste("No sample-level QC tables are available.", + "Please try executing functions such as sampleSummaryStats first.") + stop(p) }else{ allStatsNames <- names(metadata(inSCE)$sctk$sample_summary) if(is.null(allStatsNames) || length(allStatsNames) == 0){ - stop(paste("No sample-level QC tables are available.", - "Please try executing functions such as sampleSummaryStats first.")) + paste("No sample-level QC tables are available.", + "Please try executing functions such as sampleSummaryStats first.") + stop(p) }else{ return(names(metadata(inSCE)$sctk$sample_summary)) } diff --git a/R/scDblFinder_doubletDetection.R b/R/scDblFinder_doubletDetection.R index 97a290f4f..c798e1d4a 100644 --- a/R/scDblFinder_doubletDetection.R +++ b/R/scDblFinder_doubletDetection.R @@ -96,7 +96,7 @@ runScDblFinder <- function(inSCE, if (all(sample == 1)) { metadata(inSCE)$sctk$runScDblFinder$all_cells <- argsList } else { - metadata(inSCE)$sctk$runScDblFinder <- sapply(unique(sample), + metadata(inSCE)$sctk$runScDblFinder <- vapply(unique(sample), function(x) return(argsList), simplify = FALSE, USE.NAMES = TRUE) diff --git a/R/scater_PCA.R b/R/scater_PCA.R index d85ae34bf..f51d4afe5 100644 --- a/R/scater_PCA.R +++ b/R/scater_PCA.R @@ -56,7 +56,8 @@ scaterPCA <- function(inSCE, useAssay = "logcounts", useFeatureSubset = NULL, } subset_row <- .parseUseFeatureSubset(inSCE, useFeatureSubset, altExpObj = sce, returnType = "logical") - message(paste0(date(), " ... Computing Scater PCA.")) + p <- paste0(date(), " ... Computing Scater PCA.") + message(p) withr::with_seed(seed, { pca <- scater::calculatePCA(useMat$mat, ncomponents = nComponents, scale = scale, ntop = ntop, diff --git a/R/scrublet_doubletDetection.R b/R/scrublet_doubletDetection.R index e353beefb..e2b713b09 100644 --- a/R/scrublet_doubletDetection.R +++ b/R/scrublet_doubletDetection.R @@ -135,7 +135,8 @@ runScrublet <- function(inSCE, #assayNames(inSCE)[which(useAssay %in% assayNames(inSCE))] <- "counts" #useAssay <- "counts" - message(paste0(date(), " ... Running 'scrublet'")) + p <- paste0(date(), " ... Running 'scrublet'") + message(p) ## Getting current arguments values argsList <- mget(names(formals()),sys.frame(sys.nframe())) @@ -240,7 +241,8 @@ runScrublet <- function(inSCE, colData(inSCE) = cbind(colData(inSCE), output) }, error=function(cond) { - message(paste0(date(), " ... Scrublet did not complete successfully; Returning SCE without changes. Scrublet error:")) + p <- paste0(date(), " ... Scrublet did not complete successfully; Returning SCE without changes. Scrublet error:") + message(p) message(cond) } ) diff --git a/R/sctkQCUtils.R b/R/sctkQCUtils.R index 1d9a1023d..c16bc9e88 100644 --- a/R/sctkQCUtils.R +++ b/R/sctkQCUtils.R @@ -34,7 +34,8 @@ exportSCEToSeurat <- function(inSCE, prefix="sample", outputDir="./", overwrite= } if (file.exists(filePath) && !isTRUE(overwrite)) { - stop(paste0(path, " already exists. Change 'outputDir' or set 'overwrite' to TRUE.")) + p <- paste0(path, " already exists. Change 'outputDir' or set 'overwrite' to TRUE.") + stop(p) } @@ -66,8 +67,9 @@ exportSCE <- function(inSCE, format = c("SCE", "AnnData", "FlatFile", "HTAN", "Seurat")) { if (any(!format %in% c("SCE", "AnnData", "FlatFile", "HTAN", "Seurat"))) { + p <- paste(format[!format %in% c("SCE", "AnnData", "FlatFile", "HTAN")], sep = ",") warning("Output format must be 'SCE', 'AnnData', 'HTAN', 'Seurat' or 'FlatFile'. Format ", - paste(format[!format %in% c("SCE", "AnnData", "FlatFile", "HTAN")], sep = ","), + p, " is not supported now. ") # "Only output the supported formats in the provided options. " } @@ -849,6 +851,7 @@ qcInputProcess <- function(preproc, } ## preproc is not one of the method above. Stop the pipeline. - stop(paste0("'", preproc, "' not supported.")) + p <- paste0("'", preproc, "' not supported.") + stop(p) } diff --git a/R/seuratFunctions.R b/R/seuratFunctions.R index ea17b515b..a7bf23c5c 100644 --- a/R/seuratFunctions.R +++ b/R/seuratFunctions.R @@ -1443,11 +1443,12 @@ convertSCEToSeurat <- seuratObject@reductions[[eval(parse(text = paste0(i, "ReducedDim")))]] seuratObject@reductions[[eval(parse(text = paste0(i, "ReducedDim")))]] <- NULL + p <- paste0( + i, "ReducedDim" + ) message( "'", - eval(parse(text = paste0( - i, "ReducedDim" - ))), + eval(parse(text = p)), "' reducedDim from input SCE object saved to the default ", i, " slot of seurat object." @@ -1597,7 +1598,8 @@ runSeuratIntegration <- function(inSCE, kWeight, ndims = 10) { if (!useAssay %in% SummarizedExperiment::assayNames(inSCE)) { - stop(paste(useAssay, "not found in the input object assays")) + p <- paste(useAssay, "not found in the input object assays") + stop(p) } if (is.null(batch)) { stop("batch variable must be provided for batch-correction") diff --git a/man/MitoGenes.Rd b/man/MitoGenes.Rd index a46684171..aad1d7631 100644 --- a/man/MitoGenes.Rd +++ b/man/MitoGenes.Rd @@ -10,6 +10,9 @@ A list \usage{ data("MitoGenes") } +\value{ +List of mitochondrial genes of multiple reference +} \description{ A list of gene set that contains mitochondrial genes of multiple reference (hg38, hg19, mm10 and mm9). It contains multiple types of gene identifier: diff --git a/man/SEG.Rd b/man/SEG.Rd index 119c1ff16..068961590 100644 --- a/man/SEG.Rd +++ b/man/SEG.Rd @@ -14,6 +14,9 @@ charactor vector. \usage{ data('SEG') } +\value{ +Stably Expressed Gene (SEG) list obect, with SEG sets for human and mouse. +} \description{ The two gene sets came from dataset called `segList` of package `scMerge`. } diff --git a/man/mouseBrainSubsetSCE.Rd b/man/mouseBrainSubsetSCE.Rd index 260cc9368..8ec825a2f 100644 --- a/man/mouseBrainSubsetSCE.Rd +++ b/man/mouseBrainSubsetSCE.Rd @@ -14,6 +14,9 @@ DOI: 10.1126/science.aaa1934 \usage{ data("mouseBrainSubsetSCE") } +\value{ +A subset of 30 cells from a single cell RNA-Seq experiment +} \description{ A subset of 30 cells from a single cell RNA-Seq experiment from Zeisel, et al. Science 2015. The data was produced from cells from the mouse diff --git a/man/msigdb_table.Rd b/man/msigdb_table.Rd index 7275084e9..45bd1ed32 100644 --- a/man/msigdb_table.Rd +++ b/man/msigdb_table.Rd @@ -10,6 +10,9 @@ A data.frame. \usage{ data("msigdb_table") } +\value{ +A table of gene set categories +} \description{ A table of gene set categories that can be download from MSigDB. The categories and descriptions can be found here: diff --git a/man/sce.Rd b/man/sce.Rd index 1d4ac89b7..a0b45e8df 100644 --- a/man/sce.Rd +++ b/man/sce.Rd @@ -11,6 +11,10 @@ A \link[SingleCellExperiment]{SingleCellExperiment} object. \usage{ data("scExample") } +\value{ +Example Single Cell RNA-Seq data in SingleCellExperiment Object, +subset of 10x public dataset +} \description{ https://support.10xgenomics.com/single-cell-gene-expression/datasets/2.1.0/pbmc4k A subset of 390 barcodes and top 200 genes were included in this example. diff --git a/man/sceBatches.Rd b/man/sceBatches.Rd index ac69db233..cc69dc6b1 100644 --- a/man/sceBatches.Rd +++ b/man/sceBatches.Rd @@ -11,6 +11,10 @@ An object of class \code{SingleCellExperiment} with 100 rows and 250 columns. \usage{ data('sceBatches') } +\value{ +Example Single Cell RNA-Seq data in SingleCellExperiment object, with +different batches annotated +} \description{ Two batches of pancreas scRNAseq dataset are combined with their original counts. Cell types and batches are annotated in `colData(sceBatches)`.