Skip to content

Commit 6a38bef

Browse files
committed
Plot ty data for each rep
1 parent e9a1f31 commit 6a38bef

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

fluoressential/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from skimage import img_as_float
99
from skimage.io import imread
1010

11-
from fluoressential.plot import plot_bgd, plot_img
12-
from fluoressential.process import calc_imgs_cmax, list_img_fps, subtract_bgd
11+
from fluoressential.plot import plot_bgd, plot_img, plot_ty
12+
from fluoressential.process import calc_dF_F0, calc_imgs_cmax, list_img_fps, subtract_bgd
1313

1414

1515
def img_task(img_fp, results_dp, sub_bgd_kwargs, plot_img_kwargs):
@@ -41,6 +41,7 @@ def analyze_imgs(rep_dp, gau_scale=1, vert_scale=2, ct_cutoff=0.1, cmax=None, sh
4141
df = pd.DataFrame(data)
4242
y_csv_fp = results_dp / "y.csv"
4343
df.to_csv(y_csv_fp, index=False)
44+
return df
4445

4546

4647
def main():
@@ -80,7 +81,12 @@ def main():
8081
for class_dp in [Path(class_dp) for class_dp in class_dps]:
8182
for rep_dp in [dp for dp in natsorted(class_dp.glob("*")) if dp.is_dir()]:
8283
print(rep_dp)
83-
analyze_imgs(rep_dp, gau_scale=4, vert_scale=2, ct_cutoff=0.05, cmax=None, show_cbar=True, sbar_microns=22, t_unit="s")
84+
ty_df = analyze_imgs(rep_dp, gau_scale=4, vert_scale=2, ct_cutoff=0.05, cmax=None, show_cbar=True, sbar_microns=22, t_unit="s")
85+
ty_df = calc_dF_F0(ty_df.astype(float))
86+
fig_fp = rep_dp / "results" / "y.png"
87+
xlabel = "Time (s)"
88+
ylabel = r"$\mathbf{\Delta F/F_{0}}$"
89+
plot_ty(fig_fp, ty_df, xlabel=xlabel, ylabel=ylabel)
8490

8591
## RFP Reporter Expression ##
8692
## 293T Input Intensity ##

fluoressential/plot.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,24 @@ def plot_bgd(fig_fp, img, bgd):
9999
bg_rows = np.argsort(np.var(img, axis=1))[-100:-1:10]
100100
row_i = np.random.choice(bg_rows.shape[0])
101101
bg_row = bg_rows[row_i]
102-
fig, ax = plt.subplots(figsize=(24, 20))
102+
fig, ax = plt.subplots(figsize=(24, 16))
103103
ax.plot(img[bg_row, :], color="#648FFF")
104104
ax.plot(bgd[bg_row, :], color="#785EF0")
105105
fig.savefig(fig_fp, dpi=100)
106106
plt.close("all")
107+
108+
109+
def plot_ty(fig_fp, ty_df, xlabel, ylabel):
110+
fig_fp = Path(fig_fp)
111+
fig_fp.parent.mkdir(parents=True, exist_ok=True)
112+
with sns.axes_style("whitegrid"), mpl.rc_context(STYLE):
113+
fig, ax = plt.subplots(figsize=(24, 16))
114+
sns.lineplot(ax=ax, data=ty_df, x="t", y="y", color="#785EF0")
115+
ax.set_xlabel(xlabel)
116+
ax.set_ylabel(ylabel)
117+
ax.locator_params(axis="x", nbins=10)
118+
ax.locator_params(axis="y", nbins=10)
119+
fig.tight_layout()
120+
fig.canvas.draw()
121+
fig.savefig(fig_fp, dpi=100)
122+
plt.close("all")

fluoressential/process.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ def calc_imgs_cmax(imgs_dp, sub_bgd_kwargs):
7272
max_img = subtract_bgd(img_as_float(imread(max_img_fp)), **sub_bgd_kwargs)[0]
7373
cmax = np.percentile(max_img, 99.99)
7474
return cmax
75+
76+
77+
def calc_dF_F0(y_df):
78+
F0 = y_df["y"].iloc[:5].mean()
79+
dF = y_df["y"] - F0
80+
y_df["y"] = dF / F0
81+
return y_df

fluoressential/style.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PALETTE = ["#8069EC", "#EA822C", "#2ECC71", "#D143A4", "#F1C40F", "#34495E", "#648FFF"]
22

33
STYLE = {
4-
"figure.figsize": (24, 20),
4+
"figure.figsize": (24, 16),
55
"lines.linewidth": 16,
66
"lines.markersize": 24,
77
"lines.markeredgecolor": "#212121",
@@ -28,10 +28,10 @@
2828
"ytick.major.size": 36,
2929
"xtick.major.width": 12,
3030
"ytick.major.width": 12,
31-
"xtick.minor.size": 12,
32-
"ytick.minor.size": 12,
33-
"xtick.minor.width": 4,
34-
"ytick.minor.width": 4,
31+
"xtick.minor.size": 18,
32+
"ytick.minor.size": 18,
33+
"xtick.minor.width": 6,
34+
"ytick.minor.width": 6,
3535
"legend.fontsize": 64,
3636
"legend.handletextpad": 0.4,
3737
"legend.labelspacing": 0.4,

0 commit comments

Comments
 (0)