Skip to content

Commit

Permalink
PCA plots and enrichment tables has been fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseCorCab committed Sep 18, 2024
1 parent d75a225 commit 3b1b114
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions inst/templates/pca_enr.Rmd
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
```{r , echo=FALSE, results='asis', message=FALSE, warning=FALSE}
print_go_tables <- function(all_enr) {
cat("\n\n\n<br>")
cat('<div style="display:flex; flex-wrap: wrap;">')
for (dimension in names(all_enr)) {
cat('<div style ="width:50%">')
cat(paste0("\n**",dimension,"**<br>"))
top_GOs <- head(all_enr[[dimension]], 10)
if (nrow(top_GOs) != 0){
top_GOs <- top_GOs[,c("GO.ID","Term","p.value","fdr")]
top_GOs[,c("p.value","fdr")]<- format(top_GOs[,c("p.value","fdr")], scientific = TRUE, digits = 3)
merged_df <- all_enr |>
purrr::imap(~ rename_fdr_column(.x, .y)) |>
purrr::reduce(dplyr::full_join, by = c("GO.ID", "Term"))
merged_columns <- colnames(merged_df)[!colnames(merged_df) %in% c("GO.ID", "Term")]
merged_df[,merged_columns]<- format(merged_df[,merged_columns], scientific = TRUE, digits = 3)
print(htmltools::tagList(
DT::datatable(top_GOs, filter = 'top', rownames = FALSE, extensions = c('Buttons','ColReorder'),
DT::datatable(merged_df, filter = 'top', rownames = FALSE, extensions = c('Buttons','ColReorder'),
options = list(
colReorder = TRUE,
dom = 'lftBip',
buttons = c('copy', 'csv', 'excel')))
))
} else {
cat("\n**No enrichments found**\n")
}
cat("</div>")
}
}
cat("</div>")
rename_fdr_column <- function(df, name) {
df <- df[df$fdr <= 0.05,]
df |>
dplyr::select(GO.ID, Term, fdr) |>
dplyr::rename(!!name := fdr)
}
```
```{r "{{funsys}}_enr", echo=FALSE, results='asis', message=FALSE, warning=FALSE}
Expand All @@ -35,18 +35,20 @@ last_dim <- 1
while (last_dim < func_results$pca_data$all_genes$dim_to_keep){
plot(FactoMineR::plot.PCA(func_results$pca_data$all_genes$pca_data,
invisible = "quali",
axis = c(last_dim, last_dim + 1),
axes = c(last_dim, last_dim + 1),
title = paste0(last_dim, " and ", last_dim + 1, " PCs")))
last_dim <- last_dim + 2
}
print_go_tables(pca_enr_all)
cat("<br> This table shows the enrichment FDR of Gene ontology terms in gene contibution to PCs<br>")
cat("### **Functional enrichments of HCPC clusters using all genes**\n")
plot(func_results$pca_data$all_genes$res.hcpc, choice="tree", title="")
plot(func_results$pca_data$all_genes$res.hcpc, axes=c(1,2), choice="map", draw.tree= FALSE)
print_go_tables(pca_cl_all)
cat("<br> This table shows the enrichment FDR of Gene ontology terms in gene contibution to HCPC clusters<br>")
cat("### **Functional enrichments of PCs using only DEGs**\n")
Expand All @@ -55,12 +57,13 @@ last_dim <- 1
while (last_dim < func_results$pca_data$DEGs$dim_to_keep){
plot(FactoMineR::plot.PCA(func_results$pca_data$DEGs$pca_data,
invisible = "quali",
axis = c(last_dim, last_dim + 1),
axes = c(last_dim, last_dim + 1),
title = paste0(last_dim, " and ", last_dim + 1, " PCs")))
last_dim <- last_dim + 2
}
print_go_tables(pca_enr_degs)
cat("<br> This table shows the enrichment FDR of Gene ontology terms in gene contibution to PCs<br>")
cat("### **Functional enrichments of HCPC clusters using only DEGs**\n")
Expand All @@ -69,6 +72,7 @@ plot(func_results$pca_data$DEGs$res.hcpc, axes=c(1,2), choice="map", draw.tree=
print_go_tables(pca_cl_degs)
cat("<br> This table shows the enrichment FDR of Gene ontology terms in gene contibution to HCPC clusters<br>")
```

0 comments on commit 3b1b114

Please sign in to comment.