Skip to content

Commit

Permalink
Make suggested changes besides imports file
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyTLin committed Jun 3, 2024
1 parent fc8ae8d commit 1e6743b
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 270 deletions.
4 changes: 2 additions & 2 deletions bicytok/distanceMetricFuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sklearn.neighbors import KernelDensity

from .imports import importCITE
from .selectivityFuncs import convFactCalc, getSampleAbundances
from .selectivityFuncs import convFactCalc, calcReceptorAbundances

path_here = dirname(dirname(__file__))

Expand Down Expand Up @@ -635,7 +635,7 @@ def correlation(cell_type, relevant_epitopes):
"""Calculates the Pearson correlation between two celltypes receptor counts"""
epitopesList = pd.read_csv("./bicytok/data/epitopeList.csv")
epitopes = list(epitopesList["Epitope"].unique())
epitopesDF = getSampleAbundances(epitopes, np.array([cell_type]))
epitopesDF = calcReceptorAbundances(epitopes, np.array([cell_type]))
epitopesDF = epitopesDF[epitopesDF["CellType2"] == (cell_type)]
corr = epitopesDF[relevant_epitopes].corr(method="pearson")
sorted_corr = corr.stack().sort_values(ascending=False)
Expand Down
81 changes: 0 additions & 81 deletions bicytok/figures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@
matplotlib.rcParams["legend.borderpad"] = 0.35


# Armaan: When declaring constants at the top of a file, it is good practice to
# choose a descriptive name, use ALL CAPS (e.g. DOSE_MAT), and possibly add a
# brief comment. Also, this particular variable isn't used anywhere.
dosemat = np.array(
[
84,
28,
9.333333,
3.111,
1.037037,
0.345679,
0.115226,
0.038409,
0.012803,
0.004268,
0.001423,
0.000474,
]
)


def getSetup(
figsize: tuple[float, float], gridd: tuple[int, int], multz=None
) -> tuple[list[Axes], matplotlib.figure.Figure]:
Expand Down Expand Up @@ -94,19 +73,11 @@ def genFigure():
exec("from bicytok.figures." + nameOut + " import makeFigure", globals())
ff = makeFigure() # noqa: F821

# Armaan: add function argument here to toggle the commented code if it's
# needed else delete the comment.

# for non cluster maps:
# ff.savefig(fdir + nameOut + ".svg", dpi=ff.dpi, bbox_inches="tight", pad_inches=0)
# for cluster maps:
ff.savefig(fdir + nameOut + ".svg", bbox_inches="tight", pad_inches=0)

print(f"Figure {sys.argv[1]} is done after {time.time() - start} seconds.\n")


# Armaan: resolve this (delete the function or the comment)
# NOTE: CHECK IF WE NEED THIS
def subplotLabel(axs: list[Axes]):
"""Place subplot labels on figure."""
for ii, ax in enumerate(axs):
Expand All @@ -119,55 +90,3 @@ def subplotLabel(axs: list[Axes]):
fontweight="bold",
va="top",
)


cellSTATlimDict = {
"Treg": (47000, 54000),
"Thelper": (20000, 25000),
"CD8": (6200, 7500),
"NK": (4000, 5000),
}
# Armaan: Unused variable
ratioSTATlimDict = {"Treg/NK": (0, 4000), "Treg/CD8": (0, 1500)}


# Armaan: resolve this
# NOTE: CHECK IF WE NEED THIS
def plotBispecific(ax: Axes, df, cellType: str, val=False):
"""Plots all experimental vs. Predicted Values"""

data_low = df.loc[(df.Cell == cellType) & (df.Affinity == "Low")]
data_med = df.loc[(df.Cell == cellType) & (df.Affinity == "Medium")]
data_high = df.loc[(df.Cell == cellType) & (df.Affinity == "High")]

sns.lineplot(
x="Abundance",
y="Predicted",
data=data_low,
label="Low(1e6)",
ax=ax,
legend="brief",
)
sns.lineplot(
x="Abundance",
y="Predicted",
data=data_med,
label="Med(1e8)",
ax=ax,
legend="brief",
)
sns.lineplot(
x="Abundance",
y="Predicted",
data=data_high,
label="High(1e10)",
ax=ax,
legend="brief",
)
ax.set(
title=cellType + " - Dosed at 1nM",
xlabel=r"Epitope X Abundance",
ylabel="pSTAT",
xscale="log",
ylim=cellSTATlimDict[cellType],
)
46 changes: 24 additions & 22 deletions bicytok/figures/figure1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@
from ..selectivityFuncs import (
get_cell_bindings,
calcReceptorAbundances,
optimizeDesign,
optimizeSelectivityAffs,
)
from .common import getSetup

path_here = dirname(dirname(__file__))

plt.rcParams["svg.fonttype"] = "none"

"""signal: Receptor that the ligand is delivering signal to; selectivity and target bound are with respect to engagement

"""SIGNAL: Receptor that the ligand is delivering signal to; selectivity and target bound are with respect to engagement
with this receptor
allTargets: List of paired [(target receptor, valency)] combinations for each targeting receptor; to be used for targeting
ALL_TARGETS: List of paired [(target receptor, valency)] combinations for each targeting receptor; to be used for targeting
the target cell, not signaling
cells: Array of cells that will be sampled from and used in calculations
targCell: Target cell whose selectivity will be maximized
startingAff: Starting affinity to modulate from in order to maximize selectivity for the targCell"""
signal = ["CD122", 1]
allTargets = [
CELLS: Array of cells that will be sampled from and used in calculations
TARG_CELL: Target cell whose selectivity will be maximized
STARTING_AFF: Starting affinity to modulate from in order to maximize selectivity for the targCell"""

