Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressed comments R1-1 and R2-4 #10

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 77 additions & 30 deletions analysis/figures.Figure3.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,96 @@ library(ggbeeswarm)
source("./code/functions.R")
```

# Load data

```{r}
abs_counts <- fread("./data/Traditional_IF_absolute_cell_counts.csv")
colnames(abs_counts) <- gsub(" ","_",colnames(abs_counts))
abs_counts <- abs_counts %>%
pivot_longer(cols = Endo_Pre:BZ_2d,
names_to = "sample",
values_to = "cell_count") %>%
separate(sample, into = c("region","timepoint"), sep = "_") %>%
subset(timepoint != "Pre")
## Read in quantified data
all_cell_types_quantified <- fread("./review/all_cell_types_per_region_counts_perctentages_20241212.csv")

ccr2_monomacro <- all_cell_types_quantified %>%
subset(final_cell_type == "Mono / Macros Ccr2+") %>%
subset(timepoint %in% c("4h","24h","48h")) %>%
subset(region_name %in% c("border_zone","infarct_core","epicardial_region","endocardial_region"))

# Replace abbreviations with full labels
abs_counts$region <- gsub("Endo","Endocard",abs_counts$region)
abs_counts$region <- gsub("Core","Infarct core",abs_counts$region)
abs_counts$region <- gsub("Epi","Epicard",abs_counts$region)
abs_counts$region <- gsub("BZ","Border zone",abs_counts$region)
abs_counts$region <- factor(abs_counts$region, levels = c("Endocard","Infarct core","Epicard","Border zone"))
ccr2_monomacro$region_name <- gsub("border_zone","Border zone",ccr2_monomacro$region_name)
ccr2_monomacro$region_name <- gsub("infarct_core","Infarct core",ccr2_monomacro$region_name)
ccr2_monomacro$region_name <- gsub("epicardial_region","Epicardium",ccr2_monomacro$region_name)
ccr2_monomacro$region_name <- gsub("endocardial_region","Endocardium",ccr2_monomacro$region_name)

abs_counts$timepoint <- gsub("1d","24h",abs_counts$timepoint)
abs_counts$timepoint <- gsub("2d","2 days",abs_counts$timepoint)
abs_counts$timepoint <- factor(abs_counts$timepoint, levels = c("Pre","4h","24h","2 days"))
ccr2_monomacro$region_name <- factor(ccr2_monomacro$region_name,
levels = c("Endocardium","Infarct core","Epicardium","Border zone"))
ccr2_monomacro$timepoint <- factor(ccr2_monomacro$timepoint,
levels = c("4h","24h","48h"))

abs_plot <- ggplot(abs_counts,aes(timepoint,cell_count)) +
seqIF_ccr2_relquant <- ggplot(ccr2_monomacro,aes(x = timepoint,y = count_per_mm2)) +
stat_summary(
fun.y = mean,
geom = "bar",
width = 0.9,
size = 0.3,
color = "black",
fill = "lightgrey") +
labs(y = "Absolute cell number") +
geom_beeswarm(size = 2 , pch = 21, color = "black", aes(fill = region)) +
facet_grid(.~ region) +
geom_beeswarm(size = 2, pch = 21, color = "black", aes(fill = region_name)) +
labs(x = "Time",
y = expression("Cells /"~mm^2)) +
#expression(paste("Mo / M",phi," per "~mm^2))
facet_grid(. ~ region_name) +
scale_fill_manual(values = c("#337272","#f0f0f0","#b062c2","#2c95c5")) +
theme(axis.title = element_text(face="bold"),
legend.position = "none") +
scale_fill_manual(values = c("#337272","#f0f0f0","#b062c2","#2c95c5")) +
theme(panel.border = element_rect(color = "black", fill = NA, size = 0.75)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
axis.title.x = element_blank())

