load packages etc.
library(conos) require(pagoda2) devtools::load_all('/home/larsc/SecretUtils') library(tidyverse) library(cowplot)
epilepsy_con <- readRDS(file.path('/home/larsc/data/10x_preproced_graphed.rds')) epilepsy_annot <- readRDS(file.path('/home/demharters/R/projects/UPF9_14_17_19_22_23_24_32_33/metadata_10x_final.rds'))
Fix annotation a little bit
epilepsy_annot$cellid <- rownames(epilepsy_annot)
nr of cells in each subtype for each condition
condition_split <- split(epilepsy_annot$subtype, epilepsy_annot$condition, drop=TRUE) condition_split %>% lapply(table)
Read unaligned graph adj obtained with pagoda2 on the whole raw matrix
eps_unaligned_adj <- readMM('/home/larsc/data/eps_unaligned_adj.mtx')
paga_subtype_condition <- GeneratePagaItems(eps_unaligned_adj, epilepsy_annot$subtype, epilepsy_annot$condition, by.subtypes.condition = T, log.scale=F) paga_subtype_condition$scatter.plot # has matrix, data frame and plot
Distance matrix tsne plot, using only a single n_sample x n_sample matrix, using log scale
samples_connectivities <- GeneratePagaItems(eps_unaligned_adj, sample.vector=epilepsy_annot$sample, by.sample=T, log.scale=T, pseudo.connectivity = 1e-3) # put it in log scale for better visualization, so we add a small pseudo connectivity SecretUtils::PlotDistanceMatRed(samples_connectivities$connectivities, epilepsy_annot$sample, epilepsy_annot$subtype, epilepsy_annot$sample, epilepsy_annot$cellid, epilepsy_annot$condition, perplexity=2, max_iter=1e5, by.subtype=F)
Within conditions distances
samples_connectivities <- GeneratePagaItems(eps_unaligned_adj, sample.vector=epilepsy_annot$sample, by.sample=T) SecretUtils::ConditionDistanceDensity(samples_connectivities$connectivities, epilepsy_annot$sample, epilepsy_annot$subtype, epilepsy_annot$sample, epilepsy_annot$cellid, epilepsy_annot$condition, notch=F, by.subtype=F)
Using subtype-sample partitions
paga_subtype_samples <- GeneratePagaItems(eps_unaligned_adj, epilepsy_annot$subtype, epilepsy_annot$condition, epilepsy_annot$sample, by.subtypes.samples = T) paga_subtype_samples$sub.cond.plot
Deeper look at between distances
GeneratePagaPlot(paga_subtype_samples$paga.df, subset='between')
log scale
paga_subtype_samples_unlin <- GeneratePagaItems(eps_unaligned_adj, epilepsy_annot$subtype, epilepsy_annot$condition, epilepsy_annot$sample, by.subtypes.samples = T, log.scale=T, pseudo.connectivity=1e-3) paga_subtype_samples_unlin$sub.cond.plot GeneratePagaPlot(paga_subtype_samples_unlin$paga.df, subset='between', log.scale=T)
pancreas_con <- readRDS('/home/larsc/data/pancreas_indrop_conos_precced_graphed.rds') location_of_annot <- '/d0-mendel/home/viktor_petukhov/SmallProjects/conos_back/data/conditions/seurat_islets/indrop/design_info.csv' pancreas_annot <- location_of_annot %>% data.table::fread(sep=",",header=T) %>% as.data.frame()
nr of cells in each subtype for each condition, lots of very small partitions so they will be distorting the results
condition_split <- split(pancreas_annot$CellType, pancreas_annot$Disease, drop=TRUE) condition_split %>% lapply(table)
Create unaligned matrix
raw_pancreas <- RbindRaw(pancreas_con) unaligned_pancreas <- SecretUtils::GenerateUnalignedAdj(raw_pancreas, pancreas_annot$CellId)
Scatter plot of PAGA values for subtype-condition partitions
paga_subtype_condition <- GeneratePagaItems(unaligned_pancreas, pancreas_annot$CellType, pancreas_annot$Disease, by.subtypes.condition = T) paga_subtype_condition$scatter.plot
Distance matrix tsne plot, using only a single n_sample x n_sample matrix.
samples_connectivities <- GeneratePagaItems(unaligned_pancreas, sample.vector=pancreas_annot$Individual, by.sample=T) # put it in log scale for better visualization, so we add a small pseudo connectivity SecretUtils::PlotDistanceMatRed(log(samples_connectivities$connectivities+1e-6), pancreas_annot$Individual, pancreas_annot$CellType, pancreas_annot$Individual, pancreas_annot$CellId, pancreas_annot$Disease, perplexity=1, max_iter=1e5, by.subtype=F)
Within conditions distances using same single sample x sample matrix (we only have 1 diseased sample/individual)
SecretUtils::ConditionDistanceDensity(samples_connectivities$connectivities, pancreas_annot$Individual, pancreas_annot$CellType, pancreas_annot$Individual, pancreas_annot$CellId, pancreas_annot$Disease, notch=F, by.subtype=F)
paga_subtype_samples <- GeneratePagaItems(unaligned_pancreas, pancreas_annot$CellType, pancreas_annot$Disease, pancreas_annot$Individual, by.subtypes.samples = T) paga_subtype_samples$sub.cond.plot
closer look at between distances
GeneratePagaPlot(paga_subtype_samples$paga.df, subset='between')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.