From fd37c8653e284952af229e73362b792132d2e60a Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 02:43:23 -0700 Subject: [PATCH 01/16] improve phenotype plotting functions --- screenpro/plotting.py | 318 +++++++++++++++++++++++++++--------------- 1 file changed, 207 insertions(+), 111 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index da7ed43..6ba4ed4 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -63,117 +63,7 @@ def draw_threshold(x, threshold, pseudo_sd): return threshold * pseudo_sd * (1 if x > 0 else -1) / abs(x) -def prep_data(df_in, threshold, ctrl_label): - df = df_in.copy() - - df = ann_score_df(df, threshold=threshold, ctrl_label = ctrl_label) - - df['-log10(pvalue)'] = np.log10(df.pvalue) * -1 - - return df - - -def plot_volcano(ax, df_in, threshold, up_hit='resistance_hit', down_hit='sensitivity_hit', - ctrl_label = 'no-targeting', - dot_size=1, - xlim_l=-5, xlim_r=5, - ylim=6): - df = prep_data(df_in, threshold, ctrl_label) - - # Scatter plot for each category - ax.scatter(df.loc[df['label'] == 'target_non_hit', 'score'], - df.loc[df['label'] == 'target_non_hit', '-log10(pvalue)'], - alpha=0.1, s=dot_size, c='black', label='target_non_hit') - ax.scatter(df.loc[df['label'] == up_hit, 'score'], df.loc[df['label'] == up_hit, '-log10(pvalue)'], - alpha=0.9, s=dot_size, c='#fcae91', label=up_hit) - ax.scatter(df.loc[df['label'] == down_hit, 'score'], df.loc[df['label'] == down_hit, '-log10(pvalue)'], - alpha=0.9, s=dot_size, c='#bdd7e7', label=down_hit) - ax.scatter(df.loc[df['label'] == ctrl_label, 'score'], - df.loc[df['label'] == ctrl_label, '-log10(pvalue)'], - alpha=0.1, s=dot_size, c='gray', label=ctrl_label) - - # Set x-axis and y-axis labels - ax.set_xlabel('phenotype score') - ax.set_ylabel('-log10(p-value)') - - # Set x-axis limits - ax.set_xlim(xlim_l, xlim_r) - - # Set y-axis limits - ax.set_ylim(0.1, ylim) - - # Add legend - ax.legend() - - -def label_as_black(ax, df_in, label, threshold, size=2, size_txt="auto", - ctrl_label = 'no-targeting', - t_x=.5, t_y=-0.1): - df = prep_data(df_in, threshold, ctrl_label) - - target_data = df[df['target'] == label] - - # Scatter plot for labeled data - ax.scatter(target_data['score'], target_data['-log10(pvalue)'], - s=size, linewidth=0.5, edgecolors='black', facecolors='black', label='target') - - if size_txt == None: - pass - elif size_txt == 'auto': - size_txt = size * 2 - else: - # Annotate the points - for i, _ in enumerate(target_data['target']): - txt = target_data['target'].iloc[i] - ax.annotate(txt, (target_data['score'].iloc[i] + t_x, target_data['-log10(pvalue)'].iloc[i] + t_y), - color='black', size=size_txt) - - -def label_sensitivity_hit(ax, df_in, label, threshold, size=2, size_txt="auto", - ctrl_label = 'no-targeting', - t_x=.5, t_y=-0.1): - df = prep_data(df_in, threshold, ctrl_label) - - target_data = df[df['target'] == label] - - # Scatter plot for labeled data - ax.scatter(target_data['score'], target_data['-log10(pvalue)'], - s=size, linewidth=0.5, edgecolors='black', facecolors='#3182bd', label='target') - - if size_txt == None: - pass - elif size_txt == 'auto': - size_txt = size * 2 - else: - # Annotate the points - for i, _ in enumerate(target_data['target']): - txt = target_data['target'].iloc[i] - ax.annotate(txt, (target_data['score'].iloc[i] + t_x, target_data['-log10(pvalue)'].iloc[i] + t_y), - color='black', size=size_txt) - - -def label_resistance_hit(ax, df_in, label, threshold, size=2, size_txt="auto", - ctrl_label = 'no-targeting', - t_x=.5, t_y=-0.1): - df = prep_data(df_in, threshold, ctrl_label) - - target_data = df[df['target'] == label] - - # Scatter plot for labeled data - ax.scatter(target_data['score'], target_data['-log10(pvalue)'], - s=size, linewidth=0.5, edgecolors='black', facecolors='#de2d26', label='target') - - if size_txt == None: - pass - elif size_txt == 'auto': - size_txt = size * 2 - else: - # Annotate the points - for i, _ in enumerate(target_data['target']): - txt = target_data['target'].iloc[i] - ax.annotate(txt, (target_data['score'].iloc[i] + t_x, target_data['-log10(pvalue)'].iloc[i] + t_y), - color='black', size=size_txt) - +## Scatter plot of replicates def plotReplicateScatter(ax, adat_in, x, y, title, min_val=None, max_val=None, log_transform=True): adat = adat_in[[x, y], :].copy() @@ -208,3 +98,209 @@ def plotReplicateScatter(ax, adat_in, x, y, title, min_val=None, max_val=None, l ax.get_legend().remove() ax.grid(False) + + +## Phenotype plotting functions + +class PheScatterPlot: + + def __init__(self,threshold=3,ctrl_label='no-targeting') -> None: + self.threshold = threshold + self.ctrl_label = ctrl_label + + def _prepare_score_df(self, df_in): + df = df_in.copy() + + df = ann_score_df(df, self.threshold, self.ctrl_label) + + df['-log10(pvalue)'] = np.log10(df.pvalue) * -1 + + return df + + def _label_by_color(self, ax, df_in, label, size=2, size_txt="auto", + x_col='score', y_col='-log10(pvalue)', + edgecolors='black', facecolors='black', + textcolor='black', + t_x=.5, t_y=-0.1): + df = self._prepare_score_df(df_in, self.threshold, self.ctrl_label) + + target_data = df[df['target'] == label] + + # Scatter plot for labeled data + ax.scatter( + target_data[x_col], target_data[y_col], + s=size, linewidth=0.5, + edgecolors=edgecolors, + facecolors=facecolors, label='target' + ) + + if size_txt == None: + pass + elif size_txt == 'auto': + size_txt = size * 2 + else: + # Annotate the points + for i, _ in enumerate(target_data['target']): + txt = target_data['target'].iloc[i] + ax.annotate(txt, (target_data[x_col].iloc[i] + t_x, target_data[y_col].iloc[i] + t_y), + color=textcolor, size=size_txt) + + +class Volcano(PheScatterPlot): + + def __init__(self, threshold=3, ctrl_label='no-targeting') -> None: + super().__init__(threshold, ctrl_label) + + def plot(self, ax, df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', + xlabel='phenotype score', + ylabel='-log10(pvalue)', + dot_size=1, + xlims=(-5, 5), + ylim=6): + df = self._prepare_score_df(df_in, self.threshold, self.ctrl_label) + xlim_l, xlim_r = xlims + + # Scatter plot for each category + ax.scatter( df.loc[df['label'] == 'target_non_hit', 'score'], + df.loc[df['label'] == 'target_non_hit', '-log10(pvalue)'], + alpha=0.1, s=dot_size, c='black', label='target_non_hit') + + ax.scatter( df.loc[df['label'] == up_hit, 'score'], + df.loc[df['label'] == up_hit, '-log10(pvalue)'], + alpha=0.9, s=dot_size, c='#fcae91', label=up_hit) + + ax.scatter( df.loc[df['label'] == down_hit, 'score'], + df.loc[df['label'] == down_hit, '-log10(pvalue)'], + alpha=0.9, s=dot_size, c='#bdd7e7', label=down_hit) + + ax.scatter( df.loc[df['label'] == self.ctrl_label, 'score'], + df.loc[df['label'] == self.ctrl_label, '-log10(pvalue)'], + alpha=0.1, s=dot_size, c='gray', label=self.ctrl_label) + + # Set x-axis and y-axis labels + ax.set_xlabel(xlabel) + ax.set_ylabel(ylabel) + + # Set x-axis limits + ax.set_xlim(xlim_l, xlim_r) + + # Set y-axis limits + ax.set_ylim(0.1, ylim) + + # Add legend + ax.legend() + + def label_as_black(self, ax, df_in, label, size=2, size_txt="auto", + t_x=.5, t_y=-0.1): + self._label_by_color(ax, df_in, label, size, size_txt, + edgecolors='black', facecolors='black', + textcolor='black', + t_x=t_x, t_y=t_y) + + def label_sensitivity_hit(self, ax, df_in, label, size=2, size_txt="auto", + t_x=.5, t_y=-0.1): + self._label_by_color(ax, df_in, label, size, size_txt, + edgecolors='black', facecolors='#3182bd', + textcolor='black', + t_x=t_x, t_y=t_y) + + def label_resistance_hit(self, ax, df_in, label, size=2, size_txt="auto", + t_x=.5, t_y=-0.1): + self._label_by_color(ax, df_in, label, size, size_txt, + edgecolors='black', facecolors='#de2d26', + textcolor='black', + t_x=t_x, t_y=t_y) + + +class RhoGammaScatter(PheScatterPlot): + def __init__(self, screen, threshold=3, ctrl_label='no-targeting') -> None: + self.screen = screen + super().__init__(threshold, ctrl_label) + + def _prep_data(self): + + gamma = self.screen.getPhenotypeScores( + run_name=self.run_name, + score_name=self.gamma_score_name, + ctrl_label=self.ctrl_label, + threshold=self.threshold, + ) + + rho = self.screen.getPhenotypeScores( + run_name=self.run_name, + score_name=self.rho_score_name, + ctrl_label=self.ctrl_label, + threshold=self.threshold + ) + + rho = self._prepare_score_df(rho, self.threshold, self.ctrl_label) + gamma = self._prepare_score_df(gamma, self.threshold, self.ctrl_label) + + return rho, gamma + + def plot(self, ax, + up_hit='resistance_hit', down_hit='sensitivity_hit', + dot_size=1, + xlabel=None, + ylabel=None, + xlims=(-5, 5), + ylims=(-5, 5)): + + rho_df, gamma_df = self._prep_data(self.screen) + + # Scatter plot for each category + ax.scatter( rho_df.loc[rho_df['label'] == 'target_non_hit', 'score'], + gamma_df.loc[rho_df['label'] == 'target_non_hit', 'score'], + alpha=0.1, s=dot_size, c='black', label='target_non_hit') + + ax.scatter( rho_df.loc[rho_df['label'] == up_hit, 'score'], + gamma_df.loc[rho_df['label'] == up_hit, 'score'], + alpha=0.9, s=dot_size, c='#fcae91', label=up_hit) + + ax.scatter( rho_df.loc[rho_df['label'] == down_hit, 'score'], + gamma_df.loc[rho_df['label'] == down_hit, 'score'], + alpha=0.9, s=dot_size, c='#bdd7e7', label=down_hit) + + ax.scatter( rho_df.loc[rho_df['label'] == self.ctrl_label, 'score'], + gamma_df.loc[rho_df['label'] == self.ctrl_label, 'score'], + alpha=0.1, s=dot_size, c='gray', label=self.ctrl_label) + + # Set x-axis and y-axis labels + if not xlabel: + ax.set_xlabel('rho score') + else: + ax.set_xlabel(xlabel) + if not ylabel: + ax.set_ylabel('gamma score') + else: + ax.set_ylabel(ylabel) + + # Set x-axis limits + ax.set_xlim(xlims) + ax.set_ylim(ylims) + + # Add legend + ax.legend() + + def label_as_black(self, ax, label, size=2, size_txt="auto", + t_x=.5, t_y=-0.1): + self._label_by_color(ax, label, size, size_txt, + edgecolors='black', facecolors='black', + textcolor='black', + t_x=t_x, t_y=t_y) + + def label_sensitivity_hit(self, ax, label, size=2, size_txt="auto", + t_x=.5, t_y=-0.1): + + self._label_by_color(ax, label, size, size_txt, + edgecolors='black', facecolors='#3182bd', + textcolor='black', + t_x=t_x, t_y=t_y) + + def label_resistance_hit(self, ax, label, size=2, size_txt="auto", + t_x=.5, t_y=-0.1): + + self._label_by_color(ax, label, size, size_txt, + edgecolors='black', facecolors='#de2d26', + textcolor='black', + t_x=t_x, t_y=t_y) From 6b6c330ec820b42e1b82ea829be6cbff55f51f86 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 02:47:22 -0700 Subject: [PATCH 02/16] mend --- screenpro/plotting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index 6ba4ed4..37003b1 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -157,7 +157,7 @@ def plot(self, ax, df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', dot_size=1, xlims=(-5, 5), ylim=6): - df = self._prepare_score_df(df_in, self.threshold, self.ctrl_label) + df = self._prepare_score_df(df_in) xlim_l, xlim_r = xlims # Scatter plot for each category @@ -233,8 +233,8 @@ def _prep_data(self): threshold=self.threshold ) - rho = self._prepare_score_df(rho, self.threshold, self.ctrl_label) - gamma = self._prepare_score_df(gamma, self.threshold, self.ctrl_label) + rho = self._prepare_score_df(rho) + gamma = self._prepare_score_df(gamma) return rho, gamma From 6bbcbf2df51bddaea74322d9956e901dfd701052 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 02:53:23 -0700 Subject: [PATCH 03/16] mend --- screenpro/plotting.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index 37003b1..e6ff035 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -104,25 +104,26 @@ def plotReplicateScatter(ax, adat_in, x, y, title, min_val=None, max_val=None, l class PheScatterPlot: - def __init__(self,threshold=3,ctrl_label='no-targeting') -> None: - self.threshold = threshold - self.ctrl_label = ctrl_label + def __init__(self) -> None: + pass - def _prepare_score_df(self, df_in): + def _prepare_score_df(self, df_in,threshold,ctrl_label): df = df_in.copy() - df = ann_score_df(df, self.threshold, self.ctrl_label) + df = ann_score_df(df, threshold, ctrl_label) df['-log10(pvalue)'] = np.log10(df.pvalue) * -1 return df - def _label_by_color(self, ax, df_in, label, size=2, size_txt="auto", + def _label_by_color(self, ax, df_in, label, + threshold,ctrl_label, + size=2, size_txt="auto", x_col='score', y_col='-log10(pvalue)', edgecolors='black', facecolors='black', textcolor='black', t_x=.5, t_y=-0.1): - df = self._prepare_score_df(df_in, self.threshold, self.ctrl_label) + df = self._prepare_score_df(df_in, threshold, ctrl_label) target_data = df[df['target'] == label] @@ -149,7 +150,9 @@ def _label_by_color(self, ax, df_in, label, size=2, size_txt="auto", class Volcano(PheScatterPlot): def __init__(self, threshold=3, ctrl_label='no-targeting') -> None: - super().__init__(threshold, ctrl_label) + self.threshold = threshold + self.ctrl_label = ctrl_label + super().__init__() def plot(self, ax, df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', xlabel='phenotype score', @@ -214,8 +217,10 @@ def label_resistance_hit(self, ax, df_in, label, size=2, size_txt="auto", class RhoGammaScatter(PheScatterPlot): def __init__(self, screen, threshold=3, ctrl_label='no-targeting') -> None: + self.threshold = threshold + self.ctrl_label = ctrl_label self.screen = screen - super().__init__(threshold, ctrl_label) + super().__init__() def _prep_data(self): From 7074179360a5cc70dc8334920cb64e18708a8aa8 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 02:56:39 -0700 Subject: [PATCH 04/16] mend --- screenpro/plotting.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index e6ff035..818a650 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -160,7 +160,7 @@ def plot(self, ax, df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', dot_size=1, xlims=(-5, 5), ylim=6): - df = self._prepare_score_df(df_in) + df = self._prepare_score_df(df_in, self.threshold, self.ctrl_label) xlim_l, xlim_r = xlims # Scatter plot for each category @@ -195,21 +195,27 @@ def plot(self, ax, df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', def label_as_black(self, ax, df_in, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): - self._label_by_color(ax, df_in, label, size, size_txt, + self._label_by_color(ax, df_in, label, + threshold=self.threshold, ctrl_label=self.ctrl_label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='black', textcolor='black', t_x=t_x, t_y=t_y) def label_sensitivity_hit(self, ax, df_in, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): - self._label_by_color(ax, df_in, label, size, size_txt, + self._label_by_color(ax, df_in, label, + threshold=self.threshold, ctrl_label=self.ctrl_label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='#3182bd', textcolor='black', t_x=t_x, t_y=t_y) def label_resistance_hit(self, ax, df_in, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): - self._label_by_color(ax, df_in, label, size, size_txt, + self._label_by_color(ax, df_in, label, + threshold=self.threshold, ctrl_label=self.ctrl_label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='#de2d26', textcolor='black', t_x=t_x, t_y=t_y) @@ -238,8 +244,8 @@ def _prep_data(self): threshold=self.threshold ) - rho = self._prepare_score_df(rho) - gamma = self._prepare_score_df(gamma) + rho = self._prepare_score_df(rho, self.threshold, self.ctrl_label) + gamma = self._prepare_score_df(gamma, self.threshold, self.ctrl_label) return rho, gamma @@ -289,7 +295,9 @@ def plot(self, ax, def label_as_black(self, ax, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): - self._label_by_color(ax, label, size, size_txt, + self._label_by_color(ax, label, + threshold=self.threshold, ctrl_label=self.ctrl_label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='black', textcolor='black', t_x=t_x, t_y=t_y) @@ -297,7 +305,9 @@ def label_as_black(self, ax, label, size=2, size_txt="auto", def label_sensitivity_hit(self, ax, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): - self._label_by_color(ax, label, size, size_txt, + self._label_by_color(ax, label, + threshold=self.threshold, ctrl_label=self.ctrl_label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='#3182bd', textcolor='black', t_x=t_x, t_y=t_y) @@ -305,7 +315,9 @@ def label_sensitivity_hit(self, ax, label, size=2, size_txt="auto", def label_resistance_hit(self, ax, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): - self._label_by_color(ax, label, size, size_txt, + self._label_by_color(ax, label, + threshold=self.threshold, ctrl_label=self.ctrl_label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='#de2d26', textcolor='black', t_x=t_x, t_y=t_y) From 3ca371ae3738e56732d71bb9c722bbb2eda4f9ad Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 03:01:55 -0700 Subject: [PATCH 05/16] mend --- screenpro/plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index 818a650..1a8d0e0 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -110,7 +110,7 @@ def __init__(self) -> None: def _prepare_score_df(self, df_in,threshold,ctrl_label): df = df_in.copy() - df = ann_score_df(df, threshold, ctrl_label) + df = ann_score_df(df, threshold=threshold, ctrl_label=ctrl_label) df['-log10(pvalue)'] = np.log10(df.pvalue) * -1 From 264cd9d4b7fbb6e39e4a51fb9a3693e87b33f0af Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 03:16:05 -0700 Subject: [PATCH 06/16] mend --- screenpro/plotting.py | 112 ++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 54 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index 1a8d0e0..521ade8 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -104,26 +104,49 @@ def plotReplicateScatter(ax, adat_in, x, y, title, min_val=None, max_val=None, l class PheScatterPlot: - def __init__(self) -> None: - pass + def __init__(self, threshold, ctrl_label) -> None: + self.threshold = threshold + self.ctrl_label = ctrl_label - def _prepare_score_df(self, df_in,threshold,ctrl_label): - df = df_in.copy() + def _prep_data(self, screen): - df = ann_score_df(df, threshold=threshold, ctrl_label=ctrl_label) + gamma = screen.getPhenotypeScores( + run_name=self.run_name, + score_name=self.gamma_score_name, + ctrl_label=self.ctrl_label, + threshold=self.threshold, + ) + + rho = screen.getPhenotypeScores( + run_name=self.run_name, + score_name=self.rho_score_name, + ctrl_label=self.ctrl_label, + threshold=self.threshold + ) - df['-log10(pvalue)'] = np.log10(df.pvalue) * -1 + gamma = ann_score_df( + gamma, + up_hit='up_hit', down_hit='essential_hit', + threshold=self.threshold, ctrl_label=self.ctrl_label + ) + gamma['-log10(pvalue)'] = np.log10(gamma.pvalue) * -1 - return df + rho = ann_score_df( + rho, + up_hit='resistance_hit', down_hit='sensitivity_hit', + threshold=self.threshold, ctrl_label=self.ctrl_label + ) + rho['-log10(pvalue)'] = np.log10(rho.pvalue) * -1 + + return gamma, rho def _label_by_color(self, ax, df_in, label, - threshold,ctrl_label, size=2, size_txt="auto", x_col='score', y_col='-log10(pvalue)', edgecolors='black', facecolors='black', textcolor='black', t_x=.5, t_y=-0.1): - df = self._prepare_score_df(df_in, threshold, ctrl_label) + df = self._prepare_score_df(df_in, self.threshold, self.ctrl_label) target_data = df[df['target'] == label] @@ -150,19 +173,27 @@ def _label_by_color(self, ax, df_in, label, class Volcano(PheScatterPlot): def __init__(self, threshold=3, ctrl_label='no-targeting') -> None: - self.threshold = threshold - self.ctrl_label = ctrl_label - super().__init__() + super().__init__(threshold, ctrl_label) - def plot(self, ax, df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', + def plot(self, ax, screen, score, xlabel='phenotype score', ylabel='-log10(pvalue)', dot_size=1, xlims=(-5, 5), - ylim=6): - df = self._prepare_score_df(df_in, self.threshold, self.ctrl_label) - xlim_l, xlim_r = xlims - + ylims=(0.1,6) + ): + gamma, rho = self._prep_data(screen) + + if score == 'gamma': + df = gamma + up_hit = 'up_hit' + down_hit = 'essential_hit' + + elif score == 'rho': + df = rho + up_hit = 'resistance_hit' + down_hit = 'sensitivity_hit' + # Scatter plot for each category ax.scatter( df.loc[df['label'] == 'target_non_hit', 'score'], df.loc[df['label'] == 'target_non_hit', '-log10(pvalue)'], @@ -185,10 +216,10 @@ def plot(self, ax, df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', ax.set_ylabel(ylabel) # Set x-axis limits - ax.set_xlim(xlim_l, xlim_r) + ax.set_xlim(xlims) # Set y-axis limits - ax.set_ylim(0.1, ylim) + ax.set_ylim(ylims) # Add legend ax.legend() @@ -196,7 +227,6 @@ def plot(self, ax, df_in, up_hit='resistance_hit', down_hit='sensitivity_hit', def label_as_black(self, ax, df_in, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): self._label_by_color(ax, df_in, label, - threshold=self.threshold, ctrl_label=self.ctrl_label, size=size, size_txt=size_txt, edgecolors='black', facecolors='black', textcolor='black', @@ -205,7 +235,6 @@ def label_as_black(self, ax, df_in, label, size=2, size_txt="auto", def label_sensitivity_hit(self, ax, df_in, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): self._label_by_color(ax, df_in, label, - threshold=self.threshold, ctrl_label=self.ctrl_label, size=size, size_txt=size_txt, edgecolors='black', facecolors='#3182bd', textcolor='black', @@ -214,7 +243,6 @@ def label_sensitivity_hit(self, ax, df_in, label, size=2, size_txt="auto", def label_resistance_hit(self, ax, df_in, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): self._label_by_color(ax, df_in, label, - threshold=self.threshold, ctrl_label=self.ctrl_label, size=size, size_txt=size_txt, edgecolors='black', facecolors='#de2d26', textcolor='black', @@ -222,42 +250,21 @@ def label_resistance_hit(self, ax, df_in, label, size=2, size_txt="auto", class RhoGammaScatter(PheScatterPlot): - def __init__(self, screen, threshold=3, ctrl_label='no-targeting') -> None: - self.threshold = threshold - self.ctrl_label = ctrl_label - self.screen = screen - super().__init__() - - def _prep_data(self): - - gamma = self.screen.getPhenotypeScores( - run_name=self.run_name, - score_name=self.gamma_score_name, - ctrl_label=self.ctrl_label, - threshold=self.threshold, - ) - - rho = self.screen.getPhenotypeScores( - run_name=self.run_name, - score_name=self.rho_score_name, - ctrl_label=self.ctrl_label, - threshold=self.threshold - ) - - rho = self._prepare_score_df(rho, self.threshold, self.ctrl_label) - gamma = self._prepare_score_df(gamma, self.threshold, self.ctrl_label) - - return rho, gamma + def __init__(self, threshold=3, ctrl_label='no-targeting') -> None: + super().__init__(threshold, ctrl_label) - def plot(self, ax, - up_hit='resistance_hit', down_hit='sensitivity_hit', + def plot(self, ax, screen, dot_size=1, xlabel=None, ylabel=None, xlims=(-5, 5), ylims=(-5, 5)): - rho_df, gamma_df = self._prep_data(self.screen) + rho_df, gamma_df = self._prep_data(screen) + + # color by rho score labels + up_hit = 'resistance_hit' + down_hit = 'sensitivity_hit' # Scatter plot for each category ax.scatter( rho_df.loc[rho_df['label'] == 'target_non_hit', 'score'], @@ -296,7 +303,6 @@ def plot(self, ax, def label_as_black(self, ax, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): self._label_by_color(ax, label, - threshold=self.threshold, ctrl_label=self.ctrl_label, size=size, size_txt=size_txt, edgecolors='black', facecolors='black', textcolor='black', @@ -306,7 +312,6 @@ def label_sensitivity_hit(self, ax, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): self._label_by_color(ax, label, - threshold=self.threshold, ctrl_label=self.ctrl_label, size=size, size_txt=size_txt, edgecolors='black', facecolors='#3182bd', textcolor='black', @@ -316,7 +321,6 @@ def label_resistance_hit(self, ax, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): self._label_by_color(ax, label, - threshold=self.threshold, ctrl_label=self.ctrl_label, size=size, size_txt=size_txt, edgecolors='black', facecolors='#de2d26', textcolor='black', From bbd556002f208c25570df597af15c87e00ae4508 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 03:32:35 -0700 Subject: [PATCH 07/16] mend --- screenpro/plotting.py | 98 +++++++++++++------------------------------ 1 file changed, 29 insertions(+), 69 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index 521ade8..25f1c01 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -102,22 +102,25 @@ def plotReplicateScatter(ax, adat_in, x, y, title, min_val=None, max_val=None, l ## Phenotype plotting functions -class PheScatterPlot: - - def __init__(self, threshold, ctrl_label) -> None: +class DrugScreenPlots: + def __init__(self, screen, treated, untreated, t0='T0', threshold=3, ctrl_label='negative_control',run_name='auto'): + self.screen = screen self.threshold = threshold self.ctrl_label = ctrl_label + self.run_name = run_name + self.gamma_score_name = f'gamma:{untreated}_vs_{t0}' + self.rho_score_name = f'rho:{treated}_vs_{untreated}' - def _prep_data(self, screen): + def _prep_data(self): - gamma = screen.getPhenotypeScores( + gamma = self.screen.getPhenotypeScores( run_name=self.run_name, score_name=self.gamma_score_name, ctrl_label=self.ctrl_label, threshold=self.threshold, ) - rho = screen.getPhenotypeScores( + rho = self.screen.getPhenotypeScores( run_name=self.run_name, score_name=self.rho_score_name, ctrl_label=self.ctrl_label, @@ -169,20 +172,14 @@ def _label_by_color(self, ax, df_in, label, ax.annotate(txt, (target_data[x_col].iloc[i] + t_x, target_data[y_col].iloc[i] + t_y), color=textcolor, size=size_txt) - -class Volcano(PheScatterPlot): - - def __init__(self, threshold=3, ctrl_label='no-targeting') -> None: - super().__init__(threshold, ctrl_label) - - def plot(self, ax, screen, score, + def volcanoPlot(self, ax, score, xlabel='phenotype score', ylabel='-log10(pvalue)', dot_size=1, xlims=(-5, 5), ylims=(0.1,6) ): - gamma, rho = self._prep_data(screen) + gamma, rho = self._prep_data() if score == 'gamma': df = gamma @@ -224,43 +221,14 @@ def plot(self, ax, screen, score, # Add legend ax.legend() - def label_as_black(self, ax, df_in, label, size=2, size_txt="auto", - t_x=.5, t_y=-0.1): - self._label_by_color(ax, df_in, label, - size=size, size_txt=size_txt, - edgecolors='black', facecolors='black', - textcolor='black', - t_x=t_x, t_y=t_y) - - def label_sensitivity_hit(self, ax, df_in, label, size=2, size_txt="auto", - t_x=.5, t_y=-0.1): - self._label_by_color(ax, df_in, label, - size=size, size_txt=size_txt, - edgecolors='black', facecolors='#3182bd', - textcolor='black', - t_x=t_x, t_y=t_y) - - def label_resistance_hit(self, ax, df_in, label, size=2, size_txt="auto", - t_x=.5, t_y=-0.1): - self._label_by_color(ax, df_in, label, - size=size, size_txt=size_txt, - edgecolors='black', facecolors='#de2d26', - textcolor='black', - t_x=t_x, t_y=t_y) - - -class RhoGammaScatter(PheScatterPlot): - def __init__(self, threshold=3, ctrl_label='no-targeting') -> None: - super().__init__(threshold, ctrl_label) - - def plot(self, ax, screen, + def scatterRhoGamma(self, ax, dot_size=1, - xlabel=None, - ylabel=None, + xlabel='rho score', + ylabel='gamma score', xlims=(-5, 5), ylims=(-5, 5)): - rho_df, gamma_df = self._prep_data(screen) + rho_df, gamma_df = self._prep_data() # color by rho score labels up_hit = 'resistance_hit' @@ -284,14 +252,8 @@ def plot(self, ax, screen, alpha=0.1, s=dot_size, c='gray', label=self.ctrl_label) # Set x-axis and y-axis labels - if not xlabel: - ax.set_xlabel('rho score') - else: - ax.set_xlabel(xlabel) - if not ylabel: - ax.set_ylabel('gamma score') - else: - ax.set_ylabel(ylabel) + ax.set_xlabel(xlabel) + ax.set_ylabel(ylabel) # Set x-axis limits ax.set_xlim(xlims) @@ -299,29 +261,27 @@ def plot(self, ax, screen, # Add legend ax.legend() - - def label_as_black(self, ax, label, size=2, size_txt="auto", + + def label_as_black(self, ax, df_in, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): - self._label_by_color(ax, label, - size=size, size_txt=size_txt, + self._label_by_color(ax, df_in, label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='black', textcolor='black', t_x=t_x, t_y=t_y) - - def label_sensitivity_hit(self, ax, label, size=2, size_txt="auto", - t_x=.5, t_y=-0.1): - self._label_by_color(ax, label, - size=size, size_txt=size_txt, + def label_sensitivity_hit(self, ax, df_in, label, size=2, size_txt="auto", + t_x=.5, t_y=-0.1): + self._label_by_color(ax, df_in, label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='#3182bd', textcolor='black', t_x=t_x, t_y=t_y) - - def label_resistance_hit(self, ax, label, size=2, size_txt="auto", + + def label_resistance_hit(self, ax, df_in, label, size=2, size_txt="auto", t_x=.5, t_y=-0.1): - - self._label_by_color(ax, label, - size=size, size_txt=size_txt, + self._label_by_color(ax, df_in, label, + size=size, size_txt=size_txt, edgecolors='black', facecolors='#de2d26', textcolor='black', t_x=t_x, t_y=t_y) From 49a34546f1710866182927be9929d2bf0ab43399 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 03:37:04 -0700 Subject: [PATCH 08/16] mend --- screenpro/plotting.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index 25f1c01..32da89a 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -119,6 +119,7 @@ def _prep_data(self): ctrl_label=self.ctrl_label, threshold=self.threshold, ) + gamma['-log10(pvalue)'] = np.log10(gamma.pvalue) * -1 rho = self.screen.getPhenotypeScores( run_name=self.run_name, @@ -126,19 +127,6 @@ def _prep_data(self): ctrl_label=self.ctrl_label, threshold=self.threshold ) - - gamma = ann_score_df( - gamma, - up_hit='up_hit', down_hit='essential_hit', - threshold=self.threshold, ctrl_label=self.ctrl_label - ) - gamma['-log10(pvalue)'] = np.log10(gamma.pvalue) * -1 - - rho = ann_score_df( - rho, - up_hit='resistance_hit', down_hit='sensitivity_hit', - threshold=self.threshold, ctrl_label=self.ctrl_label - ) rho['-log10(pvalue)'] = np.log10(rho.pvalue) * -1 return gamma, rho From f3bb7203f0de7eda1a79973f8fb5276fce05f466 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 04:01:53 -0700 Subject: [PATCH 09/16] mend --- screenpro/plotting.py | 146 ++++++++++++++++++++++++++++-------------- 1 file changed, 99 insertions(+), 47 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index 32da89a..c370a8f 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -102,7 +102,7 @@ def plotReplicateScatter(ax, adat_in, x, y, title, min_val=None, max_val=None, l ## Phenotype plotting functions -class DrugScreenPlots: +class DrugScreenPlotter: def __init__(self, screen, treated, untreated, t0='T0', threshold=3, ctrl_label='negative_control',run_name='auto'): self.screen = screen self.threshold = threshold @@ -110,35 +110,16 @@ def __init__(self, screen, treated, untreated, t0='T0', threshold=3, ctrl_label= self.run_name = run_name self.gamma_score_name = f'gamma:{untreated}_vs_{t0}' self.rho_score_name = f'rho:{treated}_vs_{untreated}' + self.tau_score_name = f'tau:{treated}_vs_{t0}' - def _prep_data(self): - - gamma = self.screen.getPhenotypeScores( - run_name=self.run_name, - score_name=self.gamma_score_name, - ctrl_label=self.ctrl_label, - threshold=self.threshold, - ) - gamma['-log10(pvalue)'] = np.log10(gamma.pvalue) * -1 - - rho = self.screen.getPhenotypeScores( - run_name=self.run_name, - score_name=self.rho_score_name, - ctrl_label=self.ctrl_label, - threshold=self.threshold - ) - rho['-log10(pvalue)'] = np.log10(rho.pvalue) * -1 - - return gamma, rho - def _label_by_color(self, ax, df_in, label, size=2, size_txt="auto", x_col='score', y_col='-log10(pvalue)', edgecolors='black', facecolors='black', textcolor='black', t_x=.5, t_y=-0.1): - df = self._prepare_score_df(df_in, self.threshold, self.ctrl_label) - + + df = df_in.copy() target_data = df[df['target'] == label] # Scatter plot for labeled data @@ -160,24 +141,42 @@ def _label_by_color(self, ax, df_in, label, ax.annotate(txt, (target_data[x_col].iloc[i] + t_x, target_data[y_col].iloc[i] + t_y), color=textcolor, size=size_txt) - def volcanoPlot(self, ax, score, - xlabel='phenotype score', - ylabel='-log10(pvalue)', - dot_size=1, - xlims=(-5, 5), - ylims=(0.1,6) + def _prep_data(self): + + gamma = self.screen.getPhenotypeScores( + run_name=self.run_name, + score_name=self.gamma_score_name, + ctrl_label=self.ctrl_label, + threshold=self.threshold, + ) + gamma['-log10(pvalue)'] = np.log10(gamma.pvalue) * -1 + + tau = self.screen.getPhenotypeScores( + run_name=self.run_name, + score_name='tau', + ctrl_label=self.ctrl_label, + threshold=self.threshold + ) + tau['-log10(pvalue)'] = np.log10(tau.pvalue) * -1 + + rho = self.screen.getPhenotypeScores( + run_name=self.run_name, + score_name=self.rho_score_name, + ctrl_label=self.ctrl_label, + threshold=self.threshold + ) + rho['-log10(pvalue)'] = np.log10(rho.pvalue) * -1 + + return gamma, tau, rho + + def _volcano( + self, ax, df, up_hit, down_hit, + xlabel='phenotype score', + ylabel='-log10(pvalue)', + dot_size=1, + xlims=(-5, 5), + ylims=(0.1,6) ): - gamma, rho = self._prep_data() - - if score == 'gamma': - df = gamma - up_hit = 'up_hit' - down_hit = 'essential_hit' - - elif score == 'rho': - df = rho - up_hit = 'resistance_hit' - down_hit = 'sensitivity_hit' # Scatter plot for each category ax.scatter( df.loc[df['label'] == 'target_non_hit', 'score'], @@ -209,14 +208,67 @@ def volcanoPlot(self, ax, score, # Add legend ax.legend() - def scatterRhoGamma(self, ax, - dot_size=1, - xlabel='rho score', - ylabel='gamma score', - xlims=(-5, 5), - ylims=(-5, 5)): + def drawVolcanoRho( + self, ax, + dot_size=1, + xlabel='auto', + ylabel='-log10(pvalue)', + xlims=(-5, 5), + ylims=(0.1, 6) + ): + _, _, rho_df = self._prep_data() + if xlabel == 'auto': + xlabel = self.rho_score_name + + self._volcano(ax, rho_df, + up_hit='resistance_hit', down_hit='sensitivity_hit', + xlabel=xlabel, ylabel=ylabel, + dot_size=dot_size, xlims=xlims, ylims=ylims) + + def drawVolcanoGamma( + self, ax, + dot_size=1, + xlabel='auto', + ylabel='-log10(pvalue)', + xlims=(-5, 5), + ylims=(0.1, 6) + ): + gamma_df, _, _ = self._prep_data() + if xlabel == 'auto': + xlabel = self.gamma_score_name + + self._volcano(ax, gamma_df, + up_hit='up_hit', down_hit='essential_hit', + xlabel=xlabel, ylabel=ylabel, + dot_size=dot_size, xlims=xlims, ylims=ylims) + + def drawVolcanoTau( + self, ax, + dot_size=1, + xlabel='auto', + ylabel='-log10(pvalue)', + xlims=(-5, 5), + ylims=(0.1, 6) + ): + _, tau_df, _, = self._prep_data() + if xlabel == 'auto': + xlabel = self.tau_score_name + + self._volcano(ax, tau_df, + up_hit='up_hit', down_hit='down_hit', + xlabel=xlabel, ylabel=ylabel, + dot_size=dot_size, xlims=xlims, ylims=ylims) + + def drawRhoGammaScatter( + self, ax, + dot_size=1, + xlabel='rho score', + ylabel='gamma score', + xlims=(-5, 5), + ylims=(-5, 5) + ): - rho_df, gamma_df = self._prep_data() + gamma_df, _, rho_df = self._prep_data() # color by rho score labels up_hit = 'resistance_hit' From a36e8124bc737c68b6ee4288f2118d708c70d82c Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 04:05:33 -0700 Subject: [PATCH 10/16] mend --- screenpro/plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index c370a8f..6dafd12 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -153,7 +153,7 @@ def _prep_data(self): tau = self.screen.getPhenotypeScores( run_name=self.run_name, - score_name='tau', + score_name=self.tau_score_name, ctrl_label=self.ctrl_label, threshold=self.threshold ) From ab60c3f913a43155dfe07f5565c42a2523d540a6 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 04:11:28 -0700 Subject: [PATCH 11/16] update auto labels --- screenpro/plotting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index 6dafd12..bbc61e2 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -218,7 +218,7 @@ def drawVolcanoRho( ): _, _, rho_df = self._prep_data() if xlabel == 'auto': - xlabel = self.rho_score_name + xlabel = self.rho_score_name.replace(':', ': ').replace('_', ' ') self._volcano(ax, rho_df, up_hit='resistance_hit', down_hit='sensitivity_hit', @@ -235,7 +235,7 @@ def drawVolcanoGamma( ): gamma_df, _, _ = self._prep_data() if xlabel == 'auto': - xlabel = self.gamma_score_name + xlabel = self.gamma_score_name.replace(':', ': ').replace('_', ' ') self._volcano(ax, gamma_df, up_hit='up_hit', down_hit='essential_hit', @@ -252,7 +252,7 @@ def drawVolcanoTau( ): _, tau_df, _, = self._prep_data() if xlabel == 'auto': - xlabel = self.tau_score_name + xlabel = self.tau_score_name.replace(':', ': ').replace('_', ' ') self._volcano(ax, tau_df, up_hit='up_hit', down_hit='down_hit', From 9a78e86a7163573518902aae2c829324226bbf07 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 04:13:30 -0700 Subject: [PATCH 12/16] update auto labels --- screenpro/plotting.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index bbc61e2..c915d24 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -262,13 +262,18 @@ def drawVolcanoTau( def drawRhoGammaScatter( self, ax, dot_size=1, - xlabel='rho score', - ylabel='gamma score', + xlabel='auto', + ylabel='auto', xlims=(-5, 5), ylims=(-5, 5) ): gamma_df, _, rho_df = self._prep_data() + + if xlabel == 'auto': + xlabel = self.gamma_score_name.replace(':', ': ').replace('_', ' ') + if ylabel == 'auto': + ylabel = self.rho_score_name.replace(':', ': ').replace('_', ' ') # color by rho score labels up_hit = 'resistance_hit' From cea7b70c5a846e6fd57e87720f938e9c683e31a3 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 04:22:16 -0700 Subject: [PATCH 13/16] fix axis order --- screenpro/plotting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index c915d24..a6022e9 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -271,9 +271,9 @@ def drawRhoGammaScatter( gamma_df, _, rho_df = self._prep_data() if xlabel == 'auto': - xlabel = self.gamma_score_name.replace(':', ': ').replace('_', ' ') + xlabel = self.rho_score_name.replace(':', ': ').replace('_', ' ') if ylabel == 'auto': - ylabel = self.rho_score_name.replace(':', ': ').replace('_', ' ') + ylabel = self.gamma_score_name.replace(':', ': ').replace('_', ' ') # color by rho score labels up_hit = 'resistance_hit' From a3f85c8e5537de97e3be92e09d3cb9d6639bd7e8 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 04:28:06 -0700 Subject: [PATCH 14/16] add more options for label functions --- screenpro/plotting.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index a6022e9..beee440 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -113,8 +113,8 @@ def __init__(self, screen, treated, untreated, t0='T0', threshold=3, ctrl_label= self.tau_score_name = f'tau:{treated}_vs_{t0}' def _label_by_color(self, ax, df_in, label, + x_col, y_col, size=2, size_txt="auto", - x_col='score', y_col='-log10(pvalue)', edgecolors='black', facecolors='black', textcolor='black', t_x=.5, t_y=-0.1): @@ -307,25 +307,35 @@ def drawRhoGammaScatter( # Add legend ax.legend() - def label_as_black(self, ax, df_in, label, size=2, size_txt="auto", + def label_as_black(self, ax, df_in, label, + x_col='score', y_col='-log10(pvalue)', + size=2, size_txt="auto", + t_x=.5, t_y=-0.1): self._label_by_color(ax, df_in, label, + x_col=x_col, y_col=y_col, size=size, size_txt=size_txt, edgecolors='black', facecolors='black', textcolor='black', t_x=t_x, t_y=t_y) - def label_sensitivity_hit(self, ax, df_in, label, size=2, size_txt="auto", + def label_sensitivity_hit(self, ax, df_in, label, + x_col='score', y_col='-log10(pvalue)', + size=2, size_txt="auto", t_x=.5, t_y=-0.1): self._label_by_color(ax, df_in, label, + x_col=x_col, y_col=y_col, size=size, size_txt=size_txt, edgecolors='black', facecolors='#3182bd', textcolor='black', t_x=t_x, t_y=t_y) - def label_resistance_hit(self, ax, df_in, label, size=2, size_txt="auto", + def label_resistance_hit(self, ax, df_in, label, + x_col='score', y_col='-log10(pvalue)', + size=2, size_txt="auto", t_x=.5, t_y=-0.1): self._label_by_color(ax, df_in, label, + x_col=x_col, y_col=y_col, size=size, size_txt=size_txt, edgecolors='black', facecolors='#de2d26', textcolor='black', From 19df3e43958a32536fcb70cfddcbfd7c695748ed Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 04:44:09 -0700 Subject: [PATCH 15/16] optional df as input --- screenpro/plotting.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/screenpro/plotting.py b/screenpro/plotting.py index beee440..318304a 100644 --- a/screenpro/plotting.py +++ b/screenpro/plotting.py @@ -210,13 +210,15 @@ def _volcano( def drawVolcanoRho( self, ax, + rho_df=None, dot_size=1, xlabel='auto', ylabel='-log10(pvalue)', xlims=(-5, 5), ylims=(0.1, 6) ): - _, _, rho_df = self._prep_data() + if rho_df is None: + _, _, rho_df = self._prep_data() if xlabel == 'auto': xlabel = self.rho_score_name.replace(':', ': ').replace('_', ' ') @@ -227,13 +229,15 @@ def drawVolcanoRho( def drawVolcanoGamma( self, ax, + gamma_df=None, dot_size=1, xlabel='auto', ylabel='-log10(pvalue)', xlims=(-5, 5), ylims=(0.1, 6) ): - gamma_df, _, _ = self._prep_data() + if gamma_df is None: + gamma_df, _, _ = self._prep_data() if xlabel == 'auto': xlabel = self.gamma_score_name.replace(':', ': ').replace('_', ' ') @@ -244,13 +248,15 @@ def drawVolcanoGamma( def drawVolcanoTau( self, ax, + tau_df=None, dot_size=1, xlabel='auto', ylabel='-log10(pvalue)', xlims=(-5, 5), ylims=(0.1, 6) ): - _, tau_df, _, = self._prep_data() + if tau_df is None: + _, tau_df, _, = self._prep_data() if xlabel == 'auto': xlabel = self.tau_score_name.replace(':', ': ').replace('_', ' ') From 8085b48130015f3afb241e7211e91e45a0e17580 Mon Sep 17 00:00:00 2001 From: "Abolfazl (Abe)" Date: Fri, 31 May 2024 05:17:01 -0700 Subject: [PATCH 16/16] bump version 0.3.4 --- screenpro/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screenpro/__init__.py b/screenpro/__init__.py index 4e4dabe..f795b93 100644 --- a/screenpro/__init__.py +++ b/screenpro/__init__.py @@ -9,6 +9,6 @@ from .ngs import Counter from .assays import PooledScreens, GImaps -__version__ = "0.3.3" +__version__ = "0.3.4" __author__ = "Abe Arab" __email__ = 'abea@arcinstitute.org' # "abarbiology@gmail.com"