save_plot(filename = "./plots/Figure_3.tradIF-absolute_cell_counts.pdf",
plot = abs_plot,
base_asp = 1.8,
base_height = 3)
axis.title.x = element_blank())
seqIF_ccr2_relquant

save_plot(filename = "./plots/Figure_3.SeqIF-absolute_cell_counts.pdf",
plot = seqIF_ccr2_relquant,
base_asp = 1.8,
base_height = 3)
```




<!-- # ```{r} -->
<!-- # abs_counts <- fread("./data/Traditional_IF_absolute_cell_counts.csv") -->
<!-- # colnames(abs_counts) <- gsub(" ","_",colnames(abs_counts)) -->
<!-- # abs_counts <- abs_counts %>% -->
<!-- # pivot_longer(cols = Endo_Pre:BZ_2d, -->
<!-- # names_to = "sample", -->
<!-- # values_to = "cell_count") %>% -->
<!-- # separate(sample, into = c("region","timepoint"), sep = "_") %>% -->
<!-- # subset(timepoint != "Pre") -->
<!-- # -->
<!-- # # Replace abbreviations with full labels -->
<!-- # abs_counts$region <- gsub("Endo","Endocard",abs_counts$region) -->
<!-- # abs_counts$region <- gsub("Core","Infarct core",abs_counts$region) -->
<!-- # abs_counts$region <- gsub("Epi","Epicard",abs_counts$region) -->
<!-- # abs_counts$region <- gsub("BZ","Border zone",abs_counts$region) -->
<!-- # abs_counts$region <- factor(abs_counts$region, levels = c("Endocard","Infarct core","Epicard","Border zone")) -->
<!-- # -->
<!-- # abs_counts$timepoint <- gsub("1d","24h",abs_counts$timepoint) -->
<!-- # abs_counts$timepoint <- gsub("2d","2 days",abs_counts$timepoint) -->
<!-- # abs_counts$timepoint <- factor(abs_counts$timepoint, levels = c("Pre","4h","24h","2 days")) -->
<!-- # -->
<!-- # abs_plot <- ggplot(abs_counts,aes(timepoint,cell_count)) + -->
<!-- # stat_summary( -->
<!-- # fun.y = mean, -->
<!-- # geom = "bar", -->
<!-- # width = 0.9, -->
<!-- # size = 0.3, -->
<!-- # color = "black", -->
<!-- # fill = "lightgrey") + -->
<!-- # labs(y = "Absolute cell number") + -->
<!-- # geom_beeswarm(size = 2 , pch = 21, color = "black", aes(fill = region)) + -->
<!-- # facet_grid(.~ region) + -->
<!-- # theme(axis.title = element_text(face="bold"), -->
<!-- # legend.position = "none") + -->
<!-- # scale_fill_manual(values = c("#337272","#f0f0f0","#b062c2","#2c95c5")) + -->
<!-- # theme(panel.border = element_rect(color = "black", fill = NA, size = 0.75)) + -->
<!-- # theme(axis.text.x = element_text(angle = 45, hjust = 1), -->
<!-- # axis.title.x = element_blank()) -->
<!-- # -->
<!-- # save_plot(filename = "./plots/Figure_3.tradIF-absolute_cell_counts.pdf", -->
<!-- # plot = abs_plot, -->
<!-- # base_asp = 1.8, -->
<!-- # base_height = 3) -->
```
151 changes: 142 additions & 9 deletions analysis/figures.supplementary_figure_5.molkart_spatial_plots.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ sample_plots <- lapply(sample_names, function(sample) {
scale_color_manual(values = named_colors
) +
theme(legend.position = "right",
legend.title = element_text(size = 20),
legend.text = element_text(size = 16)) + # Hide legend or adjust as needed
legend.title = element_text(size = 15),
legend.text = element_text(size = 14)) + # Hide legend or adjust as needed
guides(color = guide_legend(title = "Cell types",override.aes = list(size = 6))) +
labs(title = "")

Expand All @@ -104,28 +104,28 @@ sample_plots <- lapply(sample_names, function(sample) {
title = "Control",
y = "Replicate 1") +
theme(plot.tag = element_text(size = 20, face = "bold"),
plot.title = element_text(hjust=0.5, size = 20, face = "bold"),
axis.title.y = element_text(size = 20,angle = 90, face = "bold")
plot.title = element_text(hjust=0.5, size = 15, face = "bold"),
axis.title.y = element_text(size = 15,angle = 90, face = "bold")
)
} else if(sample == "sample_4h_r1_s1"){
p <- p +
labs(title = "4 hours") +
theme(plot.tag = element_text(size = 20, face = "bold"),
plot.title = element_text(hjust=0.5, size = 20, face = "bold"))
plot.title = element_text(hjust=0.5, size = 15, face = "bold"))
} else if(sample == "sample_2d_r1_s1"){
p <- p +
labs(title = "2 days") +
theme(plot.tag = element_text(size = 20, face = "bold"),
plot.title = element_text(hjust=0.5, size = 20, face = "bold"))
plot.title = element_text(hjust=0.5, size = 15, face = "bold"))
} else if(sample == "sample_4d_r1_s1"){
p <- p +
labs(title = "4 days") +
theme(plot.tag = element_text(size = 20, face = "bold"),
plot.title = element_text(hjust=0.5, size = 20, face = "bold"))
plot.title = element_text(hjust=0.5, size = 15, face = "bold"))
} else if (sample == "sample_control_r2_s1"){
p <- p +
labs(y = "Replicate 2") +
theme(axis.title.y = element_text(size = 20,angle = 90, face = "bold")
theme(axis.title.y = element_text(size = 15,angle = 90, face = "bold")
)
}

Expand Down Expand Up @@ -195,10 +195,143 @@ ct_time_barplot
```



