Skip to content

Commit

Permalink
Fix some ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyTLin committed Jun 3, 2024
1 parent 1e6743b commit af875e1
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 65 deletions.
28 changes: 17 additions & 11 deletions bicytok/distanceMetricFuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
path_here = dirname(dirname(__file__))


def KL_EMD_1D(ax, targCell, numFactors, RNA=False, offTargState=0) -> pd.DataFrame:
def KL_EMD_1D(ax, targCell, numFactors, offTargState=0) -> pd.DataFrame:
"""
Finds markers which have average greatest difference (EMD and KL) from other cells
:param ax: Axes to plot on
:param targCell: Target cell type for analysis
:param numFactors: Number of top factors to consider
:param RNA: Boolean flag indicating RNA data (optional)
:param offTargState: State of off-target comparison (0 for all non-memory Tregs, 1 for all non-Tregs, 2 for naive Tregs)
:param offTargState: State of off-target comparison (0 for all non-memory Tregs,
1 for all non-Tregs, 2 for naive Tregs)
:return:
corrsDF: DataFrame containing marker information and their Wasserstein Distance and KL Divergence values
corrsDF: DataFrame containing marker information and their Wasserstein Distance
and KL Divergence values
"""
CITE_DF = importCITE()
markerDF = pd.DataFrame(columns=["Marker", "Cell Type", "Amount"])
Expand Down Expand Up @@ -132,10 +133,12 @@ def EMD_2D(dataset, signal_receptor, target_cells, special_receptor, ax):
:param dataset: DataFrame containing the dataset
:param signal_receptor: Name of the signal receptor
:param target_cells: Target cell type for analysis
:param special_receptor: Special receptor to consider (optional, used for just calculating distance for 2 receptors)
:param special_receptor: Special receptor to consider
(optional, used for just calculating distance for 2 receptors)
:param ax: Matplotlib Axes object for plotting (optional)
:return:
List of tuples format: (recep1, recep2, OT value) containing optimal transport distances and receptor information
List of tuples format: (recep1, recep2, OT value) containing
optimal transport distances and receptor information
"""
CITE_DF = importCITE()
weightDF = convFactCalc(CITE_DF)
Expand Down Expand Up @@ -269,8 +272,8 @@ def EMD_3D(dataset1, target_cells, ax=None):
:param target_cells: Target cell type for analysis
:param ax: Matplotlib Axes object for plotting (optional)
:return:
List of tuples (format: (recep1, recep2, recep 3, OT value) containing optimal transport distances and receptor information for 3D analysis
List of tuples (format: (recep1, recep2, recep 3, OT value) containing
optimal transport distances and receptor information for 3D analysis
"""
CITE_DF = importCITE()

