diff --git a/.DS_Store b/.DS_Store index 81914b4f..2b21082f 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/DESCRIPTION b/DESCRIPTION index 39b026bf..40311f0c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: ArchR Type: Package -Date: 2020-10-01 +Date: 2020-11-23 Title: Analyzing single-cell regulatory chromatin in R. -Version: 1.0.0 +Version: 1.0.1 Authors@R: c( person("Jeffrey", "Granja", email = "jgranja.stanford@gmail.com", role = c("aut","cre")), person("Ryan", "Corces", role = "aut")) @@ -11,7 +11,7 @@ Roxygen: list(markdown = TRUE) License: GPL (>= 2) LinkingTo: Rcpp LazyData: TRUE -RoxygenNote: 7.0.2 +RoxygenNote: 7.1.1 Encoding: UTF-8 Imports: Rcpp (>= 0.12.16), diff --git a/NAMESPACE b/NAMESPACE index 398bf483..ce5679a8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(addArchRDebugging) export(addArchRGenome) export(addArchRLogging) export(addArchRThreads) +export(addArchRVerbose) export(addBgdPeaks) export(addCellColData) export(addClusters) @@ -68,6 +69,7 @@ export(getArchRDebugging) export(getArchRGenome) export(getArchRLogging) export(getArchRThreads) +export(getArchRVerbose) export(getArrowFiles) export(getAvailableMatrices) export(getBgdPeaks) diff --git a/R/AllClasses.R b/R/AllClasses.R index 9ba68568..f87ff98c 100644 --- a/R/AllClasses.R +++ b/R/AllClasses.R @@ -130,7 +130,7 @@ ArchRProject <- function( message("Getting SampleNames...") sampleNames <- unlist(.safelapply(seq_along(ArrowFiles), function(x){ - message(x, " ", appendLF = FALSE) + if(getArchRVerbose()) message(x, " ", appendLF = FALSE) .sampleName(ArrowFiles[x]) }, threads = threads)) message("") @@ -159,7 +159,7 @@ ArchRProject <- function( #Cell Information message("Getting Cell Metadata...") metadataList <- .safelapply(seq_along(ArrowFiles), function(x){ - message(x, " ", appendLF = FALSE) + if(getArchRVerbose()) message(x, " ", appendLF = FALSE) .getMetadata(ArrowFiles[x]) }, threads = threads) message("") diff --git a/R/AnnotationGenome.R b/R/AnnotationGenome.R index d35fa9ba..3d75ac3a 100644 --- a/R/AnnotationGenome.R +++ b/R/AnnotationGenome.R @@ -41,7 +41,14 @@ createGenomeAnnotation <- function( ################## message("Getting blacklist..") - blacklist <- .getBlacklist(genome = bsg@provider_version) + + genomeName <- tryCatch({ + bsg@provider_version + }, error = function(e){ + strsplit(bsg@pkgname,"\\.")[[1]][4] + }) + + blacklist <- .getBlacklist(genome = genomeName) }else{ diff --git a/R/AnnotationPeaks.R b/R/AnnotationPeaks.R index 60b30642..13df1f22 100644 --- a/R/AnnotationPeaks.R +++ b/R/AnnotationPeaks.R @@ -98,7 +98,7 @@ getMatches <- function(ArchRProj = NULL, name = NULL, annoName = NULL){ #' binary value is stored indicating whether each region is observed within the peak region. #' #' @param ArchRProj An `ArchRProject` object. -#' @param regions A `list` of `GRanges` that are to be overlapped with the `peakSet` in the `ArchRProject`. +#' @param regions A named `list` of `GRanges` that are to be overlapped with the `peakSet` in the `ArchRProject`. #' @param name The name of `peakAnnotation` object to be stored as in `ArchRProject`. #' @param force A boolean value indicating whether to force the `peakAnnotation` object indicated by `name` to be overwritten #' if it already exists in the given `ArchRProject`. @@ -136,6 +136,10 @@ addPeakAnnotations <- function( }else{ + if(is.null(names(regions))){ + names(regions) <- paste0("Region_", seq_along(regions)) + } + regionPositions <- lapply(seq_along(regions), function(x){ .logThis(regions[[x]], paste0("regions[[x]]-", x), logFile = logFile) @@ -184,6 +188,9 @@ addPeakAnnotations <- function( # Peak Overlap Matrix ############################################################# peakSet <- getPeakSet(ArchRProj) + if(is.null(peakSet)){ + .logStop("peakSet is NULL. You need a peakset to run addMotifAnnotations! See addReproduciblePeakSet!", logFile = logFile) + } allPositions <- unlist(regionPositions) .logDiffTime("Creating Peak Overlap Matrix", t1 = tstart, verbose = TRUE, logFile = logFile) @@ -431,6 +438,9 @@ addMotifAnnotations <- function( ############################################################# .logDiffTime("Finding Motif Positions with motifmatchr!", t1 = tstart, verbose = TRUE, logFile = logFile) peakSet <- ArchRProj@peakSet + if(is.null(peakSet)){ + .logStop("peakSet is NULL. You need a peakset to run addMotifAnnotations! See addReproduciblePeakSet!", logFile = logFile) + } motifPositions <- motifmatchr::matchMotifs( pwms = motifs, subject = peakSet, @@ -606,7 +616,11 @@ addArchRAnnotations <- function( } } - genome <- tolower(validBSgenome(getGenome(ArchRProj))@provider_version) + genome <- tolower(tryCatch({ + validBSgenome(getGenome(ArchRProj))$provider_version + }, error = function(e){ + strsplit(validBSgenome(getGenome(ArchRProj))@pkgname,"\\.")[[1]][4] + })) annoPath <- file.path(find.package("ArchR", NULL, quiet = TRUE), "data", "Annotations") dir.create(annoPath, showWarnings = FALSE) @@ -690,6 +704,9 @@ addArchRAnnotations <- function( # Peak Overlap Matrix ############################################################# peakSet <- getPeakSet(ArchRProj) + if(is.null(peakSet)){ + .logStop("peakSet is NULL. You need a peakset to run addMotifAnnotations! See addReproduciblePeakSet!", logFile = logFile) + } chr <- paste0(unique(seqnames(peakSet))) .logMessage("Annotating Chromosomes", verbose = TRUE, logFile = logFile) @@ -1061,6 +1078,10 @@ plotEnrichHeatmap <- function( mat <- mat[keep, ,drop = FALSE] .logThis(mat, "mat-mlog10Padj-Filter", logFile = logFile) + if(nrow(mat)==0){ + stop("No enrichments found for your cutoff!") + } + passMat <- lapply(seq_len(nrow(mat)), function(x){ (mat[x, ] >= 0.9*max(mat[x, ])) * 1 }) %>% Reduce("rbind", .) %>% data.frame @@ -1070,7 +1091,7 @@ plotEnrichHeatmap <- function( mat[mat > pMax] <- pMax if(nrow(mat)==0){ - stop("No enrichments found!") + stop("No enrichments found for your cutoff!") } mat <- .rowScale(as.matrix(mat), min = 0) diff --git a/R/ArchRBrowser.R b/R/ArchRBrowser.R index 27a01fbd..c496cc9f 100644 --- a/R/ArchRBrowser.R +++ b/R/ArchRBrowser.R @@ -1749,6 +1749,12 @@ plotBrowserTrack <- function( title <- paste0(as.character(seqnames(region)),":", start(region)-1, "-", end(region), " ", title) + #Re-Order + groupDF$group2 <- factor( + paste0(groupDF$group2), + levels = gtools::mixedsort(unique(paste0(groupDF$group2))) + ) + p <- ggplot(groupDF, aes(x=bp, y=y, width = tileSize, fill = group2, color = group2)) + geom_tile(size = scTileSize) + facet_grid(group2 ~ ., scales="free_y") + diff --git a/R/ArrowRead.R b/R/ArrowRead.R index 0fa26ae1..20bbdb6c 100644 --- a/R/ArrowRead.R +++ b/R/ArrowRead.R @@ -783,6 +783,11 @@ getMatrixFromArrow <- function( matFiles <- lapply(mat, function(x) x[[2]]) %>% Reduce("c", .) mat <- lapply(mat, function(x) x[[1]]) %>% Reduce("cbind", .) + if(!all(cellNames %in% colnames(mat))){ + .logThis(sampledCellNames, "cellNames supplied", logFile = logFile) + .logThis(colnames(mat), "cellNames from matrix", logFile = logFile) + stop("Error not all cellNames found in partialMatrix") + } mat <- mat[,sampledCellNames, drop = FALSE] mat <- .checkSparseMatrix(mat, length(sampledCellNames)) @@ -793,6 +798,11 @@ getMatrixFromArrow <- function( }else{ mat <- Reduce("cbind", mat) + if(!all(cellNames %in% colnames(mat))){ + .logThis(cellNames, "cellNames supplied", logFile = logFile) + .logThis(colnames(mat), "cellNames from matrix", logFile = logFile) + stop("Error not all cellNames found in partialMatrix") + } mat <- mat[,cellNames, drop = FALSE] mat <- .checkSparseMatrix(mat, length(cellNames)) @@ -902,6 +912,16 @@ getMatrixFromArrow <- function( stop("Means Variances and Ns lengths not identical") } + #Check if samples have NAs due to N = 1 sample or some other weird thing. + #Set it to min non NA variance + dfVars <- lapply(seq_len(nrow(dfVars)), function(x){ + vx <- dfVars[x, ] + if(any(is.na(vx))){ + vx[is.na(vx)] <- min(vx[!is.na(vx)]) + } + vx + }) %>% Reduce("rbind", .) + combinedMeans <- rowSums(t(t(dfMeans) * ns)) / sum(ns) summedVars <- rowSums(t(t(dfVars) * (ns - 1)) + t(t(dfMeans^2) * ns)) combinedVars <- (summedVars - sum(ns)*combinedMeans^2)/(sum(ns)-1) @@ -925,8 +945,6 @@ getMatrixFromArrow <- function( length(.availableCells(ArrowFiles[y], useMatrix)) }) %>% unlist - - #Compute RowVars summaryDF <- .safelapply(seq_along(featureDF), function(x){ diff --git a/R/ArrowUtils.R b/R/ArrowUtils.R index 7fa584b5..f8e4af75 100644 --- a/R/ArrowUtils.R +++ b/R/ArrowUtils.R @@ -379,10 +379,20 @@ o <- h5createGroup(outArrow, groupName) mData <- ArrowInfo[[groupName]] + cellNames <- .h5read(inArrow, "Metadata/CellNames") + idx <- which(cellNames %in% stringr::str_split(cellsKeep, pattern="#", simplify=TRUE)[,2]) + if(length(idx)==0){ + stop("No cells matching in arrow file!") + } + for(i in seq_len(nrow(mData))){ h5name <- paste0(groupName, "/", mData$name[i]) - h5write(.h5read(inArrow, h5name), file = outArrow, name = h5name) + mDatai <- .h5read(inArrow, h5name) + if(length(mDatai)==length(cellNames)){ + mDatai <- mDatai[idx] + } + h5write(mDatai, file = outArrow, name = h5name) } #2. scATAC-Fragments diff --git a/R/CreateArrow.R b/R/CreateArrow.R index 10db9ec3..d793bc69 100644 --- a/R/CreateArrow.R +++ b/R/CreateArrow.R @@ -473,7 +473,7 @@ createArrowFiles <- function( .logDiffTime("Continuing through after error ggplot for Fragment Size Distribution", t1 = tstart, logFile = logFile) #print(x) - message("\n") + if(getArchRVerbose()) message("\n") }) gc() @@ -537,7 +537,7 @@ createArrowFiles <- function( .logDiffTime("Continuing through after error ggplot for TSS by Frags", t1 = tstart, logFile = logFile) #message(x) - message("\n") + if(getArchRVerbose()) message("\n") }) @@ -1119,7 +1119,7 @@ createArrowFiles <- function( TRUE }, error = function(x){ tryCatch({ - message("Attempting to index ", file," as tabix..") + if(getArchRVerbose()) message("Attempting to index ", file," as tabix..") indexTabix(file, format = "bed") TRUE }, error = function(y){ @@ -1138,7 +1138,7 @@ createArrowFiles <- function( } }, error = function(x){ tryCatch({ - message("Attempting to index ", file," as bam...") + if(getArchRVerbose()) message("Attempting to index ", file," as bam...") indexBam(file) TRUE }, error = function(y){ @@ -1278,7 +1278,7 @@ createArrowFiles <- function( o <- .suppressAll(h5createDataset(tmpFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) o <- .suppressAll(h5createDataset(tmpFile, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = 0, size = max(nchar(RG@values)) + 1)) - o <- h5write(obj = cbind(dt$V2,dt$V3-dt$V2), file = tmpFile, name = chrPos) + o <- h5write(obj = cbind(dt$V2,dt$V3 - dt$V2 + 1), file = tmpFile, name = chrPos) o <- h5write(obj = RG@lengths, file = tmpFile, name = chrRGLengths) o <- h5write(obj = RG@values, file = tmpFile, name = chrRGValues) @@ -1314,7 +1314,7 @@ createArrowFiles <- function( o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = 0, size = max(nchar(RG@values)) + 1)) - o <- h5write(obj = cbind(dt$V2,dt$V3-dt$V2), file = tmpChrFile, name = chrPos) + o <- h5write(obj = cbind(dt$V2,dt$V3 - dt$V2 + 1), file = tmpChrFile, name = chrPos) o <- h5write(obj = RG@lengths, file = tmpChrFile, name = chrRGLengths) o <- h5write(obj = RG@values, file = tmpChrFile, name = chrRGValues) @@ -1650,7 +1650,7 @@ createArrowFiles <- function( o <- .suppressAll(h5createDataset(tmpFile, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = 0, size = max(nchar(RG@values)) + 1)) - o <- h5write(obj = cbind(dt$start,dt$end-dt$start), file = tmpFile, name = chrPos) + o <- h5write(obj = cbind(dt$start, dt$end - dt$start + 1), file = tmpFile, name = chrPos) o <- h5write(obj = RG@lengths, file = tmpFile, name = chrRGLengths) o <- h5write(obj = RG@values, file = tmpFile, name = chrRGValues) @@ -1686,7 +1686,7 @@ createArrowFiles <- function( o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = 0, size = max(nchar(RG@values)) + 1)) - o <- h5write(obj = cbind(dt$start,dt$end-dt$start), file = tmpChrFile, name = chrPos) + o <- h5write(obj = cbind(dt$start, dt$end - dt$start + 1), file = tmpChrFile, name = chrPos) o <- h5write(obj = RG@lengths, file = tmpChrFile, name = chrRGLengths) o <- h5write(obj = RG@values, file = tmpChrFile, name = chrRGValues) @@ -1930,14 +1930,29 @@ createArrowFiles <- function( chrPos <- paste0("Fragments/",chr,"/Ranges") chrRGLengths <- paste0("Fragments/",chr,"/RGLengths") chrRGValues <- paste0("Fragments/",chr,"/RGValues") - o <- h5createGroup(outArrow, paste0("Fragments/",chr)) - o <- .suppressAll(h5createDataset(outArrow, chrPos, storage.mode = "integer", dims = c(length(fragments), 2), level = 0)) - o <- .suppressAll(h5createDataset(outArrow, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) - o <- .suppressAll(h5createDataset(outArrow, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = 0, - size = max(nchar(mcols(fragments)$RG@values)) + 1)) - o <- h5write(obj = cbind(start(fragments),width(fragments)), file = outArrow, name = chrPos) - o <- h5write(obj = mcols(fragments)$RG@lengths, file = outArrow, name = chrRGLengths) - o <- h5write(obj = mcols(fragments)$RG@values, file = outArrow, name = chrRGValues) + + if(lengthRG == 0){ + + .logMessage(msg = paste0(prefix, " detected 0 Fragments in cells passing filtering threshold for ", chr), logFile = logFile) + + o <- h5createGroup(outArrow, paste0("Fragments/",chr)) + o <- .suppressAll(h5createDataset(outArrow, chrPos, storage.mode = "integer", dims = c(0, 2), level = 0)) + o <- .suppressAll(h5createDataset(outArrow, chrRGLengths, storage.mode = "integer", dims = c(0, 1), level = 0)) + o <- .suppressAll(h5createDataset(outArrow, chrRGValues, storage.mode = "character", dims = c(0, 1), level = 0, + size = 10)) + + }else{ + + o <- h5createGroup(outArrow, paste0("Fragments/",chr)) + o <- .suppressAll(h5createDataset(outArrow, chrPos, storage.mode = "integer", dims = c(length(fragments), 2), level = 0)) + o <- .suppressAll(h5createDataset(outArrow, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) + o <- .suppressAll(h5createDataset(outArrow, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = 0, + size = max(nchar(mcols(fragments)$RG@values)) + 1)) + + o <- h5write(obj = cbind(start(fragments),width(fragments)), file = outArrow, name = chrPos) + o <- h5write(obj = mcols(fragments)$RG@lengths, file = outArrow, name = chrRGLengths) + o <- h5write(obj = mcols(fragments)$RG@values, file = outArrow, name = chrRGValues) + } #Free Some Memory! rm(fragments) @@ -1995,15 +2010,26 @@ createArrowFiles <- function( chrRGLengths <- paste0(chr, "._.RGLengths") chrRGValues <- paste0(chr, "._.RGValues") - #HDF5 Write - o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(length(fragments), 2), level = 0)) - o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) - o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = 0, - size = max(nchar(mcols(fragments)$RG@values)) + 1)) - - o <- h5write(obj = cbind(start(fragments),width(fragments)), file = tmpChrFile, name = chrPos) - o <- h5write(obj = mcols(fragments)$RG@lengths, file = tmpChrFile, name = chrRGLengths) - o <- h5write(obj = mcols(fragments)$RG@values, file = tmpChrFile, name = chrRGValues) + if(lengthRG == 0){ + + #HDF5 Write + o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(0, 2), level = 0)) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(0, 1), level = 0)) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", dims = c(0, 1), level = 0, + size = 10)) + + }else{ + + #HDF5 Write + o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(length(fragments), 2), level = 0)) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = 0, + size = max(nchar(mcols(fragments)$RG@values)) + 1)) + + o <- h5write(obj = cbind(start(fragments),width(fragments)), file = tmpChrFile, name = chrPos) + o <- h5write(obj = mcols(fragments)$RG@lengths, file = tmpChrFile, name = chrRGLengths) + o <- h5write(obj = mcols(fragments)$RG@values, file = tmpChrFile, name = chrRGValues) + } #Free Some Memory! rm(fragments) diff --git a/R/Embedding.R b/R/Embedding.R index ba59be35..e0ead19c 100644 --- a/R/Embedding.R +++ b/R/Embedding.R @@ -207,9 +207,18 @@ addUMAP <- function( } +#New Save UWOT +.saveUWOT <- function(model, file){ + tryCatch({ + uwot::save_uwot(model = model, file = file, verbose = TRUE) + }, error = function(e){ + .saveUWOT_Deprecated(model = model, file = file) #backwards to previous version + }) +} + #save_uwot does not work because tarring doesnt work for some reason on Stanford's compute server #Adapted from save_uwot -.saveUWOT <- function(model, file){ +.saveUWOT_Deprecated <- function(model, file){ file <- file.path(normalizePath(dirname(file)), basename(file)) wd <- getwd() mod_dir <- tempfile(pattern = "dir") @@ -243,8 +252,17 @@ addUMAP <- function( return(o) } +#New Save UWOT +.loadUWOT <- function(file){ + tryCatch({ + uwot::load_uwot(file = file, verbose = TRUE) + }, error = function(e){ + .loadUWOT_Deprecated(file = file, nDim = nDim) #backwards to previous version + }) +} + #Adapted from load_uwot -.loadUWOT <- function(file, nDim = NULL){ +.loadUWOT_Deprecated <- function(file, nDim = NULL){ model <- NULL tryCatch({ mod_dir <- tempfile(pattern = "dir") diff --git a/R/FilterCells.R b/R/FilterCells.R index 6ef51514..54a89ac1 100644 --- a/R/FilterCells.R +++ b/R/FilterCells.R @@ -99,7 +99,7 @@ filterDoublets <- function(ArchRProj = NULL, cutEnrich = 1, cutScore = -Inf, fil } ArchRProj <- addProjectSummary(ArchRProj = ArchRProj, name = "filterDoublets", - summary = c("Date" = Sys.time(), cutEnrich = cutEnrich, cutScore = cutScore, filterRatio = filterRatio)) + summary = c(cutEnrich = cutEnrich, cutScore = cutScore, filterRatio = filterRatio)) ArchRProj diff --git a/R/GgplotUtils.R b/R/GgplotUtils.R index c0339437..609caa08 100644 --- a/R/GgplotUtils.R +++ b/R/GgplotUtils.R @@ -952,8 +952,10 @@ theme_ArchR <- function( .checkCairo <- function(){ tryCatch({ + tmp <- dev.cur() Cairo::Cairo(type='raster') dev.off() + dev.set(tmp) TRUE }, error = function(e){ FALSE diff --git a/R/GlobalDefaults.R b/R/GlobalDefaults.R index 26854c57..aae3753b 100644 --- a/R/GlobalDefaults.R +++ b/R/GlobalDefaults.R @@ -8,7 +8,8 @@ ArchRDefaults <- list( ArchR.logging = TRUE, ArchR.genome = NA, ArchR.chrPrefix = TRUE, - ArchR.debugging = FALSE + ArchR.debugging = FALSE, + ArchR.verbose = TRUE ) .onAttach <- function(libname, pkgname){ @@ -27,9 +28,30 @@ ArchRDefaults <- list( if(!.checkCairo()){ packageStartupMessage("WARNING : Cairo check shows Cairo is not functional.\n ggplot2 rasterization will not be available without Cario.\n This may cause issues editing plots with many thousands of points from single cells.") } + if(.checkJupyter()){ + packageStartupMessage("Detected Jupyer Notebook session. Disabling Log Messages!\n\tIf this is undesired use `addArchRVerbose(TRUE)`") + addArchRVerbose(verbose = FALSE) + } invisible() } +#Check Jupyer Status +.checkJupyter <- function(){ + tryCatch({ + sysID <- Sys.getenv("JPY_PARENT_PID") + if(!is.character(sysID)){ + return(FALSE) + } + if(sysID == ""){ + FALSE + }else{ + TRUE + } + },error= function(e){ + FALSE + }) +} + #' Install extra packages used in ArchR that are not installed by default #' #' This function will install extra packages used in ArchR that are not installed by default. diff --git a/R/GroupCoverages.R b/R/GroupCoverages.R index 549ec840..63859218 100644 --- a/R/GroupCoverages.R +++ b/R/GroupCoverages.R @@ -195,7 +195,11 @@ addGroupCoverages <- function( args$ArrowFiles <- getArrowFiles(ArchRProj) args$availableChr <- .availableSeqnames(getArrowFiles(ArchRProj)) args$chromLengths <- getChromLengths(ArchRProj) - args$cellsInArrow <- split(rownames(getCellColData(ArchRProj)), getCellColData(ArchRProj)$Sample) + #args$cellsInArrow <- split(rownames(getCellColData(ArchRProj)), getCellColData(ArchRProj)$Sample) + args$cellsInArrow <- cellsInArrow <- split( + rownames(getCellColData(ArchRProj)), + stringr::str_split(rownames(getCellColData(ArchRProj)), pattern="\\#", simplify=TRUE)[,1] + ) args$covDir <- file.path(getOutputDirectory(ArchRProj), "GroupCoverages", groupBy) args$parallelParam <- parallelParam args$threads <- threads @@ -218,9 +222,6 @@ addGroupCoverages <- function( nCells <- lapply(seq_along(batchOut),function(x) batchOut[[x]]$nCells) %>% unlist nFragments <- lapply(seq_along(batchOut),function(x) batchOut[[x]]$nFragments) %>% unlist - #Enable Hdf5 File Locking - h5enableFileLocking() - #Add To Project coverageMetadata <- DataFrame( Group = stringr::str_split(names(unlistGroups), pattern = "\\._.", simplify=TRUE)[,1], @@ -245,6 +246,9 @@ addGroupCoverages <- function( ArchRProj@projectMetadata$GroupCoverages[[groupBy]] <- SimpleList(Params = Params, coverageMetadata = coverageMetadata) + #Enable Hdf5 File Locking + h5enableFileLocking() + .logDiffTime(sprintf("Finished Creation of Coverage Files!"), tstart, addHeader = FALSE) .endLogging(logFile = logFile) @@ -671,7 +675,7 @@ addGroupCoverages <- function( .getCoverageMetadata <- function(ArchRProj = NULL, groupBy = NULL, useGroups = NULL, minCells = NULL){ coverageMetadata <- ArchRProj@projectMetadata$GroupCoverages[[groupBy]]$coverageMetadata if(is.null(coverageMetadata)){ - stop("No Coverage Metadata found for : ", groupBy) + stop("No Coverage Metadata found for : ", groupBy, ". Please run addGroupCoverages!") } if(!is.null(useGroups)){ if(sum(coverageMetadata[,1] %in% useGroups) == 0){ diff --git a/R/GroupExport.R b/R/GroupExport.R index b13b5a1e..87bf3719 100644 --- a/R/GroupExport.R +++ b/R/GroupExport.R @@ -222,7 +222,11 @@ getGroupBW <- function( o <- suppressWarnings(file.remove(list.files(bwDir2, full.names = TRUE))) - cellsInArrow <- split(rownames(getCellColData(ArchRProj)), getCellColData(ArchRProj)$Sample) + #cellsInArrow <- split(rownames(getCellColData(ArchRProj)), getCellColData(ArchRProj)$Sample) + cellsInArrow <- split( + rownames(getCellColData(ArchRProj)), + stringr::str_split(rownames(getCellColData(ArchRProj)), pattern="\\#", simplify=TRUE)[,1] + ) availableChr <- .availableSeqnames(head(getArrowFiles(ArchRProj))) chromLengths <- getChromLengths(ArchRProj) chromSizes <- getChromSizes(ArchRProj) diff --git a/R/IntegrativeAnalysis.R b/R/IntegrativeAnalysis.R index 909e0f30..543d1eff 100644 --- a/R/IntegrativeAnalysis.R +++ b/R/IntegrativeAnalysis.R @@ -821,7 +821,7 @@ addCoAccessibility <- function( o$idx2 <- NULL o <- o[!is.na(o$correlation),] - o$TStat <- (o$correlation / sqrt((max(1-o$correlation^2, 0.00000000000000001))/(length(knnObj)-2))) #T-statistic P-value + o$TStat <- (o$correlation / sqrt((pmax(1-o$correlation^2, 0.00000000000000001, na.rm = TRUE))/(length(knnObj)-2))) #T-statistic P-value o$Pval <- 2*pt(-abs(o$TStat), length(knnObj) - 2) o$FDR <- p.adjust(o$Pval, method = "fdr") o$VarQuantile1 <- .getQuantiles(o$Variability1) @@ -1028,9 +1028,16 @@ addPeak2GeneLinks <- function( tstart <- Sys.time() dfAll <- .safelapply(seq_along(ArrowFiles), function(x){ + cNx <- paste0(names(ArrowFiles)[x], "#", h5read(ArrowFiles[x], paste0(useMatrix, "/Info/CellNames"))) + pSx <- tryCatch({ + h5read(ArrowFiles[x], paste0(useMatrix, "/Info/predictionScore")) + }, error = function(e){ + if(getArchRVerbose()) message("No predictionScore found. Continuing without predictionScore!") + rep(9999999, length(cNx)) + }) DataFrame( - cellNames = paste0(names(ArrowFiles)[x], "#", h5read(ArrowFiles[x], paste0(useMatrix, "/Info/CellNames"))), - predictionScore = h5read(ArrowFiles[x], paste0(useMatrix, "/Info/predictionScore")) + cellNames = cNx, + predictionScore = pSx ) }, threads = threads) %>% Reduce("rbind", .) @@ -1173,7 +1180,7 @@ addPeak2GeneLinks <- function( o$Correlation <- rowCorCpp(as.integer(o$A), as.integer(o$B), assay(seATAC), assay(seRNA)) o$VarAssayA <- .getQuantiles(matrixStats::rowVars(assay(seATAC)))[o$A] o$VarAssayB <- .getQuantiles(matrixStats::rowVars(assay(seRNA)))[o$B] - o$TStat <- (o$Correlation / sqrt((max(1-o$Correlation^2, 0.00000000000000001))/(ncol(seATAC)-2))) #T-statistic P-value + o$TStat <- (o$Correlation / sqrt((pmax(1-o$Correlation^2, 0.00000000000000001, na.rm = TRUE))/(ncol(seATAC)-2))) #T-statistic P-value o$Pval <- 2*pt(-abs(o$TStat), ncol(seATAC) - 2) o$FDR <- p.adjust(o$Pval, method = "fdr") out <- o[, c("A", "B", "Correlation", "FDR", "VarAssayA", "VarAssayB")] diff --git a/R/IterativeLSI.R b/R/IterativeLSI.R index 97f1dcac..57300734 100644 --- a/R/IterativeLSI.R +++ b/R/IterativeLSI.R @@ -803,9 +803,7 @@ addIterativeLSI <- function( UMAPParams$n_threads <- floor(threads / 2) uwotUmap <- do.call(uwot::umap, UMAPParams) - #Plot - pdf(file.path(outDir, paste0("Save-LSI-Iteration-",j,".pdf")), width = 6, height = 6) - + #Plot p1 <- ggPoint( uwotUmap[,1], uwotUmap[,2], @@ -831,6 +829,7 @@ addIterativeLSI <- function( theme(axis.text.x = element_blank(), axis.ticks.x = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank()) + pdf(file.path(outDir, paste0("Save-LSI-Iteration-",j,".pdf")), width = 6, height = 6) .fixPlotSize(p1, plotWidth = 6, plotHeight = 6) grid::grid.newpage() .fixPlotSize(p2, plotWidth = 6, plotHeight = 6) diff --git a/R/LoggerUtils.R b/R/LoggerUtils.R index f704cf94..bc498e08 100644 --- a/R/LoggerUtils.R +++ b/R/LoggerUtils.R @@ -56,6 +56,33 @@ getArchRDebugging <- function(){ ArchRDebugging } +#' Set ArchR Verbosity for Log Messaging +#' +#' This function will set ArchR logging verbosity. +#' +#' @param verbose A boolean describing whether to printMessages in addition to logging with ArchR. +#' @export +addArchRVerbose <- function(verbose = TRUE){ + .validInput(input = verbose, name = "verbose", valid = "boolean") + message("Setting addArchRVerbose = ", verbose) + options(ArchR.verbose = verbose) + return(invisible(0)) +} + +#' Set ArchR Verbosity for Log Messaging +#' +#' This function will get ArchR logging verbosity. +#' +#' @export +getArchRVerbose <- function(){ + ArchRVerbose <- options()[["ArchR.verbose"]] + if(!is.logical(ArchRVerbose)){ + options(ArchR.verbose = TRUE) + return(TRUE) + } + ArchRVerbose +} + #' Create a Log File for ArchR #' #' This function will create a log file for ArchR functions. If ArchRLogging is not TRUE @@ -113,9 +140,9 @@ createLogFile <- function( }else{ msg <- sprintf("%s : %s, %s %s %s", Sys.time(), main, dt, units, tail) } - message(msg) + if(getArchRVerbose()) message(msg) }, error = function(x){ - message("Time Error : ", x) + if(getArchRVerbose()) message("Time Error : ", x) }) } @@ -172,7 +199,7 @@ createLogFile <- function( } } - message("ArchR logging to : ", logFile, + if(getArchRVerbose()) message("ArchR logging to : ", logFile, "\nIf there is an issue, please report to github with logFile!") #Begin With @@ -220,8 +247,12 @@ createLogFile <- function( useLogs = getArchRLogging() ){ - msg <- utils::capture.output(message(...), type = "message") - msg <- paste0(msg, collapse = "\n") + if(getArchRVerbose()){ + msg <- utils::capture.output(message(...), type = "message") + msg <- paste0(msg, collapse = "\n") + }else{ + msg <- "SuppressedMessaged due to getArchRVerbose() is FALSE!" + } if(is.null(msg)){ stop("Message must be provided when logging!") @@ -556,7 +587,7 @@ createLogFile <- function( cat(paste0("Elapsed Time Minutes = ", mn), file = logFile, append = TRUE) cat(paste0("\nElapsed Time Hours = ", hr), file = logFile, append = TRUE) cat("\n\n-------\n\n\n\n", file = logFile, append = TRUE) - message("ArchR logging successful to : ", logFile) + if(getArchRVerbose()) message("ArchR logging successful to : ", logFile) }, error = function(x){ }) diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index 0cf5bf56..0ed03a5b 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -410,6 +410,10 @@ getMarkerFeatures <- function( } + .logThis(o, paste0(group, "_", seqnames[y], "_diffResult"), logFile = logFile) + + o + }) %>% Reduce("rbind", .) idxFilter <- rowSums(pairwiseDF[,c("mean1","mean2")]) != 0 diff --git a/R/MatrixDeviations.R b/R/MatrixDeviations.R index 6fd0d467..fd9de175 100644 --- a/R/MatrixDeviations.R +++ b/R/MatrixDeviations.R @@ -378,11 +378,17 @@ addDeviationsMatrix <- function( if("z" %in% tolower(out)){ z <- t(vapply(results, function(x) x[["z"]], rep(0, length(cn)))) + if(length(cn)==1){ + z <- matrix(z, ncol=length(cn)) + } }else{ z <- matrix(0, nrow = ncol(annotationsMatrix), ncol = length(cn)) } if("deviations" %in% tolower(out)){ dev <- t(vapply(results, function(x) x[["dev"]], rep(0, length(cn)))) + if(length(cn)==1){ + dev <- matrix(dev, ncol=length(cn)) + } }else{ dev <- matrix(0, nrow = ncol(annotationsMatrix), ncol = length(cn)) } diff --git a/R/MatrixGeneScores.R b/R/MatrixGeneScores.R index 1325d4ce..ef34822d 100644 --- a/R/MatrixGeneScores.R +++ b/R/MatrixGeneScores.R @@ -100,6 +100,10 @@ addGeneScoreMatrix <- function( stop("Error Input Arrow Files do not all exist!") } + if(inherits(mcols(genes)$symbol, "list") | inherits(mcols(genes)$symbol, "SimpleList")){ + stop("Found a list in genes symbol! This is an incorrect format. Please correct your genes!") + } + .startLogging(logFile = logFile) .logThis(mget(names(formals()),sys.frame(sys.nframe())), "addGeneScoreMatrix Input-Parameters", logFile = logFile) @@ -191,6 +195,10 @@ addGeneScoreMatrix <- function( .validInput(input = force, name = "force", valid = c("boolean")) .validInput(input = tmpFile, name = "tmpFile", valid = c("character", "null")) + if(inherits(mcols(genes)$symbol, "list") | inherits(mcols(genes)$symbol, "SimpleList")){ + stop("Found a list in genes symbol! This is an incorrect format. Please correct your genes!") + } + ArrowFile <- ArrowFiles[i] sampleName <- .sampleName(ArrowFile) diff --git a/R/ProjectMethods.R b/R/ProjectMethods.R index 5609cf0f..1cb18b7d 100644 --- a/R/ProjectMethods.R +++ b/R/ProjectMethods.R @@ -363,24 +363,56 @@ getPeakSet <- function(ArchRProj = NULL){ #' #' @param ArchRProj An `ArchRProject` object. #' @param peakSet A `GRanges` object containing the set of regions that define all peaks in the desired peak set. +#' @param genomeAnnotation The genomeAnnotation (see `createGenomeAnnotation()`) to be used for generating peak metadata such as nucleotide +#' information (GC content) or chromosome sizes. #' @param force If a `peakSet` object has already been added to the given `ArchRProject`, the value of `force` determines #' whether or not to overwrite this `peakSet`. #' @export -addPeakSet <- function(ArchRProj = NULL, peakSet = NULL, force = FALSE){ +addPeakSet <- function( + ArchRProj = NULL, + peakSet = NULL, + genomeAnnotation = getGenomeAnnotation(ArchRProj), + force = FALSE + ){ + .validInput(input = ArchRProj, name = "ArchRProj", valid = "ArchRProject") .validInput(input = peakSet, name = "peakSet", valid = c("GRanges")) .validInput(input = force, name = "force", valid = c("boolean")) + genomeAnnotation <- .validGenomeAnnotation(genomeAnnotation) + if(is.null(ArchRProj@peakSet) | force){ + #Index The Peak Set peakSet <- lapply(split(peakSet, seqnames(peakSet)), function(x){ mcols(x)$idx <- seq_along(x) x }) %>% Reduce("c", .) %>% sortSeqlevels %>% sort + + #Get NucleoTide Content + peakSet <- tryCatch({ + .requirePackage(genomeAnnotation$genome) + .requirePackage("Biostrings",source="bioc") + BSgenome <- eval(parse(text = genomeAnnotation$genome)) + BSgenome <- validBSgenome(BSgenome) + nucFreq <- BSgenome::alphabetFrequency(getSeq(BSgenome, peakSet)) + mcols(peakSet)$GC <- round(rowSums(nucFreq[,c("G","C")]) / rowSums(nucFreq),4) + mcols(peakSet)$N <- round(nucFreq[,c("N")] / rowSums(nucFreq),4) + peakSet + }, error = function(e){ + peakSet + }) + + #Add PeakSet ArchRProj@peakSet <- peakSet + }else{ + stop("Error peakSet exists! Set force=TRUE to override!") + } + return(ArchRProj) + } ########################################################################################## @@ -571,6 +603,10 @@ getGenes <- function(ArchRProj = NULL, symbols = NULL){ genes <- genes[which(tolower(genes$symbol) %in% tolower(symbols))] } + if(inherits(mcols(genes)$symbol, "list") | inherits(mcols(genes)$symbol, "SimpleList")){ + stop("Found a list in genes symbol! This is an incorrect format. Please correct your genes!") + } + genes } diff --git a/R/RNAIntegration.R b/R/RNAIntegration.R index 53a367f6..8e11b27e 100644 --- a/R/RNAIntegration.R +++ b/R/RNAIntegration.R @@ -43,6 +43,7 @@ #' @param reduction The Seurat reduction method to use for integrating modalities. See `Seurat::FindTransferAnchors()` for possible reduction methods. #' @param addToArrow A boolean value indicating whether to add the log2-normalized transcript counts from the integrated matched RNA to the Arrow files. #' @param scaleTo Each column in the integrated RNA matrix will be normalized to a column sum designated by `scaleTo` prior to adding to Arrow files. +#' @param genesUse If desired a character vector of gene names to use for integration instead of determined ones from Seurat::variableGenes. #' @param nameCell A column name to add to `cellColData` for the predicted scRNA-seq cell in the specified `ArchRProject`. This is useful for identifying which cell was closest to the scATAC-seq cell. #' @param nameGroup A column name to add to `cellColData` for the predicted scRNA-seq group in the specified `ArchRProject`. See `groupRNA` for more details. #' @param nameScore A column name to add to `cellColData` for the predicted scRNA-seq score in the specified `ArchRProject`. These scores represent @@ -77,6 +78,7 @@ addGeneIntegrationMatrix <- function( reduction = "cca", addToArrow = TRUE, scaleTo = 10000, + genesUse = NULL, nameCell = "predictedCell", nameGroup = "predictedGroup", nameScore = "predictedScore", @@ -110,6 +112,7 @@ addGeneIntegrationMatrix <- function( .validInput(input = reduction, name = "reduction", valid = c("character")) .validInput(input = addToArrow, name = "addToArrow", valid = c("boolean")) .validInput(input = scaleTo, name = "scaleTo", valid = c("numeric")) + .validInput(input = genesUse, name = "genesUse", valid = c("character", "null")) .validInput(input = nameCell, name = "nameCell", valid = c("character")) .validInput(input = nameGroup, name = "nameGroup", valid = c("character")) .validInput(input = nameScore, name = "nameScore", valid = c("character")) @@ -385,7 +388,9 @@ addGeneIntegrationMatrix <- function( .logDiffTime(sprintf("%s Identifying Variable Genes", prefix), tstart, verbose = verbose, logFile = logFile) subRNA <- FindVariableFeatures(object = subRNA, nfeatures = nGenes, verbose = FALSE) subRNA <- ScaleData(object = subRNA, verbose = FALSE) - genesUse <- VariableFeatures(object = subRNA) + if(is.null(genesUse)){ + genesUse <- VariableFeatures(object = subRNA) + } ############################################################################################## #2. Get Gene Score Matrix and Create Seurat ATAC diff --git a/R/ReproduciblePeakSet.R b/R/ReproduciblePeakSet.R index fd6393df..8699e748 100644 --- a/R/ReproduciblePeakSet.R +++ b/R/ReproduciblePeakSet.R @@ -262,7 +262,7 @@ addReproduciblePeakSet <- function( }else if(tolower(peakMethod) == "tiles"){ - .logMessage("Calling Peaks with TileMatrix", logFile = logFile) + .logMessage("Calling Peaks with TileMatrix. We recommend using the Macs2 Version.\nThis method is still under development.", logFile = logFile) useMatrix <- "TileMatrix" @@ -325,11 +325,13 @@ addReproduciblePeakSet <- function( #Compute Row Sums Across All Samples .logDiffTime("Computing Total Accessibility Across All Features", tstart, addHeader = FALSE, verbose = verbose) totalAcc <- .getRowSums(ArrowFiles = ArrowFiles, useMatrix = useMatrix, seqnames = chrToRun) + .logThis(totalAcc, "PeakCallTiles-totalAcc", logFile=logFile) nTiles <- nrow(totalAcc) gc() #Pre-Filter 0s topFeatures <- totalAcc[which(totalAcc$rowSums != 0), ] + .logThis(topFeatures, "PeakCallTiles-topFeatures", logFile=logFile) #Group Matrix #Consider reading in group-wise if this is getting too large? @@ -344,9 +346,12 @@ addReproduciblePeakSet <- function( asSparse = TRUE, verbose = FALSE ) - + .logThis(groupMat, "PeakCallTiles-groupMat", logFile=logFile) + .logDiffTime(sprintf("Created Pseudo-Grouped Tile Matrix (%s GB)", round(object.size(groupMat) / 10^9, 3)), tstart, addHeader = FALSE, verbose = verbose) expectation <- Matrix::colSums(groupMat) / nTiles + .logMessage(paste0("colSums = ", Matrix::colSums(groupMat)), logFile = logFile) + .logMessage(paste0("nTiles = ", nTiles), logFile = logFile) .logMessage(paste0("Expectation = ", expectation), logFile = logFile) ##################################################### @@ -401,6 +406,8 @@ addReproduciblePeakSet <- function( }, threads = threads) %>% Reduce("rbind", .) + .logThis(groupPeaks, "PeakCallTiles-groupPeaks", logFile=logFile) + groupPeaks <- groupPeaks[order(groupPeaks$normmlogp, decreasing=TRUE), ] ##################################################### diff --git a/R/Trajectory.R b/R/Trajectory.R index c1931e30..ceee126d 100644 --- a/R/Trajectory.R +++ b/R/Trajectory.R @@ -72,7 +72,9 @@ addTrajectory <- function( } if(sum(unique(groupDF[,1]) %in% trajectory) < 3){ - .logStop("trajectory must span at least 3 groups in groupBy!", logFile = logFile) + if(!force){ + .logStop("trajectory must span at least 3 groups in groupBy!", logFile = logFile) + } } if(is.null(embedding)){ @@ -475,6 +477,13 @@ plotTrajectoryHeatmap <- function( } mat <- assay(seTrajectory) + + if(!is.null(grepExclude)){ + idxExclude <- grep(grepExclude, rownames(mat)) + if(length(idxExclude) > 0){ + mat <- mat[-grep(grepExclude, rownames(mat)), , drop = FALSE] + } + } #Rows with NA rSNA <- rowSums(is.na(mat)) @@ -676,7 +685,7 @@ plotTrajectory <- function( .validInput(input = pal, name = "pal", valid = c("character", "null")) .validInput(input = size, name = "size", valid = c("numeric")) .validInput(input = rastr, name = "rastr", valid = c("boolean")) - .validInput(input = quantCut, name = "quantCut", valid = c("numeric")) + .validInput(input = quantCut, name = "quantCut", valid = c("numeric", "null")) .validInput(input = quantHex, name = "quantHex", valid = c("numeric")) .validInput(input = discreteSet, name = "discreteSet", valid = c("character", "null")) .validInput(input = continuousSet, name = "continuousSet", valid = c("character", "null")) @@ -693,6 +702,10 @@ plotTrajectory <- function( .startLogging(logFile = logFile) .logThis(mget(names(formals()),sys.frame(sys.nframe())), "Input-Parameters", logFile=logFile) + if(is.null(quantCut)){ + quantCut <- c(0, 1) + } + #Make Sure ColorBy is valid! if(length(colorBy) > 1){ stop("colorBy must be of length 1!") diff --git a/R/VisualizeData.R b/R/VisualizeData.R index 6f2daa8d..d675abd4 100644 --- a/R/VisualizeData.R +++ b/R/VisualizeData.R @@ -95,12 +95,12 @@ plotPDF <- function( if(inherits(plotList[[i]], "patchwork")){ - message("Plotting Patchwork!") + if(getArchRVerbose()) message("Plotting Patchwork!") print(plotList[[i]]) }else{ - message("Plotting Ggplot!") + if(getArchRVerbose()) message("Plotting Ggplot!") if(!is.null(attr(plotList[[i]], "ratioYX"))){ .fixPlotSize(plotList[[i]], plotWidth = width, plotHeight = height, height = attr(plotList[[i]], "ratioYX"), newPage = FALSE) @@ -116,7 +116,7 @@ plotPDF <- function( }else if(inherits(plotList[[i]], "gtable")){ - message("Plotting Gtable!") + if(getArchRVerbose()) message("Plotting Gtable!") print(grid::grid.draw(plotList[[i]])) if(i != length(plotList)){ @@ -124,7 +124,7 @@ plotPDF <- function( } }else if(inherits(plotList[[i]], "HeatmapList") | inherits(plotList[[i]], "Heatmap") ){ - message("Plotting ComplexHeatmap!") + if(getArchRVerbose()) message("Plotting ComplexHeatmap!") padding <- 15 draw(plotList[[i]], @@ -135,7 +135,7 @@ plotPDF <- function( }else{ - message("Plotting Other") + if(getArchRVerbose()) message("Plotting Other") print(plotList[[i]]) @@ -147,7 +147,7 @@ plotPDF <- function( }, error = function(x){ - message(x) + if(getArchRVerbose()) message(x) }) @@ -320,7 +320,7 @@ plotEmbedding <- function( } if(!is.null(imputeWeights)){ - message("Imputing Matrix") + if(getArchRVerbose()) message("Imputing Matrix") colorMat <- matrix(colorParams$color, nrow=1) colnames(colorMat) <- rownames(df) colorMat <- imputeMatrix(mat = colorMat, imputeWeights = imputeWeights, logFile = logFile) @@ -367,7 +367,7 @@ plotEmbedding <- function( .logThis(colorMat, "colorMat-Before-Impute", logFile = logFile) if(!is.null(imputeWeights)){ - message("Imputing Matrix") + if(getArchRVerbose()) message("Imputing Matrix") colorMat <- imputeMatrix(mat = as.matrix(colorMat), imputeWeights = imputeWeights, logFile = logFile) if(!inherits(colorMat, "matrix")){ colorMat <- matrix(colorMat, ncol = nrow(df)) @@ -401,11 +401,11 @@ plotEmbedding <- function( } - message("Plotting Embedding") + if(getArchRVerbose()) message("Plotting Embedding") ggList <- lapply(seq_along(colorList), function(x){ - message(x, " ", appendLF = FALSE) + if(getArchRVerbose()) message(x, " ", appendLF = FALSE) plotParamsx <- .mergeParams(colorList[[x]], plotParams) @@ -483,7 +483,7 @@ plotEmbedding <- function( }) names(ggList) <- name - message("") + if(getArchRVerbose()) message("") if(length(ggList) == 1){ ggList <- ggList[[1]] @@ -663,7 +663,7 @@ plotGroups <- function( pl <- lapply(seq_along(colorList), function(x){ - message(paste0(x, " "), appendLF = FALSE) + if(getArchRVerbose()) message(paste0(x, " "), appendLF = FALSE) if(is.null(ylim)){ ylim <- range(colorList[[x]]$color,na.rm=TRUE) %>% extendrange(f = 0.05) @@ -692,7 +692,7 @@ plotGroups <- function( }) names(pl) <- name - message("") + if(getArchRVerbose()) message("") if(length(name)==1){ pl[[1]] @@ -764,7 +764,7 @@ plotGroups <- function( cellNamesList <- split(rownames(getCellColData(ArchRProj)), getCellColData(ArchRProj)$Sample) values <- .safelapply(seq_along(cellNamesList), function(x){ - message(x, " ", appendLF = FALSE) + if(getArchRVerbose()) message(x, " ", appendLF = FALSE) valuesx <- tryCatch({ o <- h5closeAll() ArrowFile <- getSampleColData(ArchRProj)[names(cellNamesList)[x],"ArrowFiles"] @@ -792,7 +792,7 @@ plotGroups <- function( valuesx }, threads = threads) %>% Reduce("cbind", .) values <- values[, ArchRProj$cellNames, drop = FALSE] - message("") + if(getArchRVerbose()) message("") gc() .logThis(values, "Feature-Matrix", logFile = logFile) @@ -804,7 +804,7 @@ plotGroups <- function( #Values Summary if(!is.null(log2Norm)){ if(log2Norm){ - message("Log2 Normalizing...") + if(getArchRVerbose()) message("Log2 Normalizing...") values <- log2(values + 1) } } diff --git a/man/ArchRPalettes.Rd b/man/ArchRPalettes.Rd index 61cc1e60..c74ad672 100644 --- a/man/ArchRPalettes.Rd +++ b/man/ArchRPalettes.Rd @@ -4,7 +4,9 @@ \name{ArchRPalettes} \alias{ArchRPalettes} \title{List of color palettes that can be used in plots} -\format{An object of class \code{list} of length 30.} +\format{ +An object of class \code{list} of length 30. +} \usage{ ArchRPalettes } diff --git a/man/addArchRVerbose.Rd b/man/addArchRVerbose.Rd new file mode 100644 index 00000000..dadc3508 --- /dev/null +++ b/man/addArchRVerbose.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/LoggerUtils.R +\name{addArchRVerbose} +\alias{addArchRVerbose} +\title{Set ArchR Verbosity for Log Messaging} +\usage{ +addArchRVerbose(verbose = TRUE) +} +\arguments{ +\item{verbose}{A boolean describing whether to printMessages in addition to logging with ArchR.} +} +\description{ +This function will set ArchR logging verbosity. +} diff --git a/man/addGeneIntegrationMatrix.Rd b/man/addGeneIntegrationMatrix.Rd index 9b89ffdb..dba7957d 100644 --- a/man/addGeneIntegrationMatrix.Rd +++ b/man/addGeneIntegrationMatrix.Rd @@ -28,6 +28,7 @@ addGeneIntegrationMatrix( reduction = "cca", addToArrow = TRUE, scaleTo = 10000, + genesUse = NULL, nameCell = "predictedCell", nameGroup = "predictedGroup", nameScore = "predictedScore", @@ -98,6 +99,8 @@ correlation to sequencing depth that is greater than the \code{corCutOff}, it wi \item{scaleTo}{Each column in the integrated RNA matrix will be normalized to a column sum designated by \code{scaleTo} prior to adding to Arrow files.} +\item{genesUse}{If desired a character vector of gene names to use for integration instead of determined ones from Seurat::variableGenes.} + \item{nameCell}{A column name to add to \code{cellColData} for the predicted scRNA-seq cell in the specified \code{ArchRProject}. This is useful for identifying which cell was closest to the scATAC-seq cell.} \item{nameGroup}{A column name to add to \code{cellColData} for the predicted scRNA-seq group in the specified \code{ArchRProject}. See \code{groupRNA} for more details.} diff --git a/man/addPeakAnnotations.Rd b/man/addPeakAnnotations.Rd index d96db49d..72775a9f 100644 --- a/man/addPeakAnnotations.Rd +++ b/man/addPeakAnnotations.Rd @@ -15,7 +15,7 @@ addPeakAnnotations( \arguments{ \item{ArchRProj}{An \code{ArchRProject} object.} -\item{regions}{A \code{list} of \code{GRanges} that are to be overlapped with the \code{peakSet} in the \code{ArchRProject}.} +\item{regions}{A named \code{list} of \code{GRanges} that are to be overlapped with the \code{peakSet} in the \code{ArchRProject}.} \item{name}{The name of \code{peakAnnotation} object to be stored as in \code{ArchRProject}.} diff --git a/man/addPeakSet.Rd b/man/addPeakSet.Rd index 26b597d7..81dcd3e6 100644 --- a/man/addPeakSet.Rd +++ b/man/addPeakSet.Rd @@ -4,13 +4,21 @@ \alias{addPeakSet} \title{Add a peak set to an ArchRProject} \usage{ -addPeakSet(ArchRProj = NULL, peakSet = NULL, force = FALSE) +addPeakSet( + ArchRProj = NULL, + peakSet = NULL, + genomeAnnotation = getGenomeAnnotation(ArchRProj), + force = FALSE +) } \arguments{ \item{ArchRProj}{An \code{ArchRProject} object.} \item{peakSet}{A \code{GRanges} object containing the set of regions that define all peaks in the desired peak set.} +\item{genomeAnnotation}{The genomeAnnotation (see \code{createGenomeAnnotation()}) to be used for generating peak metadata such as nucleotide +information (GC content) or chromosome sizes.} + \item{force}{If a \code{peakSet} object has already been added to the given \code{ArchRProject}, the value of \code{force} determines whether or not to overwrite this \code{peakSet}.} } diff --git a/man/getArchRVerbose.Rd b/man/getArchRVerbose.Rd new file mode 100644 index 00000000..0ed46322 --- /dev/null +++ b/man/getArchRVerbose.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/LoggerUtils.R +\name{getArchRVerbose} +\alias{getArchRVerbose} +\title{Set ArchR Verbosity for Log Messaging} +\usage{ +getArchRVerbose() +} +\description{ +This function will get ArchR logging verbosity. +}