Skip to content

Commit

Permalink
Update with testing and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranja-cartographybio committed Jul 2, 2022
1 parent 55f0923 commit 44a0d27
Show file tree
Hide file tree
Showing 202 changed files with 4,060 additions and 266 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LazyData: TRUE
RoxygenNote: 7.1.2
Encoding: UTF-8
Imports:
devtools,
ggplot2,
SummarizedExperiment,
data.table,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export(addArchRAnnotations)
export(addArchRChrPrefix)
export(addArchRDebugging)
export(addArchRGenome)
export(addArchRH5Level)
export(addArchRLocking)
export(addArchRLogging)
export(addArchRThreads)
Expand Down Expand Up @@ -68,6 +69,7 @@ export(findMacs2)
export(getArchRChrPrefix)
export(getArchRDebugging)
export(getArchRGenome)
export(getArchRH5Level)
export(getArchRLogging)
export(getArchRThreads)
export(getArchRVerbose)
Expand Down Expand Up @@ -112,6 +114,7 @@ export(getSampleColData)
export(getSampleNames)
export(getSeqnames)
export(getTSS)
export(getTestArrow)
export(getTestFragments)
export(getTestProject)
export(getTrajectory)
Expand Down Expand Up @@ -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)
55 changes: 54 additions & 1 deletion R/AllClasses.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' @useDynLib ArchR
#' @importFrom Rcpp sourceCpp
#' @importClassesFrom GenomicRanges GRanges
#' @importFrom GenomicRanges GRanges
#' @import data.table
NULL
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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){

Expand Down Expand Up @@ -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 = "./",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -789,7 +843,6 @@ subsetArchRProject <- function(

}


setMethod(
f = "colnames",
signature = c("x" = "ArchRProject"),
Expand Down
45 changes: 43 additions & 2 deletions R/AnnotationGenome.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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"))
Expand Down Expand Up @@ -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({
Expand Down
114 changes: 113 additions & 1 deletion R/AnnotationPeaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

#############################################################
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 44a0d27

Please sign in to comment.