Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
abearab committed Nov 19, 2023
1 parent 8613ed4 commit abaa6a8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 55 deletions.
54 changes: 0 additions & 54 deletions screenpro/phenoScore.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,57 +273,3 @@ def matrixTest(x, y, x_ctrl, y_ctrl, math, ave_reps, test = 'ttest', growth_rate
p_values = matrixStat(x, y, test=test, ave_reps=ave_reps)

return scores, p_values


def ann_score_df(df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', ctrl_label='non-targeting', threshold=10):
"""
Annotate score dataframe with hit labels using given `threshold`
(i.e. `score/pseudo_sd * -np.log10(pvalue) >= threshold`).
Args:
df_in (pd.DataFrame): score dataframe
up_hit (str): up hit label
down_hit (str): down hit label
ctrl_label (str): control label
threshold (int): threshold
Returns:
pd.DataFrame: annotated score dataframe
"""
# make a copy of input dataframe
df = df_in.copy()

# rename/reformat columns
df.columns = ['target', 'score', 'pvalue']
df['score'] = df['score'].astype(float)
df['pvalue'] = df['pvalue'].astype(float)

# calculate pseudo_sd
pseudo_sd = df[df['target'].str.contains(ctrl_label)]['score'].tolist()
pseudo_sd = np.std(pseudo_sd)

df['label'] = '.'

# annotate hits: up
df.loc[
(df['score'] > 0) & (~df['target'].str.contains(ctrl_label)) &
(df['score']/pseudo_sd * -np.log10(df['pvalue']) >= threshold), 'label'
] = up_hit

# annotate hits: down
df.loc[
(df['score'] < 0) & (~df['target'].str.contains(ctrl_label)) &
(df['score']/pseudo_sd * -np.log10(df['pvalue']) <= -threshold), 'label'
] = down_hit

# annotate control
df.loc[df['target'].str.contains(ctrl_label), 'label'] = ctrl_label

# annotate non-hit
df.loc[df['label'] == '.', 'label'] = 'target_non_hit'

# reorder factors
df['label'] = pd.Categorical(
df['label'],
categories=[down_hit, up_hit, ctrl_label, 'target_non_hit']
)

return df
2 changes: 1 addition & 1 deletion screenpro/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import scanpy as sc
import matplotlib.pyplot as plt
import matplotlib
from phenoScore import ann_score_df
from .utils import ann_score_df

# variables
almost_black = '#111111'
Expand Down

0 comments on commit abaa6a8

Please sign in to comment.