Skip to content

Commit

Permalink
More hardcoded plotting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-polk committed Feb 7, 2025
1 parent 60a2de3 commit f6a328d
Showing 1 changed file with 127 additions and 1 deletion.
128 changes: 127 additions & 1 deletion fluorescence_assay/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def create_grid_of_plots(
# Thus "A" - "B" gives the corrected fluorescence for replicate 1,
# and each well corresponds to a different ligand concentration
#
# TODO: Generalize implementation of
# TODO: Generalize implementation of these plotting functions
# TODO: Remove redundancies
#

def plot_fluorescence_spectra(df: plate_reader.DFData, concentrations: List[float], protein: str, ligand: str, pdf: Optional[PdfPages] = None):
Expand Down Expand Up @@ -182,6 +183,131 @@ def plot_fluorescence_spectra(df: plate_reader.DFData, concentrations: List[floa
fig.colorbar(cm.ScalarMappable(norm=norm, cmap="Greys"), cax=cax2, ticks=[0,0.25,0.5,0.75], format="%.2f", label="Ligand Concentration (µM) in (-) Protein")
plt.suptitle(f"{protein}:{ligand}");

if pdf is not None:
pdf.savefig()
plt.close()

def plot_absorbance_spectra(df: plate_reader.DFData, concentrations: List[float], protein: str, ligand: str, pdf: Optional[PdfPages] = None):
""""""

fig = plt.figure(figsize=(21,14))

norm = colors.AsinhNorm(linear_width=0.005, vmin=min(concentrations), vmax=max(concentrations))

axes = create_grid_of_plots(2,
3,
hspace=0,
wspace=0.04,
fig=fig,
xlabel="Wavelength (nm)",
ylabel="Absorbance (AU)",
titles=["Replicate 1",
"Replicate 2",
"Replicate 3"
]
)

plot2row = {"0": "A",
"1": "C",
"2": "E",
"3": "B",
"4": "D",
"5": "F"
}

for i in range(6):

ax = axes[i]

row = plot2row[str(i)]

spectra = df.get_row(row)

if i in [0, 1, 2]:
cmap = "winter_r"
else:
cmap = "Greys"

plot_spectra(spectra, concentrations, ax, cmap=cmap, norm=norm)

ax.set_xlim([240,800])
ax.set_ylim([0,5])

x0, y0, dx, dy = axes[2].get_position().bounds
cax1 = fig.add_axes([x0+dx+0.01, y0, 0.0125, dy])
cax2 = fig.add_axes([x0+dx+0.01, y0-dy, 0.0125, dy])

fig.colorbar(cm.ScalarMappable(norm=norm, cmap="winter_r"), cax=cax1, ticks=[0,0.25,0.5,0.75], format="%.2f", label="Ligand Concentration (µM) in (+) Protein")
fig.colorbar(cm.ScalarMappable(norm=norm, cmap="Greys"), cax=cax2, ticks=[0,0.25,0.5,0.75], format="%.2f", label="Ligand Concentration (µM) in (-) Protein")
plt.suptitle(f"{protein}:{ligand}");

if pdf is not None:
pdf.savefig()
plt.close()

def plot_absorbance_280(df: plate_reader.DFData, concentrations: List[float], protein: str, ligand: str, pdf: Optional[PdfPages] = None):
""""""

fig, ax = plt.subplots()

A280 = df.get_WL("280")

pos = [A280.get_row(row) for row in ["A", "C", "E"]] # (+) protein
neg = [A280.get_row(row) for row in ["B", "D", "F"]] # (-) protein

spectra = [pos, neg]

colors = ["red", "blue", "green"]
markers = ["+", "."]
label = ["+", "-"]

for i in range(len(spectra)):

m = markers[i]

for j in range(len(spectra[i])):

c = colors[j]
s = spectra[i][j]

ax.plot(concentrations, s, color=c, marker=m, linestyle="None", label=f"Replicate {j+1}, {label[i]}Protein")

ax.set_box_aspect(1)
ax.set_xlabel("Concentration (µM)")
ax.set_ylabel("Absorbance at 280 nm (AU)")
ax.set_xlim([-0.05,1.05])
ax.set_title(f"{protein}:{ligand}")
ax.legend()

if pdf is not None:
pdf.savefig()
plt.close()

def plot_dose_response_curves(df: plate_reader.DFData, concentrations: List[float], protein: str, ligand: str, pdf: Optional[PdfPages] = None):
""""""

fig = plt.figure(figsize=(21,7))

axes = create_grid_of_plots(1,
3,
hspace=0,
wspace=0.05,
fig=fig,
xlabel="Concentration (µM)",
ylabel="Corrected Emission at 440 nm (RFU)",
titles=["Replicate 1","Replicate 2","Replicate 3"])

dose_response_map = {"0": ("A", "B"), "1": ("C", "D"), "2": ("E", "F")}

for i in range(3):

pos = df.get_WL("440").get_row(dose_response_map[str(i)][0]) # (+) protein
neg = df.get_WL("440").get_row(dose_response_map[str(i)][1]) # (-) protein

dose_response = pos - neg

axes[i].plot(concentrations, dose_response, "ko")

if pdf is not None:
pdf.savefig()
plt.close()

0 comments on commit f6a328d

Please sign in to comment.