## C) Dotplot for subclustering of immune cell types

```{r}
immune_cells <- subset(seurat_object,
anno_cell_type_lvl2 %in% c("Myeloid_cells","Lymphoid_cells"))
```

```{r}
library(viridis)
immune_cells_dotplot <- DotPlot(immune_cells,
features = c("Csf3r","Ccl2","C1qa","Arg1","Cd3e","Ighm","Cd74"),
group.by = "anno_cell_type_lvl3") +
RotatedAxis() +
scale_colour_viridis(option="magma") +
geom_point(aes(size=pct.exp), shape = 21, colour="black", stroke=0.5) +
guides(size=guide_legend(override.aes=list(shape=21, colour="black", fill="black"))) +
labs(tags = "c") + theme(plot.tag = element_text(size = 20, face = "bold"))
immune_cells_dotplot
```


## D) Spatial plot for immune subclustering

```{r}
## Perform similar rotation correction on images as in main Supplementary Figure 5
metadata <- [email protected]

## Set sample order for patchwork
sample_names <- c("sample_4h_r1_s1",
"sample_2d_r1_s1",
"sample_4h_r2_s2",
"sample_2d_r2_s1")

new_metadata <- data.frame()
# For each sample in sample_names, apply a rotation function to x and y positions in metadata
for(sample in sample_names){
meta_sub <- subset(metadata,sample_ID == sample)
if(sample == "sample_control_r1_s1"){ # rotate 90 degrees counter clockwise
y_orig <- meta_sub$Y_centroid
x_orig <- meta_sub$X_centroid
meta_sub$X_centroid <- y_orig * -1
meta_sub$Y_centroid <- x_orig
}else if(sample == "sample_control_r2_s1"){ # rotate 90 degrees counter clockwise
meta_sub$X_centroid <- meta_sub$X_centroid * -1
meta_sub$Y_centroid <- meta_sub$Y_centroid * 1
}else if(sample == "sample_4h_r1_s1"){ # rotate 90 degrees counter clockwise
meta_sub$X_centroid <- meta_sub$X_centroid * -1
meta_sub$Y_centroid <- meta_sub$Y_centroid * 1
}else if(sample == "sample_4h_r2_s2"){ # rotate 90 degrees counter clockwise
y_orig <- meta_sub$Y_centroid
x_orig <- meta_sub$X_centroid
meta_sub$X_centroid <- y_orig * -1
meta_sub$Y_centroid <- x_orig
}else if(sample == "sample_2d_r1_s1"){ # rotate 90 degrees counter clockwise
meta_sub$X_centroid <- meta_sub$X_centroid * -1
meta_sub$Y_centroid <- meta_sub$Y_centroid * -1
}else if(sample == "sample_4d_r2_s1"){ # rotate 90 degrees counter clockwise
y_orig <- meta_sub$Y_centroid
meta_sub$Y_centroid <- meta_sub$X_centroid * -1
meta_sub$X_centroid <- y_orig * 1
}
new_metadata <- rbind(new_metadata,meta_sub)
}
new_metadata
```


