|
15 | 15 | ){ |
16 | 16 | gene_names <- rownames(seurat_obj) |
17 | 17 | clusters <- seurat_obj[[group_key]][[group_key]] |
18 | | - unique_clusters <- levels(clusters) |
| 18 | + unique_clusters <- unique(clusters) |
19 | 19 |
|
20 | 20 | pcent <- list() |
21 | 21 | n_genes <- dim(seurat_obj)[1] |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 |
|
| 168 | + |
| 169 | +.validate_marker_table <- function(marker_table, sorted_clusters){ |
| 170 | + log_info("Checking markers table...") |
| 171 | + df_like_classes <- c("data.frame", "tbl_df", "tbl", "data.table") |
| 172 | + if (inherits(marker_table, df_like_classes)){ |
| 173 | + log_info(paste("Provided markers data is a dataframe", cli::symbol$tick)) |
| 174 | + } |
| 175 | + |
| 176 | + if (any(is.na(marker_table))){ |
| 177 | + log_info("NA value(s) found in the table") |
| 178 | + } |
| 179 | + else{ log_info(paste("No NA values", cli::symbol$tick))} |
| 180 | + |
| 181 | + table_cols <- names(marker_table) |
| 182 | + if ("cluster" %in% table_cols){ |
| 183 | + log_info(paste("'cluster' column found in marker table", cli::symbol$tick)) |
| 184 | + } |
| 185 | + else{log_info("cluster column not found in marker table, rename your column to 'cluster' if its name is different" )} |
| 186 | + |
| 187 | + # gene symbol column exist? |
| 188 | + # has gene symbols? |
| 189 | + if ("gene" %in% table_cols){ |
| 190 | + gene_sym_pattern <- "^[A-Z]([A-Z0-9-]+|[a-z0-9-]+)$" |
| 191 | + if (is.null(grepl(gene_sym_pattern,marker_table$gene))){ |
| 192 | + log_warn("Not gene symbols?") |
| 193 | + } |
| 194 | + else {log_info(paste("Found gene symbols", cli::symbol$tick))} |
| 195 | + } |
| 196 | + # cluster labels == seurat obj labels? |
| 197 | + if (setequal(sorted_clusters, as.vector(marker_table$cluster))){ |
| 198 | + log_info(paste("Correct cluster labels", cli::symbol$tick)) |
| 199 | + } |
| 200 | + else{ |
| 201 | + log_error("Please check if cluster labels are consistent between marker table and seurat obj!") |
| 202 | + } |
| 203 | + |
| 204 | + log_info(paste("Markers check: done", cli::symbol$tick)) |
| 205 | +} |
| 206 | + |
168 | 207 | # Transform CyteType Results for Seurat Integration |
169 | 208 |
|
170 | 209 | .transform_results_seurat <- function(raw_results = NULL, job_id = NULL, filename = NULL, cluster_map = NULL){ |
|
0 commit comments