-
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
4 changed files
with
1,618 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
title: "AUCell" | ||
author: "Xue Xiao" | ||
date: "2024-06-20" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
|
||
## Install AUCell | ||
```{r eval=FALSE, echo=FALSE, message=FALSE, warning=FALSE} | ||
BiocManager::install("AUCell") | ||
``` | ||
|
||
## Load Packages | ||
```{r} | ||
library(AUCell) | ||
library(Matrix) | ||
library(SummarizedExperiment) | ||
library(Seurat) | ||
``` | ||
|
||
|
||
## Load Genesets and Datasets | ||
```{r} | ||
setwd("/Users/xuexiao/Library/CloudStorage/[email protected]/My Drive/Lab/Projects/Dedifferentiation/Data") | ||
CC1_markers <- read.csv("CC1_markers.csv", header = T, row.names = 1) | ||
CC1_geneset <- CC1_markers$Genes | ||
CSC_markers_0.007 <- read.csv("filtered_markers_above_0_007.csv", header = T, row.names = 1) | ||
CSC_geneset_0.007 <- CSC_markers_0.007$GENE | ||
CSC_markers_0.006 <- read.csv("filtered_markers_above_0_006.csv", header = T, row.names = 1) | ||
CSC_geneset_0.006 <- CSC_markers_0.006$GENE | ||
CSC_markers_0.005 <- read.csv("filtered_markers_above_0_005.csv", header = T, row.names = 1) | ||
CSC_geneset_0.005 <- CSC_markers_0.005$GENE | ||
gene_sets <- list( | ||
CC1 = CC1_geneset, | ||
CSC_0.007 = CSC_geneset_0.007, | ||
CSC_0.006 = CSC_geneset_0.006, | ||
CSC_0.005 = CSC_geneset_0.005 | ||
) | ||
common_genes <- intersect(CC1_geneset, CSC_geneset_0.005) | ||
``` | ||
|
||
|
||
```{r} | ||
# Open Seurat File | ||
seurat_obj <- readRDS("~/Library/CloudStorage/[email protected]/My Drive/Lab/Projects/Dedifferentiation/Data/Cancer_cell_in_house_magic_cytotrace.rds") | ||
# Extract the expression matrix | ||
expr_matrix <- GetAssayData(seurat_obj, layer = "counts") | ||
``` | ||
|
||
## Run AUCell | ||
```{r} | ||
# Build the rankings | ||
cells_rankings <- AUCell_buildRankings(expr_matrix, nCores = 1, plotStats = TRUE) | ||
# Calculate the AUCell scores | ||
cells_AUC <- AUCell_calcAUC(gene_sets, cells_rankings) | ||
# Add AUCell scores to Seurat metadata | ||
aucell_scores <- as.data.frame(t(as.data.frame(cells_AUC@assays@data$AUC))) | ||
colnames(aucell_scores) <- paste0("AUCell_", colnames(aucell_scores)) | ||
seurat_obj <- AddMetaData(seurat_obj, metadata = aucell_scores) | ||
# View the Seurat object metadata to check if scores were added | ||
head([email protected]) | ||
``` | ||
|
||
## Visualization | ||
```{r inline_plot, fig.width=7, fig.height=5} | ||
# Define custom color palette | ||
custom_colors <- scale_color_gradientn(colors = c("gray", "yellow", "red")) | ||
# Visualize the AUCell scores with custom color scheme | ||
FeaturePlot(seurat_obj, features = colnames(aucell_scores), pt.size = 0.2, label = T) & custom_colors | ||
``` | ||
|
||
|
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,60 @@ | ||
--- | ||
title: "BCSCdb" | ||
author: "Xue Xiao" | ||
date: "2024-06-18" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
|
||
## Load packages | ||
```{r} | ||
library(ggplot2) | ||
``` | ||
|
||
|
||
## Load all CSC markers | ||
```{r} | ||
setwd("/Users/xuexiao/Library/CloudStorage/[email protected]/My Drive/Lab/Projects/Dedifferentiation/Data") | ||
all_CSC_markers <- read.csv("CSC_Biomarker_2022_All.csv", header = F) | ||
head(all_CSC_markers) | ||
length(unique(all_CSC_markers$V1)) | ||
``` | ||
|
||
## Filter top 100 markers | ||
```{r} | ||
## Unique markers | ||
unique_CSC_markers <- all_CSC_markers[!duplicated(all_CSC_markers$V1), ] | ||
## Sort the CSC markers in descending order of global score | ||
sorted_CSC_markers <- unique_CSC_markers[order(-as.numeric(unique_CSC_markers$V11)), ] | ||
## Check distribution of global score | ||
ggplot(unique_CSC_markers, aes(x = V11)) + | ||
geom_histogram(binwidth = 0.05, fill = "blue", color = "black", alpha = 0.7) + | ||
scale_x_continuous(limits = c(-0.1, 1), breaks = seq(-1, 1, by = 0.05)) + | ||
labs(title = "Distribution of Global Scores", | ||
x = "Global Score", | ||
y = "Frequency") + | ||
theme_minimal() + | ||
stat_bin(binwidth = 0.05, geom = "text", aes(label = ..count..), vjust = -0.5, color = "black") | ||
## Select the top 100 markers according to global score | ||
table(unique_CSC_markers$V11) | ||
``` | ||
|
||
|
||
```{r} | ||
sum(unique_CSC_markers$V11 > 0.007, na.rm = TRUE) # 105 genes | ||
sum(unique_CSC_markers$V11 > 0.006, na.rm = TRUE) # 158 genes | ||
sum(unique_CSC_markers$V11 > 0.005, na.rm = TRUE) # 269 genes | ||
``` | ||
## Filter genes with global score | ||
```{r} | ||
filtered_markers <- unique_CSC_markers[unique_CSC_markers$V11 > 0.005, ] | ||
unique_gene_names <- as.list(filtered_markers$V1) | ||
colnames(filtered_markers) <- c("GENE", "MARKER_TYPE", "EXPRESSION_LEVEL", "HGNC_ID", "CANCER_TYPE", "HISTOLOGICAL_TYPE", "CELL_LINE", "CSC_ENRICHMENT", "METHOD", "CONFIDENCE_SCORING", "GLOBAL_SCORING", "PUBMED_ID") | ||
write.csv(filtered_markers, "/Users/xuexiao/Library/CloudStorage/[email protected]/My Drive/Lab/Projects/Dedifferentiation/Data/filtered_markers_above_0_005.csv") | ||
``` | ||
|
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,174 @@ | ||
--- | ||
title: "OC_CAF_Crosstalk" | ||
output: html_document | ||
date: "2024-05-21" | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
|
||
## Package Installation | ||
```{r, eval=FALSE} | ||
# install.packages("devtools") | ||
devtools::install_github("immunogenomics/presto") | ||
devtools::install_github("jinworks/cellchat") | ||
``` | ||
|
||
## Load Packages | ||
```{r} | ||
library(Seurat) | ||
library(cellchat) | ||
library(ggplot2) | ||
library(ggplotify) | ||
``` | ||
|
||
|
||
## Load Data | ||
```{r} | ||
load("~/Library/CloudStorage/[email protected]/My Drive/Lab/Projects/OC_CAF_Crosstalk/GSE165897/Secreted_Signaling_GSE165897_Object.RData") | ||
load("~/Desktop/Lab/Projects/OC_CAF_Crosstalk/Secreted_Signalingin_house_Object.RData") | ||
load("~/Desktop/Lab/Projects/OC_CAF_Crosstalk/Secreted_Signaling_Object.RData") | ||
cellchat@meta$labels[cellchat@meta$labels == "Epithelial_cells"] <- "OC_cells" | ||
cellchat@meta$labels[cellchat@meta$labels == "Smooth_muscle_cells"] <- "CAFs" | ||
table(cellchat@idents) | ||
cellchat <- setIdent(cellchat, ident.use = "labels") | ||
``` | ||
|
||
## Create cellchat Object | ||
```{r} | ||
data.input <- in_house_seurat[["RNA"]]$data # normalized data matrix | ||
# For Seurat version >= “5.0.0”, get the normalized data via `seurat_object[["RNA"]]$data` | ||
Idents(in_house_seurat) <- "subcluster" | ||
labels <- Idents(in_house_seurat) | ||
colnames([email protected]) | ||
meta <- data.frame(labels = labels, row.names = names(labels)) # create a dataframe of the cell labels | ||
cellchat <- createcellchat(object = in_house_seurat, group.by = "subcluster", assay = "RNA") | ||
``` | ||
## Set the ligand-receptor interaction database | ||
```{r} | ||
cellchatDB <- cellchatDB.human | ||
cellchatDB.use <- subsetDB(cellchatDB, search = "Secreted Signaling", key = "annotation") | ||
cellchat@DB <- cellchatDB.use | ||
cellchat <- subsetData(cellchat) | ||
``` | ||
|
||
## Run cellchat | ||
```{r} | ||
ptm = Sys.time() | ||
future::plan("multisession", workers = 8) | ||
cellchat <- identifyOverExpressedGenes(cellchat) | ||
cellchat <- identifyOverExpressedInteractions(cellchat) | ||
execution.time = Sys.time() - ptm | ||
print(as.numeric(execution.time, units = "secs")) | ||
cellchat <- computeCommunProb(cellchat, type = "triMean") | ||
cellchat <- filterCommunication(cellchat, min.cells = 10) | ||
cellchat <- computeCommunProbPathway(cellchat) | ||
``` | ||
|
||
```{r} | ||
cellchat <- aggregateNet(cellchat) | ||
execution.time = Sys.time() - ptm | ||
print(as.numeric(execution.time, units = "secs")) | ||
``` | ||
|
||
|
||
## Visualization | ||
```{r} | ||
# Aggregated Cell-Cell Communication Network (Total Interactions) | ||
ptm = Sys.time() | ||
groupSize <- as.numeric(table(cellchat@idents)) | ||
par(mfrow = c(1,2), xpd=TRUE) | ||
netVisual_circle(cellchat@net$count, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Number of interactions") | ||
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength") | ||
plot1 <- as.ggplot(~netVisual_circle(cellchat@net$count, vertex.weight = groupSize, | ||
weight.scale = TRUE, label.edge = FALSE, | ||
title.name = "Number of interactions")) | ||
# Save the first plot | ||
ggsave("Number_of_interactions.pdf", plot = plot1, width = 6, height = 6) | ||
# Convert the second plot to a ggplot object | ||
plot2 <- as.ggplot(~netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, | ||
weight.scale = TRUE, label.edge = FALSE, | ||
title.name = "Interaction weights/strength")) | ||
# Save the second plot | ||
ggsave("Interaction_weights_strength.pdf", plot = plot2, width = 6, height = 6) | ||
getwd() | ||
setwd("/Users/xuexiao/Library/CloudStorage/[email protected]/My Drive/Lab/Figure/Data") | ||
``` | ||
|
||
|
||
```{r} | ||
# Network Centrality Scores | ||
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "netP") | ||
netAnalysis_signalingRole_network(cellchat, signaling = pathways.show, width = 13, height = 5, font.size = 10) | ||
``` | ||
```{r} | ||
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways | ||
ht1 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "outgoing") | ||
ht2 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "incoming") | ||
ht1 + ht2 | ||
netAnalysis_signalingRole_heatmap(cellchat, signaling = c("PDGF", "ncWNT"), width = 8, height = 5, font.size = 10) | ||
ht | ||
``` | ||
```{r} | ||
# show all the significant signaling pathways from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use') | ||
netVisual_chord_gene(cellchat, sources.use = c(1:3), targets.use = c(4:13), slot.name = "netP", legend.pos.x = 10, small.gap = 0.2, lab.cex = 0.5) | ||
``` | ||
|
||
|
||
```{r} | ||
pathways.show <- c("PDGF") | ||
``` | ||
|
||
### Circle plot | ||
```{r} | ||
par(mfrow=c(1,1)) | ||
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "circle") | ||
``` | ||
### Chord diagram | ||
```{r} | ||
par(mfrow=c(1,1)) | ||
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "chord") | ||
``` | ||
### Heatmap | ||
```{r} | ||
par(mfrow=c(1,1)) | ||
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds") | ||
``` | ||
### Contribution | ||
```{r} | ||
netAnalysis_contribution(cellchat, signaling = pathways.show, font.size = 10, width = 20) | ||
``` | ||
### Single L-R pair | ||
```{r} | ||
pairLR.PDGF <- extractEnrichedLR(cellchat, signaling = pathways.show, geneLR.return = FALSE) | ||
LR.show <- pairLR.PDGF[4,] # show one ligand-receptor pair | ||
``` | ||
|
||
```{r} | ||
# Chord plot | ||
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = "chord") | ||
# Circle plot | ||
#netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = "circle") | ||
``` | ||
```{r} | ||
netVisual_bubble(cellchat, sources.use = c(4:13), targets.use = c(1:3), signaling = c("PDGF"), remove.isolate = FALSE, sort.by.target = TRUE) | ||
netVisual_bubble(cellchat, sources.use = c(1:3), targets.use = c(4:13), signaling = c("PDGF"), remove.isolate = FALSE) | ||
netVisual_bubble(cellchat, sources.use = c(1:3), targets.use = c(4:13), signaling = c("ncWNT"), remove.isolate = FALSE) | ||
``` | ||
```{r} | ||
netVisual_chord_gene(cellchat, sources.use = c(4:13), targets.use = c(1:3), signaling = c("PDGF"),legend.pos.x = 8) | ||
netVisual_chord_gene(cellchat, sources.use = c(1:3), targets.use = c(4:13), signaling = c("ncWNT"),legend.pos.x = 8, small.gap = 0.1) | ||
``` | ||
|
||
## Save CellChat object | ||
```{r} | ||
saveRDS(cellChat, file = "~/Library/CloudStorage/[email protected]/My Drive/Lab/Projects/OC_CAF_Crosstalk/Imputed_in_house/cellchat_in_house.rds") | ||
``` | ||
|
Oops, something went wrong.