Skip to content
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
402 changes: 402 additions & 0 deletions 7.figures/Figure1_Workflow_and_Class_Chart.ipynb

Large diffs are not rendered by default.

Binary file added 7.figures/figures/figure1_panelB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions 7.figures/nbconverted/Figure1_Workflow_and_Class_Chart.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(grid))
suppressPackageStartupMessages(library(patchwork))
suppressPackageStartupMessages(library(RColorBrewer))

# Load variables important for plotting (e.g., themes, phenotypes, etc.)
source("themes.r")

figure_dir <- "figures"
output_main_figure_1 <- file.path(figure_dir, "main_figure_1_class_count_and_workflow.png")

url <- "https://raw.githubusercontent.com/WayScience/mitocheck_data/b7abbdfda06d8dcc8e897cb9b89674b8d7a49c49/4.analyze_data/results/single_cell_class_counts.csv"
class_count_df <- read.csv(url)

# only take the rows from ic data type
class_count_df <- subset(class_count_df, Dataset_Type == 'ic')

# remove folded class as it isn't used the analysis
class_count_df <- subset(class_count_df, Mitocheck_Phenotypic_Class != 'Folded')

# add category as a column
# Now phenotype_categories is available in your script
class_count_df <- class_count_df %>%
mutate(Phenotype_Category = case_when(
Mitocheck_Phenotypic_Class %in% phenotype_categories$Interphase ~ "Interphase",
Mitocheck_Phenotypic_Class %in% phenotype_categories$Mitosis ~ "Mitosis",
Mitocheck_Phenotypic_Class %in% phenotype_categories$`Mitotic conseq.` ~ "Mitotic consequences",
Mitocheck_Phenotypic_Class %in% phenotype_categories$`Dynamic changes` ~ "Dynamic changes",
Mitocheck_Phenotypic_Class %in% phenotype_categories$Other ~ "Other",
TRUE ~ "Unknown"
))

dim(class_count_df)
head(class_count_df)

# Reorder Mitocheck_Phenotypic_Class based on the sum of Single_Cell_Counts
class_count_df$Mitocheck_Phenotypic_Class <- reorder(class_count_df$Mitocheck_Phenotypic_Class, -class_count_df$Single_Cell_Counts)

# Creating the bar chart
class_counts_plot <-
ggplot(class_count_df, aes(x = Mitocheck_Phenotypic_Class, y = Single_Cell_Counts, fill = Phenotype_Category)) +
geom_bar(stat = "identity", position = "dodge") +

# Adding labels and title
labs(x = "MitoCheck phenotypic class", y = "Single cell counts", fill = "Phenotype category") +

theme_bw() +

scale_fill_brewer(palette = "Dark2") +

theme(
axis.text.x = element_text(angle = 45, hjust = 1, size = 16), # Adjust font size for x-axis labels
axis.text.y = element_text(size = 16), # Adjust font size for y-axis labels
axis.title.x = element_text(size = 20), # Adjust font size for x-axis title
axis.title.y = element_text(size = 20), # Adjust font size for y-axis title
legend.title = element_text(size = 20), # Adjust font size for legend title
legend.text = element_text(size = 18), # Adjust font size for legend text
legend.position = c(0.98, 0.98), # Adjust the position of the legend within the plot
legend.justification = c("right", "top"), # Align legend to the right and top
legend.box.just = "right", # Justify the legend box to the right
legend.margin = margin(0, 0, 0, 0) # Remove extra margin around the legend
) +

# Adding annotations above each bar as integers in bold
geom_text(
aes(label = ifelse(Single_Cell_Counts != 0, as.character(Single_Cell_Counts), "")),
position = position_dodge(width = 0.9), vjust = -0.5,
size = 6 # Adjust font size for the count labels
) +

# Set y-axis limit to 450
ylim(0, 450)

class_counts_plot

workflow_path = file.path("./figures/figure1_panelB.png")
workflow_img = png::readPNG(workflow_path)

# Get the dimensions of the image
img_height <- nrow(workflow_img)
img_width <- ncol(workflow_img)

# Calculate the aspect ratio
aspect_ratio <- img_height / img_width

# Plot the workflow image from BioRender to a ggplot object
workflow <- ggplot() +
annotation_custom(
rasterGrob(workflow_img, interpolate = TRUE),
xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf
) +
theme_void() +
coord_fixed(ratio = aspect_ratio, clip = "off") +
theme(plot.margin = margin(0, 0, 0, 0, "cm")) # Adjust margins as needed

workflow

align_plot_gg <- (
free(class_counts_plot) /
workflow
) + plot_layout(heights = c(2, 2.25))

fig_1_gg <- (
align_plot_gg
) + plot_annotation(tag_levels = "A") & theme(plot.tag = element_text(size = 25))

# Save or display the plot
ggsave(output_main_figure_1, dpi = 500, height = 14, width = 14)

fig_1_gg
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Phenotypic Profiling Model

## Dataset and analysis approach

![main_figure_1](./7.figures/figures/main_figure_1_class_count_and_workflow.png)

> Figure 1. Dataset and analysis approach. (A) Single-cell counts per labeled phenotype stratified by phenotype category. The labeled MitoCheck dataset included a total of 2,916 single nuclei. The original dataset contained labels for 16 classes, but we have removed “folded” because of low counts. Counts are not evenly distributed between the classes. (B) Our analysis pipeline incorporated image analysis, image-based profiling, and machine learning.

## Environment Setup

Perform the following steps to set up the `phenotypic_profiling` environment necessary for processing data in this repository.
Expand Down Expand Up @@ -81,4 +87,4 @@ These intermediate data are available on the [Way Lab Zenodo page](https://zenod
Specific code and steps used are available within each module folder.

The [Way Lab](https://www.waysciencelab.com/) always strives for readable, reproducible computational biology analyses and workflows.
If you struggle to understand or reproduce anything in this repository please [file an issue](https://github.com/WayScience/mitocheck_data/issues/new/choose)!
If you struggle to understand or reproduce anything in this repository please [file an issue](https://github.com/WayScience/mitocheck_data/issues/new/choose)!