<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
from membranequant import *
%matplotlib notebook<jupyter_output><empty_output><jupyter_text>Investigating spatial differences in fluorescent signal patterns around the embryo An assumption of our model is that membrane and cytoplasmic reference profiles do not vary around the circumference of the cell (allowing us to use single cytoplasmic and membrane profiles for all positions). Here, I test this assumption.  Cytoplasmic reference profile  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>Set up quantifiersWe can specify to focus quantification to either the midcell or poles by setting the position_weights parameter in ImageQuant.e.g. For the polar quantifier use weights of 1 for polar regions and weights of 0.1 for midcell regions. This way, concentration and alignment parameters are set everywhere, but global cytbg is influenced mainly by polar regions<jupyter_code>from scipy.special import erf

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

polar_weights = np.r_[np.ones(20), np.zeros(40) + 0.1, np.ones(40), np.zeros(40) + 0.1, np.ones(20)]
midcell_weights = 1 - polar_weights

iq_polar = ImageQuant(images, roi=rois, cyt_only=True, uni_cyt=True, iterations=2, adaptive_cytbg=True, thickness=thickness, cytbg=cytbg, descent_steps=200, nfits=160, periodic=False, position_weights=polar_weights, freedom=20)
iq_midcell = ImageQuant(images, roi=rois, cyt_only=True, uni_cyt=True, iterations=2, adaptive_cytbg=True, thickness=thickness, cytbg=cytbg, descent_steps=200, nfits=160, periodic=False, position_weights=midcell_weights, freedom=20)<jupyter_output><empty_output><jupyter_text>Run quantification<jupyter_code>iq_polar.run()
iq_midcell.run()<jupyter_output>100%|██████████| 200/200 [00:18<00:00, 10.61it/s]
100%|██████████| 200/200 [00:19<00:00, 10.47it/s]
  0%|          | 0/200 [00:00<?, ?it/s]<jupyter_text>Plot reference profilesLooks very similar between midcell and poles<jupyter_code>fig, ax = plt.subplots()
ax.plot(iq_polar.cytbg[5:-5] / max(iq_polar.cytbg[5:-5]), label='Polar Cytoplasmic reference')
ax.plot(iq_midcell.cytbg[5:-5] / max(iq_midcell.cytbg[5:-5]), label='Midcell Cytoplasmic reference')
ax.set_ylim(bottom=0)
ax.legend()
ax.set_xlabel('Position')
ax.set_ylabel('Normalised intensity')
fig.set_size_inches(6,4)<jupyter_output><empty_output><jupyter_text>Membrane reference profile  Import data<jupyter_code>path = '../test_datasets/dataset2_par2_neon'
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>Set up quantifiers<jupyter_code>sigma = 2
thickness = 60
membg = np.exp(-((np.arange(thickness) - thickness / 2) ** 2) / (2 * sigma ** 2))
cytbg = np.loadtxt('saved_cyt_ref_profile.txt')

polar_weights = np.r_[np.ones(20), np.zeros(40) + 0.1, np.ones(40), np.zeros(40) + 0.1, np.ones(20)]
midcell_weights = 1 - polar_weights

iq_polar = ImageQuant(images, roi=rois, iterations=2, adaptive_membg=True, thickness=50, cytbg=cytbg, membg=membg, descent_steps=200, uni_cyt=True, nfits=160, position_weights=polar_weights, freedom=10)
iq_midcell = ImageQuant(images, roi=rois, iterations=2, adaptive_membg=True, thickness=50, cytbg=cytbg, membg=membg, descent_steps=200, uni_cyt=True, nfits=160, position_weights=midcell_weights, freedom=10)<jupyter_output><empty_output><jupyter_text>Run quantification<jupyter_code>iq_polar.run()
iq_midcell.run()<jupyter_output>100%|██████████| 200/200 [00:06<00:00, 29.11it/s]
100%|██████████| 200/200 [00:06<00:00, 29.24it/s]
  0%|          | 0/200 [00:00<?, ?it/s]<jupyter_text>Plot reference profilesThey are not exactly the same, but very similar (within ~5% all over). Difference may be due to local curvature, or the fact that the midcell region covers the domain boundary.<jupyter_code>fig, ax = plt.subplots()
ax.plot(iq_polar.membg[5:-5] / max(iq_polar.membg[5:-5]), label='Polar Membrane reference')
ax.plot(iq_midcell.membg[5:-5] / max(iq_midcell.membg[5:-5]), label='Midcell Membrane reference')
ax.set_ylim(bottom=0)
ax.legend(loc=1)
ax.set_xlabel('Position')
ax.set_ylabel('Normalised intensity')
fig.set_size_inches(6,4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13345943673812527, 'fraction_numerical': 0.04560739806641446, 'mean_word_length': 6.879139072847682, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 35, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '15931', 'license': 'MIT', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1683, 'n_words': 400, 'path': 'notebooks/control_profile_spatial_variation.ipynb', 'repo_name': 'tsmbland/membranequant', 'size': '4758'}