-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
139 lines (94 loc) · 4.68 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ISCHIA
<!-- badges: start -->
<!-- badges: end -->
ISCHIA is a framework for analysis of cell-types and Ligand-Receptor cooccurrences in spatial transcriptomics/proteomics data
## Installation
You can install the development version of ISCHIA from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("ati-lz/ISCHIA")
```
## Example
Here we present an example analysis of Visium IBD samples as presented in the manuscript
```{r dependencies, message=FALSE,warning=FALSE}
# Loading required packages
library(ISCHIA)
library(robustbase)
library(data.table)
library(ggplot2)
library(Seurat)
library(dplyr)
```
```{r preparation}
## You can download the example dataset from Zenodo repository,[10.5281/zenodo.7589581] IBD_Visium_SeuratObj.RData
# here we will subset the dataset to only one sample
load(url("https://zenodo.org/record/7636442/files/IBD_visium_SeuratObj_small.RData?download=1"))
IBD.visium.P4
# Extracting the deconvoluted cell type probability matrix from metadata
deconv.mat <- as.matrix(IBD.visium.P4@meta.data[,9:28])
colnames(deconv.mat) <- sapply(colnames(deconv.mat), function(x) unlist(strsplit(x, split = "_"))[2])
head(deconv.mat)
```
## Celltype Composition clustering
```{r Composition_clustering}
# Deciding about the k
Composition.cluster.k(deconv.mat, 20)
# Composition clustering of the deconvoluted spatial spots
IBD.visium.P4 <- Composition.cluster(IBD.visium.P4, deconv.mat, 8)
#not good...Idents(IBD.visium.P4) <- "CompositionCluster_CC"
table(IBD.visium.P4$CompositionCluster_CC)
SpatialDimPlot(IBD.visium.P4, group.by = c("CompositionCluster_CC")) + scale_fill_manual(values = c("cyan", "orange", "purple","green","yellow","blue", "red","black"))
```
We can check the leading cell types of each CC
```{r Celltype_enrichment, message=FALSE, warning=FALSE}
Composition_cluster_enrichedCelltypes(IBD.visium.P4,"CC4", deconv.mat)
Composition_cluster_enrichedCelltypes(IBD.visium.P4,"CC7", deconv.mat)
```
We can explore the UMAP representation of the spot based on their deconvoluted cell type composition
```{r umap}
IBD.visium.P4.umap <- Composition_cluster_umap(IBD.visium.P4, deconv.mat)
IBD.visium.P4.umap$umap.cluster.gg
IBD.visium.P4.umap$umap.deconv.gg
```
## Celltype Cooccurrence analysis
We choose CC4 and CC7 to check the celltype cooccurrences
```{r celltype_cooccurrence}
CC4.celltype.cooccur <- spatial.celltype.cooccurence(spatial.object=IBD.visium.P4,
deconv.prob.mat=deconv.mat,
COI="CC4", prob.th= 0.05, Condition=unique(IBD.visium.P4$orig.ident))
plot.celltype.cooccurence(CC4.celltype.cooccur)
CC7.celltype.cooccur <- spatial.celltype.cooccurence(spatial.object=IBD.visium.P4,
deconv.prob.mat=deconv.mat,
COI="CC7", prob.th= 0.05, Condition=unique(IBD.visium.P4$orig.ident))
plot.celltype.cooccurence(CC7.celltype.cooccur)
```
##Cooccurrence of ligand and receptors
As the LR cooccurrence takes a lon time to run, for now Im just commenting out the command, will work on it later
```{r LR_cooccurrence}
lr_network = readRDS(url("https://zenodo.org/record/3260758/files/lr_network.rds"))
all.LR.network <- cbind(lr_network[,c("from","to")], LR_Pairs=paste(lr_network$from, lr_network$to, sep = "_"))
all.LR.network.exp <- all.LR.network[which(all.LR.network$from %in% rownames(IBD.visium.P4) & all.LR.network$to %in% rownames(IBD.visium.P4)),]
# To reduce the computation time for this example, we randomly sample from the whole dataset of LR interactions
all.LR.network.exp <- sample_n(all.LR.network.exp,500)
all.LR.genes <- unique(c(all.LR.network.exp$from, all.LR.network.exp$to))
all.LR.genes.comm <- intersect(all.LR.genes, rownames(IBD.visium.P4))
LR.pairs <- all.LR.network.exp$LR_Pairs
LR.pairs.AllCombos <- combn(all.LR.genes.comm, 2, paste0, collapse = "_")
#CC4.Enriched.LRs <- Enriched.LRs(IBD.visium.P4, c("CC4"), unique(IBD.visium.P4$orig.ident), all.LR.genes.comm, LR.pairs, 1, 0.2)
#CC7.Enriched.LRs <- Enriched.LRs(IBD.visium.P4, c("CC7"), unique(IBD.visium.P4$orig.ident), all.LR.genes.comm, LR.pairs, 1, 0.2)
#CC1vsCC4.Enriched.LRs.Specific <- Diff.cooc.LRs(CC4.Enriched.LRs, CC7.Enriched.LRs, 0.05, 0.1)
#ChordPlot.Enriched.LRs(CC4.Enriched.LRs$COI.enrcihed.LRs[1:20,])
#SankeyPlot.Diff.LRs(CC4.Enriched.LRs$COI.enrcihed.LRs, CC7.Enriched.LRs$COI.enrcihed.LRs)
```