Expand Down Expand Up @@ -416,7 +419,8 @@ def EMD_3D(dataset1, target_cells, ax=None):
receptor3_off_target_counts.astype(float)
/ average_receptor_counts_3
)
# Calculate the EMD between on-target and off-target counts for both receptors # change this so its two [||]
# Calculate the EMD between on-target and off-target counts for
# both receptors # change this so its two [||]
on_target_counts = np.concatenate(
(
receptor1_on_target_counts[:, np.newaxis],
Expand Down Expand Up @@ -495,7 +499,8 @@ def EMD_3D(dataset1, target_cells, ax=None):

def calculate_kl_divergence_2D(targCellMark, offTargCellMark):
"""
calculates the Kullback-Leibler (KL) divergence between two probability distributions
calculates the Kullback-Leibler (KL) divergence between two
probability distributions
*used in combination with 1D or 2D KL functions
:param targCellMark: Target cell marker data
:param offTargCellMark: Off-target cell marker data
Expand Down Expand Up @@ -525,7 +530,8 @@ def KL_divergence_2D(dataset, signal_receptor, target_cells, special_receptor, a
:param dataset: DataFrame containing the dataset
:param signal_receptor: Name of the signal receptor
:param target_cells: Target cell type for analysis
:param special_receptor: Special receptor to consider (optional, used for just calculating distance for 2 receptors)
:param special_receptor: Special receptor to consider
(optional, used for just calculating distance for 2 receptors)
:param ax: Matplotlib Axes object for plotting (optional)
:return:
Sorted list of tuples containing KL Divergence values and receptor information
Expand Down
1 change: 0 additions & 1 deletion bicytok/figures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import matplotlib
import matplotlib.figure
import numpy as np
import seaborn as sns
from matplotlib import gridspec
from matplotlib import pyplot as plt
Expand Down
17 changes: 11 additions & 6 deletions bicytok/figures/figure1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
plt.rcParams["svg.fonttype"] = "none"


"""SIGNAL: Receptor that the ligand is delivering signal to; selectivity and target bound are with respect to engagement
with this receptor
ALL_TARGETS: List of paired [(target receptor, valency)] combinations for each targeting receptor; to be used for targeting
"""SIGNAL: Receptor that the ligand is delivering signal to; selectivity and
target bound are with respect to engagement with this receptor
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
TARG_CELL: Target cell whose selectivity will be maximized
STARTING_AFF: Starting affinity to modulate from in order to maximize selectivity for the targCell"""
STARTING_AFF: Starting affinity to modulate from in order to
maximize selectivity for the targCell, affinities are K_a in L/mol"""

SIGNAL = ["CD122", 1]
ALL_TARGETS = [
Expand Down Expand Up @@ -56,9 +58,12 @@

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."""
"""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 != TARG_CELL]
Expand Down
4 changes: 3 additions & 1 deletion bicytok/figures/figure3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
"NK_CD56bright",
]


def makeFigure():
"""Figure file to generate bar plots for amount of signal receptor bound to each given cell type"""
"""Figure file to generate bar plots for amount of signal receptor
bound to each given cell type"""
ax, f = getSetup((8, 3), (1, 2))

affs = np.array([SECONDARY_AFF, 8.5, 8.5])
Expand Down
6 changes: 4 additions & 2 deletions bicytok/figures/figure4.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

SIGNAL = ["CD122", 1]
ALL_TARGETS = [("CD25", 1), ("CD278", 1), ("CD45RB", 1), ("CD4-2", 1), ("CD81", 1)]
DOSE = 10e-2 #TODO: ADD UNITS
DOSE = 10e-2 # In Molarity

CELLS = np.array(
[
Expand All @@ -34,8 +34,10 @@
)
targCell = "Treg"


def makeFigure():
"""Figure file to generate bispecific ligand selectivity heatmap of selectivity for each bispecific pairing."""
"""Figure file to generate bispecific ligand selectivity heatmap of
selectivity for each bispecific pairing."""
ax, f = getSetup((4, 3), (1, 1))

offTCells = CELLS[CELLS != targCell]
Expand Down
26 changes: 14 additions & 12 deletions bicytok/figures/figure5.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@
ALL_TARGETS = [["CD25", "CD278"], ["CD25", "CD4-2"], ["CD25", "CD45RB"]]
DOSE = 10e-2
CELLS = np.array(
[
"CD8 Naive",
"NK",
"CD8 TEM",
"CD4 Naive",
"CD4 CTL",
"CD8 TCM",
"CD8 Proliferating",
"Treg",
]
)
[
"CD8 Naive",
"NK",
"CD8 TEM",
"CD4 Naive",
"CD4 CTL",
"CD8 TCM",
"CD8 Proliferating",
"Treg",
]
)
TARG_CELL = "Treg"


def makeFigure():
"""Figure file to generate plots of bispecific ligand selectivity for combinations of different KL divergences, EMDs, and anti-correlations."""
"""Figure file to generate plots of bispecific ligand selectivity for
combinations of different KL divergences, EMDs, and anti-correlations."""
ax, f = getSetup((9, 3), (1, 3))

CITE_DF = importCITE()
Expand Down
10 changes: 7 additions & 3 deletions bicytok/figures/figure6.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
]
CELL_LEVEL = "CellType2"


def makeFigure():
"""Figure file to generate bar plots of 1D KL divergence and EMD values of most unique receptor for each given cell type/subset."""
"""Figure file to generate bar plots of 1D KL divergence and EMD values
of most unique receptor for each given cell type/subset."""
ax, f = getSetup((12, 4), (1, 2))

CITE_DF = importCITE()
Expand All @@ -58,10 +60,12 @@ def makeFigure():
markAvg = np.mean(CITE_DF[marker].values)
if markAvg > 0.0001:
targCellMark = (
CITE_DF.loc[CITE_DF[CELL_LEVEL] == targCell][marker].values / markAvg
CITE_DF.loc[CITE_DF[CELL_LEVEL] == targCell][marker].values
/ markAvg
)
offTargCellMark = (
CITE_DF.loc[CITE_DF[CELL_LEVEL] != targCell][marker].values / markAvg
CITE_DF.loc[CITE_DF[CELL_LEVEL] != targCell][marker].values
/ markAvg
)
if np.mean(targCellMark) > np.mean(offTargCellMark):
kdeTarg = KernelDensity(kernel="gaussian").fit(
Expand Down
4 changes: 3 additions & 1 deletion bicytok/figures/figure7.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

TARGET_CELL = "Treg"


def makeFigure():
"""Figure to generate clustermaps of EMD values for receptors + specified cell type"""
"""Figure to generate clustermaps of EMD values for receptors
+ specified cell type"""
ax, f = getSetup((40, 40), (1, 1))

markerDF = importCITE()
Expand Down
5 changes: 3 additions & 2 deletions bicytok/figures/figure8.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@

TARGET_CELL = "Treg"


def makeFigure():
"""clustermaps of KL values for receptors + specified cell type"""
ax, f = getSetup((40, 40), (1, 1))

markerDF = importCITE()
new_df = markerDF.head(1000)
receptors = []
for column in new_df.columns:
if column not in ["CellType1", "CellType2", "CellType3", "Cell"]:
receptors.append(column)

receptors = ["CD25", "CD35"]
TARGET_CELL = "Treg"
resultsKL = []
Expand Down
11 changes: 6 additions & 5 deletions bicytok/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ def importReceptors():
# Armaan: lru_cache mutable return value
@lru_cache(maxsize=None)
def makeCITEdf():
"""Makes cite surface epitope csv for given cell type, DON'T USE THIS UNLESS DATA NEEDS RESTRUCTURING"""
"""Makes cite surface epitope csv for given cell type,
DON'T USE THIS UNLESS DATA NEEDS RESTRUCTURING"""
"""
matrixDF = pd.read_csv(join(path_here, "bicytok/data/CITEmatrix.gz"), compression='gzip', header=0, sep=' ', quotechar='"', error_bad_lines=False)
matrixDF = pd.read_csv(join(path_here, "bicytok/data/CITEmatrix.gz"),
compression='gzip', header=0, sep=' ', quotechar='"', error_bad_lines=False)
matrixDF = matrixDF.iloc[:, 0:-2]
matrixDF.columns = ["Marker", "Cell", "Number"]
matrixDF.to_csv(join(path_here, "bicytok/data/CITEmatrix.csv"), index=False)
Expand Down Expand Up @@ -152,9 +154,8 @@ def makeTregSC():
stim_an.obs.index = barcodes["barcode"].values
stim_an.obs["Condition"] = stim

if (
i == 0
): # First condition - load features for later labeling (all conditions have same genes)
if i == 0: # First condition - load features for later labeling
# (all conditions have same genes)
Treg_h5ad = stim_an
features = pd.read_csv(
gzip.open(
Expand Down
Loading

0 comments on commit af875e1

Please sign in to comment.