Skip to content

Commit

Permalink
Thursday
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianNGitahi committed Oct 13, 2023
1 parent 9685a9b commit 673c767
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 152 deletions.
55 changes: 30 additions & 25 deletions Bleach_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

# import functions from the simulation and bleaching libraries
from s_functions import simulate_neuron, simulate_nm_conc, simulate_flourescence_signal
from b_factory import bleach_1, bleach_2, bleach_3, bleach_4
from b_factory import bleach_nm, bleach_dnm, bleach_t, bleach_all


# ANALYSIS 1: comparing the different contributions at one timescale for the bleach factor
# ANALYSIS 1:

# choose the timescale for the bleach factor
chosen_tau = 10e4
Expand All @@ -28,45 +28,50 @@
# create timesteps array for the plot
t = np.linspace(0,nm_conc.size-1,nm_conc.size)

b1 = bleach_1(K_D = 1000, tau=chosen_tau, F_max = 45, F_min = 10, nm_conc=nm_conc, bline_len=5000)
b2 = bleach_2(K_D = 1000, tau=chosen_tau, F_max = 45, F_min = 10, nm_conc=nm_conc, bline_len=5000)
b3 = bleach_3(K_D = 1000, tau=chosen_tau, F_max = 45, F_min = 10, nm_conc=nm_conc, bline_len=5000)
b4 = bleach_4(K_D = 1000, tau=chosen_tau, F_max = 45, F_min = 10, nm_conc=nm_conc, bline_len=5000)
b1 = bleach_nm(K_D = 1000, tau=chosen_tau, F_max = 45, F_min = 10, nm_conc=nm_conc, bline_len=5000)
b2 = bleach_dnm(K_D = 1000, tau=chosen_tau, F_max = 45, F_min = 10, nm_conc=nm_conc, bline_len=5000)
b3 = bleach_t(K_D = 1000, tau=chosen_tau, F_max = 45, F_min = 10, nm_conc=nm_conc, bline_len=5000)
b4 = bleach_all(K_D = 1000, tau=chosen_tau, F_max = 45, F_min = 10, nm_conc=nm_conc, bline_len=5000)


# create a fit for the initial values of the bleach 2 and 4 result and subtract it -- revise this later
# create a fit for the initial values of the bleach 4 result and subtract it -- revise this later
# it should be a fit of the f value
poly2 = np.polyfit(t,b2,2)
fit2 = np.polyval(poly2,t)

poly4 = np.polyfit(t,b4,2)
fit4 = np.polyval(poly4,t)

plt.show()


plt.plot(t,b1,label='bleach 1')
#plt.plot(t,b2,label='bleach 2')
# plt.plot(fit2, label='fit2')
plt.plot(b2-fit2,label='subtracted 2')

# ANALYSIS 2: comparing how the different bleaches affect the signal to noise ratio

plt.plot(t,b3,label='bleach 3')
#plt.plot(t,b4,label='bleach 4')
plt.plot(b4-fit4,label='subtracted 4')
# define the signal to noise ratio

plt.xlabel('time(ms)')
plt.ylabel('Delta F/F0')
plt.title('Flourescence intensity signal over time')
plt.legend()
# get the signal t

plt.show()


# ANALYSIS 2:
# ANALYSIS 3:
# check this bleaching effect 1 for different values of tau -- different bleach factor
#different_taus = np.array([10e6,10e5,10e4,10e3,10e2,10e1,10e0])




# ANALYSIS 3:
# check this bleaching effect 1 for different values of tau -- different bleach factor
#different_taus = np.array([10e6,10e5,10e4,10e3,10e2,10e1,10e0])


# PREVIOUS ANALYSIS: comparing the different contributions at one timescale for the bleach factor
# plt.plot(t,b1,label='bleach 1')
# plt.plot(t,b2,label='bleach 2')

# plt.plot(t,b3,label='bleach 3')
# #plt.plot(t,b4,label='bleach 4')
# plt.plot(b4-fit4,label='subtracted 4')

# plt.xlabel('time(ms)')
# plt.ylabel('Delta F/F0')
# plt.title('Flourescence intensity signal over time')
# plt.legend()


63 changes: 0 additions & 63 deletions Frate.py

This file was deleted.

186 changes: 142 additions & 44 deletions Simulation.ipynb

Large diffs are not rendered by default.

Binary file modified __pycache__/b_factory.cpython-311.pyc
Binary file not shown.
74 changes: 54 additions & 20 deletions b_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
bg_tissue = 1.5

# ANALYSIS 1: bleaching factor acting on the [NM] contribution to F
def bleach_1(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):
def bleach_nm(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):

