# Reviewer diagnostics from per_subclass.csv: excess range, cross-brain reliability of excess.
import sys, numpy as np, pandas as pd
from scipy.stats import spearmanr
t = pd.read_csv(sys.argv[1], index_col=0)
print("n", len(t), "excess range", t.excess.min(), t.excess.max(), "sd", t.excess.std())
print("abs excess > 0.04:", (t.excess.abs() > 0.04).sum())
for b in ["zhuang1","zhuang2","zhuang3","zhuang4"]:
    m = t[f"n_{b}"] >= 200
    r = spearmanr(t.excess[m], t[f"excess_{b}"][m])
    print(b, "units", m.sum(), "rho(excess_allen, excess_b)", round(r.statistic,3), "p", r.pvalue)
z = ["excess_zhuang1","excess_zhuang2","excess_zhuang3"]
m = (t[["n_zhuang1","n_zhuang2","n_zhuang3"]] >= 200).all(axis=1)
print("pairwise among zhuang1-3:", spearmanr(t.loc[m, z]).statistic.round(3).tolist())
print("rho(excess, pericyte excess)", spearmanr(t.excess, t.excess_pericyte).statistic)
print("rho(E, n)", spearmanr(t.E, t.n).statistic, "rho(excess,n)", spearmanr(t.excess, t.n).statistic)
print(t.groupby("class").agg(E=("E","mean"), excess=("excess","mean"), k=("E","size")).sort_values("E").round(3).to_string())
