From 74856abaebf053c5f869efdcdbc1461f3979f8b0 Mon Sep 17 00:00:00 2001
From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr>
Date: Mon, 4 Jan 2021 09:26:48 +0100
Subject: [PATCH] src/find_interaction_cluster/nt_and_community.py: fix
 make_barplot_perm function

---
 src/find_interaction_cluster/nt_and_community.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/find_interaction_cluster/nt_and_community.py b/src/find_interaction_cluster/nt_and_community.py
index 838dc6a5..7ca5a53d 100644
--- a/src/find_interaction_cluster/nt_and_community.py
+++ b/src/find_interaction_cluster/nt_and_community.py
@@ -472,10 +472,13 @@ def make_barplot_perm(df_bar: pd.DataFrame, outfile: Path, cpnt_type: str,
     """
     sns.set(context="poster")
     df_ctrl = df_bar.loc[df_bar[f"id_{feature}"] == 'ctrl', :]
-    df_bar = df_bar.loc[df_bar[f"id_{feature}"] != 'ctrl', :]
-    g = sns.catplot(x="community", y=cpnt, data=df_bar, kind="bar",
+    df_bar = df_bar.loc[df_bar[f"id_{feature}"] != 'ctrl', :].copy()
+    g2 = sns.catplot(x="community", y=cpnt, data=df_bar, kind="bar",
                     ci="sd", aspect=2.5, height=14, errwidth=0.5, capsize=.4,
                     palette= ["darkgray"] * (df_bar.shape[0]))
+    g = sns.catplot(x="community", y=cpnt, data=df_bar, kind="point",
+                    ci="sd", aspect=2.5, height=14, errwidth=0.5, capsize=.4,
+                    scale=0.5, palette= ["darkgray"] * (df_bar.shape[0]))
     xrange = g.ax.get_xlim()
     df_ctrl.plot(x="community", y=cpnt, kind="scatter", ax=g.ax,
                  yerr= "ctrl_std", legend=False, zorder=10,
@@ -488,7 +491,7 @@ def make_barplot_perm(df_bar: pd.DataFrame, outfile: Path, cpnt_type: str,
     g.set(xticklabels=[])
     g.ax.set_ylabel(f'Frequency of {cpnt}')
     df_bara = df_bar.drop_duplicates(subset="community", keep="first")
-    for i, p in enumerate(g.ax.patches):
+    for i, p in enumerate(g2.ax.patches):
         stats = "*" if df_bara.iloc[i, :]["p-adj"] < 0.05 else ""
         com = df_bara.iloc[i, :]["community"]
         csd = np.std(df_bar.loc[df_bar["community"] == com, cpnt])
@@ -837,6 +840,7 @@ def multiple_nt_lm_launcher(ps: int,
               f"must be 'exon' not '{region}'. Setting it to exon. " \
               f"(corresponds to the concatenation of exons for all genes)"
         logging.warning(msg)
+        region = 'exon'
     logging.info(f"Checking if communities as an effect on {component_type} "
                  "frequency")
     project = get_projects(global_weight, project)
-- 
GitLab