<jupyter_start><jupyter_text>Instructions: click restart and run all above. Figures will show once the entire notebook has finished running (will take a few minutes)<jupyter_code>import sys
sys.path.append('..')
import numpy as np
import matplotlib.pyplot as plt
import glob
import ipywidgets as widgets
from tqdm import tqdm
%matplotlib notebook

from membranequant import ImageQuant, direcslist, load_image, af_subtraction, save_img<jupyter_output><empty_output><jupyter_text>Assessing inter-embryo reference profile variationA key assumption of the model is that common reference profiles can be used for all embryos, which we believe to be valid because embryo geometry and imaging conditions are conserved. However, I have previously only performed reference profile calibration on single embryos or multiple embryos in batch, which doesn't give any information about possible inter-embryo variation. Here, I perform calibration on multiple single embryos to test for this  Cytoplasmic reference profile inter-embryo variationPerforming cytoplasmic reference calibration on a few single embryos to see how variable it is between embryos. Using PKC-3 in a par-3 mutant as before.  Import data<jupyter_code>path = '../test_datasets/dataset3_pkc3_par3mutant'
paths = direcslist(path)
images = [load_image(p + '/af_corrected.tif') for p in paths]
rois = [np.loadtxt(p + '/ROI.txt') for p in paths]<jupyter_output><empty_output><jupyter_text>Run analysis<jupyter_code>from scipy.special import erf

sigma = 2
thickness = 50
cytbg = (1 + erf((np.arange(thickness) - thickness / 2) / sigma)) / 2

cytbgs = []
for img, roi in zip(images, rois):
    iq = ImageQuant(img, roi=roi, cyt_only=True, uni_cyt=True, iterations=2, adaptive_cytbg=True, thickness=thickness, cytbg=cytbg, descent_steps=200, nfits=100, freedom=10)
    iq.run()
    cytbgs.append(iq.cytbg)
cytbgs_norm = [x / np.max(x) for x in cytbgs]<jupyter_output>100%|██████████| 200/200 [00:02<00:00, 73.15it/s]
100%|██████████| 200/200 [00:02<00:00, 83.51it/s]
  4%|▍         | 9/200 [00:00<00:02, 83.58it/s]<jupyter_text>FiguresAs we can see, the shape of the profile is highly conserved between embryos(excluding last position as there are sometimes artefacts at this position - not sure why)<jupyter_code>fig, ax = plt.subplots()
for c in cytbgs_norm:
    ax.plot(c[:-1])
cytbg_arr = np.array(cytbgs_norm)
fig, ax = plt.subplots()
mean = np.mean(cytbg_arr, axis=0)[:-1]
std = np.std(cytbg_arr, axis=0)[:-1]
ax.plot(mean)
ax.fill_between(np.arange(len(mean)), mean-std, mean+std, alpha=0.2)<jupyter_output><empty_output><jupyter_text>Membrane reference profile inter-embryo variationPerforming membrane reference calibration on a few single embryos to see how variable it is between embryos. Using polarised PAR-2 Neon as before, and the cytoplasmic profile generated [here](./5_intro_to_imagequant.ipynb).  Import data<jupyter_code>path2 = '../test_datasets/dataset2_par2_neon'
paths2 = direcslist(path2)
images2 = [load_image(p + '/af_corrected.tif') for p in paths2]
rois2 = [np.loadtxt(p + '/ROI.txt') for p in paths2]<jupyter_output><empty_output><jupyter_text>Run analysis<jupyter_code>sigma = 2
thickness = 50
membg = np.exp(-((np.arange(thickness) - thickness / 2) ** 2) / (2 * sigma ** 2))
cytbg = np.loadtxt('saved_cyt_ref_profile.txt')

membgs = []
for img, roi in zip(images2, rois2):
    iq = ImageQuant(img, roi=roi, iterations=2, adaptive_membg=True, adaptive_cytbg=False, thickness=50, cytbg=cytbg, membg=membg, descent_steps=200, uni_cyt=True, nfits=100, freedom=10)
    iq.run()
    membgs.append(iq.membg)
membgs_norm = [x / np.max(x) for x in membgs]<jupyter_output>100%|██████████| 200/200 [00:03<00:00, 58.37it/s]
100%|██████████| 200/200 [00:03<00:00, 60.02it/s]
  3%|▎         | 6/200 [00:00<00:03, 57.64it/s]<jupyter_text>FiguresAs we can see, the shape of the profile is highly conserved between embryos:<jupyter_code>fig, ax = plt.subplots()
for m in membgs_norm:
    ax.plot(m[:-1])
membg_arr = np.array(membgs_norm)
fig, ax = plt.subplots()
mean = np.mean(membg_arr, axis=0)[:-1]
std = np.std(membg_arr, axis=0)[:-1]
ax.plot(mean)
ax.fill_between(np.arange(len(mean)), mean-std, mean+std, alpha=0.2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12829025373488262, 'fraction_numerical': 0.04339577898980318, 'mean_word_length': 5.60093896713615, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '13295', 'license': 'MIT', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1503, 'n_words': 416, 'path': 'notebooks/control_profile_variation.ipynb', 'repo_name': 'tsmbland/membranequant', 'size': '4217'}