Skip to content

Commit

Permalink
update release_1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffmgranja committed Jun 3, 2022
1 parent 2b3c722 commit 55f0923
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 70 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 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(addArchRLocking)
export(addArchRLogging)
export(addArchRThreads)
export(addArchRVerbose)
Expand Down Expand Up @@ -153,6 +154,7 @@ export(projectBulkATAC)
export(recoverArchRProject)
export(reformatFragmentFiles)
export(saveArchRProject)
export(setArchRLocking)
export(subsetArchRProject)
export(subsetCells)
export(theme_ArchR)
Expand Down
72 changes: 44 additions & 28 deletions R/AnnotationPeaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,41 +390,57 @@ addMotifAnnotations <- function(
motifs <- obj$motifs
motifSummary <- obj$motifSummary

}else if(tolower(motifSet)=="cisbp"){
}else if(tolower(motifSet) %in% c("cisbp", "cisbptest")){

.requirePackage("chromVARmotifs",installInfo='devtools::install_github("GreenleafLab/chromVARmotifs")')
if(tolower(species) == "mus musculus"){
if(version == 1){
message("Using version 1 motifs!")
data("mouse_pwms_v1")
motifs <- mouse_pwms_v1
}else if(version == 2){
message("Using version 2 motifs!")
data("mouse_pwms_v2")
motifs <- mouse_pwms_v2
}else{
stop("Only versions 1 and 2 exist!")
}
obj <- .summarizeChromVARMotifs(motifs)
motifs <- obj$motifs
motifSummary <- obj$motifSummary
}else if(tolower(species) == "homo sapiens"){
if(version == 1){
message("Using version 1 motifs!")
data("human_pwms_v1")
motifs <- human_pwms_v1
}else if(version == 2){

if(tolower(motifSet) == "cisbptest"){

message("Using version 2 motifs!")
data("human_pwms_v2")
motifs <- human_pwms_v2
subset <- grep("PAX5|CEBPA|CEBPB|IRF4|ETS1|EOMES", names(motifs), value=TRUE)
motifs <- motifs[subset]
obj <- .summarizeChromVARMotifs(motifs)
motifs <- obj$motifs
motifSummary <- obj$motifSummary

}else{

if(tolower(species) == "mus musculus"){
if(version == 1){
message("Using version 1 motifs!")
data("mouse_pwms_v1")
motifs <- mouse_pwms_v1
}else if(version == 2){
message("Using version 2 motifs!")
data("mouse_pwms_v2")
motifs <- mouse_pwms_v2
}else{
stop("Only versions 1 and 2 exist!")
}
obj <- .summarizeChromVARMotifs(motifs)
motifs <- obj$motifs
motifSummary <- obj$motifSummary
}else if(tolower(species) == "homo sapiens"){
if(version == 1){
message("Using version 1 motifs!")
data("human_pwms_v1")
motifs <- human_pwms_v1
}else if(version == 2){
message("Using version 2 motifs!")
data("human_pwms_v2")
motifs <- human_pwms_v2
}else{
stop("Only versions 1 and 2 exist!")
}
obj <- .summarizeChromVARMotifs(motifs)
motifs <- obj$motifs
motifSummary <- obj$motifSummary
}else{
stop("Only versions 1 and 2 exist!")
stop("Species not recognized homo sapiens, mus musculus supported by CisBP!")
}
obj <- .summarizeChromVARMotifs(motifs)
motifs <- obj$motifs
motifSummary <- obj$motifSummary
}else{
stop("Species not recognized homo sapiens, mus musculus supported by CisBP!")

}

}else if(tolower(motifSet)=="encode"){
Expand Down
19 changes: 12 additions & 7 deletions R/CreateArrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,21 @@ createArrowFiles <- function(
args$registryDir <- file.path(QCDir, "CreateArrowsRegistry")
args$cleanTmp <- NULL

if(subThreading){
h5disableFileLocking()
}else{
#H5 File Lock Check
h5lock <- setArchRLocking()
if(h5lock){
if(subThreading){
message("subThreadhing Disabled since ArchRLocking is TRUE see `addArchRLocking`")
subThreading <- FALSE
}
args$threads <- length(inputFiles)
}else{
if(subThreading){
message("subThreadhing Enabled since ArchRLocking is FALSE see `addArchRLocking`")
}
}

#Default Param
args$minTSS <- NULL

#Run With Parallel or lapply
Expand All @@ -228,10 +237,6 @@ createArrowFiles <- function(
paste0(args$outputNames,".arrow")[file.exists(paste0(args$outputNames,".arrow"))]
})

if(subThreading){
h5enableFileLocking()
}

.endLogging(logFile = logFile)

return(outArrows)
Expand Down
81 changes: 78 additions & 3 deletions R/GlobalDefaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
########################################################
ArchRDefaults <- list(
ArchR.threads = 1,
ArchR.locking = FALSE,
ArchR.logging = TRUE,
ArchR.genome = NA,
ArchR.chrPrefix = TRUE,
Expand Down Expand Up @@ -359,6 +360,80 @@ getArchRThreads <- function(){
}
}

##########################################################################################
# H5 File Locking
##########################################################################################

#' Add a globally-applied H5 file locking setup
#'
#' This function will set the default H5 file locking parameters
#'
#' @param locking The default value for H5 File Locking
#' @export
addArchRLocking <- function(locking=FALSE){

.validInput(input = locking, name = "locking", valid = "boolean")

#Check if Lockign is Valid
h5test <- h5testFileLocking(".")
if(!h5test){
message(
"H5 Locking is not enabled based on 'h5testFileLocking'.\nSetting ArchRLocking locking to ",
locking, "."
)
locking <- TRUE
}else{
message("Setting ArchRLocking to ", locking, ".")
}
options(ArchR.locking = locking)

}

#' Set a globally-applied H5 file locking setup
#'
#' This function will set the default H5 file locking parameters to the system
#'
#' @export
setArchRLocking <- function(){

#Get Value
.ArchRLocking <- options()[["ArchR.locking"]]
if(is.null(.ArchRLocking)){
.ArchRLocking <- TRUE
}else if(!is.logical(.ArchRLocking)){
.ArchRLocking <- TRUE
}

#Get Environment Value
h5lock <- tryCatch({
Sys.getenv("HDF5_USE_FILE_LOCKING")
}, error = function(e){
""
})
if(h5lock=="FALSE"){
h5lock <- FALSE
}else if(h5lock==""){
h5lock <- TRUE
}else{
stop("H5 Locking Not Valid!")
}

#Set Environmental Value
if(.ArchRLocking != h5lock){
if(.ArchRLocking){
message("Enabling H5 File Locking. If this is not desired check `addArchRLocking`.")
h5enableFileLocking()
}else{
message("Disabling H5 File Locking. If this is not desired check `addArchRLocking`.")
h5disableFileLocking()
}
}

#Return Value
.ArchRLocking

}

##########################################################################################
# Create Gene/Genome Annotation
##########################################################################################
Expand All @@ -380,7 +455,7 @@ addArchRGenome <- function(genome = NULL, install = TRUE){
.validInput(input = genome, name = "genome", valid = "character")
.validInput(input = install, name = "install", valid = c("boolean"))

supportedGenomes <- c("hg19","hg38","mm9","mm10","hg19test")
supportedGenomes <- c("hg19","hg38","mm9","mm10","hg19test", "hg19test2")

if(tolower(genome) %ni% supportedGenomes){

Expand All @@ -400,7 +475,7 @@ addArchRGenome <- function(genome = NULL, install = TRUE){
stop("BSgenome for hg19 not installed! Please install by setting install = TRUE or by the following:\n\tBiocManager::install(\"BSgenome.Hsapiens.UCSC.hg19\")")
}
}
}else if(tolower(genome)=="hg19test"){
}else if(tolower(genome) %in% c("hg19test", "hg19test2")){
if(!requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)){
if(install){
message("BSgenome for hg19 not installed! Now installing by the following:\n\tBiocManager::install(\"BSgenome.Hsapiens.UCSC.hg19\")")
Expand Down Expand Up @@ -470,7 +545,7 @@ getArchRGenome <- function(
.validInput(input = geneAnnotation, name = "geneAnnotation", valid = "boolean")
.validInput(input = genomeAnnotation, name = "genomeAnnotation", valid = "boolean")

supportedGenomes <- c("hg19","hg38","mm9","mm10","hg19test")
supportedGenomes <- c("hg19","hg38","mm9","mm10","hg19test", "hg19test2")
.ArchRGenome <- options()[["ArchR.genome"]]

if(!is.null(.ArchRGenome)){
Expand Down
18 changes: 11 additions & 7 deletions R/GroupCoverages.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,26 @@ addGroupCoverages <- function(
)
args$covDir <- file.path(getOutputDirectory(ArchRProj), "GroupCoverages", groupBy)
args$parallelParam <- parallelParam
args$threads <- threads
args$verbose <- verbose
args$tstart <- tstart
args$logFile <- logFile
args$registryDir <- file.path(getOutputDirectory(ArchRProj), "GroupCoverages", "batchRegistry")

#H5 File Lock Check
h5lock <- setArchRLocking()
if(h5lock){
args$threads <- 1
}else{
if(threads > 1){
message("subThreadhing Enabled since ArchRLocking is FALSE see `addArchRLocking`")
}
args$threads <- threads
}

#####################################################
# Batch Apply to Create Insertion Coverage Files
#####################################################

#Disable Hdf5 File Locking
h5disableFileLocking()

#Batch Apply
.logDiffTime(sprintf("Creating Coverage Files!"), tstart, addHeader = FALSE)
batchOut <- .batchlapply(args)
Expand Down Expand Up @@ -256,9 +263,6 @@ addGroupCoverages <- function(

ArchRProj@projectMetadata$GroupCoverages[[groupBy]] <- SimpleList(Params = Params, coverageMetadata = coverageMetadata)

#Enable Hdf5 File Locking
h5enableFileLocking()

.logDiffTime(sprintf("Finished Creation of Coverage Files!"), tstart, addHeader = FALSE)
.endLogging(logFile = logFile)

Expand Down
15 changes: 9 additions & 6 deletions R/GroupExport.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,15 @@ getGroupBW <- function(
chromSizes <- getChromSizes(ArchRProj)
tiles <- unlist(slidingWindows(chromSizes, width = tileSize, step = tileSize))

if(threads > 1){
h5disableFileLocking()
#H5 File Lock Check
h5lock <- setArchRLocking()
if(h5lock){
threads <- 1
}else{
if(threads > 1){
message("subThreadhing Enabled since ArchRLocking is FALSE see `addArchRLocking`")
}
args$threads <- threads
}

covFiles <- c()
Expand Down Expand Up @@ -264,10 +271,6 @@ getGroupBW <- function(

}

if(threads > 1){
h5enableFileLocking()
}

.endLogging(logFile = logFile)

covFiles
Expand Down
29 changes: 27 additions & 2 deletions R/IterativeLSI.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ addIterativeLSI <- function(
stop("Please provide more than 1000 varFeatures!")
}

if(nCells(ArchRProj) < 500){
message(
"Detected less than 500 Cells.\n",
"\t`filterBias` disabled.\n",
"\t`outlierQuantiles` disabled\n",
"\t`sampleCellsPre` disabled\n",
"\t`testBias` in `addClusters` disabled\n"
)
filterBias <- FALSE
outlierQuantiles <- c(0, 1)
sampleCellsPre <- NULL
clusterParams$testBias <- FALSE
}

.startLogging(logFile = logFile)
.logThis(mget(names(formals()),sys.frame(sys.nframe())), "IterativeLSI Input-Parameters", logFile=logFile)

Expand Down Expand Up @@ -235,8 +249,14 @@ addIterativeLSI <- function(
.logDiffTime("Computing Top Features", tstart, addHeader = FALSE, verbose = verbose, logFile = logFile)
nFeature <- varFeatures[1]
rmTop <- floor((1-filterQuantile) * totalFeatures)
topIdx <- head(order(totalAcc$rowSums, decreasing=TRUE), nFeature + rmTop)[-seq_len(rmTop)]
if(sum(totalAcc$rowSums > 0) > 2.25 * varFeatures){
topIdx <- head(order(totalAcc$rowSums, decreasing=TRUE), nFeature + rmTop)[-seq_len(rmTop)]
}else{
message("Not Enough Non-Zero Features to Filter!")
topIdx <- head(order(totalAcc$rowSums, decreasing=TRUE), nFeature)
}
topFeatures <- totalAcc[sort(topIdx),]
topFeatures <- topFeatures[topFeatures$rowSums > 0,]

gc()

Expand Down Expand Up @@ -268,10 +288,11 @@ addIterativeLSI <- function(
.logDiffTime("Computing Variable Features", tstart, addHeader = FALSE, verbose = verbose, logFile = logFile)
nFeature <- varFeatures[1]
if(nFeature > 0.5 * nrow(totalAcc)){
stop("nFeature for variable selection must be at leat 1/2 the total features!")
stop("nFeature for variable selection must be at most 1/2 the total features!")
}
topIdx <- head(order(totalAcc$combinedVars, decreasing=TRUE), nFeature)
topFeatures <- totalAcc[sort(topIdx),]
topFeatures <- topFeatures[topFeatures$combinedMeans > 0,]

gc()

Expand All @@ -281,6 +302,10 @@ addIterativeLSI <- function(

}

if(nrow(topFeatures) < varFeatures){
stop(sprintf("Not Enough Features Found in data (%s)!", nrow(topFeatures)))
}

cellDepth <- tryCatch({
df <- getCellColData(ArchRProj = ArchRProj, select = depthCol)
v <- df[,1]
Expand Down
Loading

0 comments on commit 55f0923

Please sign in to comment.