<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Estimation of the number of quiescent cells
Adding intra and interexperimental error. In the future maybe better do bootstrapping.
Step1:  Check for significant differences
Let $N_q$ be the total number of quiescent cells in the spatial zone reaching from $-800\mu m$ to the posterior tip of the spinal cord and $l_{cell}$ the anteroposterior length of the cells, $N_{q,s}$ the mean number of quiescent cells per cross section and $L$ the outgrowth of the spinal cord and $L_0$ the source zone length. Then, the following euqation holds
Step2:  ttest vs day0
Step3:  Plot
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import scipy as sp
from scipy import stats
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
exec(open('settings.py').read(), globals())
cell_numbers = pd.read_csv('../data/cell_number_data.csv')
outgrowth = pd.read_csv('../data/outgrowth.csv')
lcell = 13.2
lcell_sem = 0.1
L0 = 800.0
cell_numbers = cell_numbers.query('pos > -@L0')
cell_numbers['quiescent'] = cell_numbers['SOX2'] - cell_numbers['PCNA']
cell_numbers_space_mean = cell_numbers[['ID', 'time', 'quiescent']].groupby('ID').agg({'time': ['mean'], 'quiescent': ['mean', 'sem']})
cell_numbers_mean = cell_numbers_space_mean.groupby([('time', 'mean')]).agg({('quiescent', 'mean'): ['mean', 'sem'], ('quiescent', 'sem'): ['mean']})
cell_numbers_mean['quiescent_delta'] = cell_numbers_mean['quiescent', 'mean', 'sem'] + cell_numbers_mean['quiescent', 'sem', 'mean']
cell_numbers_mean.index.name = 'time'
cell_numbers_mean['outgrowth'] = outgrowth.groupby('time').mean()['length']
cell_numbers_mean['outgrowth_sem'] = outgrowth.groupby('time').sem()['length']
for i, row in cell_numbers_space_mean.iterrows():
    cell_numbers_space_mean.loc[i, 'outgrowth'] =     float(outgrowth.groupby('time').mean().loc[int(row['time'])])
    cell_numbers_space_mean.loc[i, 'outgrowth_sem'] = float(outgrowth.groupby('time').sem()['length'].loc[int(row['time'])])
cell_numbers_space_mean
Nq = pd.DataFrame(index = cell_numbers_mean.index)
Nq['mean'] = (cell_numbers_mean['outgrowth'] + L0) / lcell * cell_numbers_mean['quiescent', 'mean', 'mean']
Nq['delta'] = Nq['mean'] * (lcell_sem / lcell + cell_numbers_mean['outgrowth_sem'] / cell_numbers_mean['outgrowth'] + cell_numbers_mean['quiescent', 'mean', 'sem'] / cell_numbers_mean['quiescent', 'mean', 'mean'])
Nq.loc[0, 'delta'] = Nq.loc[0, 'mean'] * ((lcell_sem / lcell + float(cell_numbers_mean.loc[0, ('quiescent', 'mean', 'sem')]) / cell_numbers_mean.loc[0, ('quiescent', 'mean', 'mean')]))
Nq
Explanation: Estimation of the number of quiescent cells
Adding intra and interexperimental error. In the future maybe better do bootstrapping.
End of explanation
day = dict()
for time in Nq.index:
    day[time] = sp.array(cell_numbers_space_mean[cell_numbers_space_mean['time', 'mean'] == time]['quiescent', 'mean'])
    day[time] = day[time] * (float(outgrowth.groupby('time').mean().loc[time]) + L0)
Explanation: Check for significant differences
Let $N_q$ be the total number of quiescent cells in the spatial zone reaching from $-800\mu m$ to the posterior tip of the spinal cord and $l_{cell}$ the anteroposterior length of the cells, $N_{q,s}$ the mean number of quiescent cells per cross section and $L$ the outgrowth of the spinal cord and $L_0$ the source zone length. Then, the following euqation holds:
\begin{align}
N_q = N_{q,s} \frac{L + L_0}{l_{cell}}
\end{align}
As $l_{cell}$ is constant (Rodrigo Albors, Tazaki et al., eLife, 2015) we test if 
\begin{align}
N_q \cdot l_{cell} = N_{q,s} (L + L_0)
\end{align}
is significantly different to infer if $N_q$ is significantly different.
End of explanation
for time in Nq.index:
    print 'Day 0 vs Day {0}: p = {1:.2f}'.format(time, sp.stats.ttest_ind(day[0], day[time]).pvalue)
Explanation: ttest vs day0
End of explanation
from matplotlib.markers import TICKDOWN
def significance_bar(start,end,height,displaystring,linewidth = 1,markersize = 3,boxpad  =0.3,fontsize = 12,color = 'k'):
    # draw a line with downticks at the ends
    plt.plot([start,end],[height]*2,'-',color = color,lw=linewidth,marker = TICKDOWN,markeredgewidth=linewidth,markersize = markersize)
    # draw the text with a bounding box covering up the line
    plt.text(0.5*(start+end),height,displaystring,ha = 'center',va='center',size = fontsize)
fig, ax = plt.subplots(1, figsize = (1, 31.5/25.0))
ax.errorbar(Nq.index,\
            Nq['mean'],
            Nq['delta'],
            fmt = 'ko', ls = '-')
significance_bar(0, 4, 305.0, '*')
significance_bar(0, 6, 340.0, '*')
ax.set_xlim(-0.7, 8.7)
ax.set_ylim(0, 370)
ax.set_yticks(sp.arange(0, 350, 100))
ax.set_xlabel('Time (days)')
ax.set_ylabel('# SOX2+/PCNA- cells', labelpad = 8)
plt.savefig('../figure_plots/Fig2_total_number_quiescent.svg')
plt.show()
Explanation: Plot
End of explanation
<END_TASK>