# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import sys, os, glob
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
import logging
from scipy.interpolate import UnivariateSpline, interp1d
from statsmodels.stats.multicomp import pairwise_tukeyhsd, MultiComparison
from statsmodels.stats.libqsturng import psturng
import scipy.stats as stats

# logging.basicConfig(stream=sys.stdout, format='%(asctime)s - %(levelname)s - %(message)s', level=logging.DEBUG)
logging.basicConfig(stream=sys.stdout, format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)

# %matplotlib inline
font = {'family' : 'Arial',
        'size'   : 7}
matplotlib.rc('font', **font)
plt.rcParams['svg.fonttype'] = 'none'

# Make a folder if it is not already there to store exported figures
# !mkdir ../jupyter_figures

# +
# Read in measurements

df = pd.read_csv('../data/SMG-Cdh1-smFISH-quantification-summary/20171021-Cdh1-TMR-processingAll-Summary-4042-surface-layer-ROIs-14.txt', sep='\t')
df['area_type'] = ['Outer bud'] * len(df)
df['mRNA_density'] = df.inside_ROI / df.area_ROI * 100
df_OB1 = df
df

df = pd.read_csv('../data/SMG-Cdh1-smFISH-quantification-summary/20171021-Cdh1-TMR-processingAll-Summary-3531-bud-interior-ROIs-14.txt', sep='\t')
df['area_type'] = ['Inner bud'] * len(df)
df['mRNA_density'] = df.inside_ROI / df.area_ROI * 100
df_IB1 = df

df = pd.read_csv('../data/SMG-Cdh1-smFISH-quantification-summary/20171021-Cdh1-Atto655-processingAll-Summary-1598-surface-layer-ROIs.txt', sep='\t')
df['area_type'] = ['Outer bud'] * len(df)
df['mRNA_density'] = df.inside_ROI / df.area_ROI * 100
df_OB2 = df

df = pd.read_csv('../data/SMG-Cdh1-smFISH-quantification-summary/20171021-Cdh1-Atto655-processingAll-Summary-1526-bud-interior-ROIs.txt', sep='\t')
df['area_type'] = ['Inner bud'] * len(df)
df['mRNA_density'] = df.inside_ROI / df.area_ROI * 100
df_IB2 = df

df = pd.read_csv('../data/SMG-Cdh1-smFISH-quantification-summary/20170331-Cdh1-Quasar670-processingAll-Summary-9454-outer-layer-ROI.txt', sep='\t')
df['area_type'] = ['Outer bud'] * len(df)
df['mRNA_density'] = df.inside_ROI / df.area_ROI * 100
df_OB3 = df

df = pd.read_csv('../data/SMG-Cdh1-smFISH-quantification-summary/20170331-Cdh1-Quasar670-processingAll-Summary-4847-bud-interior-ROI.txt', sep='\t')
df['area_type'] = ['Inner bud'] * len(df)
df['mRNA_density'] = df.inside_ROI / df.area_ROI * 100
df_IB3 = df


# +
df_OB = pd.concat([df_OB1, df_OB2, df_OB3])
df_OB.reset_index(inplace=True)
# df_OB

df_IB = pd.concat([df_IB1, df_IB2, df_IB3])
df_IB.reset_index(inplace=True)
# df_IB

# -

# Paired ttest for the outer bud and inner bud mRNA density (measurements are related)
stats.ttest_rel(df_OB.mRNA_density, df_IB.mRNA_density)

df = pd.concat([df_OB1, df_IB1, df_OB2, df_IB2, df_OB3, df_IB3])
df.reset_index(inplace=True)
df

# +
outputPrefix = 'Cdh1-smFISH-related-scatterplot'
outputFigPath = "../jupyter_figures/" + outputPrefix + ".svg"

fig_width=1.8
fig_height=0.6
fig = plt.figure(figsize=(fig_width,fig_height), dpi=300)
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])

# sns.swarmplot(df.area_type, df.mRNA_density)
for file_name in df.file_name.unique():
    df_temp = df[df.file_name == file_name]
    sns.lineplot(data=df_temp, y='area_type', x='mRNA_density',
                 size=1,
                 color='gray',
                 legend=False,
                 estimator=None,
                 sort=False)
    sns.swarmplot(data=df_temp,
                  size=3,
                  color='white',
                  edgecolor='black',
                  linewidth=.7,
                  y='area_type', x='mRNA_density')

# plt.ylim(0, 4)
plt.xlim(0, 30)

plt.xlabel('Cdh1 mRNAs / 100 µm2')
plt.ylabel(None)

for o in fig.findobj():
    o.set_clip_on(False)
for o in ax.findobj():
    o.set_clip_on(False)

if outputFigPath is not None:
    plt.savefig(outputFigPath)

# -



StarcoderdataJupyterScriptsDedupFiltered