```{r}
## Make a spatial plot for each sample and organize them using patchwork
sample_plots <- lapply(sample_names, function(sample) {
meta_sub <- subset(new_metadata,sample_ID == sample)
meta_sub$anno_cell_type_lvl3 <- gsub("_"," ",meta_sub$anno_cell_type_lvl3)

# Generate the plot
## Add a line of blank space on top of the plot
p <- ggplot(meta_sub, aes(x = X_centroid,
y = Y_centroid,
color = anno_cell_type_lvl3)) +
dark_theme_void() +
geom_point(size = 0.4) +
theme(legend.position = "right",
legend.title = element_text(size = 15),
legend.text = element_text(size = 14)) + # Hide legend or adjust as needed
guides(color = guide_legend(title = "Immune cell types",
override.aes = list(size = 6))) +
labs(title = "")

## Manually add tags and titles to plots for visual improvements
if(sample == "sample_control_r1_s1"){
p <- p +
labs(tag = "a",
title = "Control",
y = "Replicate 1") +
theme(plot.tag = element_text(size = 20, face = "bold"),
plot.title = element_text(hjust=0.5, size = 15, face = "bold"),
axis.title.y = element_text(size = 15,angle = 90, face = "bold")
)
} else if(sample == "sample_4h_r1_s1"){
p <- p +
labs(title = "4 hours") +
theme(plot.tag = element_text(size = 20, face = "bold"),
plot.title = element_text(hjust=0.5, size = 15, face = "bold")) +
labs(tags = "d") + theme(plot.tag = element_text(size = 20, face = "bold"))
} else if(sample == "sample_2d_r1_s1"){
p <- p +
labs(title = "2 days") +
theme(plot.tag = element_text(size = 20, face = "bold"),
plot.title = element_text(hjust=0.5, size = 15, face = "bold"))
} else if(sample == "sample_4d_r1_s1"){
p <- p +
labs(title = "4 days") +
theme(plot.tag = element_text(size = 20, face = "bold"),
plot.title = element_text(hjust=0.5, size = 15, face = "bold"))
} else if (sample == "sample_control_r2_s1"){
p <- p +
labs(y = "Replicate 2") +
theme(axis.title.y = element_text(size = 15,angle = 90, face = "bold")
)
}


# Return the plot
return(p)
})

spatial_plot_immune_cells <- wrap_plots(sample_plots,ncol = 2, nrows = 2) + plot_layout(guides = "collect") & theme(legend.position = 'right')
spatial_plot_immune_cells
```



## Merge plots

```{r}
wrapped_plots <- (sample_plots_arranged / ct_time_barplot) + plot_layout(nrow = 2, ncol = 1)
wrapped_plots <- sample_plots_arranged / ct_time_barplot / (immune_cells_dotplot | spatial_plot_immune_cells) +
plot_layout(nrow = 3, ncol = 1)
wrapped_plots

save_plot(wrapped_plots,
Expand Down
Loading