Import modules:
import ratioimage.ratio_images as ri
import ratioimage.plot_results as rp
Load in images and segmentations (label images):
C0_imgs = ri.create_img_dict_from_folder(load_pattern="data/PercevalHR_data/imgs/*C0.tiff")
C1_imgs = ri.create_img_dict_from_folder(load_pattern="data/PercevalHR_data/imgs/*C1.tiff")
lab_imgs = ri.create_img_dict_from_folder(
load_pattern="data/PercevalHR_data/segs/*.tif", label=True
)
C0_imgs.keys()
Display example pair of ratio images + segmentation using plotting function from clonedetective
.
from clonedetective.utils import plot_new_images
img_name = "a1g01"
plot_new_images(
[C0_imgs[img_name], C1_imgs[img_name], lab_imgs[img_name]],
["C0 channel", "C1 channel", "label image (segmentation)"],
interpolation="none",
)
Measure regionprops of images and calculate ratio of intensities. Output is a tidy dataframe
df = ri.ratiometric_measure_region_props_to_tidy_df(C1_imgs, C0_imgs, lab_imgs)
df = ri.split_img_key_col_to_sample_id_and_replicates(
df, sample_id_colname="genotype", split_regex=r"g"
)
df = ri.sample_id_to_categories(
df, sample_id_colname="genotype", old_to_new_sample_ids={"a1": "ctrl", "a2": "mut"}
)
df.head()
Plot results - aggregated per cell:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(1.75, 2.5))
rp.tidy_create_strip_box_plot(
x="genotype",
y="ratio_mean_int",
data=df,
ax=ax,
y_axis_limit=4,
y_label="PercevalHR 488/405\n(Relative ATP/ADP)",
palette=["#95a5a6", "#95a5a6"],
)
Plot results - aggregated per image/replicate:
grouped_df = (
df.groupby(["genotype", "rep_id"]).agg({"ratio_mean_int": "mean"}).reset_index()
)
fig, ax = plt.subplots(figsize=(1.75, 2.5))
rp.tidy_create_swarm_box_plot(
x="genotype",
y="ratio_mean_int",
ax=ax,
data=grouped_df,
y_axis_limit=2.5,
y_label="PercevalHR 488/405\n(Relative ATP/ADP)",
palette=["#95a5a6", "#95a5a6"],
)
Create ratiometric images:
ratio_imgs = ri.create_dict_of_ratio_images(C1_imgs, C0_imgs, lab_imgs)
ratio_imgs.keys()
plot_new_images(
[ratio_imgs['a1g01'], ratio_imgs['a2g01']],
["a1g01 ratio image", "a2g01 ratio image"],
img_cmap="magma",
vmax=2.5,
figure_shape=(1, 2),
figure_size=(10, 5),
colorbar=True,
colorbar_title="PercevalHR 488/405"
)