Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #66 from fungenomics/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
alvaannett authored Sep 7, 2023
2 parents c03e1ce + 62af385 commit 363a182
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Notebooks/annotate_report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ marker_genes = strsplit(params$marker_genes, split = ' ')[[1]]
```

```{r}
harmonize_unresolved = function(pred, ref_labels){
pred %>%
column_to_rownames('cellname') %>%
mutate(across(where(is.character), ~ifelse(. %in% c(ref_labels$label, 'No Consensus'), ., 'Unresolved'))) %>%
return()
}
plot_tool_correlation_heatmap = function(seurat, tools){
mat = [email protected] %>%
Expand Down Expand Up @@ -155,7 +162,7 @@ x = [email protected] %>%
color_class_seurat = function(seurat, meta_column, pal){
list = list()
pal['Unsure'] = 'red'
pal['Unresolved'] = 'red'
pal['No Consensus'] = 'red'
Idents(seurat) = meta_column
class = (table([email protected][[meta_column]]) %>% as.data.frame() %>% filter(Freq > 20))$Var
Expand Down Expand Up @@ -194,7 +201,7 @@ umap_plotly = function(seurat, meta_column, pal){
return(p2)
}
calculate_percentage_unsure = function(pred, order){
calculate_percentage_unresolved = function(pred, order){
warn = pred %>%
select(order) %>%
pivot_longer(order) %>%
Expand All @@ -203,7 +210,7 @@ calculate_percentage_unsure = function(pred, order){
count(value, .drop = F) %>%
mutate(frac = n/sum(n)*100) %>%
filter(!(!name == 'Consensus' & value == 'No Consensus')) %>%
filter(value %in% c('No Consensus', 'Unsure')) %>%
filter(value %in% c('No Consensus', 'Unresolved')) %>%
mutate(warn = case_when(frac >= 70 ~ 'HIGH',
frac < 70 & frac > 30 ~ 'MEDIUM',
frac <= 30 ~ 'LOW'))
Expand Down Expand Up @@ -251,7 +258,7 @@ for(r in refs){
list[[r]]$lab = data.table::fread(paste0(params$output_dir, '/model/', r, '/labels.csv'), header = T)
list[[r]]$pred = data.table::fread(paste0(params$output_dir, '/', params$sample, '/', r, '/Prediction_Summary.tsv')) %>%
harmonize_unsure(., list[[r]]$lab)
harmonize_unresolved(., list[[r]]$lab)
# create reference pal
list[[r]]$pal = create_color_pal(list[[r]]$lab$label)
Expand Down Expand Up @@ -319,9 +326,9 @@ for(r in refs){
cat(" \n## Prediction QC \n")
cat("<h3>Percentage Unsure</h3>")
cat("<h3>Percentage Unresolved</h3>")
calculate_percentage_unsure(list[[r]]$pred, order = tools) %>%
calculate_percentage_unresolved(list[[r]]$pred, order = tools) %>%
kbl(escape = FALSE, row.names = F) %>%
kable_styling(position = "center") %>%
print()
Expand Down

0 comments on commit 363a182

Please sign in to comment.