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

import NotebookImport
from DX_by_cancer_short import *

# cd ../DX/Notebooks/

from Immune_Stroma_Scoring import *

vc = codes.ix[matched_rna.columns.get_level_values(0).unique()].value_counts()
vc.sum()

cancers = ti(vc > 40)

pd.DataFrame({c: spearman_pandas(rr.p, t_h[c] - t_m[c]) for c in cancers}).T.sort('p')

#Do not import
fig, axs = subplots(3,3, figsize=(9,9), sharex=True, sharey=True)
axs = axs.flatten()
for i,c in enumerate(cancers):
    ax = axs[i]
    s1, s2 = match_series(t_h[c].dropna(), t_m[c].dropna())
    s1.ix[ti(immune>0)].hist(bins=10, ax=ax)
    ax.set_xlabel(c)
    ax.set_ylabel('Density');
sns.despine(fig)
fig.tight_layout()

#Do not import
fig, axs = subplots(3,3, figsize=(9,9), sharex=True, sharey=True)
axs = axs.flatten()
for i,c in enumerate(cancers):
    ax = axs[i]
    s1, s2 = match_series(t_h[c].dropna(), t_m[c].dropna())
    s1.ix[ti(stromal>0)].hist(bins=10, ax=ax)
    ax.set_xlabel(c)
    ax.set_ylabel('Density');
sns.despine(fig)
fig.tight_layout()

# +
m2 = matched_tn.ix[:, ti(immune_score_dx > 0)]

dx2 = {c: dx_group(codes==c, m2) for c in cancers}
dx2 = pd.concat(dx2, axis=1)
dx2 = dx2.ix[dx_rna.index]
# -

t_m2 = dx2.xs(('miss','frac'), axis=1, level=[1,2])
t_h2 = dx2.xs(('hit','frac'), axis=1, level=[1,2])
num_dx2 = dx2.xs(('hit','num_dx'), axis=1, level=[1,2])
t_m2 = t_m2.mask(num_dx < 30)



StarcoderdataJupyterScriptsDedupFiltered