Skip to content

Instantly share code, notes, and snippets.

@vjcitn
Created September 1, 2024 21:06
Show Gist options
  • Save vjcitn/e5916d7698638fe9117b5ea27deb7563 to your computer and use it in GitHub Desktop.
Save vjcitn/e5916d7698638fe9117b5ea27deb7563 to your computer and use it in GitHub Desktop.
code that uses ggplot and some cell-level summaries on XenSPEP/XenSCE
library(plotly)
library(ggplot2)
library(XenSCE)
if (!exists("gbm")) load("gbm.rda")
print.xen_ggprep = function(x, ...) {
cat(sprintf("xen_ggprep instance for %d cells with %d cell boundary vertices.\n", ncol(x$sampd), nrow(x$bounds)))
}
ggprep_seg = function(xsce, xlim=c(5800,6200), ylim=c(6300, 6700), show_tx=TRUE) {
bounds = getCellBoundaries(xsce)
bounds = bounds[bounds$vertex_x > xlim[1] &
bounds$vertex_x < xlim[2] & bounds$vertex_y > ylim[1] & bounds$vertex_y < ylim[2],]
c4 <- as.data.frame(bounds)
#ggplot(c4, aes(x=vertex_x, y=vertex_y, group=cell_id)) + geom_path() -> pas
tx = getTranscripts(xsce)
# tx[which(as.character(tx$cell_id) %in% unique(c4$cell_id)),] -> myt
myt = tx[tx$x_location > xlim[1] & tx$x_location < xlim[2] &
tx$y_location > ylim[1] & tx$y_location < ylim[2], ]
sampd = as.data.frame(SummarizedExperiment::colData(xsce[, unique(c4$cell_id)]))
sizq = cut(sampd$cell_area, c(0, quantile(sampd$cell_area, c(.2,.4,.6,.8)), max(sampd$cell_area)+.01))
sampd$sizq = sizq
bounds = dplyr::left_join(c4, sampd, by="cell_id")
ans = list(bounds=bounds, txdata=myt)
class(ans) = c("xen_ggprep", "list")
ans
# ggplot(c4, aes(x=vertex_x, y=vertex_y, group=cell_id)) +
# geom_path() +
# geom_point(data=myt, aes(x=x_location, y=y_location,
# text=as.character(feature_name)), size=.05, colour="grey", alpha=.2)
}
ss = ggprep_seg(gbm)
plot.xen_ggprep = function(x, y, ...) {
ggplot(x$bounds, aes(x=vertex_x, y=vertex_y, group=cell_id, colour=sizq, fill=sizq)) +
geom_polygon() + geom_path(colour="black")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment