Skip to content

Commit

Permalink
Merge pull request #694 from joshua-d-campbell/master
Browse files Browse the repository at this point in the history
Merging from devel for new release 2.8.1
  • Loading branch information
joshua-d-campbell authored Mar 20, 2023
2 parents 654e1cc + 405e3da commit fcde6d7
Show file tree
Hide file tree
Showing 547 changed files with 22,485 additions and 4,524 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ exec/png
.covrignore
^pkgdown$
^\.github$
^vignettes/articles/*
^images
9 changes: 8 additions & 1 deletion .github/workflows/BioC-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ jobs:
if: runner.os == 'macOS'
run: brew install fftw

- uses: r-lib/actions/setup-r-dependencies@v1
- name: Manual Install
run: |
install.packages("BiocManager")
BiocManager::install("ggtree")
shell: Rscript {0}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck
cache-version: 2

- name: Install XQuartz on macOS
if: runner.os == 'macOS'
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- name: Setup Python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: '3.8'

Expand All @@ -57,7 +57,7 @@ jobs:
which python
shell: bash

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
Expand All @@ -71,16 +71,18 @@ jobs:
if: runner.os == 'macOS'
run: brew install fftw

- uses: r-lib/actions/setup-r-dependencies@v1
with:
extra-packages: rcmdcheck

- name: Install Celda devel
- name: Manual Install
run: |
install.packages("devtools")
devtools::install_github("campbio/celda@devel")
install.packages("BiocManager")
BiocManager::install("ggtree")
shell: Rscript {0}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache-version: 2
extra-packages: any::rcmdcheck
needs: check

- name: Install XQuartz on macOS
if: runner.os == 'macOS'
run: brew install xquartz --cask
Expand Down
12 changes: 7 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Package: singleCellTK
Type: Package
Title: Comprehensive and Interactive Analysis of Single Cell RNA-Seq Data
Version: 2.8.0
Version: 2.8.1
Authors@R: c(person(given="Yichen", family="Wang", email="wangych@bu.edu", role=c("aut", "cre"),
comment = c(ORCID = "0000-0003-4347-5199")),
person(given="Irzam", family="Sarfraz", email="isarfraz@bu.edu", role=c("aut"),
comment = c(ORCID = "0000-0001-8121-792X")),
person(given="Rui", family="Hong", email="rzhong@bu.edu", role=c("aut")),
person(given="Yusuke", family="Koga", email="ykoga07@bu.edu", role=c("aut")),
person(given="Salam", family="Alabdullatif", email="salamha@bu.edu", role=c("aut")),
person(given="Nida", family="Pervaiz", email="nidapervaiz27@gmail.com", role=c("aut")),
person(given="David", family="Jenkins", email="dfj@bu.edu", role=c("aut"),
comment = c(ORCID = "0000-0002-7451-4288")),
person(given="Vidya", family="Akavoor", email="vidyaap@bu.edu", role=c("aut")),
Expand Down Expand Up @@ -64,7 +65,7 @@ Imports:
KernSmooth,
limma,
MAST,
Matrix,
Matrix (>= 1.5-3),
matrixStats,
methods,
msigdbr,
Expand Down Expand Up @@ -94,7 +95,7 @@ Imports:
reticulate (>= 1.14),
tools,
tximport,
fishpond,
eds,
withr,
GSEABase,
R.utils,
Expand All @@ -113,8 +114,9 @@ Imports:
TrajectoryUtils,
scuttle,
utils,
stats
RoxygenNote: 7.2.1
stats,
zellkonverter
RoxygenNote: 7.2.3
Suggests:
testthat,
Rsubread,
Expand Down
24 changes: 23 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ export(plotSCEViolin)
export(plotSCEViolinAssayData)
export(plotSCEViolinColData)
export(plotScDblFinderResults)
export(plotScanpyDotPlot)
export(plotScanpyEmbedding)
export(plotScanpyHVG)
export(plotScanpyHeatmap)
export(plotScanpyMarkerGenes)
export(plotScanpyMarkerGenesDotPlot)
export(plotScanpyMarkerGenesHeatmap)
export(plotScanpyMarkerGenesMatrixPlot)
export(plotScanpyMarkerGenesViolin)
export(plotScanpyMatrixPlot)
export(plotScanpyPCA)
export(plotScanpyPCAGeneRanking)
export(plotScanpyPCAVariance)
export(plotScanpyViolin)
export(plotScdsHybridResults)
export(plotScrubletResults)
export(plotSeuratElbow)
Expand Down Expand Up @@ -182,6 +196,14 @@ export(runQuickUMAP)
export(runSCANORAMA)
export(runSCMerge)
export(runScDblFinder)
export(runScanpyFindClusters)
export(runScanpyFindHVG)
export(runScanpyFindMarkers)
export(runScanpyNormalizeData)
export(runScanpyPCA)
export(runScanpyScaleData)
export(runScanpyTSNE)
export(runScanpyUMAP)
export(runScranSNN)
export(runScrublet)
export(runSeuratFindClusters)
Expand Down Expand Up @@ -245,7 +267,7 @@ import(DelayedArray)
import(DropletUtils)
import(GSVAdata)
import(SingleCellExperiment)
import(fishpond)
import(eds)
importFrom(BiocParallel,SerialParam)
importFrom(S4Vectors,"metadata<-")
importFrom(S4Vectors,metadata)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Changes in Version 2.8.1 (2022-03-10)
================================================================================
* Added scanpy wrapper functions for use from console
* Added scanpy UI curated workflow
* Integrated scanpy to a la carte workflow
* Fixed a bug in importing fluidigm dataset
* Updated downloading features in the Shiny app
* Added error checking around Enrichr functions
* Minor tweaks to plot defaults

Changes in Version 2.8.0 (2022-12-19)
================================================================================
* Updated version to match Bioconductor version
Expand Down
56 changes: 37 additions & 19 deletions R/enrichRSCE.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ runEnrichR <- function(inSCE,
internetConnection <- suppressWarnings(Biobase::testBioCConnection())
#check for internet connection
if (!internetConnection){
stop("Please connect to the Internet and continue..")
stop("The Enrichr database could not be queried. No internet connection available.")
}
err <- tryCatch(
{
Expand All @@ -95,38 +95,42 @@ runEnrichR <- function(inSCE,
)
#options(enrichR.base.address = "https://maayanlab.cloud/Enrichr/")
#options(enrichR.live = TRUE)
temp_db <- enrichR::listEnrichrDbs()
temp_db <- NULL
err <- tryCatch(
{
temp_db <- .getEnrichrDB(noConnect = "error")
},
error = function(e) {}
)
enrdb <- temp_db$libraryName
#test for db existing
if (is.null(db)){
db <- enrdb
} else if (!all(db %in% enrdb)){
db.notFound <- db[!db %in% enrdb]
stop("database ", paste(db.notFound, collapse = ", "), " do not exist.")
stop("Database(s) ", paste(db.notFound, collapse = ", "), " were not found in Enrichr.")
}

enriched <- enrichR::enrichr(features, db)
enriched <- data.frame(data.table::rbindlist(enriched, use.names = TRUE,
fill = TRUE,
idcol = "Database_selected"))

enriched$link <- vapply(enriched$Database_selected, function(x){
temp_db$link[temp_db$libraryName %in% x]
}, FUN.VALUE = character(1))

#sort the results based on p-values
enriched <- enriched[order(enriched$P.value, decreasing = FALSE), ]

#round the numeric values to their 7th digit
#nums <- vapply(enriched, is.numeric, FUN.VALUE = logical(1))
#enriched[, nums] <- round(enriched[, nums], digits = 7)
if(!is.null(enriched) && nrow(enriched) > 0) {

#sort the results based on p-values
enriched <- enriched[order(enriched$P.value, decreasing = FALSE), ]

getEnrichRResult(inSCE, analysisName) <- list(result = enriched,
param = list(
features = features,
by = by,
db = db
))
} else {
stop("No enrichments identified. No enrichment results were created.")
}

getEnrichRResult(inSCE, analysisName) <- list(result = enriched,
param = list(
features = features,
by = by,
db = db
))
return(inSCE)
}

Expand Down Expand Up @@ -181,3 +185,17 @@ setReplaceMethod("getEnrichRResult",
S4Vectors::metadata(inSCE)$sctk$runEnrichR[[analysisName]] <- value
return(inSCE)
})

.getEnrichrDB <- function(noConnect = c("warn", "error", "ignore")) {
db <- NULL
noConnect <- match.arg(noConnect)
db <- enrichR::listEnrichrDbs()
if(is.null(db)) {
if(noConnect == "error") {
stop("Connection to the online Enrichr database could not be established. No database information retrieved.")
} else if (noConnect == "warn") {
warning("Connection to the online Enrichr database could not be established. No database information retrieved.")
}
}
return(db)
}
55 changes: 49 additions & 6 deletions R/getTopHVG.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#' @param inSCE Input \linkS4class{SingleCellExperiment} object
#' @param method Specify which method to use for variable gene extraction
#' from Seurat \code{"vst"}, \code{"mean.var.plot"}, \code{"dispersion"} or
#' Scran \code{"modelGeneVar"}. Default \code{"vst"}
#' Scran \code{"modelGeneVar"} or Scanpy \code{"seurat"}, \code{"cell_ranger"},
#' \code{"seurat_v3"}. Default \code{"vst"}
#' @param hvgNumber Specify the number of top variable genes to extract.
#' @param useFeatureSubset Get the feature names in the HVG list set by
#' \code{setTopHVG}. Will ignore \code{method} and \code{hvgNumber} if not
Expand Down Expand Up @@ -52,7 +53,8 @@
#' @importFrom S4Vectors metadata
getTopHVG <- function(inSCE,
method = c("vst", "dispersion",
"mean.var.plot", "modelGeneVar"),
"mean.var.plot", "modelGeneVar", "seurat",
"seurat_v3", "cell_ranger"),
hvgNumber = 2000,
useFeatureSubset = NULL,
featureDisplay = metadata(inSCE)$featureDisplay) {
Expand All @@ -64,7 +66,12 @@ getTopHVG <- function(inSCE,
} else {
metrics <- .dfFromHVGMetric(inSCE, method)
metrics <- metrics[order(-metrics$v_rank),]
metrics <- metrics[metrics$v_rank > 0, ]
if (method == "seurat"){
metrics <- metrics[metrics$v_plot > 0, ]
}
else{
metrics <- metrics[metrics$v_rank > 0, ]
}
if (method == "mean.var.plot") {
means.use <- (metrics$mean > 0.1) & (metrics$mean < 8)
dispersions.use <- (metrics$v_plot > 1) & (metrics$v_plot < Inf)
Expand All @@ -87,7 +94,8 @@ getTopHVG <- function(inSCE,
#' @importFrom S4Vectors metadata<-
setTopHVG <- function(inSCE,
method = c("vst", "dispersion",
"mean.var.plot", "modelGeneVar"),
"mean.var.plot", "modelGeneVar", "seurat",
"seurat_v3", "cell_ranger"),
hvgNumber = 2000,
featureSubsetName = NULL,
genes = NULL, genesBy = NULL,
Expand Down Expand Up @@ -138,13 +146,15 @@ setTopHVG <- function(inSCE,
#' @param inSCE Input \linkS4class{SingleCellExperiment} object
#' @param method Specify which method to use for variable gene extraction
#' from Seurat \code{"vst"}, \code{"mean.var.plot"}, \code{"dispersion"} or
#' Scran \code{"modelGeneVar"}. Default \code{"vst"}
#' Scran \code{"modelGeneVar"} or Scanpy \code{"seurat"}, \code{"cell_ranger"},
#' \code{"seurat_v3"}. Default \code{"vst"}
#' @return data.frame object of HVG metrics calculated by \code{method},
#' containing columns of \code{"mean"}, \code{"v_rank"}, \code{"v_plot"}
#' @noRd
.dfFromHVGMetric <- function(inSCE,
method = c("vst", "mean.var.plot", "dispersion",
"modelGeneVar")) {
"modelGeneVar", "seurat",
"seurat_v3", "cell_ranger")) {
method <- match.arg(method)
df <- data.frame(featureNames = rownames(inSCE))
if (method == "vst") {
Expand All @@ -167,6 +177,39 @@ setTopHVG <- function(inSCE,
"Run `runSeuratFindHVG()` with 'dispersion' method ",
"before using this function!")
}
}else if (method == "seurat_v3") {
m <- "means"
v_rank <- "variances"
v_plot <- "variances_norm"
if (is.null(rowData(inSCE)[[v_rank]]) ||
is.null(rowData(inSCE)[[m]]) ||
is.null(rowData(inSCE)[[v_plot]])) {
stop("Scanpy variance metric not found in inSCE. ",
"Run `runScanpyFindHVG()` with 'seurat_v3' method ",
"before using this function!")
}
}else if (method == "cell_ranger") {
m <- "means"
v_rank <- "dispersions"
v_plot <- "dispersions_norm"
if (is.null(rowData(inSCE)[[v_rank]]) ||
is.null(rowData(inSCE)[[m]]) ||
is.null(rowData(inSCE)[[v_plot]])) {
stop("Scanpy dispersion metric not found in inSCE. ",
"Run `runScanpyFindHVG()` with 'cell_ranger' method ",
"before using this function!")
}
}else if (method == "seurat") {
m <- "means"
v_rank <- "dispersions"
v_plot <- "dispersions_norm"
if (is.null(rowData(inSCE)[[v_rank]]) ||
is.null(rowData(inSCE)[[m]]) ||
is.null(rowData(inSCE)[[v_plot]])) {
stop("Scanpy dispersion metric not found in inSCE. ",
"Run `runScanpyFindHVG()` with 'dispersion' method ",
"before using this function!")
}
} else if (method == "modelGeneVar") {
m <- "scran_modelGeneVar_mean"
v_rank <- "scran_modelGeneVar_bio"
Expand Down
Loading

0 comments on commit fcde6d7

Please sign in to comment.