-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
420 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#' Plot HPO pseudotime | ||
#' | ||
#' Plot the Human Phenotype Ontology (HPO) in genomic latent space, | ||
#' then compute pseudotime trajectories between a subset of phenotypes that | ||
#' are symptoms of a given disease (or set of diseases). | ||
#' @param obj \link{Seurat} object of HPO terms generated by \link{prepare_hpo}. | ||
#' @param disease_ids One or more disease IDs found within \code{dt_genes}. | ||
#' @inheritParams prepare_hpo | ||
#' @inheritParams monocle3::learn_graph | ||
#' @inheritDotParams monocle3::plot_cells | ||
#' @export | ||
plot_hpo_pseudotime <- function(obj, | ||
dt_genes = HPOExplorer::load_phenotype_to_genes(1), | ||
disease_ids=dt_genes$disease_id[1:3], | ||
learn_graph_control=list(prune_graph=FALSE), | ||
... | ||
){ | ||
requireNamespace("monocle3") | ||
requireNamespace("SeuratWrappers") | ||
gene_symbol <- disease_id <- NULL; | ||
|
||
#### Add disease metadata | ||
## Using gene overlap (670998 p2d pairs) ## | ||
# nrow(unique(dt_genes[,c("hpo_id","disease_id")])) | ||
p2d <- dt_genes[disease_id %in% disease_ids, | ||
list(count=data.table::uniqueN(gene_symbol)), | ||
by=c("hpo_id","disease_id")]#|> | ||
# data.table::dcast.data.table(formula = hpo_id~disease_id, | ||
# value.var = "count") | ||
if(nrow(p2d)==0) stopper("No hpo_ids found for the given disease_ids.") | ||
# p2d <- p2d[colnames(ref),] | ||
# ## Using annotation overlap (258276 p2d pairs) | ||
# nrow(unique(dt_annot[,c("hpo_id","disease_id")])) | ||
# p2d <- dt_annot[,count:=1]|> | ||
# data.table::dcast.data.table(formula = hpo_id~disease_id, | ||
# value.var = "count", | ||
# ) | ||
#### Merge with rest of annotations #### | ||
## make Seurat way too slow having this many columns... | ||
# dt_annot_melt <- data.table::merge.data.table(dt_annot_melt, | ||
# p2d, | ||
# by.x = "id", | ||
# by.y = "hpo_id", | ||
# all.x = TRUE) | ||
|
||
hpo_ids <- intersect(unique(p2d$hpo_id), | ||
colnames(obj)) | ||
if(length(hpo_ids)==0) { | ||
stopper("No hpo_ids oevrlapping with samples (colnames) in obj.") | ||
} | ||
cds <- SeuratWrappers::as.cell_data_set(obj) | ||
cds_sub <- monocle3::cluster_cells( | ||
cds = cds[,hpo_ids], | ||
k = max(as.integer(cds@colData$seurat_clusters))) | ||
cds_sub <- monocle3::learn_graph(cds_sub, | ||
learn_graph_control=learn_graph_control) | ||
cds_sub <- monocle3::order_cells(cds_sub, root_cells = colnames(cds_sub)) | ||
monocle3::principal_graph(cds) <- monocle3::principal_graph(cds_sub) | ||
monocle3::principal_graph_aux(cds) <- monocle3::principal_graph_aux(cds_sub) | ||
plt <- monocle3::plot_cells(cds, | ||
# color_cells_by = "ancestor_name_abnormality", | ||
# group_cells_by = "top_celltype" | ||
) | ||
return( | ||
list(data=cds, | ||
plot=plt) | ||
) | ||
# pseudo_dt <- t(cds@principal_graph_aux$UMAP$pr_graph_cell_proj_dist)|>`colnames<-`(c("umap1","umap2")) | ||
|
||
# gm <- ref@graphs$freq_nn[highlights$hpo_id, | ||
# highlights$hpo_id] | ||
# g <- igraph::graph_from_adjacency_matrix(gm) | ||
# gdt <- KGExplorer::graph_to_dt(g)[object!=subject] | ||
# ggraph(g, layout = 'stress') + | ||
# geom_edge_density() + | ||
# geom_edge_link(alpha = 0.25) | ||
# dp <- Seurat::DimPlot(ref, | ||
# group.by = disease_id, | ||
# cols.highlight = "red", | ||
# alpha = .7, | ||
# sizes.highlight = highlights[[disease_id]], | ||
# cells.highlight = list( highlights[["hpo_id"]])|> | ||
# `names<-`(disease_id)) | ||
# highlight_df <- subset(dp[[1]]$data,highlight!="Unselected") | ||
# | ||
# highlight_dt <- merge(gdt, | ||
# data.table::data.table(highlight_df,keep.rownames = "subject"), | ||
# by="subject")|> | ||
# merge(data.table::data.table(highlight_df,keep.rownames = "object"), | ||
# by=c("object","highlight",disease_id)) |> | ||
# data.table::setnames(c("umap_1.x","umap_2.x","umap_1.y","umap_2.y"), | ||
# c("x","y","xend","yend")) | ||
# # ggplot2::ggplot() | ||
# dp + ggplot2::geom_segment(data = highlight_dt, | ||
# mapping = ggplot2::aes(x = x, | ||
# xend = xend, | ||
# y = y, | ||
# yend = yend), | ||
# inherit.aes = FALSE) | ||
# dp+ | ||
# ggplot2::geom_step(data = highlight_df, | ||
# ggplot2::aes(x=umap_1, | ||
# y=umap_2)) | ||
} |
Oops, something went wrong.