Skip to content

Commit 60046e7

Browse files
authored
Fix issue with marker genes (#26)
* Update cytetype.R * Update .gitignore * Update client.R * clickable report link * error catch marker genes * Increment version number to 0.1.4
1 parent 32ceee3 commit 60046e7

5 files changed

Lines changed: 20 additions & 12 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
.quarto
99
revdep/
1010
inst/doc
11+
CyteTypeR.Rproj

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: CyteTypeR
22
Title: CyteType for R
3-
Version: 0.1.3
3+
Version: 0.1.4
44
Description: CyteTypeR is the R version of CyteType python package.'
55
Authors@R:
66
person("Nygen Analytics AB", , ,"contact@nygen.io", role = c("aut", "cre"))

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ importFrom(Seurat,AddMetaData)
1010
importFrom(Seurat,Embeddings)
1111
importFrom(Seurat,GetAssayData)
1212
importFrom(dplyr,"%>%")
13+
importFrom(dplyr,arrange)
14+
importFrom(dplyr,desc)
1315
importFrom(dplyr,filter)
1416
importFrom(dplyr,group_by)
1517
importFrom(dplyr,slice_head)

R/client.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.submit_job <- function(payload, api_url, auth_token = NULL){
33

44
submit_url <- file.path(api_url, "annotate")
5-
log_info("Submitting job to API {api_url}")
5+
log_info("Submitting job to CyteType...")
66

77
tryCatch({
88
# Validate inputs
@@ -69,8 +69,10 @@
6969
# Info for auth token uses
7070
if (!is.null(auth_token)) {
7171
log_info("Token secured report (updates automatically): \n{report_url}")
72+
cli::cli_text("{.url {report_url}}")
7273
} else {
73-
log_info("Report (updates automatically) available at: \n{report_url}")
74+
log_info("Report (updates automatically) available at: \n")
75+
cli::cli_text("{.url {report_url}}")
7476
}
7577

7678
log_info("If disconnected, retrieve results with: GetResults()")

R/cytetype.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#' }
6060
#'
6161
#' @importFrom logger log_info log_debug log_error log_warn
62-
#' @importFrom dplyr group_by filter slice_head ungroup %>%
62+
#' @importFrom dplyr group_by filter slice_head ungroup arrange desc %>%
6363
#' @importFrom tidyr pivot_longer
6464
#' @importFrom stats setNames
6565
#' @importFrom Seurat Embeddings GetAssayData AddMetaData
@@ -95,12 +95,16 @@ PrepareCyteTypeR <- function(obj,
9595

9696
marker_genes <- marker_table %>%
9797
group_by(cluster) %>%
98-
dplyr::filter(avg_log2FC > 1) %>%
98+
arrange(desc(avg_log2FC)) %>%
9999
slice_head(n = n_top_genes) %>%
100100
ungroup() %>%
101101
{split(.$gene, .$cluster)}
102102
names(marker_genes) <- cluster_map[names(marker_genes)]
103103

104+
if (any(sapply(marker_genes, function(x) !is.vector(x) || length(x) < 5))) {
105+
stop("Invalid marker genes, some clusters have fewer than 5 markers")
106+
}
107+
104108
print("Preparing visualisation data...")
105109
visualization_data <- list(
106110
coordinates = Embeddings(obj, reduction = coordinates_key),
@@ -248,13 +252,12 @@ CyteTypeR <- function(obj,
248252

249253

250254
# Job submission
251-
tryCatch({
252-
job_id <- .submit_job(query_list, api_url, auth_token)
253-
},
254-
error = function(e) {
255-
stop("Job submission failed: ", conditionMessage(e))
256-
}
257-
)
255+
256+
job_id <- .submit_job(query_list, api_url, auth_token)
257+
if (is.na(job_id)) {
258+
stop("Job submission failed.")
259+
}
260+
258261

259262
# Save job details
260263
report_url <- file.path(api_url, 'report',job_id)

0 commit comments

Comments
 (0)