-
Notifications
You must be signed in to change notification settings - Fork 1
Update user-side processing #13
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
base: master
Are you sure you want to change the base?
Changes from all commits
31691a2
68afd1d
dc3ecab
37276d0
833ac1a
6f2be1d
a923418
76f76b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,23 +2,23 @@ | |||||||||||||||||||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||||||||||||||||||||
| #' @param object Seurat object to annotate | ||||||||||||||||||||||||||||||||||||||||||||
| #' @param assay Name of the assay to use (default: 'RNA') | ||||||||||||||||||||||||||||||||||||||||||||
| #' @param ip IP address of the cloud server (default: '34.222.135.233') | ||||||||||||||||||||||||||||||||||||||||||||
| #' @param ip Hostname or IP address of the cloud server (default: 'azimuthapi.satijalab.org') | ||||||||||||||||||||||||||||||||||||||||||||
| #' @param port Port number for the API (default: 5000) | ||||||||||||||||||||||||||||||||||||||||||||
| #' @return Annotated Seurat object | ||||||||||||||||||||||||||||||||||||||||||||
| #' @importFrom httr POST GET upload_file content status_code | ||||||||||||||||||||||||||||||||||||||||||||
| #' @importFrom RCurl url.exists | ||||||||||||||||||||||||||||||||||||||||||||
| #' @export | ||||||||||||||||||||||||||||||||||||||||||||
| CloudAzimuth <- function(object = object, assay = 'RNA', ip = '34.222.135.233', | ||||||||||||||||||||||||||||||||||||||||||||
| CloudAzimuth <- function(object = object, assay = 'RNA', ip = 'azimuthapi.satijalab.org', | ||||||||||||||||||||||||||||||||||||||||||||
| port = 5000, ...) { | ||||||||||||||||||||||||||||||||||||||||||||
| message("Running Pan-Human Azimuth on the cloud!") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| layer_name <- 'data' | ||||||||||||||||||||||||||||||||||||||||||||
| data <- LayerData(object, assay = assay, layer = layer_name) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # check if data has been normalized, just using the first 5 cells | ||||||||||||||||||||||||||||||||||||||||||||
| # if data exists, check if normalized, just using the first 5 cells | ||||||||||||||||||||||||||||||||||||||||||||
| # throw an error if large values, or all integer values, are detected | ||||||||||||||||||||||||||||||||||||||||||||
| data_check <- data[,1:min(5,ncol(data))] | ||||||||||||||||||||||||||||||||||||||||||||
| if ((max(data_check) > 15) || isTRUE(all.equal(data_check,floor(data_check)))) { | ||||||||||||||||||||||||||||||||||||||||||||
| data_check <- if (!IsMatrixEmpty(data)) data[,1:min(5,ncol(data))] else NULL | ||||||||||||||||||||||||||||||||||||||||||||
| if (is.null(data_check) || (max(data_check) > 15 || isTRUE(all.equal(data_check, floor(data_check))))) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+21
|
||||||||||||||||||||||||||||||||||||||||||||
| stop("Please run NormalizeData on the data before running Azimuth") | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -46,13 +46,22 @@ CloudAzimuth <- function(object = object, assay = 'RNA', ip = '34.222.135.233', | |||||||||||||||||||||||||||||||||||||||||||
| object[[i]] <- srt[[i]] | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Copy metadata columns except QC ones | ||||||||||||||||||||||||||||||||||||||||||||
| # Copy metadata columns except QC ones, matching by cell names | ||||||||||||||||||||||||||||||||||||||||||||
| md_cols <- grep("nCount_RNA|nFeature_RNA", | ||||||||||||||||||||||||||||||||||||||||||||
| colnames(srt@meta.data), | ||||||||||||||||||||||||||||||||||||||||||||
| invert = TRUE, | ||||||||||||||||||||||||||||||||||||||||||||
| value = TRUE) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Only update metadata for cells that were processed (objects can have multiple assays w/ cell IDs formatted differently) | ||||||||||||||||||||||||||||||||||||||||||||
| assay_cells <- Cells(srt) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| for (i in md_cols) { | ||||||||||||||||||||||||||||||||||||||||||||
| object@meta.data[, i] <- srt@meta.data[, i] | ||||||||||||||||||||||||||||||||||||||||||||
| # Initialize column with NA only if it doesn't exist | ||||||||||||||||||||||||||||||||||||||||||||
| if (!i %in% colnames(object@meta.data)) { | ||||||||||||||||||||||||||||||||||||||||||||
| object@meta.data[, i] <- NA | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+59
to
+61
|
||||||||||||||||||||||||||||||||||||||||||||
| # Initialize column with NA only if it doesn't exist | |
| if (!i %in% colnames(object@meta.data)) { | |
| object@meta.data[, i] <- NA | |
| # Initialize column with type-appropriate NA only if it doesn't exist | |
| if (!i %in% colnames(object@meta.data)) { | |
| template <- srt@meta.data[[i]] | |
| n_cells <- nrow(object@meta.data) | |
| if (is.factor(template)) { | |
| # Preserve factor levels | |
| na_factor <- factor(NA, levels = levels(template)) | |
| object@meta.data[, i] <- rep(na_factor, n_cells) | |
| } else if (is.numeric(template) && !is.integer(template)) { | |
| object@meta.data[, i] <- rep(NA_real_, n_cells) | |
| } else if (is.integer(template)) { | |
| object@meta.data[, i] <- rep(NA_integer_, n_cells) | |
| } else if (is.character(template)) { | |
| object@meta.data[, i] <- rep(NA_character_, n_cells) | |
| } else { | |
| # Logical or other types fall back to logical NA | |
| object@meta.data[, i] <- rep(NA, n_cells) | |
| } |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indexing object@meta.data[assay_cells, i] will throw if any assay_cells are not present in object@meta.data rownames (which is plausible given the comment about differing cell ID formats). Update using an intersection/match of cell names so missing cells are ignored rather than erroring.
| # Update only the processed cells | |
| object@meta.data[assay_cells, i] <- srt@meta.data[assay_cells, i] | |
| # Update only the processed cells that also exist in the original object metadata | |
| common_cells <- intersect(assay_cells, rownames(object@meta.data)) | |
| if (length(common_cells) > 0) { | |
| object@meta.data[common_cells, i] <- srt@meta.data[common_cells, i] | |
| } |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process_rds_file() now treats any listen_to_progress() result other than explicit TRUE as failure. Since listen_to_progress() initializes success to FALSE, if the server never emits a success field the client will always stop even when processing succeeded. Consider initializing success to NA and only stopping on an explicit FALSE (or alternatively treat stream completion as success unless an error status is received).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
successis initialized toFALSE, so if the SSE stream never includes asuccessfield, this function will returnFALSEeven on success. Initialize toNAand only update when asuccessfield is received, or setsuccess <- TRUEon normal stream completion and flip toFALSEonly when an error/success flag indicates failure.