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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def get_contours_from_pair_of_2d_seg_image(nuc_mip,cell_mip,dft=None):
#ask if the label_img is in the dataframe
if label_img not in dft['label_img'].values:
continue
# color = np.float64(rgb_array0_255[label_img % len(rgb_array0_255)])
color = np.float64(cmapper(label_img))

# get the nucleus boundary
Expand Down Expand Up @@ -96,8 +95,6 @@ def plot_colorized_image_with_contours(img_dict,dft,feature,cmapstr,colony='test
cmap = cm.get_cmap(cmapstr)
if categorical:
cimg = np.round(cimg).astype('uint16')

# rgb = np.take(np.uint16(cmaparr*255),cimg.astype('uint16'),axis=0)

# create the figure
fig, axlist = plt.subplots(1, 1, figsize=(6, 4))
Expand Down Expand Up @@ -245,6 +242,4 @@ def run_validation_and_plot(TIMEPOINT=48,colony='medium',RESOLUTION_LEVEL=1,plot
if __name__ == '__main__':
# set the details
dft_test = run_validation_and_plot(testing=True,plot_everything=False)
dft0 = run_validation_and_plot(testing=False,plot_everything=False)
# dft0 = run_validation_and_plot(247,colony='small',RESOLUTION_LEVEL=1,plot_everything=True)
# dft0 = run_validation_and_plot(110,colony='medium',RESOLUTION_LEVEL=1,plot_everything=True)
dft0 = run_validation_and_plot(testing=False,plot_everything=False)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from nuc_morph_analysis.analyses.density.extra_checks.visually_validate_watershed_psuedo_cell_seg_workflow import get_contours_from_pair_of_2d_seg_image, draw_contours_on_image
from nuc_morph_analysis.analyses.dataset_images_for_figures.figure_helper import INTENSITIES_DICT

from nuc_morph_analysis.lib.visualization.example_tracks import EXAMPLE_TRACKS

import matplotlib
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
Expand Down Expand Up @@ -61,7 +63,7 @@ def determine_colormaps(img,key,crop_exp):
return cmap, vmin, vmax


def run_validation_and_plot(TIMEPOINT=88,track=81463,colony='medium',RESOLUTION_LEVEL=1,plot_everything=False, testing=False):
def run_validation_and_plot(TIMEPOINT=88,track=EXAMPLE_TRACKS["pseudocell_density_example"],colony='medium',RESOLUTION_LEVEL=1,plot_everything=False, testing=False):
"""
run an image through the watershed based pseudo cell segmentation and examine the outputs (as full fov and crop within that fov)
optionally, run a test image through the same pipeline
Expand Down
14 changes: 7 additions & 7 deletions nuc_morph_analysis/analyses/height/figure_3_s4_workflow.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# %%
from nuc_morph_analysis.analyses.colony_context.colony_context_analysis import plot_radial_profile
from nuc_morph_analysis.lib.preprocessing.global_dataset_filtering import load_dataset_with_features
from nuc_morph_analysis.lib.preprocessing import load_data, filter_data, global_dataset_filtering
from nuc_morph_analysis.lib.preprocessing import load_data, filter_data
from nuc_morph_analysis.lib.preprocessing.load_data import get_dataset_pixel_size
from nuc_morph_analysis.analyses.height import plot
from nuc_morph_analysis.analyses.height.plot_crowding import plot_density_schematic
from nuc_morph_analysis.analyses.height.toymodel import toymodel
from nuc_morph_analysis.analyses.height.centroid import (
get_centroid,
get_neighbor_centroids,
)
from nuc_morph_analysis.analyses.density import figure_watershed_based_density_schematic
from nuc_morph_analysis.analyses.neighbor_of_X import figure_mitotic_filtering_examples
from nuc_morph_analysis.lib.preprocessing.load_data import get_dataset_pixel_size
from pathlib import Path
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -67,13 +68,12 @@

# plot density schematic
pix_size = get_dataset_pixel_size("medium")
plot_density_schematic(
df_timepoint, track_centroid, neighbor_centroids, frame_centroids, pix_size, figdir,
)

# plot colony-averaged density over aligned colony time
plot.density_colony_time_alignment(df_all, pixel_size, interval, time_axis="colony_time",
use_old_density=False)
plot.density_colony_time_alignment(df_all, pixel_size, interval, time_axis="colony_time")

figure_watershed_based_density_schematic.run_validation_and_plot() #SuppFigS4 panel C
figure_mitotic_filtering_examples.run_validation_and_plot() #SuppFigS4 panel D, this code takes ~6 min to run

# %%
# Run and plot toy model
Expand Down
13 changes: 3 additions & 10 deletions nuc_morph_analysis/analyses/height/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def height_colony_time_alignment(
)


def calculate_mean_density(df, scale, use_old_density=False):
def calculate_mean_density(df, scale):
"""
Calculate the mean height for a given index_sequence (i.e. timepoint) and the standard deviation of the mean.

Expand All @@ -106,8 +106,6 @@ def calculate_mean_density(df, scale, use_old_density=False):
DataFrame containing the data.
pixel_size : float
Pixel size in microns.
use_old_density : bool
Whether to use the old density calculation method ('density') or the new method ('2d_area_nuc_cell_ratio')

Returns
-------
Expand All @@ -118,7 +116,7 @@ def calculate_mean_density(df, scale, use_old_density=False):
"""
mean = []
standard_dev = []
feature_col = "density" if use_old_density else "2d_area_nuc_cell_ratio"
feature_col = "2d_area_nuc_cell_ratio"
for _, df_frame in df.groupby("index_sequence"):
density = df_frame[feature_col].values * scale
mean.append(np.nanmean(density))
Expand All @@ -134,7 +132,6 @@ def density_colony_time_alignment(
show_legend=False,
error="percentile",
figdir="height/figures",
use_old_density=False,
):
"""
Plot the mean nuclear height across the colony over time for each colony. This is done in real time and colony time.
Expand All @@ -159,17 +156,14 @@ def density_colony_time_alignment(
error: str
"std" or percentile

use_old_density: bool
Whether to use the old density calculation method ('density') or the new method ('2d_area_nuc_cell_ratio')

Returns
-------
Plot of mean nuclear height across the colony over time for each colony.
"""
plt.close()
fig, ax = plt.subplots(1, 1, figsize=(5, 4))

feature_col = "density" if use_old_density else "2d_area_nuc_cell_ratio"
feature_col = "2d_area_nuc_cell_ratio"
scale, label, units, _ = get_plot_labels_for_metric(feature_col)

for colony, df_colony in df.groupby("colony"):
Expand Down Expand Up @@ -212,7 +206,6 @@ def density_colony_time_alignment(
time, mean_density, linewidth=1.2, color=color, label=COLONY_LABELS[colony], zorder=20
)

# ax.set_ylim(0.0005, 0.0065)
ax.set_ylabel(f"Average Density \n Across Colony {units}")
ax.set_xlabel(x_label)
if show_legend is True:
Expand Down
139 changes: 0 additions & 139 deletions nuc_morph_analysis/analyses/height/plot_crowding.py

This file was deleted.

Loading
Loading