# create timesteps array for the plot
n_timesteps = nm_conc.size
Expand All @@ -41,7 +41,7 @@ def bleach_1(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):
# where x is the length of the moving baseline (first element if f[0])

if i == 0:
f0 =f[0]
f0 = f[0]
elif i < bline_len:
f0 = np.average(f[:i])
else:
Expand Down Expand Up @@ -77,7 +77,7 @@ def bleach_1(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):


# ANALYSIS 2: bleaching factor acting on the contributions of the dye, F0 and [NM]
def bleach_2(K_D, tau, F_max, F_min, nm_conc, bline_len =5000):
def bleach_dnm(K_D, tau, F_max, F_min, nm_conc, bline_len =5000):

# create timesteps array for the plot
n_timesteps = nm_conc.size
Expand All @@ -88,9 +88,16 @@ def bleach_2(K_D, tau, F_max, F_min, nm_conc, bline_len =5000):
bleach = np.exp(-t/tau)

# calculate bleached f values: derived in part from eq 2 in Neher/Augustine
f= bg_tissue+ bleach*(K_D*F_min + nm_conc*F_max)/(K_D + nm_conc)
f = bg_tissue+ bleach*(K_D*F_min + nm_conc*F_max)/(K_D + nm_conc)

# define the signal array
# fit a polynmial to f and subtract it from f
poly = np.polyfit(t,f,2)
fit = np.polyval(poly,t)
f_sub = f-fit


# define the df and the df/f signal array
delta_f = np.zeros(f.size)
delta_ft_f0 = np.zeros(f.size)

# calculate f0 values and populate the signal array
Expand All @@ -101,21 +108,48 @@ def bleach_2(K_D, tau, F_max, F_min, nm_conc, bline_len =5000):
# where x is the length of the moving baseline (first element if f[0])

if i == 0:
f0 =f[0]
f0 = f_sub[0]
elif i < bline_len:
f0 = np.average(f[:i])
f0 = np.average(f_sub[:i])
else:
f0 = np.average(f[i-bline_len:i])
f0 = np.average(f_sub[i-bline_len:i])

# calculate normalized signal using the calculated f0
delta_ft_f0[i] = (f[i]-f0)/(f0)
# calculate df, and df/f, the normalized signal, using the calculated f0
delta_f[i] = f_sub[i]-f0
delta_ft_f0[i] = delta_f[i]/(f0)

print(f0)

# plot f, f - fit, df then df/f
plt.figure()
plt.subplot(2,2,1)
plt.plot(t,f, label='f')
plt.xlabel('time (ms)')
plt.ylabel('f')
plt.legend()

plt.subplot(2,2,2)
plt.plot(f_sub, label='f subtracted')
plt.plot(fit, label='fit')
plt.xlabel('time (ms)')
plt.ylabel('f-exp')

plt.legend()

plt.subplot(2,2,3)
plt.plot(t,delta_f, label='df')
plt.xlabel('time (ms)')
plt.ylabel('delta f')
plt.legend()


plt.subplot(2,2,4)
plt.plot(t,delta_ft_f0, label = 'df/f')
plt.xlabel('time(ms)')
plt.ylabel('Delta F/F0')
plt.tight_layout()
plt.legend()

# plot the normalized signal delta f/f0 at the different t
# plt.plot(t,delta_ft_f0, label = tau + 2)
# plt.xlabel('time(ms)')
# plt.ylabel('Delta F/F0')
# plt.title('Flourescence intensity signal over time (bleach 2)')
# plt.legend()

return delta_ft_f0

Expand All @@ -135,7 +169,7 @@ def bleach_2(K_D, tau, F_max, F_min, nm_conc, bline_len =5000):


# ANALYSIS 3: bleaching factor acting on the background fluorescence
def bleach_3(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):
def bleach_t(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):

# create timesteps array for the plot
n_timesteps = nm_conc.size
Expand All @@ -159,7 +193,7 @@ def bleach_3(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):
# where x is the length of the moving baseline (first element if f[0])

if i == 0:
f0 =f[0]
f0 = f[0]
elif i < bline_len:
f0 = np.average(f[:i])
else:
Expand Down Expand Up @@ -194,7 +228,7 @@ def bleach_3(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):


# ANALYSIS 4: bleaching on all contributions
def bleach_4(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):
def bleach_all(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):

# create timesteps array for the plot
n_timesteps = nm_conc.size
Expand All @@ -218,7 +252,7 @@ def bleach_4(K_D, tau, F_max, F_min, nm_conc, bline_len=5000):
# where x is the length of the moving baseline (first element if f[0])

if i == 0:
f0 =f[0]
f0 = f[0]
elif i < bline_len:
f0 = np.average(f[:i])
else:
Expand Down

0 comments on commit 673c767

Please sign in to comment.