SIGNAL = ["CD122", 1]
ALL_TARGETS = [
[("CD25", 1)],
[("CD25", 4)],
[("CD25", 1), ("CD278", 1)],
Expand All @@ -35,7 +37,7 @@
[("CD25", 4), ("CD278", 4), ("CD27", 4)],
]

cells = np.array(
CELLS = np.array(
[
"CD8 Naive",
"NK",
Expand All @@ -50,41 +52,41 @@
"NK_CD56bright",
]
)
targCell = "Treg"
TARG_CELL = "Treg"

startingAff = 8.0
STARTING_AFF = 8.0

def makeFigure():
"""Figure file to generate dose response curves for any combination of multivalent and multispecific ligands.
Outputs dose vs. selectivity for the target cell and amount of target cell bound at indicated signal receptor."""
ax, f = getSetup((6, 3), (1, 2))

offTargCells = cells[cells != targCell]
offTargCells = CELLS[CELLS != TARG_CELL]

epitopesList = pd.read_csv(join(path_here, "data/epitopeList.csv"))
epitopes = list(epitopesList["Epitope"].unique())
epitopesDF = calcReceptorAbundances(epitopes, cells)
epitopesDF = calcReceptorAbundances(epitopes, CELLS)

doseVec = np.logspace(-2, 2, num=20)
df = pd.DataFrame(columns=["Dose", "Selectivity", "Target Bound", "Ligand"])

for targetPairs in allTargets:
optimizedAffs = [startingAff]
valencies = [signal[1]]
for targetPairs in ALL_TARGETS:
optimizedAffs = [STARTING_AFF]
valencies = [SIGNAL[1]]
targets = []
naming = []
for target, valency in targetPairs:
optimizedAffs.append(startingAff)
optimizedAffs.append(STARTING_AFF)
targets.append(target)
valencies.append(valency)
naming.append("{} ({})".format(target, valency))
valencies = np.array([valencies])

for _, dose in enumerate(doseVec):
optParams = optimizeDesign(
signal[0],
optParams = optimizeSelectivityAffs(
SIGNAL[0],
targets,
targCell,
TARG_CELL,
offTargCells,
epitopesDF,
dose,
Expand All @@ -93,13 +95,13 @@ def makeFigure():
)
optimizedAffs = optParams[1]
cellBindings = get_cell_bindings(
epitopesDF, signal[0], targets, optimizedAffs, dose, valencies
epitopesDF, SIGNAL[0], targets, optimizedAffs, dose, valencies
)

data = {
"Dose": [dose],
"Selectivity": 1 / optParams[0],
"Target Bound": cellBindings["Receptor Bound"].loc[targCell],
"Target Bound": cellBindings["Receptor Bound"].loc[TARG_CELL],
"Ligand": " + ".join(naming),
"Affinities": optParams[1],
}
Expand Down
58 changes: 30 additions & 28 deletions bicytok/figures/figure3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,54 @@

from ..selectivityFuncs import (
get_cell_bindings,
getSampleAbundances,
calcReceptorAbundances,
)
from .common import getSetup


def makeFigure():
"""Figure file to generate bar plots for amount of signal receptor bound to each given cell type
secondary: signaling receptor
epitope: additional targeting receptor"""
ax, f = getSetup((8, 3), (1, 2))
"""SECONDARY: signaling receptor
EPITOPE: additional targeting receptor
SECONDARY_AFF: starting affinity of ligand and secondary receptor"""

SECONDARY = "CD122"
EPITOPE = "CD278"
SECONDARY_AFF = 6.0
VALENCY = 4

secondary = "CD122"
epitope = "CD278"
secondaryAff = 6.0
valency = 4
CELLS = [
"Treg",
"CD8 Naive",
"NK",
"CD8 TEM",
"CD4 Naive",
"CD4 CTL",
"CD8 TCM",
"CD4 TEM",
"NK Proliferating",
"NK_CD56bright",
]

affs = np.array([secondaryAff, 8.5, 8.5])
def makeFigure():
"""Figure file to generate bar plots for amount of signal receptor bound to each given cell type"""
ax, f = getSetup((8, 3), (1, 2))

cells = [
"Treg",
"CD8 Naive",
"NK",
"CD8 TEM",
"CD4 Naive",
"CD4 CTL",
"CD8 TCM",
"CD4 TEM",
"NK Proliferating",
"NK_CD56bright",
]
affs = np.array([SECONDARY_AFF, 8.5, 8.5])

epitopesList = pd.read_csv("./bicytok/data/epitopeList.csv")
epitopes = list(epitopesList["Epitope"].unique())

epitopesDF = getSampleAbundances(epitopes, cells)
epitopesDF = calcReceptorAbundances(epitopes, CELLS)

bindings = get_cell_bindings(
epitopesDF,
secondary,
["CD25", epitope],
SECONDARY,
["CD25", EPITOPE],
affs,
0.1,
np.array([[valency, valency, valency]]),
np.array([[VALENCY, VALENCY, VALENCY]]),
)
bindings["Percent Bound of Signal Receptor"] = (
bindings["Receptor Bound"] / bindings[secondary]
bindings["Receptor Bound"] / bindings[SECONDARY]
) * 10

palette = sns.color_palette("husl", 10)
Expand Down
Loading

0 comments on commit 1e6743b

Please sign in to comment.