diff --git a/.DS_Store b/.DS_Store index 3c59563c..8878ebdc 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/DESCRIPTION b/DESCRIPTION index 6953679c..640e6ba8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,6 +14,7 @@ LazyData: TRUE RoxygenNote: 7.1.2 Encoding: UTF-8 Imports: + devtools, ggplot2, SummarizedExperiment, data.table, diff --git a/NAMESPACE b/NAMESPACE index d952a54d..236d40bf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(addArchRAnnotations) export(addArchRChrPrefix) export(addArchRDebugging) export(addArchRGenome) +export(addArchRH5Level) export(addArchRLocking) export(addArchRLogging) export(addArchRThreads) @@ -68,6 +69,7 @@ export(findMacs2) export(getArchRChrPrefix) export(getArchRDebugging) export(getArchRGenome) +export(getArchRH5Level) export(getArchRLogging) export(getArchRThreads) export(getArchRVerbose) @@ -112,6 +114,7 @@ export(getSampleColData) export(getSampleNames) export(getSeqnames) export(getTSS) +export(getTestArrow) export(getTestFragments) export(getTestProject) export(getTrajectory) @@ -161,6 +164,7 @@ export(theme_ArchR) export(trajectoryHeatmap) export(validBSgenome) import(data.table) +importClassesFrom(GenomicRanges,GRanges) importFrom(GenomicRanges,GRanges) importFrom(Rcpp,sourceCpp) useDynLib(ArchR) diff --git a/R/AllClasses.R b/R/AllClasses.R index 27df094c..38c7436b 100644 --- a/R/AllClasses.R +++ b/R/AllClasses.R @@ -1,5 +1,6 @@ #' @useDynLib ArchR #' @importFrom Rcpp sourceCpp +#' @importClassesFrom GenomicRanges GRanges #' @importFrom GenomicRanges GRanges #' @import data.table NULL @@ -87,6 +88,15 @@ setMethod("show", "ArchRProject", #' genome information such as nucleotide information or chromosome sizes. #' @param showLogo A boolean value indicating whether to show the ascii ArchR logo after successful creation of an `ArchRProject`. #' @param threads The number of threads to use for parallel execution. +#' +#' @examples +#' +#' # Get Test Arrow +#' arrow <- getTestArrow() +#' +#' # Create ArchR Project for Analysis +#' proj <- ArchRProject(arrow) +#' #' @export ArchRProject <- function( ArrowFiles = NULL, @@ -209,6 +219,15 @@ ArchRProject <- function( #' This function will recover an ArchRProject if it has broken sampleColData or cellColData due to different versions of bioconductor s4vectors. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test Project +#' proj <- getTestProject() +#' +#' # Try to Recover ArchR Project +#' proj <- recoverArchRProject(proj) +#' #' @export recoverArchRProject <- function(ArchRProj){ @@ -360,6 +379,24 @@ recoverArchRProject <- function(ArchRProj){ #' background peaks) should be ignored when re-normalizing file paths. If set to `FALSE` loading of the `ArchRProject` #' will fail unless all components can be found. #' @param showLogo A boolean value indicating whether to show the ascii ArchR logo after successful creation of an `ArchRProject`. +#' +#' @examples +#' +#' # Get Small PBMC Project Location +#' zipProj <- file.path(system.file("testdata", package="ArchR"), "PBSmall.zip") +#' +#' # Copy to current directory +#' file.copy(zipProj, basename(zipProj), overwrite = TRUE) +#' +#' # Unzip +#' unzip(basename(zipProj), overwrite = TRUE) +#' +#' # Remove +#' file.remove(basename(zipProj)) +#' +#' # Load +#' loadArchRProject("PBSmall") +#' #' @export loadArchRProject <- function( path = "./", @@ -487,6 +524,14 @@ loadArchRProject <- function( #' @param dropCells A boolean indicating whether to drop cells that are not in `ArchRProject` from corresponding Arrow Files. #' @param logFile The path to a file to be used for logging ArchR output. #' @param threads The number of threads to use for parallel execution. +#' @examples +#' +#' # Get Small Test Project +#' proj <- getTestProject() +#' +#' # Save +#' saveArchRProject(proj) +#' #' @export saveArchRProject <- function( ArchRProj = NULL, @@ -622,6 +667,15 @@ saveArchRProject <- function( #' @param logFile The path to a file to be used for logging ArchR output. #' @param threads The number of threads to use for parallel execution. #' @param force If output directory exists overwrite. +#' +#' @examples +#' +#' # Get Small Test Project +#' proj <- getTestProject() +#' +#' #Subset +#' proj <- subsetArchRProject(proj, cells = getCellNames(proj)[1:50]) +#' #' @export subsetArchRProject <- function( ArchRProj = NULL, @@ -789,7 +843,6 @@ subsetArchRProject <- function( } - setMethod( f = "colnames", signature = c("x" = "ArchRProject"), diff --git a/R/AnnotationGenome.R b/R/AnnotationGenome.R index e76026de..6956ec8f 100644 --- a/R/AnnotationGenome.R +++ b/R/AnnotationGenome.R @@ -10,6 +10,21 @@ #' @param filterChr A character vector indicating the seqlevels that should be removed if manual removal is desired for certain seqlevels. #' If no manual removal is desired, `filterChr` should be set to `NULL`. If `filter` is set to `TRUE` but `filterChr` is set to `NULL`, #' non-standard chromosomes will still be removed as defined in `filterChrGR()`. +#' +#' @examples +#' +#' if (!require("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)) BiocManager::install("BSgenome.Hsapiens.UCSC.hg19") +#' library(BSgenome.Hsapiens.UCSC.hg19) +#' +#' # Get Genome +#' genome <- BSgenome.Hsapiens.UCSC.hg19 +#' +#' # Create Genome Annotation +#' genomeAnno <- createGenomeAnnotation(genome) +#' +#' # Also can create from a string if BSgenome exists +#' genomeAnno <- createGenomeAnnotation("hg19") +#' #' @export createGenomeAnnotation <- function( genome = NULL, @@ -78,6 +93,27 @@ createGenomeAnnotation <- function( #' @param exons A `GRanges` object containing gene exon coordinates. Must have a symbols column matching the symbols column of `genes`. #' @param TSS A `GRanges` object containing standed transcription start site coordinates for computing TSS enrichment scores downstream. #' @param annoStyle annotation style to map between gene names and various gene identifiers e.g. "ENTREZID", "ENSEMBL". +#' @param singleStrand A boolean for GenomicFeatures::genes(`single.strand.genes.only`) parameter +#' +#' @examples +#' +#' if (!require("TxDb.Hsapiens.UCSC.hg19.knownGene", quietly = TRUE)) BiocManager::install("TxDb.Hsapiens.UCSC.hg19.knownGene") +#' if (!require("org.Hs.eg.db", quietly = TRUE)) BiocManager::install("org.Hs.eg.db") +#' library(TxDb.Hsapiens.UCSC.hg19.knownGene) +#' library(org.Hs.eg.db) +#' +#' # Get Txdb +#' TxDb <- TxDb.Hsapiens.UCSC.hg19.knownGene +#' +#' # Get OrgDb +#' OrgDb <- org.Hs.eg.db +#' +#' # Create Genome Annotation +#' geneAnno <- createGeneAnnotation(TxDb=TxDb, OrgDb=OrgDb) +#' +#' # Also can create from a string if BSgenome exists +#' geneAnno <- createGeneAnnotation("hg19") +#' #' @export createGeneAnnotation <- function( genome = NULL, @@ -86,7 +122,8 @@ createGeneAnnotation <- function( genes = NULL, exons = NULL, TSS = NULL, - annoStyle = NULL + annoStyle = NULL, + singleStrand = FALSE ){ .validInput(input = genome, name = "genome", valid = c("character", "null")) @@ -118,7 +155,11 @@ createGeneAnnotation <- function( ########################### message("Getting Genes..") - genes <- GenomicFeatures::genes(TxDb) + genes <- tryCatch({ #Legacy Catch In Case + GenomicFeatures::genes(TxDb, single.strand.genes.only = singleStrand) + }, error = function(e){ + GenomicFeatures::genes(TxDb) + }) if(is.null(annoStyle)){ isEntrez <- mcols(genes)$symbol <- tryCatch({ diff --git a/R/AnnotationPeaks.R b/R/AnnotationPeaks.R index f298dc9e..59aeb395 100644 --- a/R/AnnotationPeaks.R +++ b/R/AnnotationPeaks.R @@ -8,6 +8,15 @@ #' #' @param ArchRProj An `ArchRProject` object. #' @param name The name of the `peakAnnotation` object (i.e. Motifs) to retrieve from the designated `ArchRProject`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Peak Annotations +#' peakAnno <- getPeakAnnotation(proj) +#' #' @export getPeakAnnotation <- function(ArchRProj = NULL, name = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProj")) @@ -29,6 +38,15 @@ getPeakAnnotation <- function(ArchRProj = NULL, name = NULL){ #' @param ArchRProj An `ArchRProject` object. #' @param name The name of the `peakAnnotation` object (i.e. Motifs) to retrieve from the designated `ArchRProject`. #' @param annoName The name of a specific annotation to subset within the `peakAnnotation`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Annotation Positions +#' positions <- getPositions(proj) +#' #' @export getPositions <- function(ArchRProj = NULL, name = NULL, annoName = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProj")) @@ -65,6 +83,15 @@ getPositions <- function(ArchRProj = NULL, name = NULL, annoName = NULL){ #' @param ArchRProj An `ArchRProject` object. #' @param name The name of the `peakAnnotation` object (i.e. Motifs) to retrieve from the designated `ArchRProject`. #' @param annoName The name of a specific annotation to subset within the `peakAnnotation`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Annotation Matches +#' matches <- getMatches(proj) +#' #' @export getMatches <- function(ArchRProj = NULL, name = NULL, annoName = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProj")) @@ -104,6 +131,18 @@ getMatches <- function(ArchRProj = NULL, name = NULL, annoName = NULL){ #' @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`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Motif Positions Can Be Any Interval GRanges List +#' positions <- getPositions(proj) +#' +#' # Add Peak Annotations +#' proj <- addPeakAnnotations(proj, regions = positions) +#' #' @export addPeakAnnotations <- function( ArchRProj = NULL, @@ -291,6 +330,15 @@ addPeakAnnotations <- function( #' it already exists in the given `ArchRProject`. #' @param logFile The path to a file to be used for logging ArchR output. #' @param ... Additional parameters to be passed to `TFBSTools::getMatrixSet` for getting a JASPAR PWM object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Motif Annotations +#' proj <- addMotifAnnotations(proj, motifSet = "cisbptest", annoName = "test") +#' #' @export addMotifAnnotations <- function( ArchRProj = NULL, @@ -511,7 +559,11 @@ addMotifAnnotations <- function( # Get BSgenome Information! ############################################################# genome <- ArchRProj@genomeAnnotation$genome - BSgenome <- eval(parse(text = genome)) + BSgenome <- tryCatch({ + eval(parse(text = paste0(genome))) + }, error = function(e){ + eval(parse(text = paste0(genome,"::",genome))) + }) BSgenome <- validBSgenome(BSgenome) ############################################################# @@ -690,6 +742,15 @@ addMotifAnnotations <- function( #' @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`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Motif Annotations +#' proj <- addArchRAnnotations(proj, name = "test") +#' #' @export addArchRAnnotations <- function( ArchRProj = NULL, @@ -990,6 +1051,27 @@ addArchRAnnotations <- function( #' `cutoff` can contain any of the `assayNames` from `seMarker`. #' @param background A string that indicates whether to use a background set of matched peaks to compare against ("bgdPeaks") or all peaks ("all"). #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Markers +#' seMarker <- getMarkerFeatures( +#' ArchRProj = proj, +#' useMatrix = "PeakMatrix", +#' testMethod = "binomial", +#' binarize = TRUE +#' ) +#' +#' # Get Peak Annotation Enrichment +#' annoEnrich <- peakAnnoEnrichment( +#' seMarker = seMarker, +#' ArchRProj = proj, +#' cutOff = "FDR <= 0.1 & Log2FC >= 0" +#' ) +#' #' @export peakAnnoEnrichment <- function( seMarker = NULL, @@ -1165,6 +1247,36 @@ enrichHeatmap <- function(...){ #' @param transpose A boolean determining whether to transpose the heatmap in the plot. #' @param returnMatrix A boolean determining whether to return the matrix corresponding to the heatmap rather than generate a plot. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Markers +#' seMarker <- getMarkerFeatures( +#' ArchRProj = proj, +#' useMatrix = "PeakMatrix", +#' testMethod = "binomial", +#' binarize = TRUE +#' ) +#' +#' # Get Peak Annotation Enrichment +#' annoEnrich <- peakAnnoEnrichment( +#' seMarker = seMarker, +#' ArchRProj = proj, +#' cutOff = "FDR <= 0.1 & Log2FC >= 0" +#' ) +#' +#' # Multiply by 50 since this is a super small test sample +#' assay(annoEnrich) <- assay(annoEnrich) * 50 +#' +#' #Plot +#' p <- plotEnrichHeatmap(annoEnrich) +#' +#' #PDF +#' plotPDF(p, name = "PeakAnnoEnrich", ArchRProj = proj) +#' #' @export plotEnrichHeatmap <- function( seEnrich = NULL, diff --git a/R/ArchRBrowser.R b/R/ArchRBrowser.R index 98a1e251..bcfaac72 100644 --- a/R/ArchRBrowser.R +++ b/R/ArchRBrowser.R @@ -27,6 +27,14 @@ #' @param threads The number of threads to use for parallel execution. #' @param verbose A boolean value that determines whether standard output should be printed. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +# #Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Launch Browser with `ArchRBrowser(proj)` +#' #' @export ArchRBrowser <- function( ArchRProj = NULL, @@ -67,7 +75,9 @@ ArchRBrowser <- function( #Determine Grouping Methods ccd <- getCellColData(ArchRProj) discreteCols <- lapply(seq_len(ncol(ccd)), function(x){ - .isDiscrete(ccd[, x]) + check1 <- .isDiscrete(ccd[, x]) + check2 <- max(table(ccd[, x])) > minCells + check1 & check2 }) %>% unlist %>% {colnames(ccd)[.]} if("Clusters" %in% discreteCols){ selectCols <- "Clusters" @@ -80,22 +90,24 @@ ArchRBrowser <- function( .validInput(input = gr, name = "gr", valid = c("GRanges")) .validInput(input = upstream, name = "upstream", valid = c("integer")) .validInput(input = downstream, name = "downstream", valid = c("integer")) - #Get Info From gr - st <- start(gr) - ed <- end(gr) - #https://bioinformatics.stackexchange.com/questions/4390/expand-granges-object-different-amounts-upstream-vs-downstream - isMinus <- BiocGenerics::which(strand(gr) == "-") - isOther <- BiocGenerics::which(strand(gr) != "-") - #Forward - st[isOther] <- st[isOther] - upstream - ed[isOther] <- ed[isOther] + downstream - #Reverse - ed[isMinus] <- ed[isMinus] + upstream - st[isMinus] <- st[isMinus] - downstream - #If Any extensions now need to be flipped. - end(gr) <- pmax(st, ed) - start(gr) <- pmin(st, ed) - return(gr) + suppressWarnings({ + #Get Info From gr + st <- start(gr) + ed <- end(gr) + #https://bioinformatics.stackexchange.com/questions/4390/expand-granges-object-different-amounts-upstream-vs-downstream + isMinus <- BiocGenerics::which(strand(gr) == "-") + isOther <- BiocGenerics::which(strand(gr) != "-") + #Forward + st[isOther] <- st[isOther] - upstream + ed[isOther] <- ed[isOther] + downstream + #Reverse + ed[isMinus] <- ed[isMinus] + upstream + st[isMinus] <- st[isMinus] - downstream + #If Any extensions now need to be flipped. + end(gr) <- pmax(st, ed) + start(gr) <- pmin(st, ed) + gr + }) } @@ -311,7 +323,11 @@ ArchRBrowser <- function( groupBy <- isolate(input$grouping) groupDF <- tryCatch({ - isolate(hot_to_r(input$Metadata)) + o <- isolate(hot_to_r(input$Metadata)) + if(is.null(o)){ + stop() #switch methods! + } + o },error=function(x){ groups <- gtools::mixedsort(unique(ccd[,isolate(input$grouping)])) mdata <- data.frame( @@ -342,7 +358,6 @@ ArchRBrowser <- function( useGroups <- groupDF[groupDF[,"include"],"group"] - if(!all(.isColor(groupDF[groupDF[,"include"], "color"]))){ p <- ggplot() + xlim(c(-5,5)) + ylim(c(-5,5)) + @@ -677,6 +692,18 @@ ArchRBrowserTrack <- function(...){ #' @param title The title to add at the top of the plot next to the plot's genomic coordinates. #' @param verbose A boolean value that determines whether standard output should be printed. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' #Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Plot Track +#' p <- plotBrowserTrack(proj, geneSymbol = c("CD3D", "MS4A1"), groupBy = "CellType") +#' +#' #Plot PDF +#' plotPDF(p, name = "Track-CD3D-MS4A1", ArchRProj = proj) +#' #' @export plotBrowserTrack <- function( ArchRProj = NULL, @@ -1042,7 +1069,7 @@ plotBrowserTrack <- function( margin = margin(0,0.35,0,0.35, "cm")), strip.text.y = element_text(angle = 0), strip.background = element_rect(color="black")) + - guides(fill = FALSE, colour = FALSE) + ggtitle(title) + .gg_guides(fill = FALSE, colour = FALSE) + ggtitle(title) p @@ -1344,7 +1371,7 @@ plotBrowserTrack <- function( theme(axis.title.x=element_blank(), axis.text.x=element_blank(),axis.ticks.x=element_blank()) + theme(axis.title.y=element_blank(), axis.text.y=element_blank(),axis.ticks.y=element_blank()) + theme(legend.text = element_text(size = baseSize), strip.text.y = element_text(size = facetbaseSize, angle = 0)) + - guides(fill = guide_legend(override.aes = list(colour = NA, shape = "c", size=3)), color = FALSE) + + .gg_guides(fill = guide_legend(override.aes = list(colour = NA, shape = "c", size=3)), color = FALSE) + theme(legend.position="bottom") + theme(legend.title=element_text(size=5), legend.text=element_text(size=7), legend.key.size = unit(0.75,"line"), legend.background = element_rect(color =NA), strip.background = element_blank()) @@ -1460,7 +1487,8 @@ plotBrowserTrack <- function( scale_color_manual(values = pal) + theme(legend.text = element_text(size = baseSize)) + theme_ArchR(baseSize = baseSize, baseLineSize = borderWidth, baseRectSize = borderWidth) + - guides(color = FALSE, fill = FALSE) + theme(strip.text.y = element_text(size = facetbaseSize, angle = 0), strip.background = element_blank()) + .gg_guides(color = FALSE, fill = FALSE) + + theme(strip.text.y = element_text(size = facetbaseSize, angle = 0), strip.background = element_blank()) }else{ @@ -1579,7 +1607,7 @@ plotBrowserTrack <- function( theme_ArchR(baseSize = baseSize, baseLineSize = borderWidth, baseRectSize = borderWidth, legendPosition = "right") + theme(strip.text.y = element_text(size = facetbaseSize, angle = 0), strip.background = element_blank(), legend.box.background = element_rect(color = NA)) + - guides(color= guide_colorbar(barwidth = 0.75, barheight = 3)) + .gg_guides(color= guide_colorbar(barwidth = 0.75, barheight = 3)) }else{ @@ -1780,7 +1808,7 @@ plotBrowserTrack <- function( margin = margin(0,0.35,0,0.35, "cm")), strip.text.y = element_text(angle = 0), strip.background = element_rect(color="black")) + - guides(fill = FALSE, colour = FALSE) + ggtitle(title) + .gg_guides(fill = FALSE, colour = FALSE) + ggtitle(title) p @@ -1869,7 +1897,7 @@ plotBrowserTrack <- function( pal = pal ) + facet_wrap(x~., ncol=1,scales="free_y",strip.position="right") + - guides(fill = FALSE, colour = FALSE) + + .gg_guides(fill = FALSE, colour = FALSE) + theme_ArchR(baseSize = baseSize, baseRectSize = borderWidth, baseLineSize = tickWidth, diff --git a/R/ArrowRead.R b/R/ArrowRead.R index 8fbb09aa..ea5aa1d3 100644 --- a/R/ArrowRead.R +++ b/R/ArrowRead.R @@ -13,6 +13,15 @@ #' from the provided ArrowFile using `getCellNames()`. #' @param verbose A boolean value indicating whether to use verbose output during execution of this function. Can be set to `FALSE` for a cleaner output. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' # Get Fragments +#' frags <- getFragmentsFromProject(proj) +#' #' @export getFragmentsFromProject <- function( ArchRProj = NULL, @@ -69,6 +78,15 @@ getFragmentsFromProject <- function( #' from the provided ArrowFile using `getCellNames()`. #' @param verbose A boolean value indicating whether to use verbose output during execution of this function. Can be set to `FALSE` for a cleaner output. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' #Get Test Arrow +#' arrow <- getTestArrow() +#' +#' # Get Fragments +#' frags <- getFragmentsFromArrow(arrow) +#' #' @export getFragmentsFromArrow <- function( ArrowFile = NULL, @@ -253,6 +271,15 @@ getFragmentsFromArrow <- function( #' @param binarize A boolean value indicating whether the matrix should be binarized before return. #' This is often desired when working with insertion counts. Note that if the matrix has already been binarized previously, this should be set to `TRUE`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' # Get Fragments +#' se <- getMatrixFromProject(proj) +#' #' @export getMatrixFromProject <- function( ArchRProj = NULL, @@ -387,6 +414,15 @@ getMatrixFromProject <- function( #' @param verbose A boolean value indicating whether to use verbose output during execution of this function. Can be set to FALSE for a cleaner output. #' @param binarize A boolean value indicating whether the matrix should be binarized before return. This is often desired when working with insertion counts. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' #Get Test Arrow +#' arrow <- getTestArrow() +#' +#' # Get Fragments +#' se <- getMatrixFromArrow(arrow) +#' #' @export getMatrixFromArrow <- function( ArrowFile = NULL, diff --git a/R/ArrowUtils.R b/R/ArrowUtils.R index 0e8a0d63..f6aa660c 100644 --- a/R/ArrowUtils.R +++ b/R/ArrowUtils.R @@ -231,7 +231,7 @@ .dropGroupsFromArrow <- function( ArrowFile = NULL, dropGroups = NULL, - level = 0, + level = getArchRH5Level(), verbose = FALSE, logFile = NULL ){ @@ -328,7 +328,7 @@ inArrows = NULL, outArrows = NULL, cellsKeep = NULL, - level = 0, + level = getArchRH5Level(), verbose = FALSE, logFile = NULL, threads = 1 @@ -353,7 +353,7 @@ inArrow = NULL, outArrow = NULL, cellsKeep = NULL, - level = 0, + level = getArchRH5Level(), verbose = FALSE, logFile = NULL ){ diff --git a/R/ArrowWrite.R b/R/ArrowWrite.R index 41a216b8..7dd0fd7c 100644 --- a/R/ArrowWrite.R +++ b/R/ArrowWrite.R @@ -139,13 +139,13 @@ #Create Data Set o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group,"/i"), storage.mode = "integer", - dims = c(lengthI, 1), level = 0)) + dims = c(lengthI, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group,"/jLengths"), storage.mode = "integer", - dims = c(lengthRle, 1), level = 0)) + dims = c(lengthRle, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group,"/jValues"), storage.mode = "integer", - dims = c(lengthRle, 1), level = 0)) + dims = c(lengthRle, 1), level = getArchRH5Level())) #Write Data Set o <- .suppressAll(h5write(obj = mat@i + 1, file = ArrowFile, name = paste0(Group,"/i"))) @@ -156,7 +156,7 @@ if(!binarize){ o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group, "/x"), storage.mode = "double", - dims = c(lengthI, 1), level = 0)) + dims = c(lengthI, 1), level = getArchRH5Level())) o <- .suppressAll(h5write(obj = mat@x, file = ArrowFile, name = paste0(Group, "/x"))) @@ -169,7 +169,7 @@ if(addColSums){ cS <- Matrix::colSums(mat) o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group, "/colSums"), storage.mode = "double", - dims = c(ncol(mat), 1), level = 0)) + dims = c(ncol(mat), 1), level = getArchRH5Level())) o <- .suppressAll(h5write(obj = cS, file = ArrowFile, name = paste0(Group, "/colSums"))) } @@ -177,7 +177,7 @@ if(addRowSums){ rS <- Matrix::rowSums(mat) o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group, "/rowSums"), storage.mode = "double", - dims = c(nrow(mat), 1), level = 0)) + dims = c(nrow(mat), 1), level = getArchRH5Level())) o <- .suppressAll(h5write(obj = rS, file = ArrowFile, name = paste0(Group, "/rowSums"))) } @@ -185,7 +185,7 @@ if(addRowMeans){ rM <- Matrix::rowMeans(mat) o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group, "/rowMeans"), storage.mode = "double", - dims = c(nrow(mat), 1), level = 0)) + dims = c(nrow(mat), 1), level = getArchRH5Level())) o <- .suppressAll(h5write(obj = rM, file = ArrowFile, name = paste0(Group, "/rowMeans"))) } @@ -196,7 +196,7 @@ } rV <- computeSparseRowVariances(mat@i + 1, mat@x, rM, n = ncol(mat)) o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group, "/rowVars"), storage.mode = "double", - dims = c(nrow(mat), 1), level = 0)) + dims = c(nrow(mat), 1), level = getArchRH5Level())) o <- .suppressAll(h5write(obj = rV, file = ArrowFile, name = paste0(Group, "/rowVars"))) } @@ -218,12 +218,12 @@ #Have to write rowMeansLog2 as well o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group, "/rowMeansLog2"), storage.mode = "double", - dims = c(nrow(mat), 1), level = 0)) + dims = c(nrow(mat), 1), level = getArchRH5Level())) o <- .suppressAll(h5write(obj = rM, file = ArrowFile, name = paste0(Group, "/rowMeansLog2"))) #Write rowVarsLog2 o <- .suppressAll(h5createDataset(ArrowFile, paste0(Group, "/rowVarsLog2"), storage.mode = "double", - dims = c(nrow(mat), 1), level = 0)) + dims = c(nrow(mat), 1), level = getArchRH5Level())) o <- .suppressAll(h5write(obj = rV, file = ArrowFile, name = paste0(Group, "/rowVarsLog2"))) } diff --git a/R/BulkProjection.R b/R/BulkProjection.R index 882dd9a4..a74276cd 100644 --- a/R/BulkProjection.R +++ b/R/BulkProjection.R @@ -12,7 +12,6 @@ #' @param force A boolean value indicating whether to force the projection of bulk ATAC data even if fewer than 25% of the features are present in the bulk ATAC data set. #' @param logFile The path to a file to be used for logging ArchR output. #' @export -#' projectBulkATAC <- function( ArchRProj = NULL, seATAC = NULL, diff --git a/R/Clustering.R b/R/Clustering.R index d0bb4160..408942a8 100644 --- a/R/Clustering.R +++ b/R/Clustering.R @@ -51,6 +51,15 @@ #' exists as a column name in `cellColData`. #' @param logFile The path to a file to be used for logging ArchR output. #' @param ... Additional arguments to be provided to Seurat::FindClusters or scran::buildSNNGraph (for example, knn = 50, jaccard = TRUE) +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Peak Annotations +#' proj <- addClusters(proj, force = TRUE) +#' #' @export #' addClusters <- function( diff --git a/R/ColorPalettes.R b/R/ColorPalettes.R index 81694ee3..ddad7017 100644 --- a/R/ColorPalettes.R +++ b/R/ColorPalettes.R @@ -101,6 +101,15 @@ ArchRPalettes <- list( #' given a unique color from the designated palette set. #' @param set The name of a color palette provided in the `ArchRPalettes` list object. #' @param reverse A boolean variable that indicates whether to return the palette colors in reverse order. +#' +#' @examples +#' +#' # Vector +#' v <- c("A", "B") +#' +#' # Color Palette +#' pal <- paletteDiscrete(values = v) +#' #' @export paletteDiscrete <- function( values = NULL, @@ -140,6 +149,12 @@ paletteDiscrete <- function( #' @param set The name of a color palette provided in the `ArchRPalettes` list object. #' @param n The number of unique colors to generate as part of this continuous color palette. #' @param reverse A boolean variable that indicates whether to return the palette colors in reverse order. +#' +#' @examples +#' +#' # Color Palette +#' pal <- paletteContinuous() +#' #' @export paletteContinuous <- function( set = "solarExtra", diff --git a/R/CreateArrow.R b/R/CreateArrow.R index 4d9600a5..f01b7fa3 100644 --- a/R/CreateArrow.R +++ b/R/CreateArrow.R @@ -63,6 +63,22 @@ #' @param verbose A boolean value that determines whether standard output should be printed. #' @param cleamTmp A boolean value that determines whether to clean temp folder of all intermediate ".arrow" files. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test Fragments +#' fragments <- getTestFragments() +#' +#' # Create Arrow Files +#' arrowFiles <- createArrowFiles( +#' inputFiles = fragments, +#' sampleNames = "PBSmall", +#' minFrags = 100, +#' nChunk = 1, +#' TileMatParams=list(tileSize=10000), +#' force = TRUE +#' ) +#' #' @export #' createArrowFiles <- function( @@ -1300,10 +1316,10 @@ createArrowFiles <- function( chrRGValues <- paste0("Fragments/",chrTmp,"/RGValues") lengthRG <- length(RG@lengths) o <- h5createGroup(tmpFile, paste0("Fragments/",chrTmp)) - o <- .suppressAll(h5createDataset(tmpFile, chrPos, storage.mode = "integer", dims = c(nrow(dt), 2), level = 0)) - o <- .suppressAll(h5createDataset(tmpFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) + o <- .suppressAll(h5createDataset(tmpFile, chrPos, storage.mode = "integer", dims = c(nrow(dt), 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(tmpFile, chrRGValues, storage.mode = "character", - dims = c(lengthRG, 1), level = 0, size = max(nchar(RG@values)) + 1)) + dims = c(lengthRG, 1), level = getArchRH5Level(), size = max(nchar(RG@values)) + 1)) 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) @@ -1335,10 +1351,10 @@ createArrowFiles <- function( chrRGValues <- paste0(chrTmp, "._.RGValues") lengthRG <- length(RG@lengths) - o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(nrow(dt), 2), level = 0)) - o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) + o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(nrow(dt), 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", - dims = c(lengthRG, 1), level = 0, size = max(nchar(RG@values)) + 1)) + dims = c(lengthRG, 1), level = getArchRH5Level(), size = max(nchar(RG@values)) + 1)) o <- h5write(obj = cbind(dt$V2,dt$V3 - dt$V2 + 1), file = tmpChrFile, name = chrPos) o <- h5write(obj = RG@lengths, file = tmpChrFile, name = chrRGLengths) @@ -1676,10 +1692,10 @@ createArrowFiles <- function( chrRGValues <- paste0("Fragments/",chrTmp,"/RGValues") lengthRG <- length(RG@lengths) o <- h5createGroup(tmpFile, paste0("Fragments/",chrTmp)) - o <- .suppressAll(h5createDataset(tmpFile, chrPos, storage.mode = "integer", dims = c(nrow(dt), 2), level = 0)) - o <- .suppressAll(h5createDataset(tmpFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) + o <- .suppressAll(h5createDataset(tmpFile, chrPos, storage.mode = "integer", dims = c(nrow(dt), 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(tmpFile, chrRGValues, storage.mode = "character", - dims = c(lengthRG, 1), level = 0, size = max(nchar(RG@values)) + 1)) + dims = c(lengthRG, 1), level = getArchRH5Level(), size = max(nchar(RG@values)) + 1)) o <- h5write(obj = cbind(dt$start, dt$end - dt$start + 1), file = tmpFile, name = chrPos) o <- h5write(obj = RG@lengths, file = tmpFile, name = chrRGLengths) @@ -1712,10 +1728,10 @@ createArrowFiles <- function( chrRGValues <- paste0(chrTmp, "._.RGValues") lengthRG <- length(RG@lengths) - o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(nrow(dt), 2), level = 0)) - o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = 0)) + o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(nrow(dt), 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", - dims = c(lengthRG, 1), level = 0, size = max(nchar(RG@values)) + 1)) + dims = c(lengthRG, 1), level = getArchRH5Level(), size = max(nchar(RG@values)) + 1)) o <- h5write(obj = cbind(dt$start, dt$end - dt$start + 1), file = tmpChrFile, name = chrPos) o <- h5write(obj = RG@lengths, file = tmpChrFile, name = chrRGLengths) @@ -1919,7 +1935,7 @@ createArrowFiles <- function( #Determine Ranges and RG Pre-Allocation chr <- uniqueChr[x] - ix <- BiocGenerics::which(chunkChr == chr) + ix <- BiocGenerics::which(paste0(chunkChr) == paste0(chr)) if(threads == 1){ @@ -1932,9 +1948,9 @@ createArrowFiles <- function( 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(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 = 4)) + o <- .suppressAll(h5createDataset(outArrow, chrPos, storage.mode = "integer", dims = c(0, 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGLengths, storage.mode = "integer", dims = c(0, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGValues, storage.mode = "character", dims = c(0, 1), level = getArchRH5Level(), size = 4)) return(NULL) @@ -1950,9 +1966,11 @@ createArrowFiles <- function( mcols(fragments)$RG@values <- stringr::str_split(mcols(fragments)$RG@values, pattern = "#", simplify=TRUE)[,2] #Order RG RLE based on bcPass - fragments <- fragments[BiocGenerics::which(mcols(fragments)$RG %bcin% bcPass)] - fragments <- fragments[order(S4Vectors::match(mcols(fragments)$RG, bcPass))] - + fragments <- fragments[BiocGenerics::which(paste0(mcols(fragments)$RG) %bcin% bcPass)] + if(length(fragments) > 0){ + fragments <- fragments[order(S4Vectors::match(paste0(mcols(fragments)$RG), bcPass))] + } + #Check if Fragments are greater than minFragSize and smaller than maxFragSize fragments <- fragments[width(fragments) >= minFragSize] fragments <- fragments[width(fragments) <= maxFragSize] @@ -1975,17 +1993,17 @@ createArrowFiles <- function( .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, + o <- .suppressAll(h5createDataset(outArrow, chrPos, storage.mode = "integer", dims = c(0, 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGLengths, storage.mode = "integer", dims = c(0, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGValues, storage.mode = "character", dims = c(0, 1), level = getArchRH5Level(), 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, + o <- .suppressAll(h5createDataset(outArrow, chrPos, storage.mode = "integer", dims = c(length(fragments), 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = getArchRH5Level(), size = max(nchar(mcols(fragments)$RG@values)) + 1)) o <- h5write(obj = cbind(start(fragments),width(fragments)), file = outArrow, name = chrPos) @@ -2018,9 +2036,9 @@ createArrowFiles <- function( chrRGLengths <- paste0(chr, "._.RGLengths") chrRGValues <- paste0(chr, "._.RGValues") - 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 = 4)) + o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(0, 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(0, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", dims = c(0, 1), level = getArchRH5Level(), size = 4)) return(tmpChrFile) @@ -2035,9 +2053,17 @@ createArrowFiles <- function( }) %>% Reduce("c", .) mcols(fragments)$RG@values <- stringr::str_split(mcols(fragments)$RG@values, pattern = "#", simplify=TRUE)[,2] + if(x == 1){ + .logThis(fragments, name = paste0(prefix, " .tmpToArrow Fragments0-Chr-(",x," of ",length(uniqueChr),")-", uniqueChr[x]), logFile = logFile) + .logThis(data.frame(bc = as.vector(mcols(fragments)$RG@values)), name = paste0(prefix, " .tmpToArrow Barcodes0-Chr-(",x," of ",length(uniqueChr),")-", uniqueChr[x]), logFile = logFile) + .logThis(data.frame(bc = as.vector(bcPass)), name = paste0(prefix, " .tmpToArrow bcPass0-Chr-(",x," of ",length(uniqueChr),")-", uniqueChr[x]), logFile = logFile) + } + #Order RG RLE based on bcPass - fragments <- fragments[BiocGenerics::which(mcols(fragments)$RG %bcin% bcPass)] - fragments <- fragments[order(S4Vectors::match(mcols(fragments)$RG, bcPass))] + fragments <- fragments[BiocGenerics::which(paste0(mcols(fragments)$RG) %bcin% bcPass)] + if(length(fragments) > 0){ + fragments <- fragments[order(S4Vectors::match(paste0(mcols(fragments)$RG), bcPass))] + } #Check if Fragments are greater than minFragSize and smaller than maxFragSize fragments <- fragments[width(fragments) >= minFragSize] @@ -2058,17 +2084,17 @@ createArrowFiles <- function( 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, + o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(0, 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(0, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", dims = c(0, 1), level = getArchRH5Level(), 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, + o <- .suppressAll(h5createDataset(tmpChrFile, chrPos, storage.mode = "integer", dims = c(length(fragments), 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(tmpChrFile, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = getArchRH5Level(), size = max(nchar(mcols(fragments)$RG@values)) + 1)) o <- h5write(obj = cbind(start(fragments),width(fragments)), file = tmpChrFile, name = chrPos) @@ -2211,9 +2237,9 @@ createArrowFiles <- function( 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(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 = 4)) + o <- .suppressAll(h5createDataset(outArrow, chrPos, storage.mode = "integer", dims = c(0, 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGLengths, storage.mode = "integer", dims = c(0, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGValues, storage.mode = "character", dims = c(0, 1), level = getArchRH5Level(), size = 4)) }else{ @@ -2230,9 +2256,9 @@ createArrowFiles <- function( 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, + o <- .suppressAll(h5createDataset(outArrow, chrPos, storage.mode = "integer", dims = c(length(fragments), 2), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGLengths, storage.mode = "integer", dims = c(lengthRG, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(outArrow, chrRGValues, storage.mode = "character", dims = c(lengthRG, 1), level = getArchRH5Level(), 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) diff --git a/R/DoubletsScores.R b/R/DoubletsScores.R index c5338195..1e9302c0 100644 --- a/R/DoubletsScores.R +++ b/R/DoubletsScores.R @@ -31,6 +31,15 @@ #' @param parallelParam A list of parameters to be passed for biocparallel/batchtools parallel computing. #' @param verbose A boolean value that determines whether standard output is printed. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Doublet Scores for Small Project +#' proj <- addDoubletScores(proj, dimsToUse = 1:5, LSIParams = list(dimsToUse = 1:5, varFeatures=1000, iterations = 2)) +#' #' @export addDoubletScores <- function( input = NULL, @@ -378,50 +387,13 @@ addDoubletScores <- function( scale_colour_gradientn(colors = pal) + xlab("UMAP Dimension 1") + ylab("UMAP Dimension 2") + labs(color = "Simulated Doublet Density") + - guides(fill = FALSE) + theme_ArchR(baseSize = 10) + + .gg_guides(fill = FALSE) + theme_ArchR(baseSize = 10) + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank()) + coord_equal(ratio = diff(xlim)/diff(ylim), xlim = xlim, ylim = ylim, expand = FALSE) + ggtitle("Simulated and LSI-Projected Density Overlayed") + theme(legend.direction = "horizontal", legend.box.background = element_rect(color = NA)) - # if(!requireNamespace("ggrastr", quietly = TRUE)){ - - # message("ggrastr is not available for rastr of points, continuing without rastr!") - # message("To install ggrastr try : devtools::install_github('VPetukhov/ggrastr')") - - # pdensity <- ggplot() + - # geom_point(data = df, aes(x=X1,y=X2),color="lightgrey", size = 0.5) + - # geom_point(data = dfDoub, aes(x=x,y=y,colour=color), size = 0.5) + - # scale_colour_gradientn(colors = pal) + - # xlab("UMAP Dimension 1") + ylab("UMAP Dimension 2") + - # guides(fill = FALSE) + theme_ArchR(baseSize = 10) + - # labs(color = "Simulated Doublet Density") + - # theme(axis.text.x = element_blank(), axis.ticks.x = element_blank(), - # axis.text.y = element_blank(), axis.ticks.y = element_blank()) + - # coord_equal(ratio = diff(xlim)/diff(ylim), xlim = xlim, ylim = ylim, expand = FALSE) + - # ggtitle("Simulated and LSI-Projected Doublet Density Overlayed") + theme(legend.direction = "horizontal", - # legend.box.background = element_rect(color = NA)) - - # }else{ - - # #.requirePackage("ggrastr", installInfo = "devtools::install_github('VPetukhov/ggrastr')") - - # pdensity <- ggplot() + - # .geom_point_rast2(data = df, aes(x=X1,y=X2),color="lightgrey", size = 0.5) + - # .geom_point_rast2(data = dfDoub, aes(x=x,y=y,colour=color), size = 0.5) + - # scale_colour_gradientn(colors = pal) + - # xlab("UMAP Dimension 1") + ylab("UMAP Dimension 2") + - # labs(color = "Simulated Doublet Density") + - # guides(fill = FALSE) + theme_ArchR(baseSize = 10) + - # theme(axis.text.x = element_blank(), axis.ticks.x = element_blank(), - # axis.text.y = element_blank(), axis.ticks.y = element_blank()) + - # coord_equal(ratio = diff(xlim)/diff(ylim), xlim = xlim, ylim = ylim, expand = FALSE) + - # ggtitle("Simulated and LSI-Projected Density Overlayed") + theme(legend.direction = "horizontal", - # legend.box.background = element_rect(color = NA)) - - # } - #Plot Doublet Score pscore <- ggPoint( x = df[,1], diff --git a/R/Embedding.R b/R/Embedding.R index c71026f4..5dd79ec8 100644 --- a/R/Embedding.R +++ b/R/Embedding.R @@ -33,6 +33,15 @@ #' `name` already exists. #' @param threads The number of threads to be used for parallel computing. Default set to 1 because if set to high can cause C stack usage errors. #' @param ... Additional parameters to pass to `uwot::umap()` +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add UMAP for Small Project +#' proj <- addUMAP(proj, force = TRUE) +#' #' @export addUMAP <- function( ArchRProj = NULL, @@ -346,6 +355,15 @@ addUMAP <- function( #' `name` already exists. #' @param threads The number of threads to be used for parallel computing. #' @param ... Additional parameters for computing the TSNE embedding to pass to `Rtsne::Rtsne()` (when `method = "RTSNE"`) or to `Seurat::RunTSNE()` (when method = "FFRTSNE"). +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add UMAP for Small Project +#' proj <- addTSNE(proj, force = TRUE) +#' #' @export addTSNE <- function( ArchRProj = NULL, diff --git a/R/FilterCells.R b/R/FilterCells.R index 54a89ac1..8be9ee97 100644 --- a/R/FilterCells.R +++ b/R/FilterCells.R @@ -8,6 +8,15 @@ #' #' @param ArchRProj An `ArchRProject` object. #' @param cellNames A character vector of `cellNames` that will be subsetted of the current `ArchRProject`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Peak Annotations +#' proj <- subsetCells(proj, getCellNames(proj)[1:50]) +#' #' @export subsetCells <- function( ArchRProj = NULL, @@ -41,6 +50,18 @@ subsetCells <- function( #' This `filterRatio` allows you to apply a consistent filter across multiple different samples that may have different #' percentages of doublets because they were run with different cell loading concentrations. #' The higher the `filterRatio`, the greater the number of cells potentially removed as doublets. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Doublet Scores for Small Project +#' proj <- addDoubletScores(proj, dimsToUse = 1:5, LSIParams = list(dimsToUse = 1:5, varFeatures=1000, iterations = 2)) +#' +#' # Filter Doublets (Since Low Cells filterRatio has to be high before removing 1 cell!) +#' proj <- filterDoublets(proj, filterRatio=10) +#' #' @export filterDoublets <- function(ArchRProj = NULL, cutEnrich = 1, cutScore = -Inf, filterRatio = 1){ diff --git a/R/Footprinting.R b/R/Footprinting.R index 5fd214da..fc6b419d 100644 --- a/R/Footprinting.R +++ b/R/Footprinting.R @@ -19,6 +19,18 @@ #' @param threads The number of threads to be used for parallel computing. #' @param verbose A boolean value that determines whether standard output includes verbose sections. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Motif Positions +#' positions <- getPositions(proj) +#' +#' # Get Footprints +#' seFoot <- getFootprints(ArchRProj = proj, positions = positions, groupBy = "Clusters", minCells = 10) +#' #' @export getFootprints <- function( ArchRProj = NULL, @@ -69,7 +81,11 @@ getFootprints <- function( genome <- getGenome(ArchRProj) .requirePackage("Biostrings", source = "bioc") - BSgenome <- eval(parse(text = genome)) + BSgenome <- tryCatch({ + eval(parse(text = paste0(genome))) + }, error = function(e){ + eval(parse(text = paste0(genome,"::",genome))) + }) BSgenome <- validBSgenome(BSgenome) .logDiffTime("Computing Kmer Bias Table", tstart, verbose = verbose, logFile = logFile) @@ -344,6 +360,21 @@ getFootprints <- function( #' @param force If many footprints are requested when plot = FALSE, please set force = TRUE. #' This prevents large amount of footprint plots stored as an object. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Motif Positions +#' positions <- getPositions(proj) +#' +#' # Get Footprints +#' seFoot <- getFootprints(ArchRProj = proj, positions = positions, groupBy = "Clusters", minCells = 10) +#' +#' # Plot Footprints +#' plotFootprints(seFoot, smoothWindow = 11) +#' #' @export plotFootprints <- function( seFoot = NULL, @@ -578,8 +609,8 @@ plotFootprints <- function( ylim = c(quantile(plotFootDF$mean, 0.0001), 1.15*quantile(smoothFoot, 0.999)), xlim = c(min(plotFootDF$x),max(plotFootDF$x)) ) + theme_ArchR(baseSize = baseSize) + ggtitle(name) + - guides(fill = FALSE) + - guides(color = FALSE) + ylab(paste0(title,"Normalized Insertions")) + .gg_guides(fill = FALSE, color = FALSE) + + ylab(paste0(title,"Normalized Insertions")) #removed ggrepel due to incompatibility with coord_cartesian - see https://github.com/GreenleafLab/ArchR/issues/493#issuecomment-870012873 #ggrepel::geom_label_repel(data = plotMax, aes(label = group), size = 3, xlim = c(75, NA)) @@ -616,7 +647,7 @@ plotFootprints <- function( ) { #https://stackoverflow.com/questions/52297978/decrease-overal-legend-size-elements-and-text gg + - guides(shape = guide_legend(override.aes = list(size = pointSize)), + .gg_guides(shape = guide_legend(override.aes = list(size = pointSize)), color = guide_legend(override.aes = list(size = pointSize))) + theme(legend.title = element_text(size = baseSize), legend.text = element_text(size = baseSize), diff --git a/R/GRangesUtils.R b/R/GRangesUtils.R index 23cd8990..282f6ab5 100644 --- a/R/GRangesUtils.R +++ b/R/GRangesUtils.R @@ -15,6 +15,15 @@ #' @param pruningMode The name of the pruning method to use (from`GenomeInfoDb::seqinfo()`) when seqlevels must be removed from a `GRanges` object. #' When some of the seqlevels to drop from the given `GRanges` object are in use (i.e. have ranges on them), the ranges on these sequences need #' to be removed before the seqlevels can be dropped. Four pruning modes are currently defined: "error", "coarse", "fine", and "tidy". +#' +#' @examples +#' +#' # Add ArchR Genome +#' addArchRGenome("hg19test2") +#' +#' # Filter Chr +#' filterChrGR(getChromSizes(), remove = "chr5") +#' #' @export filterChrGR <- function( gr = NULL, @@ -24,7 +33,7 @@ filterChrGR <- function( pruningMode="coarse" ){ - .validInput(input = gr, name = "gr", valid = c("GRanges")) + .validInput(input = gr, name = "gr", valid = c("GRanges", "TxDb")) .validInput(input = remove, name = "remove", valid = c("character", "null")) .validInput(input = underscore, name = "underscore", valid = c("boolean")) .validInput(input = standard, name = "standard", valid = c("boolean")) @@ -69,6 +78,22 @@ filterChrGR <- function( #' @param decreasing A boolean value indicating whether the values in the column indicated via `by` should be ordered in decreasing #' order. If `TRUE`, the higher value in `by` will be retained. #' @param verbose A boolean value indicating whether the output should include extra reporting. +#' +#' @examples +#' +#' # Dummy GR +#' gr <- GRanges( +#' seqnames = "chr1", +#' ranges = IRanges( +#' start = c(1, 4, 11), +#' end = c(10, 12, 20) +#' ), +#' score = c(1, 2, 3) +#' ) +#' +#' # Non Overlapping +#' nonOverlappingGR(gr) +#' #' @export nonOverlappingGR <- function( gr = NULL, @@ -147,6 +172,22 @@ nonOverlappingGR <- function( #' @param gr A `GRanges` object. #' @param upstream The number of basepairs upstream (5') to extend each region in `gr` in a strand-aware fashion. #' @param downstream The number of basepairs downstream (3') to extend each region in `gr` in a strand-aware fashion. +#' +#' @examples +#' +#' # Dummy GR +#' gr <- GRanges( +#' seqnames = "chr1", +#' ranges = IRanges( +#' start = c(1, 4, 11), +#' end = c(10, 12, 20) +#' ), +#' score = c(1, 2, 3) +#' ) +#' +#' # Non Overlapping +#' extendGR(gr, 1, 2) +#' #' @export extendGR <- function(gr = NULL, upstream = NULL, downstream = NULL){ .validInput(input = gr, name = "gr", valid = c("GRanges")) diff --git a/R/GgplotUtils.R b/R/GgplotUtils.R index ec808b4b..7a5b1c5a 100644 --- a/R/GgplotUtils.R +++ b/R/GgplotUtils.R @@ -50,6 +50,21 @@ #' @param rastr A boolean value that indicates whether the plot should be rasterized using `ggrastr`. This does not rasterize #' lines and labels, just the internal portions of the plot. #' @param dpi The resolution in dots per inch to use for the plot. +#' +#' @examples +#' +#' # Create Random Data +#' m <- data.frame(matrix(rnorm(20, 2),ncol=2)) +#' m$color <- sample(c("A", "B"), 10, replace = TRUE) +#' +#' # Plot +#' p <- ggPoint(x = m[,1], y = m[,2], color = m[,3]) +#' +#' # To PDF +#' pdf("test.pdf", width = 4, height = 4) +#' p +#' dev.off() +#' #' @export ggPoint <- function( x = NULL, @@ -267,19 +282,6 @@ ggPoint <- function( raster.width = min(par('fin')), raster.height = (ratioYX * min(par('fin'))) ) - - # if(!requireNamespace("ggrastr", quietly = TRUE)){ - # message("ggrastr is not available for rastr of points, continuing without rastr!") - # message("To install ggrastr try : devtools::install_github('VPetukhov/ggrastr')") - # p <- p + geom_point(size = size, alpha = alpha) - # }else{ - # .requirePackage("ggrastr", installInfo = "devtools::install_github('VPetukhov/ggrastr')") - # p <- p + geom_point_rast( - # size = size, raster.dpi = dpi, alpha = alpha, - # raster.width=par('fin')[1], - # raster.height = (ratioYX * par('fin')[2]) - # ) - # } }else{ @@ -298,7 +300,7 @@ ggPoint <- function( } #print(pal) p <- p + scale_color_manual(values = pal) + - guides(color = guide_legend(override.aes = list(size = legendSize, shape = 15))) + .gg_guides(color = guide_legend(override.aes = list(size = legendSize, shape = 15))) } if (labelMeans) { @@ -394,6 +396,20 @@ ggPoint <- function( #' @param rastr A boolean value that indicates whether the plot should be rasterized. This does not rasterize lines and labels, just the internal portions of the plot. #' @param pal A custom palette from `ArchRPalettes` used to display the density of points on the plot. #' @param ... Additional params to be supplied to ggPoint +#' +#' @examples +#' +#' # Create Random Data +#' m <- data.frame(matrix(rnorm(20, 2),ncol=2)) +#' +#' # Plot +#' p <- ggOneToOne(x = m[,1], y = m[,2]) +#' +#' # To PDF +#' pdf("test.pdf", width = 4, height = 4) +#' p +#' dev.off() +#' #' @export ggOneToOne <- function ( x = NULL, @@ -516,6 +532,20 @@ ggOneToOne <- function ( #' them to the value of the 97.5th and 2.5th percentile values respectively. #' @param addPoints A boolean value indicating whether individual points should be shown on the hexplot. #' @param ... Additional params for plotting +#' +#' @examples +#' +#' # Create Random Data +#' m <- data.frame(matrix(rnorm(300, 2),ncol=3)) +#' +#' # Plot +#' p <- ggHex(x = m[,1], y = m[,2], color = m[,3]) +#' +#' # To PDF +#' pdf("test.pdf", width = 4, height = 4) +#' p +#' dev.off() +#' #' @export ggHex <- function( x = NULL, @@ -643,6 +673,21 @@ ggHex <- function( #' @param addBoxPlot A boolean indicating whether to add a boxplot to the plot if `plotAs="violin"`. #' @param plotAs A string indicating how the groups should be plotted. Acceptable values are "ridges" (for a `ggrides`-style plot) or "violin" (for a violin plot). #' @param ... Additional parameters to pass to `ggplot2` for plotting. +#' +#' @examples +#' +#' # Create Random Data +#' m <- data.frame(x=matrix(rnorm(10, 2),ncol=1)) +#' m$color <- sample(c("A", "B"), 10, replace = TRUE) +#' +#' # Plot +#' p <- ggGroup(x = m$color, y = m$x) +#' +#' # To PDF +#' pdf("test.pdf", width = 4, height = 4) +#' p +#' dev.off() +#' #' @export ggGroup <- function( x = NULL, @@ -787,6 +832,20 @@ ggGroup <- function( #' @param sizes A numeric vector or list of values indicating the relative size for each of the objects in `plotList` or supplied in `...`. If the plot is supplied in `...` the order is the same as the input in this function. If set to NULL all plots will be evenly distributed. #' @param type A string indicating wheter vertical ("v") or horizontal ("h") alignment should be used for the multi-plot layout. #' @param draw A boolean value indicating whether to draw the plot(s) (`TRUE`) or return a graphical object (`FALSE`). +#' @examples +#' +#' # Create Random Data +#' m <- data.frame(x=matrix(rnorm(10, 2),ncol=1)) +#' m$color <- sample(c("A", "B"), 10, replace = TRUE) +#' +#' # Plot +#' p <- ggGroup(x = m$color, y = m$x) +#' +#' # To PDF +#' pdf("test.pdf", width = 4, height = 7) +#' ggAlignPlots(p, p) +#' dev.off() +#' #' @export ggAlignPlots <- function( ..., @@ -887,6 +946,20 @@ ggAlignPlots <- function( #' @param axisTickCm The length in centimeters to be used for the axis ticks. #' @param xText90 A boolean value indicating whether the x-axis text should be rotated 90 degrees counterclockwise. #' @param yText90 A boolean value indicating whether the y-axis text should be rotated 90 degrees counterclockwise. +#' @examples +#' +#' # Create Random Data +#' m <- data.frame(x=matrix(rnorm(10, 2),ncol=1)) +#' m$color <- sample(c("A", "B"), 10, replace = TRUE) +#' +#' # Plot +#' p <- ggGroup(x = m$color, y = m$x) + theme_ArchR() +#' +#' # To PDF +#' pdf("test.pdf", width = 4, height = 7) +#' p +#' dev.off() +#' #' @export theme_ArchR <- function( color = "black", @@ -947,12 +1020,32 @@ theme_ArchR <- function( } - - ########################################################################################## # ggplot2 helper functions ########################################################################################## +#ggplot2 guides +#this funciton handles the deprecation of guides scale = FALSE -> 'none' +#I'm not sure if I change to FALSE if its backwards so this is safer for now +.gg_guides <- function(...){ + args2 <- lapply(list(...), function(a){ + if(is(a, "logical")){ + if(!a){ + a <- "none" + } + } + a + }) + tryCatch({ + guides(...) + }, warning = function(w){ + supppressWarnings(guides(...)) + }, error = function(e){ + do.call(guides, args2) + }) +} + +#Check Cairo .checkCairo <- function(){ tryCatch({ tmp <- dev.cur() diff --git a/R/GlobalDefaults.R b/R/GlobalDefaults.R index 6ae8fdb3..0cc4758e 100644 --- a/R/GlobalDefaults.R +++ b/R/GlobalDefaults.R @@ -7,6 +7,7 @@ ArchRDefaults <- list( ArchR.threads = 1, ArchR.locking = FALSE, ArchR.logging = TRUE, + ArchR.h5level = 0, ArchR.genome = NA, ArchR.chrPrefix = TRUE, ArchR.debugging = FALSE, @@ -14,6 +15,7 @@ ArchRDefaults <- list( ) ArchRDependency <- c( + "devtools", "grid", "gridExtra", "gtools", @@ -103,6 +105,12 @@ ArchRDependency <- c( #' This function will install extra packages used in ArchR that are not installed by default. #' #' @param force If you want to force a reinstall of these pacakges. +#' +#' @examples +#' +#' # Install +#' installExtraPackages() +#' #' @export installExtraPackages <- function(force = FALSE){ @@ -263,6 +271,12 @@ installExtraPackages <- function(force = FALSE){ #' This function will set the default requirement of chromosomes to have a "chr" prefix. #' #' @param chrPrefix A boolean describing the requirement of chromosomes to have a "chr" prefix. +#' +#' @examples +#' +#' # Add ArchR Chr Prefix +#' addArchRChrPrefix() +#' #' @export addArchRChrPrefix <- function(chrPrefix = TRUE){ @@ -282,6 +296,11 @@ addArchRChrPrefix <- function(chrPrefix = TRUE){ #' #' This function will get the default requirement of chromosomes to have a "chr" prefix. #' +#' @examples +#' +#' # Get ArchR Chr Prefix +#' getArchRChrPrefix() +#' #' @export getArchRChrPrefix <- function(){ @@ -312,6 +331,12 @@ getArchRChrPrefix <- function(){ #' This can be overwritten on a per-function basis using the given function's `threads` parameter. #' @param force If you request more than the total number of CPUs minus 2, ArchR will set `threads` to `(nCPU - 2)`. #' To bypass this, setting `force = TRUE` will use the number provided to `threads`. +#' +#' @examples +#' +#' # Add ArchR Threads +#' addArchRThreads() +#' #' @export addArchRThreads <- function(threads = floor(parallel::detectCores()/ 2), force = FALSE){ @@ -344,6 +369,12 @@ addArchRThreads <- function(threads = floor(parallel::detectCores()/ 2), force = #' #' This function will get the number of threads to be used for parallel execution across all ArchR functions. #' +#' +#' @examples +#' +#' # Get ArchR Threads +#' getArchRThreads() +#' #' @export getArchRThreads <- function(){ .ArchRThreads <- options()[["ArchR.threads"]] @@ -360,6 +391,55 @@ getArchRThreads <- function(){ } } +########################################################################################## +# h5 compression level +########################################################################################## + +#' Add a globally-applied compression level for h5 files +#' +#' This function will set the default compression level to be used for h5 file execution across all ArchR functions. +#' +#' @param level The default compression level to be used for h5 file execution across all ArchR functions. +#' +#' @examples +#' +#' # Add ArchR H5 Compression level +#' addArchRH5Level() +#' +#' @export +addArchRH5Level <- function(level = 0){ + + .validInput(input = level, name = "level", valid = "integer") + message("Setting default h5 compression to ", level, ".") + options(ArchR.h5level = as.integer(round(level))) + +} + +#' Get globally-applied compression level for h5 files +#' +#' This function will get the default compression level to be used for h5 file execution across all ArchR functions. +#' +#' @examples +#' +#' # Get ArchR H5 Compression level +#' getArchRH5Level() +#' +#' @export +getArchRH5Level <- function(){ + .ArchRH5Level <- options()[["ArchR.h5level"]] + if(!is.null(.ArchRH5Level)){ + if(!.isWholenumber(.ArchRH5Level)){ + message("option(.ArchRH5Level) : ", .ArchRThreads, " is not an integer. \nDid you mistakenly set this to a value without addArchRH5Level? Reseting to default!") + addArchRH5Level() + options()[["ArchR.threads"]] + }else{ + .ArchRH5Level + } + }else{ + 0 + } +} + ########################################################################################## # H5 File Locking ########################################################################################## @@ -369,6 +449,12 @@ getArchRThreads <- function(){ #' This function will set the default H5 file locking parameters #' #' @param locking The default value for H5 File Locking +#' +#' @examples +#' +#' # Disable/Add ArchR H5 Locking Globally +#' addArchRLocking(locking=FALSE) +#' #' @export addArchRLocking <- function(locking=FALSE){ @@ -393,6 +479,12 @@ addArchRLocking <- function(locking=FALSE){ #' #' This function will set the default H5 file locking parameters to the system #' +#' +#' @examples +#' +#' # Set ArchR H5 Locking Globally +#' setArchRLocking() +#' #' @export setArchRLocking <- function(){ @@ -449,6 +541,12 @@ setArchRLocking <- function(){ #' For something other than one of the currently supported, see `createGeneAnnnotation()` and `createGenomeAnnnotation()`. #' @param install A boolean value indicating whether the `BSgenome` object associated with the provided `genome` should be #' automatically installed if it is not currently installed. This is useful for helping reduce user download requirements. +#' +#' @examples +#' +#' # Add ArchR Genome to use globally +#' addArchRGenome("hg19test2") +#' #' @export addArchRGenome <- function(genome = NULL, install = TRUE){ @@ -536,6 +634,12 @@ addArchRGenome <- function(genome = NULL, install = TRUE){ #' @param genomeAnnotation A boolean value indicating whether the `genomeAnnotation` associated with the ArchRGenome should be returned #' instead of the globally defined genome. The `genomeAnnotation` is used downstream to determine things like chromosome sizes and nucleotide content. #' This function is not meant to be run with both `geneAnnotation` and `genomeAnnotation` set to `TRUE` (it is an either/or return value). +#' +#' @examples +#' +#' # Get ArchR Genome to use globally +#' getArchRGenome() +#' #' @export getArchRGenome <- function( geneAnnotation=FALSE, diff --git a/R/GroupCoverages.R b/R/GroupCoverages.R index e703c34e..7cb7e017 100644 --- a/R/GroupCoverages.R +++ b/R/GroupCoverages.R @@ -27,6 +27,15 @@ #' insertion coverage / pseudo-bulk replicate information already exists. #' @param verbose A boolean value that determines whether standard output includes verbose sections. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Group Coverages +#' proj <- addGroupCoverages(proj, force = TRUE) +#' #' @export addGroupCoverages <- function( ArchRProj = NULL, @@ -392,8 +401,8 @@ addGroupCoverages <- function( chrValues <- paste0("Coverage/",availableChr[k],"/Values") lengthRle <- length(covk@lengths) o <- h5createGroup(covFile, paste0("Coverage/",availableChr[k])) - o <- .suppressAll(h5createDataset(covFile, chrLengths, storage.mode = "integer", dims = c(lengthRle, 1), level = 0)) - o <- .suppressAll(h5createDataset(covFile, chrValues, storage.mode = "integer", dims = c(lengthRle, 1), level = 0)) + o <- .suppressAll(h5createDataset(covFile, chrLengths, storage.mode = "integer", dims = c(lengthRle, 1), level = getArchRH5Level())) + o <- .suppressAll(h5createDataset(covFile, chrValues, storage.mode = "integer", dims = c(lengthRle, 1), level = getArchRH5Level())) o <- h5write(obj = covk@lengths, file = covFile, name = chrLengths) o <- h5write(obj = covk@values, file = covFile, name = chrValues) diff --git a/R/GroupExport.R b/R/GroupExport.R index 5ed05f09..01bffbfd 100644 --- a/R/GroupExport.R +++ b/R/GroupExport.R @@ -19,6 +19,15 @@ exportGroupSE <- function(...){ #' @param threads An integer specifying the number of threads for parallel. #' @param verbose A boolean specifying to print messages during computation. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Group SE +#' se <- getGroupSE(proj, useMatrix = "PeakMatrix", groupBy = "Clusters") +#' #' @export getGroupSE <- function( ArchRProj = NULL, @@ -148,6 +157,15 @@ getGroupSE <- function( #' @param verbose A boolean specifying to print messages during computation. #' @param threads An integer specifying the number of threads for parallel. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Group BW +#' bw <- getGroupBW(proj, groupBy = "Clusters") +#' #' @export getGroupBW <- function( ArchRProj = NULL, @@ -241,7 +259,7 @@ getGroupBW <- function( if(threads > 1){ message("subThreadhing Enabled since ArchRLocking is FALSE see `addArchRLocking`") } - args$threads <- threads + threads <- threads } covFiles <- c() diff --git a/R/Harmony.R b/R/Harmony.R index ca9fbabe..d4b7deef 100644 --- a/R/Harmony.R +++ b/R/Harmony.R @@ -20,7 +20,19 @@ #' exists as a column name in `cellColData`. #' @param ... Additional arguments to be provided to harmony::HarmonyMatrix #' @export +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Confounder +#' proj <- addCellColData(proj, data = proj$TSSEnrichment > 10, name = "TSSQC", cells = getCellNames(proj)) #' +#' # Run Harmony +#' proj <- addHarmony(proj, groupBy = "TSSQC") +#' +#' @export addHarmony <- function( ArchRProj = NULL, reducedDims = "IterativeLSI", diff --git a/R/HelperUtils.R b/R/HelperUtils.R index eee04e65..c3a33cf8 100644 --- a/R/HelperUtils.R +++ b/R/HelperUtils.R @@ -8,6 +8,12 @@ #' #' @param x The value to search for in `table`. #' @param table The set of values to serve as the base for the match function. +#' +#' @examples +#' +#' #Test +#' c("A", "B", "C") %ni% c("A", "C") +#' #' @export "%ni%" <- function(x, table) !(match(x, table, nomatch = 0) > 0) @@ -17,6 +23,12 @@ #' #' @param x An `S4Vector` object to search for in `table`. #' @param table The set of `S4Vector` objects to serve as the base for the match function. +#' +#' @examples +#' +#' #Test +#' Rle(c("A", "B", "C")) %bcin% Rle(c("A", "C")) +#' #' @export '%bcin%' <- function(x, table) S4Vectors::match(x, table, nomatch = 0) > 0 @@ -26,6 +38,12 @@ #' #' @param x An `S4Vector` object to search for in `table`. #' @param table The set of `S4Vector` objects to serve as the base for the match function. +#' +#' @examples +#' +#' #Test +#' Rle(c("A", "B", "C")) %bcni% Rle(c("A", "C")) +#' #' @export '%bcni%' <- function(x, table) !(S4Vectors::match(x, table, nomatch = 0) > 0) @@ -41,6 +59,15 @@ #' @param fragmentFiles A character vector the paths to fragment files to be reformatted #' @param checkChrPrefix A boolean value that determines whether seqnames should be checked to contain #' "chr". IF set to `TRUE`, any seqnames that do not contain "chr" will be removed from the fragment files. +#' +#' @examples +#' +#' # Get Test Fragments +#' fragments <- getTestFragments() +#' +#' # Get Peak Annotations +#' fragments2 <- reformatFragmentFiles(fragments) +#' #' @export reformatFragmentFiles <- function( fragmentFiles = NULL, @@ -97,10 +124,22 @@ reformatFragmentFiles <- function( #' #' @param i A character/numeric value vector to see concordance with j. #' @param j A character/numeric value vector to see concordance with i. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Overlap of Clusters and CellType +#' confusionMatrix(proj$Clusters, proj$CellType) +#' +#' # Overlap of Cell Type and RNA Predict +#' confusionMatrix(proj$CellType, proj$predictedGroup_Un) +#' #' @export confusionMatrix <- function( - i = NULL, - j = NULL + i = NULL, + j = NULL ){ ui <- unique(i) uj <- unique(j) @@ -124,6 +163,15 @@ confusionMatrix <- function( #' @param labels A character vector containing lables to map. #' @param newLabels A character vector (same length as oldLabels) to map labels to from oldLabels. #' @param oldLabels A character vector (same length as newLabels) to map labels from to newLabels +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Peak Annotations +#' proj$ClusterLabels <- mapLabels(proj$Clusters, c("T", "B", "M"), c("C1", "C2", "C3")) +#' #' @export mapLabels <- function(labels = NULL, newLabels = NULL, oldLabels = names(newLabels)){ diff --git a/R/Imputation.R b/R/Imputation.R index bda3e0da..e6fe0e37 100644 --- a/R/Imputation.R +++ b/R/Imputation.R @@ -31,6 +31,15 @@ #' @param seed A number to be used as the seed for random number generation. It is recommended to keep track of the seed used so that you can #' reproduce results downstream. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Impute Weights +#' proj <- addImputeWeights(proj) +#' #' @export addImputeWeights <- function( ArchRProj = NULL, @@ -180,8 +189,8 @@ addImputeWeights <- function( if(useHdf5){ o <- .suppressAll(h5createGroup(file = weightFile, paste0("block", x))) - o <- .suppressAll(h5write(obj = ix, file = weightFile, name = paste0("block", x, "/Names"), level = 0)) - o <- .suppressAll(h5write(obj = as.matrix(Wt), file = weightFile, name = paste0("block", x, "/Weights"), level = 0)) + o <- .suppressAll(h5write(obj = ix, file = weightFile, name = paste0("block", x, "/Names"), level = getArchRH5Level())) + o <- .suppressAll(h5write(obj = as.matrix(Wt), file = weightFile, name = paste0("block", x, "/Weights"), level = getArchRH5Level())) return(weightFile) }else{ Wt @@ -222,6 +231,18 @@ addImputeWeights <- function( #' This function gets imputation weights from an ArchRProject to impute numeric values. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Impute Weights +#' proj <- addImputeWeights(proj) +#' +#' # Get Impute Weights +#' getImputeWeights(proj) +#' #' @export getImputeWeights <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProj")) @@ -242,6 +263,24 @@ getImputeWeights <- function(ArchRProj = NULL){ #' @param threads The number of threads to be used for parallel computing. #' @param verbose A boolean value indicating whether to use verbose output during execution of this function. Can be set to FALSE for a cleaner output. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Impute Weights +#' proj <- addImputeWeights(proj) +#' +#' # Get Impute Weights +#' iW <- getImputeWeights(proj) +#' +#' # Get Matrix +#' se <- getMatrixFromProject(proj, useMatrix = "GeneScoreMatrix") +#' +#' # Impute +#' mat <- imputeMatrix(assay(se), iW) +#' #' @export imputeMatrix <- function( mat = NULL, diff --git a/R/InputData.R b/R/InputData.R index e25e743e..90418d7d 100644 --- a/R/InputData.R +++ b/R/InputData.R @@ -2,10 +2,17 @@ #' #' This function will download data for a given tutorial and return the input files required for ArchR. #' -#' @param tutorial The name of the available tutorial for which to retreive the tutorial data. Currently, the only available option is "Hematopoiesis". +#' @param tutorial The name of the available tutorial for which to retreive the tutorial data. The main option is "Hematopoiesis". #' "Hematopoiesis" is a small scATAC-seq dataset that spans the hematopoieitic hierarchy from stem cells to differentiated cells. -#' This dataset is made up of cells from peripheral blood, bone marrow, and CD34+ sorted bone marrow. +#' This dataset is made up of cells from peripheral blood, bone marrow, and CD34+ sorted bone marrow. The second option is "Test" +#' which is downloading a small test PBMC fragments file mainly used to test the url capabilities of this function. #' @param threads The number of threads to be used for parallel computing. +#' +#' @examples +#' +#' # Get Tutorial Fragments using `test` since its smaller +#' fragments <- getTutorialData(tutorial = "test") +#' #' @export getTutorialData <- function( tutorial = "hematopoiesis", @@ -17,12 +24,12 @@ getTutorialData <- function( .validInput(input = threads, name = "threads", valid = c("integer")) ######### - #Make Sure URL doesnt timeout - oldTimeout <- getOption('timeout') - options(timeout=100000) - if(tolower(tutorial) %in% c("heme","hematopoiesis")){ + #Make Sure URL doesnt timeout + oldTimeout <- getOption('timeout') + options(timeout=100000) + if(!dir.exists("HemeFragments")){ filesUrl <- c( @@ -47,55 +54,122 @@ getTutorialData <- function( } pathFragments <- "HemeFragments" + #Set back URL Options + options(timeout=oldTimeout) + + #Return Fragment Files + inputFiles <- list.files(pathFragments, pattern = ".gz", full.names = TRUE) + names(inputFiles) <- gsub(".fragments.tsv.gz", "", list.files(pathFragments, pattern = ".gz")) + inputFiles <- inputFiles[!grepl(".tbi", inputFiles)] + inputFiles + + }else if(tolower(tutorial) == "test"){ + + #Tests URL Method + getTestFragments(version = 1) + }else{ stop("There is no tutorial data for : ", tutorial) } - #Set back URL Options - options(timeout=oldTimeout) +} - #Return Fragment Files - inputFiles <- list.files(pathFragments, pattern = ".gz", full.names = TRUE) - names(inputFiles) <- gsub(".fragments.tsv.gz", "", list.files(pathFragments, pattern = ".gz")) - inputFiles <- inputFiles[!grepl(".tbi", inputFiles)] - inputFiles +#' Get PBMC Small Test Arrow file +#' +#' V2 : This function will return a test arrow file in your cwd. +#' +#' @param version version of test arrow to return +#' +#' @examples +#' +#' # Get Test Arrow +#' arrow <- getTestArrow() +#' +#' @export +getTestArrow <- function(version = 2){ + + if(version == 2){ + #Add Genome Return Arrow + addArchRGenome("hg19test2") + arrow <- file.path(system.file("testdata", package="ArchR"), "PBSmall.arrow") + file.copy(arrow, basename(arrow), overwrite = TRUE) + basename(arrow) + }else{ + stop("test version doesnt exist!") + } } #' Get PBMC Small Test Fragments #' -#' This function will download fragments for a small PBMC test dataset (2k Cells) spanning chr1 and 2 (~20MB). +#' V1 : This function will download fragments for a small PBMC test dataset. +#' V2 : This function will return test fragments for a small PBMC test dataset in your cwd. +#' +#' @param version version of test fragments to return +#' +#' @examples +#' +#' # Get Test Fragments +#' fragments <- getTestFragments() #' #' @export -getTestFragments <- function(x){ +getTestFragments <- function(version = 2){ - #Make Sure URL doesnt timeout - oldTimeout <- getOption('timeout') - options(timeout=100000) + if(version == 1){ - if(!file.exists("PBMCSmall.tsv.gz")){ - download.file( - url = "https://jeffgranja.s3.amazonaws.com/ArchR/TestData/PBMCSmall.tsv.gz", - destfile = "PBMCSmall.tsv.gz" - ) - } - #Set back URL Options - options(timeout=oldTimeout) + #Make Sure URL doesnt timeout + oldTimeout <- getOption('timeout') + options(timeout=100000) - #Add Genome Return Name Vector - addArchRGenome("hg19test") - c("PBMC" = "PBMCSmall.tsv.gz") + if(!file.exists("PBMCSmall.tsv.gz")){ + download.file( + url = "https://jeffgranja.s3.amazonaws.com/ArchR/TestData/PBMCSmall.tsv.gz", + destfile = "PBMCSmall.tsv.gz" + ) + } + #Set back URL Options + options(timeout=oldTimeout) + + #Add Genome Return Name Vector + addArchRGenome("hg19test") + c("PBMC" = "PBMCSmall.tsv.gz") + + }else if(version == 2){ + + #Add Genome Return Name Vector + addArchRGenome("hg19test2") + fragments <- file.path(system.file("testdata", package="ArchR"), "PBSmall.tsv.gz") + file.copy(fragments, basename(fragments), overwrite = TRUE) + c("PBMC" = basename(fragments)) + + }else{ + + stop("test version doesnt exist!") + + } } + #' Get PBMC Small Test Project #' -#' This function will download an ArchRProject for a small PBMC test dataset (2k Cells) spanning chr1 and 2 (~2-300MB). +#' V1 : This function will download an ArchRProject for a small PBMC test dataset. +#' V2 : This function will return an ArchRProject for a small PBMC test dataset in your cwd. +#' +#' @param version version of test fragments to return +#' +#' @examples +#' +#' # Get Test Project +#' proj <- getTestProject() #' #' @export -getTestProject <- function(){ +getTestProject <- function(version = 2){ + + if(version == 1){ + #Make Sure URL doesnt timeout oldTimeout <- getOption('timeout') options(timeout=100000) @@ -113,6 +187,24 @@ getTestProject <- function(){ #Load addArchRGenome("hg19test") loadArchRProject("PBMCSmall") + + + }else if(version == 2){ + + #Add Genome Return Name Vector + addArchRGenome("hg19test2") + archrproj <- file.path(system.file("testdata", package="ArchR"), "PBSmall.zip") + file.copy(archrproj, basename(archrproj), overwrite = TRUE) + unzip(basename(archrproj), overwrite = TRUE) + file.remove(basename(archrproj)) + loadArchRProject("PBSmall") + + }else{ + + stop("test version doesnt exist!") + + } + } #' Get Input Files from paths to create arrows diff --git a/R/IntegrativeAnalysis.R b/R/IntegrativeAnalysis.R index 94116f75..b2594fc0 100644 --- a/R/IntegrativeAnalysis.R +++ b/R/IntegrativeAnalysis.R @@ -34,6 +34,21 @@ #' @param threads The number of threads to be used for parallel computing. #' @param verbose A boolean value that determines whether standard output should be printed. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Correlate Matrices +#' dfCor <- correlateMatrices( +#' ArchRProj = proj, +#' useMatrix1 = "GeneScoreMatrix", +#' useMatrix2 = "GeneIntegrationMatrix", +#' dimsToUse = 1:5, +#' k = 20 +#' ) +#' #' @export correlateMatrices <- function( ArchRProj = NULL, @@ -381,6 +396,22 @@ correlateMatrices <- function( #' @param force A boolean value that determines whether analysis should continue if resizing coordinates in `seTrajectory1` or #' `seTrajectory2` does not align with the strandedness. Only when `useRanges = TRUE`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Add Trajectory +#' proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) +#' +#' #Get Trajectories +#' seTraj1 <- getTrajectory(proj, useMatrix = "GeneScoreMatrix") +#' seTraj2 <- getTrajectory(proj, useMatrix = "GeneIntegrationMatrix") +#' +#' #Correlate +#' corTraj <- correlateTrajectories(seTraj1, seTraj2, corCutOff = 0.35, varCutOff1 = 0.6, varCutOff2 = 0.6) +#' #' @export correlateTrajectories <- function( seTrajectory1 = NULL, @@ -682,6 +713,15 @@ correlateTrajectories <- function( #' @param threads The number of threads to be used for parallel computing. #' @param verbose A boolean value that determines whether standard output should be printed. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Co-Accessibility +#' proj <- addCoAccessibility(proj, k = 20) +#' #' @export addCoAccessibility <- function( ArchRProj = NULL, @@ -850,6 +890,18 @@ addCoAccessibility <- function( #' This only takes affect if `returnLoops = TRUE`. #' @param returnLoops A boolean indicating to return the co-accessibility signal as a `GRanges` "loops" object designed for use with #' the `ArchRBrowser()` or as an `ArchRBrowserTrack()`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Co Accessibility +#' proj <- addCoAccessibility(proj, k = 20) +#' +#' # Get Co Accessibility +#' CoA <- getCoAccessibility(proj) +#' #' @export getCoAccessibility <- function( ArchRProj = NULL, @@ -973,6 +1025,18 @@ getCoAccessibility <- function( #' @param threads The number of threads to be used for parallel computing. #' @param verbose A boolean value that determines whether standard output should be printed. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add P2G Links +#' proj <- addPeak2GeneLinks(proj, k = 20) +#' +#' # Get P2G Links +#' p2g <- getPeak2GeneLinks(proj) +#' #' @export addPeak2GeneLinks <- function( ArchRProj = NULL, @@ -1277,6 +1341,18 @@ addPeak2GeneLinks <- function( #' @param resolution A numeric describing the bp resolution to return loops as. This helps with overplotting of correlated regions. #' @param returnLoops A boolean indicating to return the peak-to-gene links as a `GRanges` "loops" object designed for use with #' the `ArchRBrowser()` or as an `ArchRBrowserTrack()`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add P2G Links +#' proj <- addPeak2GeneLinks(proj, k = 20) +#' +#' # Get P2G Links +#' p2g <- getPeak2GeneLinks(proj) +#' #' @export getPeak2GeneLinks <- function( ArchRProj = NULL, @@ -1385,6 +1461,22 @@ peak2GeneHeatmap <- function(...){ #' @param seed A number to be used as the seed for random number generation. It is recommended to keep track of the seed used so that you can #' reproduce results downstream. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add P2G Links +#' proj <- addPeak2GeneLinks(proj, k = 20) +#' +#' # Get P2G Links +#' p2g <- getPeak2GeneLinks(proj) +#' +#' # Plot P2G +#' p <- plotPeak2GeneHeatmap(proj) +#' plotPDF(p, name = "P2G-Heatmap", ArchRProj = proj) +#' #' @export plotPeak2GeneHeatmap <- function( ArchRProj = NULL, diff --git a/R/IterativeLSI.R b/R/IterativeLSI.R index 5360d7b0..064b4d95 100644 --- a/R/IterativeLSI.R +++ b/R/IterativeLSI.R @@ -50,6 +50,7 @@ #' to the first iteration of the iterative LSI paradigm. For example, if `filterQuantile = 0.99`, any features above the 99th percentile in #' insertion counts will be ignored for the first LSI iteration. #' @param excludeChr A string of chromosomes to exclude for iterativeLSI procedure. +#' @param keep0lsi A boolean whether to keep cells with no reads in features used for LSI. #' @param saveIterations A boolean value indicating whether the results of each LSI iterations should be saved as compressed `.rds` files in #' the designated `outDir`. #' @param UMAPParams The list of parameters to pass to the UMAP function if "UMAP" if `saveIterations=TRUE`. See the function `uwot::umap()`. @@ -61,6 +62,15 @@ #' @param verbose A boolean value that determines whether standard output includes verbose sections. #' @param force A boolean value that indicates whether or not to overwrite relevant data in the `ArchRProject` object. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Iterative LSI +#' proj <- addIterativeLSI(proj, dimsToUse = 1:5, varFeatures=1000, iterations = 2, force=TRUE) +#' #' @export addIterativeLSI <- function( ArchRProj = NULL, @@ -91,6 +101,7 @@ addIterativeLSI <- function( totalFeatures = 500000, filterQuantile = 0.995, excludeChr = c(), + keep0lsi = FALSE, saveIterations = TRUE, UMAPParams = list( n_neighbors = 40, @@ -129,6 +140,7 @@ addIterativeLSI <- function( .validInput(input = totalFeatures, name = "totalFeatures", valid = c("integer")) .validInput(input = filterQuantile, name = "filterQuantile", valid = c("numeric")) .validInput(input = excludeChr, name = "excludeChr", valid = c("character", "null")) + .validInput(input = keep0lsi, name = "keep0lsi", valid = c("boolean")) .validInput(input = saveIterations, name = "saveIterations", valid = c("boolean")) .validInput(input = UMAPParams, name = "UMAPParams", valid = c("list")) .validInput(input = nPlot, name = "nPlot", valid = c("integer")) @@ -351,6 +363,7 @@ addIterativeLSI <- function( dimsToUse = dimsToUse, binarize = binarize, outlierQuantiles = outlierQuantiles, + keep0lsi = keep0lsi, sampleCells = if(j != iterations) sampleCellsPre else sampleCellsFinal, projectAll = j == iterations | projectCellsPre | sampleJ > sampleCellsPre, threads = threads, @@ -465,6 +478,7 @@ addIterativeLSI <- function( dimsToUse = dimsToUse, binarize = binarize, outlierQuantiles = outlierQuantiles, + keep0lsi = keep0lsi, sampleCells = if(j != iterations) sampleCellsPre else sampleCellsFinal, projectAll = j == iterations | projectCellsPre | sampleJ > sampleCellsPre, threads = threads, @@ -540,6 +554,7 @@ addIterativeLSI <- function( dimsToUse = NULL, binarize = TRUE, outlierQuantiles = c(0.02, 0.98), + keep0lsi = FALSE, LSIMethod = FALSE, scaleTo = 10^4, sampleCells = 5000, @@ -585,6 +600,7 @@ addIterativeLSI <- function( nDimensions = max(dimsToUse), binarize = binarize, outlierQuantiles = outlierQuantiles, + keep0lsi = keep0lsi, verbose = FALSE, seed = seed, tstart = tstart, @@ -633,6 +649,7 @@ addIterativeLSI <- function( nDimensions = max(dimsToUse), binarize = binarize, outlierQuantiles = outlierQuantiles, + keep0lsi = keep0lsi, seed = seed, tstart = tstart, logFile = logFile @@ -672,6 +689,7 @@ addIterativeLSI <- function( nDimensions = max(dimsToUse), binarize = binarize, outlierQuantiles = outlierQuantiles, + keep0lsi = keep0lsi, seed = seed, tstart = tstart, logFile = logFile @@ -687,7 +705,7 @@ addIterativeLSI <- function( .logDiffTime("Projecting Matrices with LSI-Projection (Granja* et al 2019)", tstart, addHeader = FALSE, verbose = verbose, logFile = logFile) pLSI <- .safelapply(seq_along(tmpMatFiles), function(x){ .logDiffTime(sprintf("Projecting Matrix (%s of %s) with LSI-Projection", x, length(tmpMatFiles)), tstart, addHeader = FALSE, verbose = FALSE, logFile = logFile) - .projectLSI(mat = readRDS(tmpMatFiles[x]), LSI = outLSI, verbose = FALSE, tstart = tstart, logFile = logFile) + .projectLSI(mat = readRDS(tmpMatFiles[x]), LSI = outLSI, keep0lsi = keep0lsi, verbose = FALSE, tstart = tstart, logFile = logFile) }, threads = threads2) %>% Reduce("rbind", .) #Remove Temporary Matrices @@ -1082,6 +1100,7 @@ addIterativeLSI <- function( nDimensions = 50, binarize = TRUE, outlierQuantiles = c(0.02, 0.98), + keep0lsi = FALSE, seed = 1, verbose = FALSE, tstart = NULL, @@ -1109,7 +1128,22 @@ addIterativeLSI <- function( #Compute Col Sums .logDiffTime("Computing Term Frequency", tstart, addHeader = FALSE, verbose = verbose, logFile = logFile) colSm <- Matrix::colSums(mat) + + #Check + if(keep0lsi){ + colSm[colSm==0] <- 1 + } + if(any(colSm == 0)){ + ############ + wng <- paste0( + "Filtering ", sum(colSm==0), " of ", ncol(mat), " used in LSI since 0 reads were found in the features used!", + "\nPlease consider increasing the number of varFeatures to cleanly handle this issue or", + "\nUse argument `keep0lsi` to keep 0 sum cells by setting their colSums to 1 artificially!" + ) + .logDiffTime(wng, tstart, addHeader = verbose, verbose = verbose, logFile = logFile) + warnings(wng) + ############ exclude <- which(colSm==0) mat <- mat[,-exclude, drop = FALSE] colSm <- colSm[-exclude] @@ -1213,6 +1247,7 @@ addIterativeLSI <- function( scaleTo = scaleTo, nDimensions = nDimensions, LSIMethod = LSIMethod, + keep0lsi = keep0lsi, outliers = NA, date = Sys.Date(), seed = seed @@ -1221,7 +1256,7 @@ addIterativeLSI <- function( if(filterOutliers == 1){ .logDiffTime("Projecting Outliers with LSI-Projection (Granja* et al 2019)", tstart, addHeader = FALSE, verbose = verbose, logFile = logFile) #Quick Check LSI-Projection Works - pCheck <- .projectLSI(mat = mat2, LSI = out, verbose = verbose, logFile = logFile) + pCheck <- .projectLSI(mat = mat2, LSI = out, keep0lsi = keep0lsi, verbose = verbose, logFile = logFile) pCheck2 <- out[[1]][rownames(pCheck), ] pCheck3 <- lapply(seq_len(ncol(pCheck)), function(x){ cor(pCheck[,x], pCheck2[,x]) @@ -1234,7 +1269,7 @@ addIterativeLSI <- function( } #Project LSI Outliers out$outliers <- colnames(matO) - outlierLSI <- .projectLSI(mat = matO, LSI = out, verbose = verbose, logFile = logFile) + outlierLSI <- .projectLSI(mat = matO, LSI = out, keep0lsi = keep0lsi, verbose = verbose, logFile = logFile) allLSI <- rbind(out[[1]], outlierLSI) allLSI <- allLSI[cn, , drop = FALSE] #Re-Order Correctly to original out[[1]] <- allLSI @@ -1269,6 +1304,7 @@ addIterativeLSI <- function( mat = NULL, LSI = NULL, returnModel = FALSE, + keep0lsi = FALSE, verbose = FALSE, tstart = NULL, logFile = NULL @@ -1300,7 +1336,22 @@ addIterativeLSI <- function( #TF .logDiffTime("Computing Term Frequency", tstart, addHeader = FALSE, verbose = verbose, logFile = logFile) colSm <- Matrix::colSums(mat) + + #Check + if(keep0lsi){ + colSm[colSm==0] <- 1 + } + if(any(colSm == 0)){ + ############ + wng <- paste0( + "Filtering ", sum(colSm==0), " of ", ncol(mat), " used for LSI Projection since 0 reads were found in the features used!", + "\nPlease consider increasing the number of varFeatures to cleanly handle this issue or", + "\nUse argument `keep0lsi` to keep 0 sum cells by setting their colSums to 1 artificially!" + ) + .logDiffTime(wng, tstart, addHeader = verbose, verbose = verbose, logFile = logFile) + warnings(wng) + ############ exclude <- which(colSm==0) mat <- mat[,-exclude] colSm <- colSm[-exclude] @@ -1357,7 +1408,7 @@ addIterativeLSI <- function( gc() #Clean Up Matrix - idxNA <- Matrix::which(is.na(mat),arr.ind=TRUE) + idxNA <- Matrix::which(is.na(mat), arr.ind=TRUE) if(length(idxNA) > 0){ .logDiffTime(sprintf("Zeroing %s NA elements", length(idxNA)), tstart, addHeader = FALSE, verbose = verbose, logFile = logFile) mat[idxNA] <- 0 diff --git a/R/LoggerUtils.R b/R/LoggerUtils.R index bc498e08..72fc0b28 100644 --- a/R/LoggerUtils.R +++ b/R/LoggerUtils.R @@ -7,6 +7,12 @@ #' This function will set ArchR logging #' #' @param useLogs A boolean describing whether to use logging with ArchR. +#' +#' @examples +#' +#' # Add ArchR Logging +#' addArchRLogging() +#' #' @export addArchRLogging <- function(useLogs = TRUE){ .validInput(input = useLogs, name = "useLogs", valid = "boolean") @@ -18,6 +24,11 @@ addArchRLogging <- function(useLogs = TRUE){ #' Get ArchR Logging #' #' This function will get ArchR logging +#' +#' @examples +#' +#' # Get ArchR Logging +#' getArchRLogging() #' #' @export getArchRLogging <- function(){ @@ -34,6 +45,12 @@ getArchRLogging <- function(){ #' This function will set ArchR Debugging which will save an RDS if an error is encountered. #' #' @param debug A boolean describing whether to use logging with ArchR. +#' +#' @examples +#' +#' # Add ArchR Debugging +#' addArchRDebugging() +#' #' @export addArchRDebugging <- function(debug = FALSE){ .validInput(input = debug, name = "debug", valid = "boolean") @@ -45,6 +62,11 @@ addArchRDebugging <- function(debug = FALSE){ #' Get ArchR Debugging #' #' This function will get ArchR Debugging which will save an RDS if an error is encountered. +#' +#' @examples +#' +#' # Get ArchR Debugging +#' getArchRDebugging() #' #' @export getArchRDebugging <- function(){ @@ -61,6 +83,12 @@ getArchRDebugging <- function(){ #' This function will set ArchR logging verbosity. #' #' @param verbose A boolean describing whether to printMessages in addition to logging with ArchR. +#' +#' @examples +#' +#' # Add ArchR Verbose +#' addArchRVerbose() +#' #' @export addArchRVerbose <- function(verbose = TRUE){ .validInput(input = verbose, name = "verbose", valid = "boolean") @@ -72,6 +100,11 @@ addArchRVerbose <- function(verbose = TRUE){ #' Set ArchR Verbosity for Log Messaging #' #' This function will get ArchR logging verbosity. +#' +#' @examples +#' +#' # Get ArchR Verbose +#' addArchRVerbose() #' #' @export getArchRVerbose <- function(){ @@ -90,6 +123,12 @@ getArchRVerbose <- function(){ #' #' @param name A character string to add a more descriptive name in log file. #' @param logDir The path to a directory where log files should be written. +#' +#' @examples +#' +#' # Create Log File +#' createLogFile(name = "test") +#' #' @export createLogFile <- function( name = NULL, diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index c0e655f6..56a8f390 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -43,6 +43,20 @@ markerFeatures <- function(...){ #' raw deviations ("deviations") or deviation z-scores ("z") for a chromVAR deviations matrix. #' @param verbose A boolean value that determines whether standard output is printed. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Markers +#' seMarker <- getMarkerFeatures( +#' ArchRProj = proj, +#' useMatrix = "PeakMatrix", +#' testMethod = "binomial", +#' binarize = TRUE +#' ) +#' #' @export getMarkerFeatures <- function( ArchRProj = NULL, @@ -834,6 +848,26 @@ markerHeatmap <- function(...){ #' group compared to all other cell groups. Additionally, the color palette is inverted for visualization. This is useful when #' looking for down-regulated markers (`log2(fold change) < 0`) instead of up-regulated markers (`log2(fold change) > 0`). #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' #Get Markers +#' seMarker <- getMarkerFeatures( +#' ArchRProj = proj, +#' useMatrix = "PeakMatrix", +#' testMethod = "binomial", +#' binarize = TRUE +#' ) +#' +#' #Plot Markers +#' p <- plotMarkerHeatmap(seMarker) +#' +#' #PDF +#' plotPDF(p, name = "Marker-Heatmap", ArchRProj = proj) +#' #' @export plotMarkerHeatmap <- function( seMarker = NULL, @@ -1136,6 +1170,23 @@ plotMarkerHeatmap <- function( #' of the `assayNames` from `seMarker`. #' @param n An integer that indicates the maximum number of features to return per group. #' @param returnGR A boolean indicating whether to return as a `GRanges` object. Only valid when `seMarker` is computed for a PeakMatrix. +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' #Get Markers +#' seMarker <- getMarkerFeatures( +#' ArchRProj = proj, +#' useMatrix = "PeakMatrix", +#' testMethod = "binomial", +#' binarize = TRUE +#' ) +#' +#' #Get Markers +#' getMarkers(seMarker) +#' #' @export getMarkers <- function( seMarker = NULL, @@ -1235,6 +1286,26 @@ markerPlot <- function(...){ #' @param plotAs A string indicating whether to plot a volcano plot ("Volcano") or an MA plot ("MA"). #' @param rastr A boolean value that indicates whether the plot should be rasterized using `ggrastr`. This does not rasterize #' lines and labels, just the internal portions of the plot. +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' #Get Markers +#' seMarker <- getMarkerFeatures( +#' ArchRProj = proj, +#' useMatrix = "PeakMatrix", +#' testMethod = "binomial", +#' binarize = TRUE +#' ) +#' +#' #Plot Markers +#' p <- plotMarkers(seMarker, name = "C1") +#' +#' #PDF +#' plotPDF(p, name = "Marker-Plot", ArchRProj = proj) +#' #' @export plotMarkers <- function( seMarker = NULL, diff --git a/R/MatrixDeviations.R b/R/MatrixDeviations.R index 9b2bdad5..23d3f5ed 100644 --- a/R/MatrixDeviations.R +++ b/R/MatrixDeviations.R @@ -23,6 +23,22 @@ #' @param force A boolean value indicating whether to force the matrix indicated by `matrixName` to be overwritten if it #' already exists in the ArrowFiles associated with the given `ArchRProject`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Background Peaks +#' proj <- addBgdPeaks(proj, force = TRUE) +#' +#' # Add Motif Deviations +#' proj <- addDeviationsMatrix( +#' ArchRProj = proj, +#' peakAnnotation = "Motif", +#' force = TRUE +#' ) +#' #' @export addDeviationsMatrix <- function( ArchRProj = NULL, @@ -559,6 +575,15 @@ addDeviationsMatrix <- function( #' @param name The name of the `DeviationsMatrix` object stored in the `ArchRProject`. See `addDeviationsMatrix()`. #' @param plot A boolean value indicating whether the ranked variability should be plotted for each peakAnnotation in `DeviationsMatrix`. #' @param n The number of annotations to label with `ggrepel`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Variable Motif Deviations +#' varDev <- getVarDeviations(proj) +#' #' @export getVarDeviations <- function(ArchRProj = NULL, name = "MotifMatrix", plot = TRUE, n = 25){ @@ -606,6 +631,15 @@ getVarDeviations <- function(ArchRProj = NULL, name = "MotifMatrix", plot = TRUE #' is to save this file in the `outputDirectory` of the `ArchRProject`. #' @param method A string indicating whether to use chromVAR or ArchR for background peak identification. #' @param force A boolean value indicating whether to force the file indicated by `outFile` to be overwritten if it already exists. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Background Peaks +#' proj <- addBgdPeaks(proj, force = TRUE) +#' #' @export addBgdPeaks <- function( ArchRProj = NULL, @@ -703,6 +737,15 @@ addBgdPeaks <- function( #' so that you can reproduce results downstream. #' @param method A string indicating whether to use chromVAR or ArchR for background peak identification. #' @param force A boolean value indicating whether to force the file indicated by `outFile` to be overwritten if it already exists. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Background Peaks +#' bgdPeaks <- getBgdPeaks(proj, force = TRUE) +#' #' @export getBgdPeaks <- function( ArchRProj = NULL, diff --git a/R/MatrixFeatures.R b/R/MatrixFeatures.R index 15e50137..68e80e55 100644 --- a/R/MatrixFeatures.R +++ b/R/MatrixFeatures.R @@ -17,6 +17,15 @@ #' @param parallelParam A list of parameters to be passed for biocparallel/batchtools parallel computing. #' @param force A boolean value indicating whether to force the matrix indicated by `matrixName` to be overwritten if it already exists in the `input`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Custom Matrix Which Is Just Peak Set +#' proj <- addFeatureMatrix(proj, features = getPeakSet(proj)) +#' #' @export addFeatureMatrix <- function( input = NULL, @@ -111,6 +120,15 @@ addFeatureMatrix <- function( #' @param parallelParam A list of parameters to be passed for biocparallel/batchtools parallel computing. #' @param force A boolean value indicating whether to force the "PeakMatrix" to be overwritten if it already exist in the given `ArchRProject`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Peak Matrix +#' proj <- addPeakMatrix(proj) +#' #' @export addPeakMatrix <- function( ArchRProj = NULL, diff --git a/R/MatrixGeneScores.R b/R/MatrixGeneScores.R index 8c09df66..80ec55bd 100644 --- a/R/MatrixGeneScores.R +++ b/R/MatrixGeneScores.R @@ -40,6 +40,15 @@ #' @param subThreading A boolean determining whether possible use threads within each multi-threaded subprocess if greater than the number of input samples. #' @param force A boolean value indicating whether to force the matrix indicated by `matrixName` to be overwritten if it already exist in the given `input`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Gene Score Matrix With New Model +#' proj <- addGeneScoreMatrix(proj, matrixName = "GeneScoreMatrix2", geneModel = "exp(-abs(x)/10000) + exp(-1)") +#' #' @export addGeneScoreMatrix <- function( input = NULL, diff --git a/R/MatrixTiles.R b/R/MatrixTiles.R index 4b420c50..bf47f0eb 100644 --- a/R/MatrixTiles.R +++ b/R/MatrixTiles.R @@ -18,6 +18,15 @@ #' @param parallelParam A list of parameters to be passed for biocparallel/batchtools parallel computing. #' @param force A boolean value indicating whether to force the "TileMatrix' to be overwritten if it already exist in the given `input`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Tile Matrix +#' proj <- addTileMatrix(proj, force = TRUE, tileSize = 25000) +#' #' @export addTileMatrix <- function( input = NULL, @@ -172,7 +181,7 @@ addTileMatrix <- function( cellNames = cellNames, params = dfParams, featureDF = featureDF, - force = force + force = TRUE ) ###################################### diff --git a/R/ModuleScore.R b/R/ModuleScore.R index 725276ab..8a3bd8cd 100644 --- a/R/ModuleScore.R +++ b/R/ModuleScore.R @@ -17,6 +17,20 @@ #' to keep track of the seed used so that you can reproduce results downstream. #' @param threads The number of threads to be used for parallel computing. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Module Score +#' proj <- addModuleScore(proj, useMatrix = "GeneIntegrationMatrix", nBin = 25, nBgd = 25, features = list(TScore = c('CD3D', 'CD3E'))) +#' +#' #Check +#' split(proj@cellColData$Module.TScore, proj@cellColData$CellType) %>% lapply(mean) %>% unlist +#' # B M T +#' # -5.834066 -9.176063 17.594090 +#' #' @export addModuleScore <- function( ArchRProj = NULL, @@ -99,9 +113,15 @@ addModuleScore <- function( #so that the features can be binned into nBins rS <- ArchR:::.getRowSums(ArrowFiles = getArrowFiles(ArchRProj), useMatrix = useMatrix) rS <- rS[order(rS[,3]), ] - rS$Bins <- Rle(ggplot2::cut_number(x = rS[,3] + rnorm(length(rS[,3]))/1e30, n = nBin, labels = FALSE, right = FALSE)) rS$Match <- match(paste0(rS$seqnames, ":", rS$idx), rownames(featureDF)) - + + #Determine Bins + rS$Bins <- 0 + idx <- which(rS$rowSums > 0) + rS$Bins[idx] <- ceiling(seq_along(idx) / ceiling(length(idx)/nBin)) + rS$Bins <- Rle(rS$Bins + 1) + #rS$Bins <- Rle(ggplot2::cut_number(x = rS[,3] + rnorm(length(rS[,3]))/1e30, n = nBin, labels = FALSE, right = FALSE)) + #check that the number of selected background features isnt bigger than the size of each bin if(nBgd > min(rS$Bins@lengths)){ stop("nBgd must be lower than ", min(rS$Bins@lengths), "!") diff --git a/R/ProjectMethods.R b/R/ProjectMethods.R index 1ab49b5a..71b5a889 100644 --- a/R/ProjectMethods.R +++ b/R/ProjectMethods.R @@ -7,6 +7,15 @@ #' This function gets the outputDirectory from a given ArchRProject. If null this returns "QualityControl" directory. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Output Directory +#' getOutputDirectory(proj) +#' #' @export getOutputDirectory <- function( ArchRProj = NULL @@ -33,6 +42,15 @@ getOutputDirectory <- function( #' This function gets the names of all ArrowFiles associated with a given ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Arrow Files +#' getArrowFiles(proj) +#' #' @export getArrowFiles <- function( ArchRProj = NULL @@ -63,6 +81,15 @@ getArrowFiles <- function( #' This function gets the names of all samples from a given ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Sample Names +#' getSampleNames(proj) +#' #' @export getSampleNames <- function( ArchRProj = NULL @@ -81,6 +108,15 @@ getSampleNames <- function( #' This function gets number of cells from an ArchRProject or ArrowFile #' #' @param input An `ArchRProject` object or the path to an ArrowFile. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Number of Cells +#' nCells(proj) +#' #' @export nCells <- function( input = NULL @@ -111,6 +147,15 @@ nCells <- function( #' @param select A character vector containing the column names to select from `cellColData`. #' @param summary A character vector describing which method for summarizing across group. Options include "median", "mean", or "sum". #' @param removeNA Remove NA's from summary method. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Group Summary +#' getGroupSummary(proj, groupBy = "Clusters", select = "TSSEnrichment", summary = "mean") +#' #' @export getGroupSummary <- function( ArchRProj = NULL, @@ -163,6 +208,15 @@ getGroupSummary <- function( #' @param ArchRProj An `ArchRProject` object. #' @param select A character vector containing the column names to select from `sampleColData`. #' @param drop A boolean value that indicates whether to drop the `dataframe` structure and convert to a vector if selecting only one column. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Sample Column Data +#' getSampleColData(proj) +#' #' @export getSampleColData <- function( ArchRProj = NULL, @@ -200,6 +254,15 @@ getSampleColData <- function( #' use this argument to only add data to a subset of samples. Samples where `data` is not added are set to `NA`. #' @param force A boolean value that indicates whether or not to overwrite data in a given column when the value passed to `name` #' already exists as a column name in `sampleColData`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Sample Column Data +#' addSampleColData(proj, data = 1, name = "Test", samples = "PBSmall") +#' #' @export addSampleColData <- function(ArchRProj = NULL, data = NULL, name = NULL, samples = NULL, force = FALSE){ @@ -246,6 +309,15 @@ addSampleColData <- function(ArchRProj = NULL, data = NULL, name = NULL, samples #' This function gets the cellNames from a given ArchRProject object. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Cell Names +#' getCellNames(proj) +#' #' @export getCellNames <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = "ArchRProject") @@ -260,6 +332,15 @@ getCellNames <- function(ArchRProj = NULL){ #' @param ArchRProj An `ArchRProject` object. #' @param select A character vector of column names to select from `cellColData` if you would like to subset the returned data. #' @param drop A boolean value that indicates whether to drop the `dataframe` structure and convert to a vector if selecting only one column. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Cell Column Data +#' getCellColData(proj) +#' #' @export getCellColData <- function(ArchRProj = NULL, select = NULL, drop = FALSE){ @@ -299,6 +380,15 @@ getCellColData <- function(ArchRProj = NULL, select = NULL, drop = FALSE){ #' argument to only add data to a subset of cells. Cells where `data` is not added are set to `NA`. #' @param force A boolean value indicating whether or not to overwrite data in a given column when the value passed to `name` #' already exists as a column name in `cellColData`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Cell Column Data +#' addCellColData(proj, data = proj$TSSEnrichment, name = "TSS2", cells = getCellNames(proj)) +#' #' @export addCellColData <- function(ArchRProj = NULL, data = NULL, name = NULL, cells = NULL, force = FALSE){ @@ -351,6 +441,15 @@ addCellColData <- function(ArchRProj = NULL, data = NULL, name = NULL, cells = #' This function gets the peak set as a GRanges object from an ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get PeakSet +#' getPeakSet(proj) +#' #' @export getPeakSet <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = "ArchRProject") @@ -367,6 +466,15 @@ getPeakSet <- function(ArchRProj = NULL){ #' 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`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add PeakSet +#' addPeakSet(proj, peakSet = getPeakSet(proj), force = TRUE) +#' #' @export addPeakSet <- function( ArchRProj = NULL, @@ -391,7 +499,11 @@ addPeakSet <- function( #Get NucleoTide Content peakSet <- tryCatch({ .requirePackage("Biostrings",source="bioc") - BSgenome <- eval(parse(text = genomeAnnotation$genome)) + BSgenome <- tryCatch({ + eval(parse(text = paste0(genomeAnnotation$genome))) + }, error = function(e){ + eval(parse(text = paste0(genomeAnnotation$genome,"::",genomeAnnotation$genome))) + }) BSgenome <- validBSgenome(BSgenome) nucFreq <- BSgenome::alphabetFrequency(getSeq(BSgenome, peakSet)) mcols(peakSet)$GC <- round(rowSums(nucFreq[,c("G","C")]) / rowSums(nucFreq),4) @@ -423,6 +535,18 @@ addPeakSet <- function( #' This function gets the genomeAnnotation from a given ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Genome Annotation in ArchRProj +#' getGenomeAnnotation(proj) +#' +#' # Get Genome Annotation loaded globally +#' getGenomeAnnotation() +#' #' @export getGenomeAnnotation <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProject","null")) @@ -442,6 +566,18 @@ getGenomeAnnotation <- function(ArchRProj = NULL){ #' This function gets the blacklist (the regions to be excluded from analysis) as a GRanges object from the genomeAnnotation of a given ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Blacklist in ArchRProj +#' getBlacklist(proj) +#' +#' # Get Blacklist loaded globally +#' getBlacklist() +#' #' @export getBlacklist <- function(ArchRProj = NULL){ if(is.character(ArchRProj)){ @@ -464,6 +600,18 @@ getBlacklist <- function(ArchRProj = NULL){ #' This function gets the name of the genome from the genomeAnnotation used by a given ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Genome in ArchRProj +#' getGenome(proj) +#' +#' # Get Genome loaded globally +#' getGenome() +#' #' @export getGenome <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProject","null")) @@ -483,6 +631,18 @@ getGenome <- function(ArchRProj = NULL){ #' This function gets the chromosome lengths as a GRanges object from the genomeAnnotation of a given ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get chromSizes in ArchRProj +#' getChromSizes(proj) +#' +#' # Get chromSizes loaded globally +#' getChromSizes() +#' #' @export getChromSizes <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProject","null")) @@ -502,6 +662,18 @@ getChromSizes <- function(ArchRProj = NULL){ #' This function gets the chromosome lengths as a vector from the genomeAnnotation of a given ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get chromLengths in ArchRProj +#' getChromLengths(proj) +#' +#' # Get chromLengths loaded globally +#' getChromLengths() +#' #' @export getChromLengths <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProject","null")) @@ -538,6 +710,18 @@ getChromLengths <- function(ArchRProj = NULL){ #' This function gets the geneAnnotation from a given ArchRProject #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Gene Annotation in ArchRProj +#' getGeneAnnotation(proj) +#' +#' # Get Gene Annotation loaded globally +#' getGeneAnnotation() +#' #' @export getGeneAnnotation <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProject","null")) @@ -557,6 +741,18 @@ getGeneAnnotation <- function(ArchRProj = NULL){ #' This function gets the transcription start sites (TSSs) as a GRanges object of all genes from the geneAnnotation of a given ArchRProject. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get TSS in ArchRProj +#' getTSS(proj) +#' +#' # Get TSS loaded globally +#' getTSS() +#' #' @export getTSS <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProject","null")) @@ -577,6 +773,18 @@ getTSS <- function(ArchRProj = NULL){ #' #' @param ArchRProj An `ArchRProject` object. #' @param symbols A character vector containing the gene symbols to subset from the `geneAnnotation`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Genes in ArchRProj +#' getGenes(proj) +#' +#' # Get Genes globally +#' getGenes() +#' #' @export getGenes <- function(ArchRProj = NULL, symbols = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProject","null")) @@ -616,6 +824,18 @@ getGenes <- function(ArchRProj = NULL, symbols = NULL){ #' #' @param ArchRProj An `ArchRProject` object. #' @param symbols A character vector containing the gene symbols for the genes where exons should be extracted. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Exons in ArchRProj +#' getExons(proj) +#' +#' # Get Exons globally +#' getExons() +#' #' @export getExons <- function(ArchRProj = NULL, symbols = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = c("ArchRProject","null")) @@ -669,6 +889,15 @@ getExons <- function(ArchRProj = NULL, symbols = NULL){ #' `reducedDims` were created by the dimensionality reduction method. This idea was introduced by Timothy Stuart. #' @param corCutOff A numeric cutoff for the correlation of each dimension to the sequencing depth. If the dimension has a correlation #' to sequencing depth that is greater than the `corCutOff`, it will be excluded. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Iterative LSI +#' getReducedDims(proj, reducedDims = "IterativeLSI") +#' #' @export getReducedDims <- function( ArchRProj = NULL, @@ -714,7 +943,7 @@ getReducedDims <- function( #Determine PCs to Keep if(!is.null(dimsToUse)){ - corToUse <- dimsToUse + corToUse <- intersect(dimsToUse, seq_along(corToDepth)) }else{ corToUse <- seq_along(corToDepth) } @@ -766,6 +995,15 @@ getReducedDims <- function( #' retrieve from the designated `ArchRProject`. #' @param returnDF A boolean value indicating whether to return the embedding object as a `data.frame`. Otherwise, it will return #' the full embedding object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get UMAP +#' getEmbedding(proj, embedding = "UMAP") +#' #' @export getEmbedding <- function(ArchRProj = NULL, embedding = "UMAP", returnDF = TRUE){ @@ -797,6 +1035,15 @@ getEmbedding <- function(ArchRProj = NULL, embedding = "UMAP", returnDF = TRUE){ #' #' @param ArchRProj An `ArchRProject` object. #' @param returnSummary A boolean value indicating whether to return a summary of the `ArchRProject` or to just print the summary. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Project Summary +#' getProjectSummary(proj) +#' #' @export getProjectSummary <- function(ArchRProj = NULL, returnSummary = FALSE){ @@ -827,6 +1074,15 @@ getProjectSummary <- function(ArchRProj = NULL, returnSummary = FALSE){ #' @param ArchRProj An `ArchRProject` object. #' @param name The name of the summary information to add to the `ArchRProject` object. #' @param summary A vector to add as summary information to the `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Project Summary +#' addProjectSummary(proj, name = "test", summary = "test successful") +#' #' @export addProjectSummary <- function(ArchRProj = NULL, name = NULL, summary = NULL){ @@ -858,6 +1114,15 @@ addProjectSummary <- function(ArchRProj = NULL, name = NULL, summary = NULL){ #' @param useMatrix The name of the data matrix as stored in the ArrowFiles of the `ArchRProject`. Options include "TileMatrix", "GeneScoreMatrix", etc. #' @param select A string specifying a specific feature name (or rowname) to be found with `grep`. #' @param ignoreCase A boolean value indicating whether to ignore the case (upper-case / lower-case) when searching via grep for the string passed to `select`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Features +#' getFeatures(proj, useMatrix = "GeneScoreMatrix", select = 'CD3') +#' #' @export getFeatures <- function(ArchRProj = NULL, useMatrix = "GeneScoreMatrix", select = NULL, ignoreCase = TRUE){ @@ -896,6 +1161,15 @@ getFeatures <- function(ArchRProj = NULL, useMatrix = "GeneScoreMatrix", select #' #' @param ArchRProj An `ArchRProject` object. #' @param useMatrix The name of the data matrix as stored in the ArrowFiles of the `ArchRProject`. Options include "TileMatrix", "GeneScoreMatrix", etc. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Seqnames in Matrix +#' getSeqnames(proj, useMatrix = "GeneScoreMatrix") +#' #' @export getSeqnames <- function(ArchRProj = NULL, useMatrix = "GeneScoreMatrix"){ #Validate @@ -911,6 +1185,15 @@ getSeqnames <- function(ArchRProj = NULL, useMatrix = "GeneScoreMatrix"){ #' This function gets the available matrices from the ArrowFiles in a given ArchRProject object. #' #' @param ArchRProj An `ArchRProject` object. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Get Available Matrices in ArchR Project +#' getAvailableMatrices(proj) +#' #' @export getAvailableMatrices <- function(ArchRProj = NULL){ .validInput(input = ArchRProj, name = "ArchRProj", valid = "ArchRProject") @@ -927,6 +1210,15 @@ getAvailableMatrices <- function(ArchRProj = NULL){ #' @param addRatio A boolean indicating whether to add the "`name`Ratio" to the `ArchRProject`. #' @param threads The number of threads to use for parallel execution. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Feature Counts +#' proj <- addFeatureCounts(proj, features = getPeakSet(proj), name = 'ReadsInPeaks') +#' #' @export addFeatureCounts <- function( ArchRProj = NULL, @@ -1018,19 +1310,3 @@ addFeatureCounts <- function( ArchRProj } - - -# addColorPalette <- function( -# ArchRProj = NULL, -# pal = NULL -# ){ - -# } - -# getColorPalette <- function( -# ArchRProj = NULL, -# name = NULL -# ){ - -# } - diff --git a/R/QualityControl.R b/R/QualityControl.R index 10d2c081..e691cb42 100644 --- a/R/QualityControl.R +++ b/R/QualityControl.R @@ -17,6 +17,18 @@ #' instead of plotting the TSS enrichment plot. #' @param threads An integer specifying the number of threads to use for calculation. By default this uses the number of threads set by `addArchRThreads()`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Plot TSS +#' p <- plotTSSEnrichment(proj, groupBy = "Clusters") +#' +#' # PDF +#' plotPDF(p, name = "TSS-Enrich", ArchRProj = proj) +#' #' @export plotTSSEnrichment <- function( ArchRProj = NULL, @@ -181,6 +193,18 @@ plotTSSEnrichment <- function( #' instead of plotting the fragment size distribution. #' @param threads An integer specifying the number of threads to use for calculation. By default this uses the number of threads set by `addArchRThreads()`. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Plot Frag Sizes +#' p <- plotFragmentSizes(proj, groupBy = "Clusters") +#' +#' # PDF +#' plotPDF(p, name = "Frag-Sizes", ArchRProj = proj) +#' #' @export plotFragmentSizes <- function( ArchRProj = NULL, diff --git a/R/RNAIntegration.R b/R/RNAIntegration.R index 75e2e82a..1a2826a7 100644 --- a/R/RNAIntegration.R +++ b/R/RNAIntegration.R @@ -54,6 +54,34 @@ #' @param force A boolean value indicating whether to force the matrix indicated by `matrixName` to be overwritten if it already exists in the given `input`. #' @param logFile The path to a file to be used for logging ArchR output. #' @param ... Additional params to be added to `Seurat::FindTransferAnchors` +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' #Get RNA Matrix +#' sePBMC <- readRDS( +#' file.path(system.file("testdata", package = "ArchR"), "seRNA_PBMC.rds") +#' ) +#' +#' #Gene Integration Matrix +#' proj <- addGeneIntegrationMatrix( +#' ArchRProj = proj, +#' useMatrix = "GeneScoreMatrix", +#' matrixName = "GeneIntegrationMatrix", +#' reducedDims = "IterativeLSI", +#' seRNA = sePBMC, +#' addToArrow = FALSE, +#' groupRNA = "CellType", +#' nameCell = "predictedCell_Un2", +#' nameGroup = "predictedGroup_Un2", +#' nameScore = "predictedScore_Un2", +#' dimsToUse = 1:10, +#' nGenes = 250, +#' force = TRUE +#' ) +#' #' @export addGeneIntegrationMatrix <- function( ArchRProj = NULL, @@ -566,16 +594,16 @@ addGeneIntegrationMatrix <- function( #Create Data Set o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,"/i"), storage.mode = "integer", - dims = c(lengthI, 1), level = 0)) + dims = c(lengthI, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,"/jLengths"), storage.mode = "integer", - dims = c(lengthRle, 1), level = 0)) + dims = c(lengthRle, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,"/jValues"), storage.mode = "integer", - dims = c(lengthRle, 1), level = 0)) + dims = c(lengthRle, 1), level = getArchRH5Level())) o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group, "/x"), storage.mode = "double", - dims = c(lengthI, 1), level = 0)) + dims = c(lengthI, 1), level = getArchRH5Level())) #Write Data Set o <- .suppressAll(h5write(obj = mat@i + 1, file = tmpFilei, name = paste0(Group,"/i"))) diff --git a/R/ReproduciblePeakSet.R b/R/ReproduciblePeakSet.R index 3bb1819b..ba590470 100644 --- a/R/ReproduciblePeakSet.R +++ b/R/ReproduciblePeakSet.R @@ -45,6 +45,18 @@ #' @param logFile The path to a file to be used for logging ArchR output. #' @param ... Additional parameters to be pass to `addGroupCoverages()` to get sample-guided pseudobulk cell-groupings. Only used for TileMatrix-based #' peak calling (not for MACS2). See `addGroupCoverages()` for more info. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Add Peak Matrix Tiles +#' proj <- addReproduciblePeakSet(proj, peakMethod = "tiles") +#' +#' # Add Peak Matrix Macs2 (Preferred) +#' proj <- addReproduciblePeakSet(proj, peakMethod = "macs2") +#' #' @export addReproduciblePeakSet <- function( ArchRProj = NULL, @@ -66,7 +78,7 @@ addReproduciblePeakSet <- function( promoterRegion = c(2000, 100), genomeAnnotation = getGenomeAnnotation(ArchRProj), geneAnnotation = getGeneAnnotation(ArchRProj), - plot = TRUE, + plot = TRUE, threads = getArchRThreads(), parallelParam = NULL, force = FALSE, @@ -103,7 +115,7 @@ addReproduciblePeakSet <- function( geneAnnotation <- .validGeneAnnotation(geneAnnotation) genomeAnnotation <- .validGenomeAnnotation(genomeAnnotation) geneAnnotation <- .validGeneAnnoByGenomeAnno(geneAnnotation = geneAnnotation, genomeAnnotation = genomeAnnotation) - .validInput(input = plot, name = "plot", valid = c("boolean")) + .validInput(input = plot, name = "plot", valid = c("boolean")) .validInput(input = threads, name = "threads", valid = c("integer")) .validInput(input = parallelParam, name = "parallelParam", valid = c("parallelparam", "null")) .validInput(input = force, name = "force", valid = c("boolean")) @@ -112,7 +124,17 @@ addReproduciblePeakSet <- function( tstart <- Sys.time() .startLogging(logFile = logFile) - .logThis(mget(names(formals()),sys.frame(sys.nframe())), "ReproduciblePeakSet Args", logFile=logFile) + .logThis(mget(names(formals()),sys.frame(sys.nframe())), "ReproduciblePeakSet Args", logFile=logFile) + + ##################################################### + # Create Output Directory + ##################################################### + outDir <- file.path(getOutputDirectory(ArchRProj), "PeakCalls") + outSubDir <- file.path(getOutputDirectory(ArchRProj), "PeakCalls", "ReplicateCalls") + outBedDir <- file.path(getOutputDirectory(ArchRProj), "PeakCalls", "InsertionBeds") + dir.create(outDir, showWarnings = FALSE) + dir.create(outSubDir, showWarnings = FALSE) + dir.create(outBedDir, showWarnings = FALSE) if(tolower(peakMethod) == "macs2"){ @@ -148,16 +170,6 @@ addReproduciblePeakSet <- function( .logThis(groupSummary, "PeakCallSummary", logFile = logFile) if(verbose) print(groupSummary) - ##################################################### - # Create Output Directory - ##################################################### - outDir <- file.path(getOutputDirectory(ArchRProj), "PeakCalls") - outSubDir <- file.path(getOutputDirectory(ArchRProj), "PeakCalls", "ReplicateCalls") - outBedDir <- file.path(getOutputDirectory(ArchRProj), "PeakCalls", "InsertionBeds") - dir.create(outDir, showWarnings = FALSE) - dir.create(outSubDir, showWarnings = FALSE) - dir.create(outBedDir, showWarnings = FALSE) - ##################################################### # Genome Size Presets ##################################################### @@ -228,10 +240,10 @@ addReproduciblePeakSet <- function( summitFiles = outSummitList[[i]], summitNames = summitNamesList[[i]], reproducibility = reproducibility, - extendSummits = extendSummits, - blacklist = genomeAnnotation$blacklist, - prefix = prefix, - logFile = logFile + extendSummits = extendSummits, + blacklist = genomeAnnotation$blacklist, + prefix = prefix, + logFile = logFile )) .logDiffTime(sprintf("%s Annotating and Filtering Peaks", prefix), tstart, verbose = FALSE, logFile = logFile) peaks <- sort(sortSeqlevels(peaks)) @@ -813,6 +825,11 @@ addReproduciblePeakSet <- function( #' Find the installed location of the MACS2 executable #' #' This function attempts to find the path to the MACS2 executable by serting the path and python's pip. +#' +#' @examples +#' +#' # Get Macs2 +#' findMacs2() #' #' @export findMacs2 <- function(){ diff --git a/R/Trajectory.R b/R/Trajectory.R index ceee126d..d6936b71 100644 --- a/R/Trajectory.R +++ b/R/Trajectory.R @@ -26,6 +26,15 @@ #' @param force A boolean value indicating whether to force the trajactory indicated by `name` to be overwritten if it already exists in the given `ArchRProject`. #' @param seed A number to be used as the seed for random number generation for trajectory creation. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Add Trajectory +#' proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) +#' #' @export addTrajectory <- function( ArchRProj = NULL, @@ -138,23 +147,25 @@ addTrajectory <- function( ###################################################### .logMessage("Spline Fit", logFile = logFile) matSpline <- lapply(seq_len(ncol(matFilter)), function(x){ - tryCatch({ - stats::smooth.spline( + suppressWarnings( + tryCatch({ + stats::smooth.spline( + x = initialTime, + y = matFilter[names(initialTime), x], + df = dof, + spar = spar + )[[2]] + }, error = function(e){ + errorList <- list( + it = x, x = initialTime, y = matFilter[names(initialTime), x], df = dof, spar = spar - )[[2]] - }, error = function(e){ - errorList <- list( - it = x, - x = initialTime, - y = matFilter[names(initialTime), x], - df = dof, - spar = spar - ) - .logError(e, fn = "smooth.spline", info = "", errorList = errorList, logFile = logFile) - }) + ) + .logError(e, fn = "smooth.spline", info = "", errorList = errorList, logFile = logFile) + }) + ) }) %>% Reduce("cbind",.) %>% data.frame() ###################################################### @@ -262,6 +273,18 @@ addTrajectory <- function( #' @param smoothWindow An integer value indicating the smoothing window in size (relaive to `groupEvery`) for the sequential #' trajectory matrix to better reveal temporal dynamics. #' @param threads The number of threads to be used for parallel computing. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Add Trajectory +#' proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) +#' +#' #Get Trajectory +#' seTraj <- getTrajectory(proj) +#' #' @export getTrajectory <- function( ArchRProj = NULL, @@ -418,6 +441,24 @@ trajectoryHeatmap <- function(...){ #' @param force If useSeqnames is longer than 1 if matrixClass is "Sparse.Assays.Matrix" to continue. This is not recommended because these matrices #' can be in different units. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Add Trajectory +#' proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) +#' +#' #Get Trajectory +#' seTraj <- getTrajectory(proj) +#' +#' #Plot Trajectory Heatmap +#' p <- plotTrajectoryHeatmap(seTraj) +#' +#' #Plot PDF +#' plotPDF(p, name = "Trajectory-Heatmap", ArchRProj = proj) +#' #' @export plotTrajectoryHeatmap <- function( seTrajectory = NULL, @@ -649,6 +690,21 @@ plotTrajectoryHeatmap <- function( #' @param smoothWindow An integer value indicating the smoothing window for creating inferred Arrow overlay on to embedding. #' @param logFile The path to a file to be used for logging ArchR output. #' @param ... Additional parameters to pass to `ggPoint()` or `ggHex()`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Add Trajectory +#' proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) +#' +#' #Plot Trajectory +#' p <- plotTrajectory(proj, smoothWindow = 20) +#' +#' #PDF +#' plotPDF(p, name = "Trajcetory", ArchRProj = proj) +#' #' @export plotTrajectory <- function( ArchRProj = NULL, @@ -850,11 +906,11 @@ plotTrajectory <- function( } message("Plotting") .logThis(plotParams, name = "PlotParams", logFile = logFile) - out <- do.call(ggHex, plotParams) + out <- suppressWarnings(do.call(ggHex, plotParams)) }else{ message("Plotting") .logThis(plotParams, name = "PlotParams", logFile = logFile) - out <- do.call(ggPoint, plotParams) + out <- suppressWarnings(do.call(ggPoint, plotParams)) } }else{ @@ -864,7 +920,8 @@ plotTrajectory <- function( } if(!keepAxis){ - out <- out + theme(axis.text.x=element_blank(), axis.ticks.x=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) + out <- out + theme(axis.text.x=element_blank(), axis.ticks.x=element_blank(), + axis.text.y=element_blank(), axis.ticks.y=element_blank()) } .logMessage("Plotting Trajectory", logFile = logFile) @@ -877,7 +934,7 @@ plotTrajectory <- function( .logThis(dfT, "TrajectoryDF", logFile = logFile) #Plot Pseudo-Time - out2 <- ggPoint( + out2 <- suppressWarnings(ggPoint( x = dfT$PseudoTime, y = dfT$value, color = dfT$PseudoTime, @@ -887,7 +944,7 @@ plotTrajectory <- function( pal = plotParams$pal, ratioYX = 0.5, rastr = TRUE - ) + geom_smooth(color = "black") + ) + geom_smooth(color = "black")) attr(out2, "ratioYX") <- 0.5 @@ -943,6 +1000,21 @@ plotTrajectory <- function( #' @param clusterParams A list of parameters to be added when clustering cells for monocle3 with `monocle3::cluster_cells`. #' @param graphParams A list of parameters to be added when learning graphs for monocle3 with `monocle3::learn_graph`. #' @param seed A number to be used as the seed for random number generation for trajectory creation. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Create Monocole Trajectory +#' cds <- getMonocleTrajectories( +#' ArchRProj = proj, +#' useGroups = c("C1", "C2", "C3"), +#' principalGroup = "C1", +#' groupBy = "Clusters", +#' embedding = "UMAP" +#' ) +#' #' @export getMonocleTrajectories <- function( ArchRProj = NULL, @@ -966,7 +1038,7 @@ getMonocleTrajectories <- function( .validInput(input = graphParams, name = "graphParams", valid = c("list")) .validInput(input = seed, name = "seed", valid = c("numeric")) - .requirePackage("monocle3") + .requirePackage("monocle3", installInfo = "devtools::install_github('cole-trapnell-lab/monocle3')") set.seed(seed) @@ -1019,7 +1091,7 @@ getMonocleTrajectories <- function( message("Learning Graphs") graphParams$cds <- cds - cds <- do.call(monocle3::learn_graph, graphParams) + cds <- suppressWarnings(do.call(monocle3::learn_graph, graphParams)) rm(graphParams) gc() @@ -1059,7 +1131,7 @@ getMonocleTrajectories <- function( theme(axis.text.x = element_blank(), axis.ticks.x = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank()) - + dir.create(file.path(getOutputDirectory(ArchRProj), "Monocole3"), showWarnings=FALSE) path <- file.path(getOutputDirectory(ArchRProj), "Monocole3", paste0("Plot-Results-", name, ".pdf")) message("Plotting Results - ", path) @@ -1084,6 +1156,29 @@ getMonocleTrajectories <- function( #' `useGroups` to constrain trajectory analysis. #' @param monocleCDS A monocle CDS object created from `getMonocleTrajectories`. #' @param force A boolean value indicating whether to force the trajactory indicated by `name` to be overwritten if it already exists in the given `ArchRProject`. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Create Monocole Trajectory +#' cds <- getMonocleTrajectories( +#' ArchRProj = proj, +#' useGroups = c("C1", "C2", "C3"), +#' principalGroup = "C1", +#' groupBy = "Clusters", +#' embedding = "UMAP" +#' ) +#' +#' # Add Monocole Trajectory +#' proj <- addMonocleTrajectory( +#' ArchRProj = proj, +#' name = "Trajectory_Monocole", +#' useGroups = c("C1", "C2", "C3"), +#' monocleCDS = cds +#' ) +#' #' @export addMonocleTrajectory <- function( ArchRProj = NULL, @@ -1146,6 +1241,22 @@ addMonocleTrajectory <- function( #' @param reducedDims A string indicating the name of the `reducedDims` object from the `ArchRProject` that should be used for trajectory analysis. `embedding` must equal NULL to use. #' @param force A boolean value indicating whether to force the trajactory indicated by `name` to be overwritten if it already exists in the given `ArchRProject`. #' @param seed A number to be used as the seed for random number generation for trajectory creation. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' #Add SlingShot Trajectory +#' proj <- addSlingShotTrajectories( +#' ArchRProj = proj, +#' name = "Trajectory_SlingShot", +#' useGroups = c("C1", "C2", "C3"), +#' principalGroup = "C1", +#' groupBy = "Clusters", +#' embedding = "UMAP" +#' ) +#' #' @export addSlingShotTrajectories <- function( ArchRProj = NULL, @@ -1169,7 +1280,7 @@ addSlingShotTrajectories <- function( .validInput(input = force, name = "force", valid = c("boolean")) .validInput(input = seed, name = "seed", valid = c("numeric")) - .requirePackage("slingshot") + .requirePackage("slingshot", installInfo = "BiocManager::install('slingshot')") set.seed(seed) @@ -1229,6 +1340,15 @@ addSlingShotTrajectories <- function( #' @param verbose A boolean value indicating whether to use verbose output during execution of this function. Can be set to FALSE for a cleaner output. #' @param binarize A boolean value indicating whether the matrix should be binarized before return. This is often desired when working with insertion counts. #' @param logFile The path to a file to be used for logging ArchR output. +#' +#' @examples +#' +#' # Get Test ArchR Project +#' proj <- getTestProject() +#' +#' # Export Matrix For Stream +#' exportPeakMatrixForSTREAM(proj) +#' #' @export exportPeakMatrixForSTREAM <- function( ArchRProj = NULL, @@ -1249,12 +1369,8 @@ exportPeakMatrixForSTREAM <- function( logFile = logFile ) - featureDF <- ArchR:::.getFeatureDF(getArrowFiles(ArchRProj)[1], "PeakMatrix") - - stopifnot(all(featureDF$idx == rowData(mat)$idx)) - countsDF <- Matrix::summary(assay(mat)) - peaksDF <- data.frame(as.vector(featureDF[,1]), featureDF[,3], featureDF[,4]) + peaksDF <- data.frame(rowRanges(mat))[,1:3] cellsDF <- data.frame(colnames(mat)) data.table::fwrite(countsDF, file = "STREAM_Counts.tsv.gz", sep = "\t", row.names = FALSE, col.names = FALSE) diff --git a/R/ValidationUtils.R b/R/ValidationUtils.R index 3daeeabe..335eab96 100644 --- a/R/ValidationUtils.R +++ b/R/ValidationUtils.R @@ -225,7 +225,11 @@ validBSgenome <- function(genome = NULL, masked = FALSE){ }else if(is.character(genome)){ genome <- tryCatch({ .requirePackage(genome) - bsg <- eval(parse(text = genome)) + bsg <- tryCatch({ + eval(parse(text = paste0(genome))) + }, error = function(e){ + eval(parse(text = paste0(genome,"::",genome))) + }) if(inherits(bsg, "BSgenome")){ return(bsg) }else{ diff --git a/R/VisualizeData.R b/R/VisualizeData.R index e9e327ba..90525078 100644 --- a/R/VisualizeData.R +++ b/R/VisualizeData.R @@ -17,6 +17,18 @@ #' @param useDingbats A boolean variable that determines wheter to use dingbats characters for plotting points. #' @param plotList A `list` of plots to be printed to the output PDF file. Each element of `plotList` should be a printable plot formatted #' object (ggplot2, plot, heatmap, etc). +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' #Plot UMAP +#' p <- plotEmbedding(proj, name = "Clusters") +#' +#' #PDF +#' plotPDF(p, name = "UMAP-Clusters", ArchRProj = proj) +#' #' @export plotPDF <- function( ..., @@ -86,7 +98,7 @@ plotPDF <- function( filename <- file.path(outDir, paste0(name, ".pdf")) } - o <- tryCatch({ + o <- suppressWarnings(tryCatch({ pdf(filename, width = width, height = height, useDingbats = useDingbats) for(i in seq_along(plotList)){ @@ -149,7 +161,7 @@ plotPDF <- function( if(getArchRVerbose()) message(x) - }) + })) return(invisible(0)) @@ -201,6 +213,18 @@ plotPDF <- function( #' @param threads The number of threads to be used for parallel computing. #' @param logFile The path to a file to be used for logging ArchR output. #' @param ... Additional parameters to pass to `ggPoint()` or `ggHex()`. +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' #Plot UMAP +#' p <- plotEmbedding(proj, name = "Clusters") +#' +#' #PDF +#' plotPDF(p, name = "UMAP-Clusters", ArchRProj = proj) +#' #' @export plotEmbedding <- function( ArchRProj = NULL, @@ -530,6 +554,18 @@ plotEmbedding <- function( #' @param plotAs A string that indicates whether a rigdge plot ("ridges") should be plotted or a violin plot ("violin") should be plotted. #' @param threads The number of threads to be used for parallel computing. #' @param ... Additional parameters to pass to `ggGroup()`. +#' +#' @examples +#' +#' #Get Test Project +#' proj <- getTestProject() +#' +#' #Plot Groups +#' p <- plotGroups(proj, groupBy = "Clusters", colorBy = "colData", name = "TSSEnrichment", plotAs = "violin", alpha = 0.5) +#' +#' #PDF +#' plotPDF(p, name = "Clusters-TSS", ArchRProj = proj) +#' #' @export plotGroups <- function( ArchRProj = NULL, @@ -946,7 +982,7 @@ plotGroups <- function( legend.spacing.x = unit(0, 'cm'), legend.spacing.y = unit(0, 'cm'), legend.text = element_text(size = max(size, 2)) - ) + guides(fill = guide_legend(ncol = 4), color = guide_legend(ncol = 4)) + ) + .gg_guides(fill = guide_legend(ncol = 4), color = guide_legend(ncol = 4)) )$grobs[[legend]] slh <- convertHeight( diff --git a/data/.DS_Store b/data/.DS_Store index 5008ddfc..7130d9d0 100644 Binary files a/data/.DS_Store and b/data/.DS_Store differ diff --git a/data/geneAnnoHg19test2.rda b/data/geneAnnoHg19test2.rda index 1a9f8b84..ef66d413 100644 Binary files a/data/geneAnnoHg19test2.rda and b/data/geneAnnoHg19test2.rda differ diff --git a/data/genomeAnnoHg19test2.rda b/data/genomeAnnoHg19test2.rda index 5b4fce13..f0104434 100644 Binary files a/data/genomeAnnoHg19test2.rda and b/data/genomeAnnoHg19test2.rda differ diff --git a/data/m1.rda b/data/m1.rda new file mode 100644 index 00000000..fbfe2577 Binary files /dev/null and b/data/m1.rda differ diff --git a/docs/.DS_Store b/docs/.DS_Store index a0589a20..501f46e3 100644 Binary files a/docs/.DS_Store and b/docs/.DS_Store differ diff --git a/docs/articles/.DS_Store b/docs/articles/.DS_Store index 4a2be0f2..48fc8ecd 100644 Binary files a/docs/articles/.DS_Store and b/docs/articles/.DS_Store differ diff --git a/inst/testdata/PBSmall.arrow b/inst/testdata/PBSmall.arrow new file mode 100644 index 00000000..b22f61fa Binary files /dev/null and b/inst/testdata/PBSmall.arrow differ diff --git a/inst/testdata/PBSmall.tsv.gz b/inst/testdata/PBSmall.tsv.gz new file mode 100644 index 00000000..e82006d5 Binary files /dev/null and b/inst/testdata/PBSmall.tsv.gz differ diff --git a/inst/testdata/PBSmall.tsv.gz.tbi b/inst/testdata/PBSmall.tsv.gz.tbi new file mode 100644 index 00000000..dc7b622c Binary files /dev/null and b/inst/testdata/PBSmall.tsv.gz.tbi differ diff --git a/inst/testdata/PBSmall.zip b/inst/testdata/PBSmall.zip new file mode 100644 index 00000000..6e26590e Binary files /dev/null and b/inst/testdata/PBSmall.zip differ diff --git a/inst/testdata/seRNA_PBMC.rds b/inst/testdata/seRNA_PBMC.rds new file mode 100644 index 00000000..945b5814 Binary files /dev/null and b/inst/testdata/seRNA_PBMC.rds differ diff --git a/man/.DS_Store b/man/.DS_Store index 5008ddfc..cbaf200f 100644 Binary files a/man/.DS_Store and b/man/.DS_Store differ diff --git a/man/ArchRBrowser.Rd b/man/ArchRBrowser.Rd index bbe9fa5e..de4eac18 100644 --- a/man/ArchRBrowser.Rd +++ b/man/ArchRBrowser.Rd @@ -58,3 +58,10 @@ This function will open an interactive shiny session in style of a browser track enables direct comparison across samples. Note that the genes displayed in this browser are derived from your \code{geneAnnotation} (i.e. the \code{BSgenome} object you used) so they may not match other online genome browsers that use different gene annotations. } +\examples{ + +proj <- getTestProject() + +#Launch Browser with `ArchRBrowser(proj)` + +} diff --git a/man/ArchRProject.Rd b/man/ArchRProject.Rd index 931a246e..791be003 100644 --- a/man/ArchRProject.Rd +++ b/man/ArchRProject.Rd @@ -34,3 +34,12 @@ genome information such as nucleotide information or chromosome sizes.} \description{ This function will create an ArchRProject from the provided ArrowFiles. } +\examples{ + +# Get Test Arrow +arrow <- getTestArrow() + +# Create ArchR Project for Analysis +proj <- ArchRProject(arrow) + +} diff --git a/man/addArchRAnnotations.Rd b/man/addArchRAnnotations.Rd index 3c69569e..508f5db6 100644 --- a/man/addArchRAnnotations.Rd +++ b/man/addArchRAnnotations.Rd @@ -35,3 +35,12 @@ overwritten if it already exists in the given \code{ArchRProject}.} This function adds information about which peaks in the ArchR database contain input regions to a given ArchRProject. For each peak, a binary value is stored indicating whether each region is observed within the peak region. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Motif Annotations +proj <- addArchRAnnotations(proj, name = "test") + +} diff --git a/man/addArchRChrPrefix.Rd b/man/addArchRChrPrefix.Rd index d192f5a5..5748e41d 100644 --- a/man/addArchRChrPrefix.Rd +++ b/man/addArchRChrPrefix.Rd @@ -12,3 +12,9 @@ addArchRChrPrefix(chrPrefix = TRUE) \description{ This function will set the default requirement of chromosomes to have a "chr" prefix. } +\examples{ + +# Add ArchR Chr Prefix +addArchRChrPrefix() + +} diff --git a/man/addArchRDebugging.Rd b/man/addArchRDebugging.Rd index 811a6b42..38695c29 100644 --- a/man/addArchRDebugging.Rd +++ b/man/addArchRDebugging.Rd @@ -12,3 +12,9 @@ addArchRDebugging(debug = FALSE) \description{ This function will set ArchR Debugging which will save an RDS if an error is encountered. } +\examples{ + +# Add ArchR Debugging +addArchRDebugging() + +} diff --git a/man/addArchRGenome.Rd b/man/addArchRGenome.Rd index 152a7e25..5f661e0b 100644 --- a/man/addArchRGenome.Rd +++ b/man/addArchRGenome.Rd @@ -19,3 +19,9 @@ automatically installed if it is not currently installed. This is useful for hel \description{ This function will set the genome across all ArchR functions. } +\examples{ + +# Add ArchR Genome to use globally +addArchRGenome("hg19test2") + +} diff --git a/man/addArchRH5Level.Rd b/man/addArchRH5Level.Rd new file mode 100644 index 00000000..0b667b7c --- /dev/null +++ b/man/addArchRH5Level.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/GlobalDefaults.R +\name{addArchRH5Level} +\alias{addArchRH5Level} +\title{Add a globally-applied compression level for h5 files} +\usage{ +addArchRH5Level(level = 0) +} +\arguments{ +\item{level}{The default compression level to be used for h5 file execution across all ArchR functions.} +} +\description{ +This function will set the default compression level to be used for h5 file execution across all ArchR functions. +} +\examples{ + +# Add ArchR H5 Compression level +addArchRH5Level() + +} diff --git a/man/addArchRLocking.Rd b/man/addArchRLocking.Rd index bb69350e..3ac07801 100644 --- a/man/addArchRLocking.Rd +++ b/man/addArchRLocking.Rd @@ -12,3 +12,9 @@ addArchRLocking(locking = FALSE) \description{ This function will set the default H5 file locking parameters } +\examples{ + +# Disable/Add ArchR H5 Locking Globally +addArchRLocking(locking=FALSE) + +} diff --git a/man/addArchRLogging.Rd b/man/addArchRLogging.Rd index b72349fa..f4514fc7 100644 --- a/man/addArchRLogging.Rd +++ b/man/addArchRLogging.Rd @@ -12,3 +12,9 @@ addArchRLogging(useLogs = TRUE) \description{ This function will set ArchR logging } +\examples{ + +# Add ArchR Logging +addArchRLogging() + +} diff --git a/man/addArchRThreads.Rd b/man/addArchRThreads.Rd index ab93e8f5..4c2b6779 100644 --- a/man/addArchRThreads.Rd +++ b/man/addArchRThreads.Rd @@ -17,3 +17,9 @@ To bypass this, setting \code{force = TRUE} will use the number provided to \cod \description{ This function will set the number of threads to be used for parallel computing across all ArchR functions. } +\examples{ + +# Add ArchR Threads +addArchRThreads() + +} diff --git a/man/addArchRVerbose.Rd b/man/addArchRVerbose.Rd index dadc3508..5676708b 100644 --- a/man/addArchRVerbose.Rd +++ b/man/addArchRVerbose.Rd @@ -12,3 +12,9 @@ addArchRVerbose(verbose = TRUE) \description{ This function will set ArchR logging verbosity. } +\examples{ + +# Add ArchR Verbose +addArchRVerbose() + +} diff --git a/man/addBgdPeaks.Rd b/man/addBgdPeaks.Rd index 1a2c4c37..3e991fce 100644 --- a/man/addBgdPeaks.Rd +++ b/man/addBgdPeaks.Rd @@ -37,3 +37,12 @@ is to save this file in the \code{outputDirectory} of the \code{ArchRProject}.} \description{ This function will compute background peaks controlling for total accessibility and GC-content and add this information to an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Background Peaks +proj <- addBgdPeaks(proj, force = TRUE) + +} diff --git a/man/addCellColData.Rd b/man/addCellColData.Rd index f37a47e3..019a08a8 100644 --- a/man/addCellColData.Rd +++ b/man/addCellColData.Rd @@ -29,3 +29,12 @@ already exists as a column name in \code{cellColData}.} \description{ This function adds new data to cellColData in a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Cell Column Data +addCellColData(proj, data = proj$TSSEnrichment, name = "TSS2", cells = getCellNames(proj)) + +} diff --git a/man/addClusters.Rd b/man/addClusters.Rd index f9b78ebc..f9b96e44 100644 --- a/man/addClusters.Rd +++ b/man/addClusters.Rd @@ -114,3 +114,12 @@ exists as a column name in \code{cellColData}.} \description{ This function will identify clusters from a reduced dimensions object in an ArchRProject or from a supplied reduced dimensions matrix. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Peak Annotations +proj <- addClusters(proj, force = TRUE) + +} diff --git a/man/addCoAccessibility.Rd b/man/addCoAccessibility.Rd index 881e697f..7277e5c4 100644 --- a/man/addCoAccessibility.Rd +++ b/man/addCoAccessibility.Rd @@ -66,3 +66,12 @@ of the seed used so that you can reproduce results downstream.} \description{ This function will add co-accessibility scores to peaks in a given ArchRProject } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Co-Accessibility +proj <- addCoAccessibility(proj, k = 20) + +} diff --git a/man/addDeviationsMatrix.Rd b/man/addDeviationsMatrix.Rd index 054260c2..aeff4fc3 100644 --- a/man/addDeviationsMatrix.Rd +++ b/man/addDeviationsMatrix.Rd @@ -52,3 +52,19 @@ already exists in the ArrowFiles associated with the given \code{ArchRProject}.} \description{ This function will compute peakAnnotation deviations for each ArrowFiles independently while controlling for global biases (low-memory requirement). } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Background Peaks +proj <- addBgdPeaks(proj, force = TRUE) + +# Add Motif Deviations +proj <- addDeviationsMatrix( + ArchRProj = proj, + peakAnnotation = "Motif", + force = TRUE +) + +} diff --git a/man/addDoubletScores.Rd b/man/addDoubletScores.Rd index 2d1e5bef..c7c03e25 100644 --- a/man/addDoubletScores.Rd +++ b/man/addDoubletScores.Rd @@ -71,3 +71,12 @@ For each sample in the ArrowFiles or ArchRProject provided, this function will i to each cell. This allows for removing strong heterotypic doublet-based clusters downstream. A doublet results from a droplet that contained two cells, causing the ATAC-seq data to be a mixture of the signal from each cell. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Doublet Scores for Small Project +proj <- addDoubletScores(proj, dimsToUse = 1:5, LSIParams = list(dimsToUse = 1:5, varFeatures=1000, iterations = 2)) + +} diff --git a/man/addFeatureCounts.Rd b/man/addFeatureCounts.Rd index 93ea8082..dc80932c 100644 --- a/man/addFeatureCounts.Rd +++ b/man/addFeatureCounts.Rd @@ -29,3 +29,12 @@ addFeatureCounts( \description{ This function will add total counts of scATAC cells in provided features into ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Feature Counts +proj <- addFeatureCounts(proj, features = getPeakSet(proj), name = 'ReadsInPeaks') + +} diff --git a/man/addFeatureMatrix.Rd b/man/addFeatureMatrix.Rd index 17b876ed..10627baf 100644 --- a/man/addFeatureMatrix.Rd +++ b/man/addFeatureMatrix.Rd @@ -42,3 +42,12 @@ downstream analyses when working with insertion counts.} \description{ This function for each sample will independently compute counts for each feature per cell in the provided ArchRProject or set of ArrowFiles. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Custom Matrix Which Is Just Peak Set +proj <- addFeatureMatrix(proj, features = getPeakSet(proj)) + +} diff --git a/man/addGeneIntegrationMatrix.Rd b/man/addGeneIntegrationMatrix.Rd index dba7957d..722c1561 100644 --- a/man/addGeneIntegrationMatrix.Rd +++ b/man/addGeneIntegrationMatrix.Rd @@ -124,3 +124,31 @@ the assignment accuracy of the group in the RNA cells. Lower scores represent am This function, will integrate multiple subsets of scATAC cells with a scRNA experiment, compute matched scRNA profiles and then store this in each samples ArrowFile. } +\examples{ + +#Get Test Project +proj <- getTestProject() + +#Get RNA Matrix +sePBMC <- readRDS( + file.path(system.file("testdata", package = "ArchR"), "seRNA_PBMC.rds") +) + +#Gene Integration Matrix +proj <- addGeneIntegrationMatrix( + ArchRProj = proj, + useMatrix = "GeneScoreMatrix", + matrixName = "GeneIntegrationMatrix", + reducedDims = "IterativeLSI", + seRNA = sePBMC, + addToArrow = FALSE, + groupRNA = "CellType", + nameCell = "predictedCell_Un2", + nameGroup = "predictedGroup_Un2", + nameScore = "predictedScore_Un2", + dimsToUse = 1:10, + nGenes = 250, + force = TRUE +) + +} diff --git a/man/addGeneScoreMatrix.Rd b/man/addGeneScoreMatrix.Rd index 04e50485..838aa3de 100644 --- a/man/addGeneScoreMatrix.Rd +++ b/man/addGeneScoreMatrix.Rd @@ -89,3 +89,12 @@ biasing the geneScores for genes nearby that locus.} This function, for each sample, will independently compute counts for each tile per cell and then infer gene activity scores. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Gene Score Matrix With New Model +proj <- addGeneScoreMatrix(proj, matrixName = "GeneScoreMatrix2", geneModel = "exp(-abs(x)/10000) + exp(-1)") + +} diff --git a/man/addGroupCoverages.Rd b/man/addGroupCoverages.Rd index 3622b119..0964c09f 100644 --- a/man/addGroupCoverages.Rd +++ b/man/addGroupCoverages.Rd @@ -70,3 +70,12 @@ insertion coverage / pseudo-bulk replicate information already exists.} This function will merge cells within each designated cell group for the generation of pseudo-bulk replicates and then merge these replicates into a single insertion coverage file. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Group Coverages +proj <- addGroupCoverages(proj, force = TRUE) + +} diff --git a/man/addHarmony.Rd b/man/addHarmony.Rd index 260514d4..06e3f48d 100644 --- a/man/addHarmony.Rd +++ b/man/addHarmony.Rd @@ -48,3 +48,15 @@ exists as a column name in \code{cellColData}.} \description{ This function will add the Harmony batch-corrected reduced dimensions to an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Confounder +proj <- addCellColData(proj, data = proj$TSSEnrichment > 10, name = "TSSQC", cells = getCellNames(proj)) + +# Run Harmony +proj <- addHarmony(proj, groupBy = "TSSQC") + +} diff --git a/man/addImputeWeights.Rd b/man/addImputeWeights.Rd index 0be5e36b..e06154c7 100644 --- a/man/addImputeWeights.Rd +++ b/man/addImputeWeights.Rd @@ -70,3 +70,12 @@ reproduce results downstream.} \description{ This function computes imputations weights that describe each cell as a linear combination of many cells based on a MAGIC diffusion matrix. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Impute Weights +proj <- addImputeWeights(proj) + +} diff --git a/man/addIterativeLSI.Rd b/man/addIterativeLSI.Rd index ac601e66..4054082a 100644 --- a/man/addIterativeLSI.Rd +++ b/man/addIterativeLSI.Rd @@ -29,6 +29,7 @@ addIterativeLSI( totalFeatures = 5e+05, filterQuantile = 0.995, excludeChr = c(), + keep0lsi = FALSE, saveIterations = TRUE, UMAPParams = list(n_neighbors = 40, min_dist = 0.4, metric = "cosine", verbose = FALSE, fast_sgd = TRUE), @@ -108,6 +109,8 @@ insertion counts will be ignored for the first LSI iteration.} \item{excludeChr}{A string of chromosomes to exclude for iterativeLSI procedure.} +\item{keep0lsi}{A boolean whether to keep cells with no reads in features used for LSI.} + \item{saveIterations}{A boolean value indicating whether the results of each LSI iterations should be saved as compressed \code{.rds} files in the designated \code{outDir}.} @@ -131,3 +134,12 @@ reproduce results downstream.} \description{ This function will compute an iterative LSI dimensionality reduction on an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Iterative LSI +proj <- addIterativeLSI(proj, dimsToUse = 1:5, varFeatures=1000, iterations = 2, force=TRUE) + +} diff --git a/man/addModuleScore.Rd b/man/addModuleScore.Rd index 2a27fe91..e803b23c 100644 --- a/man/addModuleScore.Rd +++ b/man/addModuleScore.Rd @@ -44,3 +44,17 @@ grouping of multiple features together into a single quantitative measurement. C function only works for modules derived from the \code{GeneScoreMatrix}. Each module is added as a new column in \code{cellColData} } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Module Score +proj <- addModuleScore(proj, useMatrix = "GeneIntegrationMatrix", nBin = 25, nBgd = 25, features = list(TScore = c('CD3D', 'CD3E'))) + +#Check +split(proj@cellColData$Module.TScore, proj@cellColData$CellType) \%>\% lapply(mean) \%>\% unlist +# B M T +# -5.834066 -9.176063 17.594090 + +} diff --git a/man/addMonocleTrajectory.Rd b/man/addMonocleTrajectory.Rd index 3364de0c..c1554b13 100644 --- a/man/addMonocleTrajectory.Rd +++ b/man/addMonocleTrajectory.Rd @@ -31,3 +31,26 @@ addMonocleTrajectory( This function will add a trajectory from a monocle CDS created from \code{getMonocleTrajectories} to an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +#Create Monocole Trajectory +cds <- getMonocleTrajectories( + ArchRProj = proj, + useGroups = c("C1", "C2", "C3"), + principalGroup = "C1", + groupBy = "Clusters", + embedding = "UMAP" +) + +# Add Monocole Trajectory +proj <- addMonocleTrajectory( + ArchRProj = proj, + name = "Trajectory_Monocole", + useGroups = c("C1", "C2", "C3"), + monocleCDS = cds +) + +} diff --git a/man/addMotifAnnotations.Rd b/man/addMotifAnnotations.Rd index 17ad7e80..b2f97061 100644 --- a/man/addMotifAnnotations.Rd +++ b/man/addMotifAnnotations.Rd @@ -57,3 +57,12 @@ it already exists in the given \code{ArchRProject}.} This function adds information about which peaks contain motifs to a given ArchRProject. For each peak, a binary value is stored indicating whether each motif is observed within the peak region. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Motif Annotations +proj <- addMotifAnnotations(proj, motifSet = "cisbptest", annoName = "test") + +} diff --git a/man/addPeak2GeneLinks.Rd b/man/addPeak2GeneLinks.Rd index 891f9ff8..f527076c 100644 --- a/man/addPeak2GeneLinks.Rd +++ b/man/addPeak2GeneLinks.Rd @@ -75,3 +75,15 @@ to keep track of the seed used so that you can reproduce results downstream.} \description{ This function will add peak-to-gene links to a given ArchRProject } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add P2G Links +proj <- addPeak2GeneLinks(proj, k = 20) + +# Get P2G Links +p2g <- getPeak2GeneLinks(proj) + +} diff --git a/man/addPeakAnnotations.Rd b/man/addPeakAnnotations.Rd index 72775a9f..45233572 100644 --- a/man/addPeakAnnotations.Rd +++ b/man/addPeakAnnotations.Rd @@ -28,3 +28,15 @@ if it already exists in the given \code{ArchRProject}.} This function adds information about which peaks contain input regions to a given ArchRProject. For each peak, a binary value is stored indicating whether each region is observed within the peak region. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Motif Positions Can Be Any Interval GRanges List +positions <- getPositions(proj) + +# Add Peak Annotations +proj <- addPeakAnnotations(proj, regions = positions) + +} diff --git a/man/addPeakMatrix.Rd b/man/addPeakMatrix.Rd index c58ecfa6..711b99f2 100644 --- a/man/addPeakMatrix.Rd +++ b/man/addPeakMatrix.Rd @@ -37,3 +37,12 @@ for downstream analyses when working with insertion counts.} This function, for each sample, will independently compute counts for each peak per cell in the provided ArchRProject using the "PeakMatrix". } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Peak Matrix +proj <- addPeakMatrix(proj) + +} diff --git a/man/addPeakSet.Rd b/man/addPeakSet.Rd index 81dcd3e6..ea07e8c2 100644 --- a/man/addPeakSet.Rd +++ b/man/addPeakSet.Rd @@ -25,3 +25,12 @@ whether or not to overwrite this \code{peakSet}.} \description{ This function adds a peak set as a GRanges object to a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add PeakSet +addPeakSet(proj, peakSet = getPeakSet(proj), force = TRUE) + +} diff --git a/man/addProjectSummary.Rd b/man/addProjectSummary.Rd index 9acf1d85..db668e8c 100644 --- a/man/addProjectSummary.Rd +++ b/man/addProjectSummary.Rd @@ -16,3 +16,12 @@ addProjectSummary(ArchRProj = NULL, name = NULL, summary = NULL) \description{ This function adds info to the projectSummary of an ArchRProject } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Project Summary +addProjectSummary(proj, name = "test", summary = "test successful") + +} diff --git a/man/addReproduciblePeakSet.Rd b/man/addReproduciblePeakSet.Rd index 7bd22e82..eef6b5d1 100644 --- a/man/addReproduciblePeakSet.Rd +++ b/man/addReproduciblePeakSet.Rd @@ -102,3 +102,15 @@ peak calling (not for MACS2). See \code{addGroupCoverages()} for more info.} This function will get insertions from coverage files, call peaks, and merge peaks to get a "Union Reproducible Peak Set". } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Peak Matrix Tiles +proj <- addReproduciblePeakSet(proj, peakMethod = "tiles") + +# Add Peak Matrix Macs2 (Preferred) +proj <- addReproduciblePeakSet(proj, peakMethod = "macs2") + +} diff --git a/man/addSampleColData.Rd b/man/addSampleColData.Rd index a15dfaba..768537e9 100644 --- a/man/addSampleColData.Rd +++ b/man/addSampleColData.Rd @@ -29,3 +29,12 @@ already exists as a column name in \code{sampleColData}.} \description{ This function adds new data to sampleColData in an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Sample Column Data +addSampleColData(proj, data = 1, name = "Test", samples = "PBSmall") + +} diff --git a/man/addSlingShotTrajectories.Rd b/man/addSlingShotTrajectories.Rd index 037a6ce0..0167b76f 100644 --- a/man/addSlingShotTrajectories.Rd +++ b/man/addSlingShotTrajectories.Rd @@ -41,3 +41,19 @@ in \code{cellColData}. This limits the groups used to identify trajectories.} This function will fit a supervised trajectory in a lower dimensional space that can then be used for downstream analyses. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +#Add SlingShot Trajectory +proj <- addSlingShotTrajectories( + ArchRProj = proj, + name = "Trajectory_SlingShot", + useGroups = c("C1", "C2", "C3"), + principalGroup = "C1", + groupBy = "Clusters", + embedding = "UMAP" +) + +} diff --git a/man/addTSNE.Rd b/man/addTSNE.Rd index 4697a3f3..8c9a6ac2 100644 --- a/man/addTSNE.Rd +++ b/man/addTSNE.Rd @@ -64,3 +64,12 @@ reproduce results downstream.} \description{ This function will compute a TSNE embedding and add it to an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add UMAP for Small Project +proj <- addTSNE(proj, force = TRUE) + +} diff --git a/man/addTileMatrix.Rd b/man/addTileMatrix.Rd index b1e71406..3096d32c 100644 --- a/man/addTileMatrix.Rd +++ b/man/addTileMatrix.Rd @@ -43,3 +43,12 @@ is to retrieve this from the \code{ArchRProject} using \code{getBlacklist()}.} \description{ This function, for each sample, will independently compute counts for each tile } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Tile Matrix +proj <- addTileMatrix(proj, force = TRUE, tileSize = 25000) + +} diff --git a/man/addTrajectory.Rd b/man/addTrajectory.Rd index 1ac0b760..7d518071 100644 --- a/man/addTrajectory.Rd +++ b/man/addTrajectory.Rd @@ -59,3 +59,12 @@ is above the provided quantile will be excluded.} This function will fit a supervised trajectory in a lower dimensional space that can then be used for downstream analyses. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +#Add Trajectory +proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) + +} diff --git a/man/addUMAP.Rd b/man/addUMAP.Rd index 00ca5503..f72cca57 100644 --- a/man/addUMAP.Rd +++ b/man/addUMAP.Rd @@ -72,3 +72,12 @@ reproduce results downstream.} \description{ This function will compute a UMAP embedding and add it to an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add UMAP for Small Project +proj <- addUMAP(proj, force = TRUE) + +} diff --git a/man/confusionMatrix.Rd b/man/confusionMatrix.Rd index a56920e9..987f3fcf 100644 --- a/man/confusionMatrix.Rd +++ b/man/confusionMatrix.Rd @@ -14,3 +14,15 @@ confusionMatrix(i = NULL, j = NULL) \description{ This function creates a confusion matrix based on two value vectors. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Overlap of Clusters and CellType +confusionMatrix(proj$Clusters, proj$CellType) + +# Overlap of Cell Type and RNA Predict +confusionMatrix(proj$CellType, proj$predictedGroup_Un) + +} diff --git a/man/correlateMatrices.Rd b/man/correlateMatrices.Rd index 6adb8515..4a8716e3 100644 --- a/man/correlateMatrices.Rd +++ b/man/correlateMatrices.Rd @@ -79,3 +79,18 @@ of the seed used so that you can reproduce results downstream.} \description{ This function will correlate 2 matrices within an ArchRProject by name matching. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Correlate Matrices +dfCor <- correlateMatrices( + ArchRProj = proj, + useMatrix1 = "GeneScoreMatrix", + useMatrix2 = "GeneIntegrationMatrix", + dimsToUse = 1:5, + k = 20 +) + +} diff --git a/man/correlateTrajectories.Rd b/man/correlateTrajectories.Rd index f824e7d3..0d080c45 100644 --- a/man/correlateTrajectories.Rd +++ b/man/correlateTrajectories.Rd @@ -62,3 +62,19 @@ computing correlations.} \description{ This function will correlate 2 trajectory matrices from getTrajectory. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +#Add Trajectory +proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) + +#Get Trajectories +seTraj1 <- getTrajectory(proj, useMatrix = "GeneScoreMatrix") +seTraj2 <- getTrajectory(proj, useMatrix = "GeneIntegrationMatrix") + +#Correlate +corTraj <- correlateTrajectories(seTraj1, seTraj2, corCutOff = 0.35, varCutOff1 = 0.6, varCutOff2 = 0.6) + +} diff --git a/man/createArrowFiles.Rd b/man/createArrowFiles.Rd index f1bd3018..ddd9f689 100644 --- a/man/createArrowFiles.Rd +++ b/man/createArrowFiles.Rd @@ -140,3 +140,19 @@ ATAC-seq signal proximal to the TSS to estimate gene activity.} \description{ This function will create ArrowFiles from input files. These ArrowFiles are the main constituent for downstream analysis in ArchR. } +\examples{ + +# Get Test Fragments +fragments <- getTestFragments() + +# Create Arrow Files +arrowFiles <- createArrowFiles( + inputFiles = fragments, + sampleNames = "PBSmall", + minFrags = 100, + nChunk = 1, + TileMatParams=list(tileSize=10000), + force = TRUE +) + +} diff --git a/man/createGeneAnnotation.Rd b/man/createGeneAnnotation.Rd index a4fd536e..5309a3e6 100644 --- a/man/createGeneAnnotation.Rd +++ b/man/createGeneAnnotation.Rd @@ -11,7 +11,8 @@ createGeneAnnotation( genes = NULL, exons = NULL, TSS = NULL, - annoStyle = NULL + annoStyle = NULL, + singleStrand = FALSE ) } \arguments{ @@ -31,7 +32,29 @@ For example, from \code{orgdb <- org.Hs.eg.db}.} \item{TSS}{A \code{GRanges} object containing standed transcription start site coordinates for computing TSS enrichment scores downstream.} \item{annoStyle}{annotation style to map between gene names and various gene identifiers e.g. "ENTREZID", "ENSEMBL".} + +\item{singleStrand}{A boolean for GenomicFeatures::genes(\code{single.strand.genes.only}) parameter} } \description{ This function will create a gene annotation object that can be used for creating ArrowFiles or an ArchRProject, etc. } +\examples{ + +if (!require("TxDb.Hsapiens.UCSC.hg19.knownGene", quietly = TRUE)) BiocManager::install("TxDb.Hsapiens.UCSC.hg19.knownGene") +if (!require("org.Hs.eg.db", quietly = TRUE)) BiocManager::install("org.Hs.eg.db") +library(TxDb.Hsapiens.UCSC.hg19.knownGene) +library(org.Hs.eg.db) + +# Get Txdb +TxDb <- TxDb.Hsapiens.UCSC.hg19.knownGene + +# Get OrgDb +OrgDb <- org.Hs.eg.db + +# Create Genome Annotation +geneAnno <- createGeneAnnotation(TxDb=TxDb, OrgDb=OrgDb) + +# Also can create from a string if BSgenome exists +geneAnno <- createGeneAnnotation("hg19") + +} diff --git a/man/createGenomeAnnotation.Rd b/man/createGenomeAnnotation.Rd index e52160c0..1a39a28d 100644 --- a/man/createGenomeAnnotation.Rd +++ b/man/createGenomeAnnotation.Rd @@ -29,3 +29,18 @@ non-standard chromosomes will still be removed as defined in \code{filterChrGR() \description{ This function will create a genome annotation object that can be used for creating ArrowFiles or an ArchRProject, etc. } +\examples{ + +if (!require("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)) BiocManager::install("BSgenome.Hsapiens.UCSC.hg19") +library(BSgenome.Hsapiens.UCSC.hg19) + +# Get Genome +genome <- BSgenome.Hsapiens.UCSC.hg19 + +# Create Genome Annotation +genomeAnno <- createGenomeAnnotation(genome) + +# Also can create from a string if BSgenome exists +genomeAnno <- createGenomeAnnotation("hg19") + +} diff --git a/man/createLogFile.Rd b/man/createLogFile.Rd index 1c46c0e6..0ee8cd79 100644 --- a/man/createLogFile.Rd +++ b/man/createLogFile.Rd @@ -15,3 +15,9 @@ createLogFile(name = NULL, logDir = "ArchRLogs", useLogs = getArchRLogging()) This function will create a log file for ArchR functions. If ArchRLogging is not TRUE this function will return NULL. } +\examples{ + +# Create Log File +createLogFile(name = "test") + +} diff --git a/man/exportPeakMatrixForSTREAM.Rd b/man/exportPeakMatrixForSTREAM.Rd index d8585568..aad27451 100644 --- a/man/exportPeakMatrixForSTREAM.Rd +++ b/man/exportPeakMatrixForSTREAM.Rd @@ -27,3 +27,12 @@ exportPeakMatrixForSTREAM( \description{ This function gets a PeakMatrix from an \code{ArchRProject} and writes it to a set of files for STREAM (https://github.com/pinellolab/STREAM) } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Export Matrix For Stream +exportPeakMatrixForSTREAM(proj) + +} diff --git a/man/extendGR.Rd b/man/extendGR.Rd index 6b161bed..8e2718ea 100644 --- a/man/extendGR.Rd +++ b/man/extendGR.Rd @@ -16,3 +16,19 @@ extendGR(gr = NULL, upstream = NULL, downstream = NULL) \description{ This function extends each region in a Genomic Ranges object by a designated upstream and downstream extension in a strand-aware fashion } +\examples{ + +# Dummy GR +gr <- GRanges( + seqnames = "chr1", + ranges = IRanges( + start = c(1, 4, 11), + end = c(10, 12, 20) + ), + score = c(1, 2, 3) +) + +# Non Overlapping +extendGR(gr, 1, 2) + +} diff --git a/man/filterChrGR.Rd b/man/filterChrGR.Rd index 07aad629..68adc22a 100644 --- a/man/filterChrGR.Rd +++ b/man/filterChrGR.Rd @@ -30,3 +30,12 @@ to be removed before the seqlevels can be dropped. Four pruning modes are curren \description{ This function allows for removal of manually designated or more broadly undesirable seqlevels from a Genomic Ranges object or similar object } +\examples{ + +# Add ArchR Genome +addArchRGenome("hg19test2") + +# Filter Chr +filterChrGR(getChromSizes(), remove = "chr5") + +} diff --git a/man/filterDoublets.Rd b/man/filterDoublets.Rd index 269c5c5f..051da595 100644 --- a/man/filterDoublets.Rd +++ b/man/filterDoublets.Rd @@ -28,3 +28,15 @@ The higher the \code{filterRatio}, the greater the number of cells potentially r \description{ This function will filter doublets from an ArchRProject after addDoubletScores() has been run. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Doublet Scores for Small Project +proj <- addDoubletScores(proj, dimsToUse = 1:5, LSIParams = list(dimsToUse = 1:5, varFeatures=1000, iterations = 2)) + +# Filter Doublets (Since Low Cells filterRatio has to be high before removing 1 cell!) +proj <- filterDoublets(proj, filterRatio=10) + +} diff --git a/man/findMacs2.Rd b/man/findMacs2.Rd index 551b7eb2..8763e98b 100644 --- a/man/findMacs2.Rd +++ b/man/findMacs2.Rd @@ -9,3 +9,9 @@ findMacs2() \description{ This function attempts to find the path to the MACS2 executable by serting the path and python's pip. } +\examples{ + +# Get Macs2 +findMacs2() + +} diff --git a/man/getArchRChrPrefix.Rd b/man/getArchRChrPrefix.Rd index 58d93982..0443046d 100644 --- a/man/getArchRChrPrefix.Rd +++ b/man/getArchRChrPrefix.Rd @@ -9,3 +9,9 @@ getArchRChrPrefix() \description{ This function will get the default requirement of chromosomes to have a "chr" prefix. } +\examples{ + +# Get ArchR Chr Prefix +getArchRChrPrefix() + +} diff --git a/man/getArchRDebugging.Rd b/man/getArchRDebugging.Rd index b0ea6d56..bb4825b7 100644 --- a/man/getArchRDebugging.Rd +++ b/man/getArchRDebugging.Rd @@ -9,3 +9,9 @@ getArchRDebugging() \description{ This function will get ArchR Debugging which will save an RDS if an error is encountered. } +\examples{ + +# Get ArchR Debugging +getArchRDebugging() + +} diff --git a/man/getArchRGenome.Rd b/man/getArchRGenome.Rd index 799a909b..38b0f3f5 100644 --- a/man/getArchRGenome.Rd +++ b/man/getArchRGenome.Rd @@ -19,3 +19,9 @@ This function is not meant to be run with both \code{geneAnnotation} and \code{g This function will retrieve the genome that is currently in use by ArchR. Alternatively, this function can return either the \code{geneAnnotation} or the \code{genomeAnnotation} associated with the globally defined genome if desired. } +\examples{ + +# Get ArchR Genome to use globally +getArchRGenome() + +} diff --git a/man/getArchRH5Level.Rd b/man/getArchRH5Level.Rd new file mode 100644 index 00000000..e13fda8f --- /dev/null +++ b/man/getArchRH5Level.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/GlobalDefaults.R +\name{getArchRH5Level} +\alias{getArchRH5Level} +\title{Get globally-applied compression level for h5 files} +\usage{ +getArchRH5Level() +} +\description{ +This function will get the default compression level to be used for h5 file execution across all ArchR functions. +} +\examples{ + +# Get ArchR H5 Compression level +getArchRH5Level() + +} diff --git a/man/getArchRLogging.Rd b/man/getArchRLogging.Rd index dfbdf2b5..8fe01b06 100644 --- a/man/getArchRLogging.Rd +++ b/man/getArchRLogging.Rd @@ -9,3 +9,9 @@ getArchRLogging() \description{ This function will get ArchR logging } +\examples{ + +# Get ArchR Logging +getArchRLogging() + +} diff --git a/man/getArchRThreads.Rd b/man/getArchRThreads.Rd index 0ae1a620..aba9f69e 100644 --- a/man/getArchRThreads.Rd +++ b/man/getArchRThreads.Rd @@ -9,3 +9,9 @@ getArchRThreads() \description{ This function will get the number of threads to be used for parallel execution across all ArchR functions. } +\examples{ + +# Get ArchR Threads +getArchRThreads() + +} diff --git a/man/getArchRVerbose.Rd b/man/getArchRVerbose.Rd index 0ed46322..04f6e42a 100644 --- a/man/getArchRVerbose.Rd +++ b/man/getArchRVerbose.Rd @@ -9,3 +9,9 @@ getArchRVerbose() \description{ This function will get ArchR logging verbosity. } +\examples{ + +# Get ArchR Verbose +addArchRVerbose() + +} diff --git a/man/getArrowFiles.Rd b/man/getArrowFiles.Rd index f225f936..29ab82b7 100644 --- a/man/getArrowFiles.Rd +++ b/man/getArrowFiles.Rd @@ -12,3 +12,12 @@ getArrowFiles(ArchRProj = NULL) \description{ This function gets the names of all ArrowFiles associated with a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Arrow Files +getArrowFiles(proj) + +} diff --git a/man/getAvailableMatrices.Rd b/man/getAvailableMatrices.Rd index 706cf739..2a4f4096 100644 --- a/man/getAvailableMatrices.Rd +++ b/man/getAvailableMatrices.Rd @@ -12,3 +12,12 @@ getAvailableMatrices(ArchRProj = NULL) \description{ This function gets the available matrices from the ArrowFiles in a given ArchRProject object. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Available Matrices in ArchR Project +getAvailableMatrices(proj) + +} diff --git a/man/getBgdPeaks.Rd b/man/getBgdPeaks.Rd index 1378b3ec..134cdf92 100644 --- a/man/getBgdPeaks.Rd +++ b/man/getBgdPeaks.Rd @@ -33,3 +33,12 @@ so that you can reproduce results downstream.} \description{ This function will get/compute background peaks controlling for total accessibility and GC-content from an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Background Peaks +bgdPeaks <- getBgdPeaks(proj, force = TRUE) + +} diff --git a/man/getBlacklist.Rd b/man/getBlacklist.Rd index e9e9a442..e2dcafad 100644 --- a/man/getBlacklist.Rd +++ b/man/getBlacklist.Rd @@ -12,3 +12,15 @@ getBlacklist(ArchRProj = NULL) \description{ This function gets the blacklist (the regions to be excluded from analysis) as a GRanges object from the genomeAnnotation of a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Blacklist in ArchRProj +getBlacklist(proj) + +# Get Blacklist loaded globally +getBlacklist() + +} diff --git a/man/getCellColData.Rd b/man/getCellColData.Rd index 378fd207..518499a0 100644 --- a/man/getCellColData.Rd +++ b/man/getCellColData.Rd @@ -16,3 +16,12 @@ getCellColData(ArchRProj = NULL, select = NULL, drop = FALSE) \description{ This function gets the cellColData from a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Cell Column Data +getCellColData(proj) + +} diff --git a/man/getCellNames.Rd b/man/getCellNames.Rd index 1ecbe4b1..9df8039c 100644 --- a/man/getCellNames.Rd +++ b/man/getCellNames.Rd @@ -12,3 +12,12 @@ getCellNames(ArchRProj = NULL) \description{ This function gets the cellNames from a given ArchRProject object. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Cell Names +getCellNames(proj) + +} diff --git a/man/getChromLengths.Rd b/man/getChromLengths.Rd index 3911630c..0b28a406 100644 --- a/man/getChromLengths.Rd +++ b/man/getChromLengths.Rd @@ -12,3 +12,15 @@ getChromLengths(ArchRProj = NULL) \description{ This function gets the chromosome lengths as a vector from the genomeAnnotation of a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get chromLengths in ArchRProj +getChromLengths(proj) + +# Get chromLengths loaded globally +getChromLengths() + +} diff --git a/man/getChromSizes.Rd b/man/getChromSizes.Rd index c1897c3a..7d98cc5b 100644 --- a/man/getChromSizes.Rd +++ b/man/getChromSizes.Rd @@ -12,3 +12,15 @@ getChromSizes(ArchRProj = NULL) \description{ This function gets the chromosome lengths as a GRanges object from the genomeAnnotation of a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get chromSizes in ArchRProj +getChromSizes(proj) + +# Get chromSizes loaded globally +getChromSizes() + +} diff --git a/man/getCoAccessibility.Rd b/man/getCoAccessibility.Rd index b97163e2..fa2ae8c9 100644 --- a/man/getCoAccessibility.Rd +++ b/man/getCoAccessibility.Rd @@ -25,3 +25,15 @@ the \code{ArchRBrowser()} or as an \code{ArchRBrowserTrack()}.} \description{ This function obtains co-accessibility data from an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Co Accessibility +proj <- addCoAccessibility(proj, k = 20) + +# Get Co Accessibility +CoA <- getCoAccessibility(proj) + +} diff --git a/man/getEmbedding.Rd b/man/getEmbedding.Rd index c08b3ca5..456f26b9 100644 --- a/man/getEmbedding.Rd +++ b/man/getEmbedding.Rd @@ -18,3 +18,12 @@ the full embedding object.} \description{ This function gets an embedding (i.e. UMAP) from a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get UMAP +getEmbedding(proj, embedding = "UMAP") + +} diff --git a/man/getExons.Rd b/man/getExons.Rd index 60cfb17d..bf927e9f 100644 --- a/man/getExons.Rd +++ b/man/getExons.Rd @@ -14,3 +14,15 @@ getExons(ArchRProj = NULL, symbols = NULL) \description{ This function gets the exons coordinates as a GRanges object from the geneAnnotation of a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Exons in ArchRProj +getExons(proj) + +# Get Exons globally +getExons() + +} diff --git a/man/getFeatures.Rd b/man/getFeatures.Rd index a9112e33..9e9530db 100644 --- a/man/getFeatures.Rd +++ b/man/getFeatures.Rd @@ -24,3 +24,12 @@ getFeatures( This function will identify available features from a given data matrix (i.e. "GeneScoreMatrix", or "TileMatrix") and return them for downstream plotting utilities. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Features +getFeatures(proj, useMatrix = "GeneScoreMatrix", select = 'CD3') + +} diff --git a/man/getFootprints.Rd b/man/getFootprints.Rd index 232a1fb0..af2adcf0 100644 --- a/man/getFootprints.Rd +++ b/man/getFootprints.Rd @@ -46,3 +46,15 @@ object will be considered for the footprint.} \description{ This function will get footprints for all samples in a given ArchRProject and return a summarized experiment object that can be used for downstream analyses } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Motif Positions +positions <- getPositions(proj) + +# Get Footprints +seFoot <- getFootprints(ArchRProj = proj, positions = positions, groupBy = "Clusters", minCells = 10) + +} diff --git a/man/getFragmentsFromArrow.Rd b/man/getFragmentsFromArrow.Rd index e8cb1c75..c83a8336 100644 --- a/man/getFragmentsFromArrow.Rd +++ b/man/getFragmentsFromArrow.Rd @@ -28,3 +28,12 @@ from the provided ArrowFile using \code{getCellNames()}.} \description{ This function retrieves the fragments from a given ArrowFile as a GRanges object. } +\examples{ + +#Get Test Arrow +arrow <- getTestArrow() + +# Get Fragments +frags <- getFragmentsFromArrow(arrow) + +} diff --git a/man/getFragmentsFromProject.Rd b/man/getFragmentsFromProject.Rd index 15ecf282..5645a2fa 100644 --- a/man/getFragmentsFromProject.Rd +++ b/man/getFragmentsFromProject.Rd @@ -28,3 +28,12 @@ from the provided ArrowFile using \code{getCellNames()}.} \description{ This function retrieves the fragments from a given ArchRProject as a GRangesList object. } +\examples{ + +#Get Test Project +proj <- getTestProject() + +# Get Fragments +frags <- getFragmentsFromProject(proj) + +} diff --git a/man/getGeneAnnotation.Rd b/man/getGeneAnnotation.Rd index 6555ce69..eae5338b 100644 --- a/man/getGeneAnnotation.Rd +++ b/man/getGeneAnnotation.Rd @@ -12,3 +12,15 @@ getGeneAnnotation(ArchRProj = NULL) \description{ This function gets the geneAnnotation from a given ArchRProject } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Gene Annotation in ArchRProj +getGeneAnnotation(proj) + +# Get Gene Annotation loaded globally +getGeneAnnotation() + +} diff --git a/man/getGenes.Rd b/man/getGenes.Rd index e33a3ced..03ba390d 100644 --- a/man/getGenes.Rd +++ b/man/getGenes.Rd @@ -14,3 +14,15 @@ getGenes(ArchRProj = NULL, symbols = NULL) \description{ This function gets the genes start and end coordinates as a GRanges object from the geneAnnotation of a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Genes in ArchRProj +getGenes(proj) + +# Get Genes globally +getGenes() + +} diff --git a/man/getGenome.Rd b/man/getGenome.Rd index f9527b19..2606e002 100644 --- a/man/getGenome.Rd +++ b/man/getGenome.Rd @@ -12,3 +12,15 @@ getGenome(ArchRProj = NULL) \description{ This function gets the name of the genome from the genomeAnnotation used by a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Genome in ArchRProj +getGenome(proj) + +# Get Genome loaded globally +getGenome() + +} diff --git a/man/getGenomeAnnotation.Rd b/man/getGenomeAnnotation.Rd index bb2892f7..53e4584a 100644 --- a/man/getGenomeAnnotation.Rd +++ b/man/getGenomeAnnotation.Rd @@ -12,3 +12,15 @@ getGenomeAnnotation(ArchRProj = NULL) \description{ This function gets the genomeAnnotation from a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Genome Annotation in ArchRProj +getGenomeAnnotation(proj) + +# Get Genome Annotation loaded globally +getGenomeAnnotation() + +} diff --git a/man/getGroupBW.Rd b/man/getGroupBW.Rd index f90166fb..c93aa62a 100644 --- a/man/getGroupBW.Rd +++ b/man/getGroupBW.Rd @@ -42,3 +42,12 @@ is "ReadsInTSS" which simultaneously normalizes tracks based on sequencing depth \description{ This function will group, summarize and export a bigwig for each group in an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Group BW +bw <- getGroupBW(proj, groupBy = "Clusters") + +} diff --git a/man/getGroupSE.Rd b/man/getGroupSE.Rd index 0759a4e4..d67e6dc2 100644 --- a/man/getGroupSE.Rd +++ b/man/getGroupSE.Rd @@ -35,3 +35,12 @@ getGroupSE( \description{ This function will group, summarize and export a summarized experiment for a assay in a ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Group SE +se <- getGroupSE(proj, useMatrix = "PeakMatrix", groupBy = "Clusters") + +} diff --git a/man/getGroupSummary.Rd b/man/getGroupSummary.Rd index 2c9c24b9..96e25d3f 100644 --- a/man/getGroupSummary.Rd +++ b/man/getGroupSummary.Rd @@ -26,3 +26,12 @@ getGroupSummary( \description{ This function summarizes a numeric cellColData entry across groupings in a ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Group Summary +getGroupSummary(proj, groupBy = "Clusters", select = "TSSEnrichment", summary = "mean") + +} diff --git a/man/getImputeWeights.Rd b/man/getImputeWeights.Rd index 2ad4864e..34ec0331 100644 --- a/man/getImputeWeights.Rd +++ b/man/getImputeWeights.Rd @@ -12,3 +12,15 @@ getImputeWeights(ArchRProj = NULL) \description{ This function gets imputation weights from an ArchRProject to impute numeric values. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Impute Weights +proj <- addImputeWeights(proj) + +# Get Impute Weights +getImputeWeights(proj) + +} diff --git a/man/getMarkerFeatures.Rd b/man/getMarkerFeatures.Rd index 5961795c..e11792f8 100644 --- a/man/getMarkerFeatures.Rd +++ b/man/getMarkerFeatures.Rd @@ -76,3 +76,17 @@ raw deviations ("deviations") or deviation z-scores ("z") for a chromVAR deviati \description{ This function will identify features that are definitional of each provided cell grouping where possible } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Markers +seMarker <- getMarkerFeatures( + ArchRProj = proj, + useMatrix = "PeakMatrix", + testMethod = "binomial", + binarize = TRUE +) + +} diff --git a/man/getMarkers.Rd b/man/getMarkers.Rd index 6bf0fc3f..b84c12b5 100644 --- a/man/getMarkers.Rd +++ b/man/getMarkers.Rd @@ -24,3 +24,20 @@ of the \code{assayNames} from \code{seMarker}.} \description{ This function will identify Markers and return a List of Features or a GRangesList for each group of significant marker features. } +\examples{ + +#Get Test Project +proj <- getTestProject() + +#Get Markers +seMarker <- getMarkerFeatures( + ArchRProj = proj, + useMatrix = "PeakMatrix", + testMethod = "binomial", + binarize = TRUE +) + +#Get Markers +getMarkers(seMarker) + +} diff --git a/man/getMatches.Rd b/man/getMatches.Rd index 36e369ab..86f18ada 100644 --- a/man/getMatches.Rd +++ b/man/getMatches.Rd @@ -17,3 +17,12 @@ getMatches(ArchRProj = NULL, name = NULL, annoName = NULL) This function gets peak annotation matches from a given ArchRProject. The peaks in the returned object are in the same order as the peaks returned by \code{getPeakSet()}. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Annotation Matches +matches <- getMatches(proj) + +} diff --git a/man/getMatrixFromArrow.Rd b/man/getMatrixFromArrow.Rd index 302302ff..17517b5f 100644 --- a/man/getMatrixFromArrow.Rd +++ b/man/getMatrixFromArrow.Rd @@ -39,3 +39,12 @@ provide the \code{ArchRProject} object here.} \description{ This function gets a given data matrix from an individual ArrowFile. } +\examples{ + +#Get Test Arrow +arrow <- getTestArrow() + +# Get Fragments +se <- getMatrixFromArrow(arrow) + +} diff --git a/man/getMatrixFromProject.Rd b/man/getMatrixFromProject.Rd index 2e96d395..6863588c 100644 --- a/man/getMatrixFromProject.Rd +++ b/man/getMatrixFromProject.Rd @@ -36,3 +36,12 @@ For example, if you added your \code{PeakMatrix} using \code{addPeakMatrix()} wi in the parameters passed to \code{getMatrixFromProject()} and the \code{PeakMatrix} will be binarized as you pull it out. No other normalization is applied to the matrix by this function. } +\examples{ + +#Get Test Project +proj <- getTestProject() + +# Get Fragments +se <- getMatrixFromProject(proj) + +} diff --git a/man/getMonocleTrajectories.Rd b/man/getMonocleTrajectories.Rd index 385e51e9..b8e84296 100644 --- a/man/getMonocleTrajectories.Rd +++ b/man/getMonocleTrajectories.Rd @@ -41,3 +41,18 @@ in \code{cellColData}. This limits the groups used to identify trajectories.} This function will use monocle3 to find trajectories and then returns a monocle CDS object that can be used as input for \code{addMonocleTrajectory}. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +#Create Monocole Trajectory +cds <- getMonocleTrajectories( + ArchRProj = proj, + useGroups = c("C1", "C2", "C3"), + principalGroup = "C1", + groupBy = "Clusters", + embedding = "UMAP" +) + +} diff --git a/man/getOutputDirectory.Rd b/man/getOutputDirectory.Rd index 080c22db..167a4db6 100644 --- a/man/getOutputDirectory.Rd +++ b/man/getOutputDirectory.Rd @@ -12,3 +12,12 @@ getOutputDirectory(ArchRProj = NULL) \description{ This function gets the outputDirectory from a given ArchRProject. If null this returns "QualityControl" directory. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Output Directory +getOutputDirectory(proj) + +} diff --git a/man/getPeak2GeneLinks.Rd b/man/getPeak2GeneLinks.Rd index 66e712f5..66c3e3d0 100644 --- a/man/getPeak2GeneLinks.Rd +++ b/man/getPeak2GeneLinks.Rd @@ -33,3 +33,15 @@ the \code{ArchRBrowser()} or as an \code{ArchRBrowserTrack()}.} \description{ This function obtains peak-to-gene links from an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add P2G Links +proj <- addPeak2GeneLinks(proj, k = 20) + +# Get P2G Links +p2g <- getPeak2GeneLinks(proj) + +} diff --git a/man/getPeakAnnotation.Rd b/man/getPeakAnnotation.Rd index 94ebae04..e1f7001c 100644 --- a/man/getPeakAnnotation.Rd +++ b/man/getPeakAnnotation.Rd @@ -14,3 +14,12 @@ getPeakAnnotation(ArchRProj = NULL, name = NULL) \description{ This function gets a peakAnnotation from a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Peak Annotations +peakAnno <- getPeakAnnotation(proj) + +} diff --git a/man/getPeakSet.Rd b/man/getPeakSet.Rd index 307ada51..790bac88 100644 --- a/man/getPeakSet.Rd +++ b/man/getPeakSet.Rd @@ -12,3 +12,12 @@ getPeakSet(ArchRProj = NULL) \description{ This function gets the peak set as a GRanges object from an ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get PeakSet +getPeakSet(proj) + +} diff --git a/man/getPositions.Rd b/man/getPositions.Rd index fde37d94..3b98ba91 100644 --- a/man/getPositions.Rd +++ b/man/getPositions.Rd @@ -16,3 +16,12 @@ getPositions(ArchRProj = NULL, name = NULL, annoName = NULL) \description{ This function gets the peak annotation positions (i.e. Motifs) from a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Annotation Positions +positions <- getPositions(proj) + +} diff --git a/man/getProjectSummary.Rd b/man/getProjectSummary.Rd index 86c514de..7daf9266 100644 --- a/man/getProjectSummary.Rd +++ b/man/getProjectSummary.Rd @@ -14,3 +14,12 @@ getProjectSummary(ArchRProj = NULL, returnSummary = FALSE) \description{ This function prints the projectSummary from an ArchRProject } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Project Summary +getProjectSummary(proj) + +} diff --git a/man/getReducedDims.Rd b/man/getReducedDims.Rd index 4ba7dedf..084f387e 100644 --- a/man/getReducedDims.Rd +++ b/man/getReducedDims.Rd @@ -34,3 +34,12 @@ to sequencing depth that is greater than the \code{corCutOff}, it will be exclud \description{ This function gets a dimensionality reduction object (i.e. UMAP, tSNE, etc) from a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Iterative LSI +getReducedDims(proj, reducedDims = "IterativeLSI") + +} diff --git a/man/getSampleColData.Rd b/man/getSampleColData.Rd index d1c776a7..9b0672ba 100644 --- a/man/getSampleColData.Rd +++ b/man/getSampleColData.Rd @@ -16,3 +16,12 @@ getSampleColData(ArchRProj = NULL, select = NULL, drop = FALSE) \description{ This function gets the sampleColData from a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Sample Column Data +getSampleColData(proj) + +} diff --git a/man/getSampleNames.Rd b/man/getSampleNames.Rd index a7b827c0..d60331ad 100644 --- a/man/getSampleNames.Rd +++ b/man/getSampleNames.Rd @@ -12,3 +12,12 @@ getSampleNames(ArchRProj = NULL) \description{ This function gets the names of all samples from a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Sample Names +getSampleNames(proj) + +} diff --git a/man/getSeqnames.Rd b/man/getSeqnames.Rd index 3306ea7c..5f1a9420 100644 --- a/man/getSeqnames.Rd +++ b/man/getSeqnames.Rd @@ -15,3 +15,12 @@ getSeqnames(ArchRProj = NULL, useMatrix = "GeneScoreMatrix") This function will identify available seqnames from a given data matrix (i.e. "GeneScoreMatrix", or "TileMatrix") and return them for downstream plotting utilities. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Seqnames in Matrix +getSeqnames(proj, useMatrix = "GeneScoreMatrix") + +} diff --git a/man/getTSS.Rd b/man/getTSS.Rd index 370f53b8..03d70166 100644 --- a/man/getTSS.Rd +++ b/man/getTSS.Rd @@ -12,3 +12,15 @@ getTSS(ArchRProj = NULL) \description{ This function gets the transcription start sites (TSSs) as a GRanges object of all genes from the geneAnnotation of a given ArchRProject. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get TSS in ArchRProj +getTSS(proj) + +# Get TSS loaded globally +getTSS() + +} diff --git a/man/getTestArrow.Rd b/man/getTestArrow.Rd new file mode 100644 index 00000000..9eb17db1 --- /dev/null +++ b/man/getTestArrow.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/InputData.R +\name{getTestArrow} +\alias{getTestArrow} +\title{Get PBMC Small Test Arrow file} +\usage{ +getTestArrow(version = 2) +} +\arguments{ +\item{version}{version of test arrow to return} +} +\description{ +V2 : This function will return a test arrow file in your cwd. +} +\examples{ + +# Get Test Arrow +arrow <- getTestArrow() + +} diff --git a/man/getTestFragments.Rd b/man/getTestFragments.Rd index 4de51bcc..1064a815 100644 --- a/man/getTestFragments.Rd +++ b/man/getTestFragments.Rd @@ -4,8 +4,18 @@ \alias{getTestFragments} \title{Get PBMC Small Test Fragments} \usage{ -getTestFragments(x) +getTestFragments(version = 2) +} +\arguments{ +\item{version}{version of test fragments to return} } \description{ -This function will download fragments for a small PBMC test dataset (2k Cells) spanning chr1 and 2 (~20MB). +V1 : This function will download fragments for a small PBMC test dataset. +V2 : This function will return test fragments for a small PBMC test dataset in your cwd. +} +\examples{ + +# Get Test Fragments +fragments <- getTestFragments() + } diff --git a/man/getTestProject.Rd b/man/getTestProject.Rd index fce9f764..3619e02b 100644 --- a/man/getTestProject.Rd +++ b/man/getTestProject.Rd @@ -4,8 +4,18 @@ \alias{getTestProject} \title{Get PBMC Small Test Project} \usage{ -getTestProject() +getTestProject(version = 2) +} +\arguments{ +\item{version}{version of test fragments to return} } \description{ -This function will download an ArchRProject for a small PBMC test dataset (2k Cells) spanning chr1 and 2 (~2-300MB). +V1 : This function will download an ArchRProject for a small PBMC test dataset. +V2 : This function will return an ArchRProject for a small PBMC test dataset in your cwd. +} +\examples{ + +# Get Test Project +proj <- getTestProject() + } diff --git a/man/getTrajectory.Rd b/man/getTrajectory.Rd index 9765e0d8..bc51bb75 100644 --- a/man/getTrajectory.Rd +++ b/man/getTrajectory.Rd @@ -43,3 +43,15 @@ trajectory matrix to better reveal temporal dynamics.} This function will get a supervised trajectory from an \code{ArchRProject} (see \code{addTrajectory}), get data from a desired matrix, and smooth each value across the input trajectory. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +#Add Trajectory +proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) + +#Get Trajectory +seTraj <- getTrajectory(proj) + +} diff --git a/man/getTutorialData.Rd b/man/getTutorialData.Rd index 2100812c..96990334 100644 --- a/man/getTutorialData.Rd +++ b/man/getTutorialData.Rd @@ -7,12 +7,19 @@ getTutorialData(tutorial = "hematopoiesis", threads = getArchRThreads()) } \arguments{ -\item{tutorial}{The name of the available tutorial for which to retreive the tutorial data. Currently, the only available option is "Hematopoiesis". +\item{tutorial}{The name of the available tutorial for which to retreive the tutorial data. The main option is "Hematopoiesis". "Hematopoiesis" is a small scATAC-seq dataset that spans the hematopoieitic hierarchy from stem cells to differentiated cells. -This dataset is made up of cells from peripheral blood, bone marrow, and CD34+ sorted bone marrow.} +This dataset is made up of cells from peripheral blood, bone marrow, and CD34+ sorted bone marrow. The second option is "Test" +which is downloading a small test PBMC fragments file mainly used to test the url capabilities of this function.} \item{threads}{The number of threads to be used for parallel computing.} } \description{ This function will download data for a given tutorial and return the input files required for ArchR. } +\examples{ + +# Get Tutorial Fragments using `test` since its smaller +fragments <- getTutorialData(tutorial = "test") + +} diff --git a/man/getVarDeviations.Rd b/man/getVarDeviations.Rd index 9e13e70e..b7e5b9b8 100644 --- a/man/getVarDeviations.Rd +++ b/man/getVarDeviations.Rd @@ -18,3 +18,12 @@ getVarDeviations(ArchRProj = NULL, name = "MotifMatrix", plot = TRUE, n = 25) \description{ This function will rank the variability of the deviations computed by ArchR and label the top variable annotations. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Variable Motif Deviations +varDev <- getVarDeviations(proj) + +} diff --git a/man/ggAlignPlots.Rd b/man/ggAlignPlots.Rd index 25c7e94c..ccc223cd 100644 --- a/man/ggAlignPlots.Rd +++ b/man/ggAlignPlots.Rd @@ -20,3 +20,18 @@ ggAlignPlots(..., plotList = NULL, sizes = NULL, type = "v", draw = TRUE) \description{ This function aligns ggplots vertically or horizontally } +\examples{ + +# Create Random Data +m <- data.frame(x=matrix(rnorm(10, 2),ncol=1)) +m$color <- sample(c("A", "B"), 10, replace = TRUE) + +# Plot +p <- ggGroup(x = m$color, y = m$x) + +# To PDF +pdf("test.pdf", width = 4, height = 7) +ggAlignPlots(p, p) +dev.off() + +} diff --git a/man/ggGroup.Rd b/man/ggGroup.Rd index d32d3e49..c493cf40 100644 --- a/man/ggGroup.Rd +++ b/man/ggGroup.Rd @@ -60,3 +60,18 @@ values of \code{x} in the desired order.} \description{ This function is a wrapper around ggplot geom_density_ridges or geom_violin to allow for plotting group distribution plots in ArchR. } +\examples{ + +# Create Random Data +m <- data.frame(x=matrix(rnorm(10, 2),ncol=1)) +m$color <- sample(c("A", "B"), 10, replace = TRUE) + +# Plot +p <- ggGroup(x = m$color, y = m$x) + +# To PDF +pdf("test.pdf", width = 4, height = 4) +p +dev.off() + +} diff --git a/man/ggHex.Rd b/man/ggHex.Rd index f690a5bd..8c758f22 100644 --- a/man/ggHex.Rd +++ b/man/ggHex.Rd @@ -68,3 +68,17 @@ them to the value of the 97.5th and 2.5th percentile values respectively.} \description{ This function will plot x,y coordinate values summarized in hexagons in a standardized manner } +\examples{ + +# Create Random Data +m <- data.frame(matrix(rnorm(300, 2),ncol=3)) + +# Plot +p <- ggHex(x = m[,1], y = m[,2], color = m[,3]) + +# To PDF +pdf("test.pdf", width = 4, height = 4) +p +dev.off() + +} diff --git a/man/ggOneToOne.Rd b/man/ggOneToOne.Rd index 3c1b79dc..28ec9830 100644 --- a/man/ggOneToOne.Rd +++ b/man/ggOneToOne.Rd @@ -62,3 +62,17 @@ ggOneToOne( \description{ This function is a wrapper around ggplot geom_point to allow for plotting one-to-one sample comparisons in ArchR. } +\examples{ + +# Create Random Data +m <- data.frame(matrix(rnorm(20, 2),ncol=2)) + +# Plot +p <- ggOneToOne(x = m[,1], y = m[,2]) + +# To PDF +pdf("test.pdf", width = 4, height = 4) +p +dev.off() + +} diff --git a/man/ggPoint.Rd b/man/ggPoint.Rd index 3adcaaff..4c5953d2 100644 --- a/man/ggPoint.Rd +++ b/man/ggPoint.Rd @@ -126,3 +126,18 @@ lines and labels, just the internal portions of the plot.} \description{ This function is a wrapper around ggplot geom_point to allow for a more intuitive plotting of ArchR data. } +\examples{ + +# Create Random Data +m <- data.frame(matrix(rnorm(20, 2),ncol=2)) +m$color <- sample(c("A", "B"), 10, replace = TRUE) + +# Plot +p <- ggPoint(x = m[,1], y = m[,2], color = m[,3]) + +# To PDF +pdf("test.pdf", width = 4, height = 4) +p +dev.off() + +} diff --git a/man/grapes-bcin-grapes.Rd b/man/grapes-bcin-grapes.Rd index 5bcf1ead..01335aef 100644 --- a/man/grapes-bcin-grapes.Rd +++ b/man/grapes-bcin-grapes.Rd @@ -14,3 +14,9 @@ x \%bcin\% table \description{ This function provides a generic matching function for S4Vector objects primarily to avoid ambiguity. } +\examples{ + +#Test +Rle(c("A", "B", "C")) \%bcin\% Rle(c("A", "C")) + +} diff --git a/man/grapes-bcni-grapes.Rd b/man/grapes-bcni-grapes.Rd index 8365ee9b..c48d64d9 100644 --- a/man/grapes-bcni-grapes.Rd +++ b/man/grapes-bcni-grapes.Rd @@ -14,3 +14,9 @@ x \%bcni\% table \description{ This function provides the reciprocal of \%bcin\% for S4Vector objects primarily to avoid ambiguity. } +\examples{ + +#Test +Rle(c("A", "B", "C")) \%bcni\% Rle(c("A", "C")) + +} diff --git a/man/grapes-ni-grapes.Rd b/man/grapes-ni-grapes.Rd index 39ea1864..22483b5c 100644 --- a/man/grapes-ni-grapes.Rd +++ b/man/grapes-ni-grapes.Rd @@ -14,3 +14,9 @@ x \%ni\% table \description{ This function is the reciprocal of \%in\%. See the match funciton in base R. } +\examples{ + +#Test +c("A", "B", "C") \%ni\% c("A", "C") + +} diff --git a/man/imputeMatrix.Rd b/man/imputeMatrix.Rd index 28f094c1..58b35aa9 100644 --- a/man/imputeMatrix.Rd +++ b/man/imputeMatrix.Rd @@ -26,3 +26,21 @@ imputeMatrix( \description{ This function gets imputation weights from an ArchRProject to impute a numerical matrix } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add Impute Weights +proj <- addImputeWeights(proj) + +# Get Impute Weights +iW <- getImputeWeights(proj) + +# Get Matrix +se <- getMatrixFromProject(proj, useMatrix = "GeneScoreMatrix") + +# Impute +mat <- imputeMatrix(assay(se), iW) + +} diff --git a/man/installExtraPackages.Rd b/man/installExtraPackages.Rd index 9a3a5559..02d7b72f 100644 --- a/man/installExtraPackages.Rd +++ b/man/installExtraPackages.Rd @@ -12,3 +12,9 @@ installExtraPackages(force = FALSE) \description{ This function will install extra packages used in ArchR that are not installed by default. } +\examples{ + +# Install +installExtraPackages() + +} diff --git a/man/loadArchRProject.Rd b/man/loadArchRProject.Rd index 58dabb3b..84f0c88c 100644 --- a/man/loadArchRProject.Rd +++ b/man/loadArchRProject.Rd @@ -18,3 +18,21 @@ will fail unless all components can be found.} \description{ This function will load a previously saved ArchRProject and re-normalize paths for usage. } +\examples{ + +# Get Small PBMC Project Location +zipProj <- file.path(system.file("testdata", package="ArchR"), "PBSmall.zip") + +# Copy to current directory +file.copy(zipProj, basename(zipProj), overwrite = TRUE) + +# Unzip +unzip(basename(zipProj), overwrite = TRUE) + +# Remove +file.remove(basename(zipProj)) + +# Load +loadArchRProject("PBSmall") + +} diff --git a/man/mapLabels.Rd b/man/mapLabels.Rd index 825225aa..ac99d9d6 100644 --- a/man/mapLabels.Rd +++ b/man/mapLabels.Rd @@ -17,3 +17,12 @@ mapLabels(labels = NULL, newLabels = NULL, oldLabels = names(newLabels)) This function takes a character vector of labels and uses a set of old and new labels to re-map from the old label set to the new label set. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Peak Annotations +proj$ClusterLabels <- mapLabels(proj$Clusters, c("T", "B", "M"), c("C1", "C2", "C3")) + +} diff --git a/man/nCells.Rd b/man/nCells.Rd index 804bef9a..c494b818 100644 --- a/man/nCells.Rd +++ b/man/nCells.Rd @@ -12,3 +12,12 @@ nCells(input = NULL) \description{ This function gets number of cells from an ArchRProject or ArrowFile } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Number of Cells +nCells(proj) + +} diff --git a/man/nonOverlappingGR.Rd b/man/nonOverlappingGR.Rd index 367e74e3..34b7d67d 100644 --- a/man/nonOverlappingGR.Rd +++ b/man/nonOverlappingGR.Rd @@ -22,3 +22,19 @@ order. If \code{TRUE}, the higher value in \code{by} will be retained.} \description{ This function returns a GRanges object containing a non-overlapping set regions derived from a supplied Genomic Ranges object. } +\examples{ + +# Dummy GR +gr <- GRanges( + seqnames = "chr1", + ranges = IRanges( + start = c(1, 4, 11), + end = c(10, 12, 20) + ), + score = c(1, 2, 3) +) + +# Non Overlapping +nonOverlappingGR(gr) + +} diff --git a/man/paletteContinuous.Rd b/man/paletteContinuous.Rd index 31c720b1..8098d201 100644 --- a/man/paletteContinuous.Rd +++ b/man/paletteContinuous.Rd @@ -16,3 +16,9 @@ paletteContinuous(set = "solarExtra", n = 256, reverse = FALSE) \description{ Continuous Color Palette } +\examples{ + +# Color Palette +pal <- paletteContinuous() + +} diff --git a/man/paletteDiscrete.Rd b/man/paletteDiscrete.Rd index d457f233..4b0953a6 100644 --- a/man/paletteDiscrete.Rd +++ b/man/paletteDiscrete.Rd @@ -18,3 +18,12 @@ given a unique color from the designated palette set.} This function assesses the number of inputs and returns a discrete color palette that is tailored to provide the most possible color contrast from the designated color set. } +\examples{ + +# Vector +v <- c("A", "B") + +# Color Palette +pal <- paletteDiscrete(values = v) + +} diff --git a/man/peakAnnoEnrichment.Rd b/man/peakAnnoEnrichment.Rd index 655e8be9..65593603 100644 --- a/man/peakAnnoEnrichment.Rd +++ b/man/peakAnnoEnrichment.Rd @@ -34,3 +34,24 @@ peakAnnoEnrichment( \description{ This function will perform hypergeometric enrichment of a given peak annotation within the defined marker peaks. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Markers +seMarker <- getMarkerFeatures( + ArchRProj = proj, + useMatrix = "PeakMatrix", + testMethod = "binomial", + binarize = TRUE +) + +# Get Peak Annotation Enrichment +annoEnrich <- peakAnnoEnrichment( + seMarker = seMarker, + ArchRProj = proj, + cutOff = "FDR <= 0.1 & Log2FC >= 0" +) + +} diff --git a/man/plotBrowserTrack.Rd b/man/plotBrowserTrack.Rd index ada70e90..64d35fa8 100644 --- a/man/plotBrowserTrack.Rd +++ b/man/plotBrowserTrack.Rd @@ -116,3 +116,15 @@ This function will plot the coverage at an input region in the style of a browse which enables direct comparison across samples. Note that the genes displayed in these plots are derived from your \code{geneAnnotation} (i.e. the \code{BSgenome} object you used) so they may not match other online genome browsers that use different gene annotations. } +\examples{ + +#Get Test ArchR Project +proj <- getTestProject() + +#Plot Track +p <- plotBrowserTrack(proj, geneSymbol = c("CD3D", "MS4A1"), groupBy = "CellType") + +#Plot PDF +plotPDF(p, name = "Track-CD3D-MS4A1", ArchRProj = proj) + +} diff --git a/man/plotEmbedding.Rd b/man/plotEmbedding.Rd index 4ed4836a..8280117d 100644 --- a/man/plotEmbedding.Rd +++ b/man/plotEmbedding.Rd @@ -92,3 +92,15 @@ if \code{colorBy} is numeric, then \code{plotAs} is set to "hex".} \description{ This function will plot an embedding stored in an ArchRProject } +\examples{ + +#Get Test Project +proj <- getTestProject() + +#Plot UMAP +p <- plotEmbedding(proj, name = "Clusters") + +#PDF +plotPDF(p, name = "UMAP-Clusters", ArchRProj = proj) + +} diff --git a/man/plotEnrichHeatmap.Rd b/man/plotEnrichHeatmap.Rd index ec4de9fe..77f8b6d5 100644 --- a/man/plotEnrichHeatmap.Rd +++ b/man/plotEnrichHeatmap.Rd @@ -49,3 +49,33 @@ lines and labels, just the internal portions of the plot.} \description{ This function will plot a heatmap of hypergeometric enrichment of a given peakAnnotation within the defined marker peaks. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Markers +seMarker <- getMarkerFeatures( + ArchRProj = proj, + useMatrix = "PeakMatrix", + testMethod = "binomial", + binarize = TRUE +) + +# Get Peak Annotation Enrichment +annoEnrich <- peakAnnoEnrichment( + seMarker = seMarker, + ArchRProj = proj, + cutOff = "FDR <= 0.1 & Log2FC >= 0" +) + +# Multiply by 50 since this is a super small test sample +assay(annoEnrich) <- assay(annoEnrich) * 50 + +#Plot +p <- plotEnrichHeatmap(annoEnrich) + +#PDF +plotPDF(p, name = "PeakAnnoEnrich", ArchRProj = proj) + +} diff --git a/man/plotFootprints.Rd b/man/plotFootprints.Rd index 62f4e3f8..bb9048f7 100644 --- a/man/plotFootprints.Rd +++ b/man/plotFootprints.Rd @@ -62,3 +62,18 @@ This prevents large amount of footprint plots stored as an object.} \description{ This function will get footprints for all samples in a given ArchRProject or a properly-formatted Summarized Experiment } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Motif Positions +positions <- getPositions(proj) + +# Get Footprints +seFoot <- getFootprints(ArchRProj = proj, positions = positions, groupBy = "Clusters", minCells = 10) + +# Plot Footprints +plotFootprints(seFoot, smoothWindow = 11) + +} diff --git a/man/plotFragmentSizes.Rd b/man/plotFragmentSizes.Rd index 87e0ebd2..149ad9b1 100644 --- a/man/plotFragmentSizes.Rd +++ b/man/plotFragmentSizes.Rd @@ -36,3 +36,15 @@ instead of plotting the fragment size distribution.} \description{ This function will plot a fragment size distribution for each sample. Only cells in the \code{ArchRProject} are used when making this plot. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Plot Frag Sizes +p <- plotFragmentSizes(proj, groupBy = "Clusters") + +# PDF +plotPDF(p, name = "Frag-Sizes", ArchRProj = proj) + +} diff --git a/man/plotGroups.Rd b/man/plotGroups.Rd index a16f907d..c0f0b6f1 100644 --- a/man/plotGroups.Rd +++ b/man/plotGroups.Rd @@ -72,3 +72,15 @@ to the value of the 97.5th and 2.5th percentile values respectively.} \description{ This function will group, summarize and then plot data from an ArchRProject for visual comparison. } +\examples{ + +#Get Test Project +proj <- getTestProject() + +#Plot Groups +p <- plotGroups(proj, groupBy = "Clusters", colorBy = "colData", name = "TSSEnrichment", plotAs = "violin", alpha = 0.5) + +#PDF +plotPDF(p, name = "Clusters-TSS", ArchRProj = proj) + +} diff --git a/man/plotMarkerHeatmap.Rd b/man/plotMarkerHeatmap.Rd index 7ad7c9d7..703a0d76 100644 --- a/man/plotMarkerHeatmap.Rd +++ b/man/plotMarkerHeatmap.Rd @@ -73,3 +73,23 @@ looking for down-regulated markers (\verb{log2(fold change) < 0}) instead of up- \description{ This function will plot a heatmap of the results from markerFeatures } +\examples{ + +#Get Test Project +proj <- getTestProject() + +#Get Markers +seMarker <- getMarkerFeatures( + ArchRProj = proj, + useMatrix = "PeakMatrix", + testMethod = "binomial", + binarize = TRUE +) + +#Plot Markers +p <- plotMarkerHeatmap(seMarker) + +#PDF +plotPDF(p, name = "Marker-Heatmap", ArchRProj = proj) + +} diff --git a/man/plotMarkers.Rd b/man/plotMarkers.Rd index 6b1a0078..ffe9d0f2 100644 --- a/man/plotMarkers.Rd +++ b/man/plotMarkers.Rd @@ -30,3 +30,23 @@ lines and labels, just the internal portions of the plot.} \description{ This function will plot one group/column of a differential markers as an MA or Volcano plot. } +\examples{ + +#Get Test Project +proj <- getTestProject() + +#Get Markers +seMarker <- getMarkerFeatures( + ArchRProj = proj, + useMatrix = "PeakMatrix", + testMethod = "binomial", + binarize = TRUE +) + +#Plot Markers +p <- plotMarkers(seMarker, name = "C1") + +#PDF +plotPDF(p, name = "Marker-Plot", ArchRProj = proj) + +} diff --git a/man/plotPDF.Rd b/man/plotPDF.Rd index 6ea4bb86..4c57c7da 100644 --- a/man/plotPDF.Rd +++ b/man/plotPDF.Rd @@ -38,3 +38,15 @@ object (ggplot2, plot, heatmap, etc).} \description{ This function will save a plot or set of plots as a PDF file in the outputDirectory of a given ArchRProject. } +\examples{ + +#Get Test Project +proj <- getTestProject() + +#Plot UMAP +p <- plotEmbedding(proj, name = "Clusters") + +#PDF +plotPDF(p, name = "UMAP-Clusters", ArchRProj = proj) + +} diff --git a/man/plotPeak2GeneHeatmap.Rd b/man/plotPeak2GeneHeatmap.Rd index 52d77d6b..c6f4d7d8 100644 --- a/man/plotPeak2GeneHeatmap.Rd +++ b/man/plotPeak2GeneHeatmap.Rd @@ -63,3 +63,19 @@ reproduce results downstream.} \description{ This function plots side by side heatmaps of linked ATAC and Gene regions from \code{addPeak2GeneLinks}. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Add P2G Links +proj <- addPeak2GeneLinks(proj, k = 20) + +# Get P2G Links +p2g <- getPeak2GeneLinks(proj) + +# Plot P2G +p <- plotPeak2GeneHeatmap(proj) +plotPDF(p, name = "P2G-Heatmap", ArchRProj = proj) + +} diff --git a/man/plotTSSEnrichment.Rd b/man/plotTSSEnrichment.Rd index 264645fa..22fe3f23 100644 --- a/man/plotTSSEnrichment.Rd +++ b/man/plotTSSEnrichment.Rd @@ -48,3 +48,15 @@ instead of plotting the TSS enrichment plot.} This function will plot a TSS enrichment plot for each sample. Cells in \code{ArchRProject} are the only ones used when making this plot. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Plot TSS +p <- plotTSSEnrichment(proj, groupBy = "Clusters") + +# PDF +plotPDF(p, name = "TSS-Enrich", ArchRProj = proj) + +} diff --git a/man/plotTrajectory.Rd b/man/plotTrajectory.Rd index bc6137f8..18a26dba 100644 --- a/man/plotTrajectory.Rd +++ b/man/plotTrajectory.Rd @@ -89,3 +89,18 @@ if \code{colorBy} is numeric, then \code{plotAs} is set to "hex".} \description{ This function will plot a trajectory that was created onto an embedding. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +#Add Trajectory +proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) + +#Plot Trajectory +p <- plotTrajectory(proj, smoothWindow = 20) + +#PDF +plotPDF(p, name = "Trajcetory", ArchRProj = proj) + +} diff --git a/man/plotTrajectoryHeatmap.Rd b/man/plotTrajectoryHeatmap.Rd index 4a22c00f..407d5587 100644 --- a/man/plotTrajectoryHeatmap.Rd +++ b/man/plotTrajectoryHeatmap.Rd @@ -64,3 +64,21 @@ can be in different units.} \description{ This function will plot a heatmap of the results from getTrajectory } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +#Add Trajectory +proj <- addTrajectory(proj, trajectory = c("C1", "C2", "C3"), embedding = "UMAP", force = TRUE) + +#Get Trajectory +seTraj <- getTrajectory(proj) + +#Plot Trajectory Heatmap +p <- plotTrajectoryHeatmap(seTraj) + +#Plot PDF +plotPDF(p, name = "Trajectory-Heatmap", ArchRProj = proj) + +} diff --git a/man/recoverArchRProject.Rd b/man/recoverArchRProject.Rd index 80fbefe9..2da818f2 100644 --- a/man/recoverArchRProject.Rd +++ b/man/recoverArchRProject.Rd @@ -12,3 +12,12 @@ recoverArchRProject(ArchRProj) \description{ This function will recover an ArchRProject if it has broken sampleColData or cellColData due to different versions of bioconductor s4vectors. } +\examples{ + +# Get Test Project +proj <- getTestProject() + +# Try to Recover ArchR Project +proj <- recoverArchRProject(proj) + +} diff --git a/man/reformatFragmentFiles.Rd b/man/reformatFragmentFiles.Rd index 933b70c2..11d43031 100644 --- a/man/reformatFragmentFiles.Rd +++ b/man/reformatFragmentFiles.Rd @@ -19,3 +19,12 @@ reformatFragmentFiles( This function provides help in reformatting Fragment Files for reading in createArrowFiles. It will handle weird anomalies found that cause errors in reading tabix bgzip'd fragment files. } +\examples{ + +# Get Test Fragments +fragments <- getTestFragments() + +# Get Peak Annotations +fragments2 <- reformatFragmentFiles(fragments) + +} diff --git a/man/saveArchRProject.Rd b/man/saveArchRProject.Rd index d9a717ab..d0aa6a98 100644 --- a/man/saveArchRProject.Rd +++ b/man/saveArchRProject.Rd @@ -30,3 +30,12 @@ saveArchRProject( \description{ This function will organize arrows and project output into a directory and save the ArchRProject for later usage. } +\examples{ + +# Get Small Test Project +proj <- getTestProject() + +# Save +saveArchRProject(proj) + +} diff --git a/man/setArchRLocking.Rd b/man/setArchRLocking.Rd index 6411bee2..4533dd45 100644 --- a/man/setArchRLocking.Rd +++ b/man/setArchRLocking.Rd @@ -9,3 +9,9 @@ setArchRLocking() \description{ This function will set the default H5 file locking parameters to the system } +\examples{ + +# Set ArchR H5 Locking Globally +setArchRLocking() + +} diff --git a/man/subsetArchRProject.Rd b/man/subsetArchRProject.Rd index 9f75916f..ff76b0c0 100644 --- a/man/subsetArchRProject.Rd +++ b/man/subsetArchRProject.Rd @@ -32,3 +32,12 @@ subsetArchRProject( \description{ This function will subset and ArchRProject by cells and save the output to a new directory and re-load the subsetted ArchRProject. } +\examples{ + +# Get Small Test Project +proj <- getTestProject() + +#Subset +proj <- subsetArchRProject(proj, cells = getCellNames(proj)[1:50]) + +} diff --git a/man/subsetCells.Rd b/man/subsetCells.Rd index cac3ee10..0313a905 100644 --- a/man/subsetCells.Rd +++ b/man/subsetCells.Rd @@ -14,3 +14,12 @@ subsetCells(ArchRProj = NULL, cellNames = NULL) \description{ This function returns an ArchRProject object that contains a specified subset of cells. } +\examples{ + +# Get Test ArchR Project +proj <- getTestProject() + +# Get Peak Annotations +proj <- subsetCells(proj, getCellNames(proj)[1:50]) + +} diff --git a/man/theme_ArchR.Rd b/man/theme_ArchR.Rd index eac42e87..043fd1bd 100644 --- a/man/theme_ArchR.Rd +++ b/man/theme_ArchR.Rd @@ -44,3 +44,18 @@ theme_ArchR( \description{ This function returns a ggplot2 theme that is black borded with black font. } +\examples{ + +# Create Random Data +m <- data.frame(x=matrix(rnorm(10, 2),ncol=1)) +m$color <- sample(c("A", "B"), 10, replace = TRUE) + +# Plot +p <- ggGroup(x = m$color, y = m$x) + theme_ArchR() + +# To PDF +pdf("test.pdf", width = 4, height = 7) +p +dev.off() + +} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 00000000..25f5e362 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(ArchR) + +test_check("ArchR") \ No newline at end of file diff --git a/tests/testthat/test_arrow.R b/tests/testthat/test_arrow.R new file mode 100644 index 00000000..63bab730 --- /dev/null +++ b/tests/testthat/test_arrow.R @@ -0,0 +1,278 @@ +# Tests for arrow +# change in random number generation in R3.6, this ensures tests will pass under older and newer Rs +# (this was implemented in Seurat's testthat) +library(ArchR) +library(testthat) +library(Matrix) +suppressWarnings(RNGversion(vstr = "3.5.3")) +set.seed(1) + +#Context +context("test_arrow") + +#Fragments +fragments <- file.path(system.file("testdata", package="ArchR"), "PBSmall.tsv.gz") + +#Check +test_that("Test Fragments Exist...", { + expect_equal(file.exists(fragments), TRUE) +}) + +################################################ +# Testing Create Arrow File +################################################ + +addArchRGenome("hg19test2") + +test_that("Test Genome is Correct Exist...", { + check1 <- all(paste0(seqnames(getGenes())) %in% c("chr5", "chr11")) + check2 <- all(paste0(seqnames(getChromSizes())) %in% c("chr5", "chr11")) + expect_equal(check1, TRUE) + expect_equal(check2, TRUE) +}) + +#Create Arrow Files +arrowFiles <- createArrowFiles( + inputFiles = fragments, + sampleNames = "PBSmall", + minFrags = 100, + nChunk = 1, + TileMatParams=list(tileSize=10000), + force = TRUE +) + +#Get Contents +test_that("Checking Arrow Contents...", { + + expect_equal( + ArchR:::.validArrow(arrowFiles), + arrowFiles + ) + + expect_equal( + ArchR:::.availableArrays(arrowFiles), + c("GeneScoreMatrix", "TileMatrix") + ) + + expect_equal( + nrow(ArchR:::.getFeatureDF(arrowFiles, "TileMatrix")), + 31593 + ) + + expect_equal( + nrow(ArchR:::.getFeatureDF(arrowFiles, "GeneScoreMatrix")), + 2454 + ) + + expect_equal( + ArchR:::.availableSeqnames(arrowFiles), + c("chr11", "chr5") + ) + + expect_equal( + ArchR:::.availableChr(arrowFiles), + c("chr11", "chr5") + ) + + expect_equal( + as.vector(table(substr(ArchR:::.availableCells(arrowFiles), 9, 9))[c("B", "M", "T")]), + c(45, 33, 49) + ) + + expect_equal( + paste0(ArchR:::.sampleName(arrowFiles)), + "PBSmall" + ) + +}) + +################################################ +# Testing Dropping Matrices +################################################ + +arrowFiles <- ArchR:::.dropGroupsFromArrow( + ArrowFile = arrowFiles, + dropGroups = c("GeneScoreMatrix", "TileMatrix") +) + +#Get Contents +test_that("Checking Arrow Contents After Drop...", { + + expect_equal( + ArchR:::.validArrow(arrowFiles), + arrowFiles + ) + + expect_equal( + paste0(ArchR:::.availableArrays(arrowFiles)), + c("")[-1] + ) + + expect_equal( + ArchR:::.availableSeqnames(arrowFiles), + c("chr11", "chr5") + ) + + expect_equal( + ArchR:::.availableChr(arrowFiles), + c("chr11", "chr5") + ) + + expect_equal( + as.vector(table(substr(ArchR:::.availableCells(arrowFiles), 9, 9))[c("B", "M", "T")]), + c(45, 33, 49) + ) + + expect_equal( + paste0(ArchR:::.sampleName(arrowFiles)), + "PBSmall" + ) + +}) + +################################################ +# Adding Tile Matrix +################################################ + +arrowFiles <- addTileMatrix( + input = arrowFiles, + tileSize = 25000, + chromSizes = getChromSizes(), + force = TRUE +) + +#Get Contents +test_that("Checking Arrow Contents after addTileMatrix", { + + expect_equal( + ArchR:::.validArrow(arrowFiles), + arrowFiles + ) + + expect_equal( + paste0(ArchR:::.availableArrays(arrowFiles)), + "TileMatrix" + ) + + expect_equal( + nrow(ArchR:::.getFeatureDF(arrowFiles, "TileMatrix")), + 12638 + ) + + expect_equal( + ArchR:::.availableSeqnames(arrowFiles), + c("chr11", "chr5") + ) + + expect_equal( + ArchR:::.availableChr(arrowFiles), + c("chr11", "chr5") + ) + + expect_equal( + as.vector(table(substr(ArchR:::.availableCells(arrowFiles), 9, 9))[c("B", "M", "T")]), + c(45, 33, 49) + ) + + expect_equal( + paste0(ArchR:::.sampleName(arrowFiles)), + "PBSmall" + ) + +}) + + +################################################ +# Adding Gene Score Matrix +################################################ + +arrowFiles <- addGeneScoreMatrix( + input = arrowFiles, + genes = getGenes() +) + +#Get Contents +test_that("Checking Arrow Contents after addGeneScoreMatrix...", { + + expect_equal( + ArchR:::.validArrow(arrowFiles), + arrowFiles + ) + + expect_equal( + ArchR:::.availableArrays(arrowFiles), + c("GeneScoreMatrix", "TileMatrix") + ) + + expect_equal( + nrow(ArchR:::.getFeatureDF(arrowFiles, "TileMatrix")), + 12638 + ) + + expect_equal( + nrow(ArchR:::.getFeatureDF(arrowFiles, "GeneScoreMatrix")), + 2454 + ) + + expect_equal( + ArchR:::.availableSeqnames(arrowFiles), + c("chr11", "chr5") + ) + + expect_equal( + ArchR:::.availableChr(arrowFiles), + c("chr11", "chr5") + ) + + expect_equal( + as.vector(table(substr(ArchR:::.availableCells(arrowFiles), 9, 9))[c("B", "M", "T")]), + c(45, 33, 49) + ) + + expect_equal( + paste0(ArchR:::.sampleName(arrowFiles)), + "PBSmall" + ) + +}) + +################################################ +# Final Checks +################################################ + +test_that("Final Checks...", { + + expect_equal( + length(getFragmentsFromArrow(arrowFiles)), + 26443 + ) + + expect_equal( + getMatrixFromArrow(arrowFiles, "GeneScoreMatrix") %>% {c(nrow(.), ncol(.))}, + c(2454, 127) + ) + + expect_equal( + getMatrixFromArrow(arrowFiles, "TileMatrix", binarize = TRUE) %>% {c(nrow(.), ncol(.))}, + c(12638, 127) + ) + +}) + +################################################ +# Clear +################################################ + +files <- list.files() +files <- files[!grepl("\\.R", files)] +for(i in seq_along(files)){ + if(dir.exists(files[i])){ + unlink(files[i], recursive=TRUE) + }else if(file.exists(files[i])){ + file.remove(files[i]) + } +} + + + + diff --git a/tests/testthat/test_cpp.R b/tests/testthat/test_cpp.R new file mode 100644 index 00000000..ecb4685f --- /dev/null +++ b/tests/testthat/test_cpp.R @@ -0,0 +1,99 @@ +# Tests for functions in src directory +# change in random number generation in R3.6, this ensures tests will pass under older and newer Rs +# (this was implemented in Seurat's testthat) +library(ArchR) +library(testthat) +library(Matrix) +suppressWarnings(RNGversion(vstr = "3.5.3")) +set.seed(1) + +#Context +context("test_cpp") + +#Default Matrices +data("m1") +m2 <- m1[rev(1:10), rev(1:10)] + +################################################ +# Testing Row Correlation +################################################ + +#Correlations +c1 <- ArchR:::rowCorCpp(1:10, 1:10, m1, m2) +c2 <- lapply(1:10, function(x){ + cor(m1[x, ], m2[x, ]) +}) %>% unlist + +#Test +test_that("Row-wise Correlation is working...", { + expect_equal(c1, c2) +}) + +################################################ +# Testing KNN Utils +################################################ + +#KNN +knnObj <- ArchR:::.computeKNN(m1, m2, k = 5) + +#Check Knn Overlap Cpp +overlapCpp <- ArchR:::determineOverlapCpp(knnObj, 3) + +#Check Knn Overlap R +overlapR <- lapply(seq_len(nrow(knnObj)), function(x){ + o <- lapply(seq_len(x-1), function(y){ + sum(knnObj[x, ] %in% knnObj[y, ]) + }) %>% unlist + if(any(o > 3)){ + -1 + }else{ + 0 + } +}) %>% unlist + +#Test +test_that("KNN Utils is working...", { + expect_equal(overlapCpp, overlapR) +}) + +################################################ +# Testing General Utils +################################################ + +#tabulate2dCpp +tab2d <- as.matrix(ArchR:::tabulate2dCpp( + x = c(0,0,2,2,3), + xmin = 0, + xmax = 3, + y = c(1,1,2,3,3), + ymin = 1, + ymax = 3 +)) + +tabSm <- as.matrix(Matrix::sparseMatrix( + i = c(1,1,2,3,3), + j = c(0,0,2,2,3) + 1, + x = c(1,1,1,1,1) +)) + +#Test +test_that("Tabulate Utils is working...", { + expect_equal(max(tab2d-tabSm) <= testthat_tolerance(), TRUE) +}) + +#rowSparseVariances +sm1 <- as(m1, "dgCMatrix") + +#Variances +var1 <- ArchR:::computeSparseRowVariances( + sm1@i + 1, sm1@x, Matrix::rowMeans(sm1), ncol(sm1)) + +var2 <- apply(m1, 1, var) + +test_that("Variance Utils is working...", { + expect_equal(max(var1-var2) <= testthat_tolerance(), TRUE) +}) + + + + diff --git a/tests/testthat/test_rd.R b/tests/testthat/test_rd.R new file mode 100644 index 00000000..e4b8e9bf --- /dev/null +++ b/tests/testthat/test_rd.R @@ -0,0 +1,35 @@ +# Tests for ArchR +# change in random number generation in R3.6, this ensures tests will pass under older and newer Rs +# (this was implemented in Seurat's testthat) +library(ArchR) +library(testthat) +library(Matrix) +suppressWarnings(RNGversion(vstr = "3.5.3")) +set.seed(1) + +clear_test_dir <- function(){ + files <- list.files() + files <- files[!grepl("\\.R", files)] + for(i in seq_along(files)){ + if(dir.exists(files[i])){ + unlink(files[i], recursive=TRUE) + }else if(file.exists(files[i])){ + file.remove(files[i]) + } + } +} + +################################################ +# Test Rd +################################################ + +fn <- list.files(system.file("man", package="ArchR"), full.names=TRUE) +fn <- grep("\\.Rd", fn, value=TRUE) +fn <- c( + fn[grepl("createArrow", fn)], + fn[!grepl("createArrow", fn)] +) +for(i in seq_along(fn)){ + test_example(path = fn[i], basename(fn[i])) + clear_test_dir() +} \ No newline at end of file diff --git a/tests/testthat/test_worklow.R b/tests/testthat/test_worklow.R new file mode 100644 index 00000000..399b022c --- /dev/null +++ b/tests/testthat/test_worklow.R @@ -0,0 +1,119 @@ +# Tests for ArchR +# change in random number generation in R3.6, this ensures tests will pass under older and newer Rs +# (this was implemented in Seurat's testthat) +library(ArchR) +library(testthat) +library(Matrix) +suppressWarnings(RNGversion(vstr = "3.5.3")) +set.seed(1) + +#Context +context("test_workflow") + +#Genome +addArchRGenome("hg19test2") + +#Arrows +arrows <- file.path(system.file("testdata", package="ArchR"), "PBSmall.arrow") + +#Project +proj <- ArchRProject(arrows, outputDirectory = "Test") + +#LSI +proj <- addIterativeLSI(proj, dimsToUse = 1:5, varFeatures=1000, iterations = 2, force=TRUE) + +#Clusters +proj <- addClusters(proj, force=TRUE, dimsToUse = 1:5) + +#Cell type +proj$CellType <- substr(getCellNames(proj), 9, 9) + +#Check Clusters +cM <- confusionMatrix(proj$CellType, proj$Clusters) + +test_that("Test Cluster Purity...", { + expect_equal(all(apply(cM / Matrix::rowSums(cM), 1, max) > 0.9), TRUE) +}) + +#UMAP +proj <- addUMAP(proj, nNeighbors = 40, dimsToUse = 1:5, minDist=0.1, force=TRUE) + +#Plot UMAP +p1 <- plotEmbedding(proj, name = "CellType", size = 3) +p2 <- plotEmbedding(proj, name = "Clusters", size = 3) +plotPDF(p1, p2, name = "UMAP", addDOC = FALSE, ArchRProj = proj) + +#Group Coverages +proj <- addGroupCoverages(proj) + +#Custom Peak Calling +proj <- addReproduciblePeakSet( + ArchRProj = proj, + groupBy = "Clusters", + peakMethod = "tiles", + minCells = 20, + cutOff = 0.1 +) + +#Macs2 Peak Calling +pathToMacs2 <- findMacs2() +proj <- addReproduciblePeakSet( + ArchRProj = proj, + groupBy = "Clusters", + pathToMacs2 = pathToMacs2, + minCells = 20, + cutOff = 0.1 +) + +#Add Peak Matrix +proj <- addPeakMatrix(proj) + +#Motif Annotations +proj <- addMotifAnnotations(ArchRProj = proj, motifSet = "cisbpTest", name = "Motif", force=TRUE) + +#Motif Deviations +proj <- addBgdPeaks(proj) +proj <- addDeviationsMatrix( + ArchRProj = proj, + peakAnnotation = "Motif", + force = TRUE +) + +#Check Matrices +se <- getMatrixFromProject(proj, "MotifMatrix") + +pval_CEBP <- t.test( + assays(se)$z["CEBPB_1", se$CellType=="T"], + assays(se)$z["CEBPB_1", se$CellType=="M"] +)$p.value + +pval_EOMES <- t.test( + assays(se)$z["EOMES_6", se$CellType=="T"], + assays(se)$z["EOMES_6", se$CellType=="M"] +)$p.value + +pval_PAX <- t.test( + assays(se)$z["PAX5_5", se$CellType=="M"], + assays(se)$z["PAX5_5", se$CellType=="B"] +)$p.value + +test_that("Test Motif Deviations...", { + expect_equal(pval_CEBP < 0.01, TRUE) + expect_equal(pval_EOMES < 0.01, TRUE) + expect_equal(pval_PAX < 0.01, TRUE) +}) + +################################################ +# Clear +################################################ + +files <- list.files() +files <- files[!grepl("\\.R", files)] +for(i in seq_along(files)){ + if(dir.exists(files[i])){ + unlink(files[i], recursive=TRUE) + }else if(file.exists(files[i])){ + file.remove(files[i]) + } +} +