Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upkeep #407

Merged
merged 9 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/check-bioc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ jobs:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, r: '4.3', bioc: '3.18', cont: "bioconductor/bioconductor_docker:RELEASE_3_18", rspm: "https://packagemanager.posit.co/cran/__linux__/jammy/latest" }
- { os: windows-latest, r: '4.3', bioc: '3.18'}
- { os: ubuntu-latest, r: '4.4', bioc: '3.20', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.posit.co/cran/__linux__/jammy/latest" }
- { os: windows-latest, r: '4.4', bioc: '3.20'}
## Check https://github.com/r-lib/actions/tree/master/examples
## for examples using the http-user-agent
env:
Expand Down Expand Up @@ -106,16 +106,16 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_18-r-4.3-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_18-r-4.3-
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-devel-r-4.4-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-devel-r-4.4-

- name: Cache R packages on Linux
if: "!contains(github.event.head_commit.message, '/nocache') && runner.os == 'Linux' "
uses: actions/cache@v3
with:
path: /home/runner/work/_temp/Library
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_18-r-4.3-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_18-r-4.3-
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-devel-r-4.4-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-devel-r-4.4-

- name: Install Linux system dependencies
if: runner.os == 'Linux'
Expand Down Expand Up @@ -289,7 +289,7 @@ jobs:
if: failure()
uses: actions/upload-artifact@master
with:
name: ${{ runner.os }}-biocversion-RELEASE_3_18-r-4.3-results
name: ${{ runner.os }}-biocversion-devel-r-4.4-results
path: check

## Note that DOCKER_PASSWORD is really a token for your dockerhub
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Authors@R:
person(given = "Kent",
family = "Riemondy",
role = c("cre", "aut"),
email = "kent.riemondy@cuanschutz.edu"),
email = "kent.riemondy@gmail.com"),
person(given = "Austin",
family = "Gillen",
role = "ctb",
Expand Down Expand Up @@ -88,7 +88,7 @@ VignetteBuilder:
ByteCompile: true
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
LazyData: true
Config/Needs/website:
pkgdown,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export(make_comb_ref)
export(marker_select)
export(matrixize_markers)
export(object_data)
export(object_loc_lookup)
export(object_ref)
export(overcluster)
export(overcluster_test)
Expand Down
130 changes: 70 additions & 60 deletions R/cellbrowsers.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' Build reference atlases from external UCSC cellbrowsers
#'
#' @param cb_url URL of cellbrowser dataset (e.g. http://cells.ucsc.edu/?ds=cortex-dev).
Expand All @@ -11,72 +10,83 @@
#' @return reference matrix
#' @examples
#' \dontrun{
#'
#'
#' # many datasets hosted by UCSC have UMI counts in the expression matrix
#' # set if_log = FALSE if the expression matrix has not been natural log transformed
#'
#' get_ucsc_reference(cb_url = "https://cells.ucsc.edu/?ds=evocell+mus-musculus+marrow",
#' cluster_col = "Clusters", if_log = FALSE)
#'
#' get_ucsc_reference(cb_url = "http://cells.ucsc.edu/?ds=muscle-cell-atlas",
#' cluster_col = "cell_annotation",
#' if_log = FALSE)
#'
#' get_ucsc_reference(
#' cb_url = "https://cells.ucsc.edu/?ds=evocell+mus-musculus+marrow",
#' cluster_col = "Clusters", if_log = FALSE
#' )
#'
#' get_ucsc_reference(
#' cb_url = "http://cells.ucsc.edu/?ds=muscle-cell-atlas",
#' cluster_col = "cell_annotation",
#' if_log = FALSE
#' )
#' }
#' @export
get_ucsc_reference <- function(cb_url,
cluster_col,
...){
if(!requireNamespace("R.utils", quietly = TRUE)) {
stop("This function requires the R.utils package, please install\n",
"install.packages('R.utils')")
}

if(!requireNamespace("data.table", quietly = TRUE)) {
stop("This function requires the data.table package, please install\n",
"install.packages('data.table')")
}

url <- httr::parse_url(cb_url)
base_url <- url
ds <- url$query$ds

# ds can include sub-datasets with syntax, "dataset+subdataset+and-so-on"
# files are hosted at urls: dataset/subdataset/andsoon/..."
ds_split <- strsplit(ds, "+", fixed = TRUE)[[1]]
ds <- paste0(ds_split, collapse = "/")
base_url$query <- ""
...) {
if (!requireNamespace("R.utils", quietly = TRUE)) {
stop(
"This function requires the R.utils package, please install\n",
"install.packages('R.utils')"
)
}

if (!requireNamespace("data.table", quietly = TRUE)) {
stop(
"This function requires the data.table package, please install\n",
"install.packages('data.table')"
)
}

url <- httr::parse_url(cb_url)
base_url <- url
ds <- url$query$ds

mdata_url <- httr::modify_url(base_url,
path = file.path(ds, "meta.tsv"))
if(!httr::http_error(mdata_url)){
mdata <- data.table::fread(mdata_url, data.table = FALSE, sep = "\t")
} else {
stop("unable to find metadata at url: ", mdata_url)
}

mat_url <- httr::modify_url(base_url,
path = file.path(ds, "exprMatrix.tsv.gz"))
if(!httr::http_error(mat_url)){
mat <- data.table::fread(mat_url, data.table = FALSE, sep = "\t")
} else {
stop("unable to find matrix at url: ", mat_url)
}
# ds can include sub-datasets with syntax, "dataset+subdataset+and-so-on"
# files are hosted at urls: dataset/subdataset/andsoon/..."
ds_split <- strsplit(ds, "+", fixed = TRUE)[[1]]
ds <- paste0(ds_split, collapse = "/")
base_url$query <- ""

rownames(mat) <- mat[, 1]
mat[, 1] <- NULL
mat <- as.matrix(mat)

mm <- max(mat)

if(mm > 50) {
dots <- list(...)
if(!"if_log" %in% names(dots) || dots$if_log) {
warning("the data matrix has a maximum value of ", mm, "\n",
"the data are likely not log transformed,\n",
"please set the if_log argument for average clusters accordingly")
mdata_url <- httr::modify_url(base_url,
path = file.path(ds, "meta.tsv")
)
if (!httr::http_error(mdata_url)) {
mdata <- data.table::fread(mdata_url, data.table = FALSE, sep = "\t")
} else {
stop("unable to find metadata at url: ", mdata_url)
}
}

average_clusters(mat, mdata, cluster_col = cluster_col, ...)
}

mat_url <- httr::modify_url(base_url,
path = file.path(ds, "exprMatrix.tsv.gz")
)
if (!httr::http_error(mat_url)) {
mat <- data.table::fread(mat_url, data.table = FALSE, sep = "\t")
} else {
stop("unable to find matrix at url: ", mat_url)
}

rownames(mat) <- mat[, 1]
mat[, 1] <- NULL
mat <- as.matrix(mat)

mm <- max(mat)

if (mm > 50) {
dots <- list(...)
if (!"if_log" %in% names(dots) || dots$if_log) {
warning(
"the data matrix has a maximum value of ", mm, "\n",
"the data are likely not log transformed,\n",
"please set the if_log argument for average clusters accordingly"
)
}
}

average_clusters(mat, mdata, cluster_col = cluster_col, ...)
}
16 changes: 10 additions & 6 deletions R/common_dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#'
#' cor_to_call(res)
#' @export
cor_to_call <- function(cor_mat,
cor_to_call <- function(
cor_mat,
metadata = NULL,
cluster_col = "cluster",
collapse_to_cluster = FALSE,
Expand Down Expand Up @@ -131,17 +132,18 @@ cor_to_call <- function(cor_mat,
#' cluster_col = "classified",
#' ref_mat = cbmc_ref
#' )
#'
#'
#' res2 <- cor_to_call(res, cluster_col = "classified")
#'
#'
#' call_to_metadata(
#' res = res2,
#' metadata = pbmc_meta,
#' cluster_col = "classified",
#' rename_prefix = "assigned"
#' )
#' @export
call_to_metadata <- function(res,
call_to_metadata <- function(
res,
metadata,
cluster_col,
per_cell = FALSE,
Expand Down Expand Up @@ -255,7 +257,8 @@ call_to_metadata <- function(res,
#' threshold = 0
#' )
#' @export
collapse_to_cluster <- function(res,
collapse_to_cluster <- function(
res,
metadata,
cluster_col,
threshold = 0) {
Expand Down Expand Up @@ -331,7 +334,8 @@ collapse_to_cluster <- function(res,
#'
#' cor_to_call_rank(res, threshold = "auto")
#' @export
cor_to_call_rank <- function(cor_mat,
cor_to_call_rank <- function(
cor_mat,
metadata = NULL,
cluster_col = "cluster",
collapse_to_cluster = FALSE,
Expand Down
Loading
Loading