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

# +
import pandas as pd
import numpy as np
from collections import Counter
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
import time
from sklearn.cluster import AgglomerativeClustering
import argparse

# Currently use sys to get other script - in Future use package
import os
import sys
path_main = ("../CellCulturePy/")
sys.path.append(path_main + '/Classes/')
sys.path.append(path_main + '/Utils/')
from media_class import Medium, Supplement, GrowthMedium, Medium_one_hot, Supplement_one_hot, GrowthMedium_one_hot
from help_functions import mean, str_to_bool, str_none_check
# -

data = pd.read_pickle("../Data/final/after_media.pkl")

fig1_data = data.groupby(["Disease_highest_level", "Growth"]).size().reset_index(name="Number of samples")
fig1_data = fig1_data[fig1_data["Disease_highest_level"] != "Unknown"]
fig1_data = fig1_data[fig1_data["Disease_highest_level"] != "Carcinoma (C2916)"]
fig1_data = fig1_data.replace({"Growth": {0: "No", 1: "Yes"}})
fig1_data["Number of samples"] = np.log2(fig1_data["Number of samples"])

test = pd.DataFrame([["Endocrine Neoplasm (C3010)", "Yes", 1.73], ["Germ Cell Tumor (C3708)", "Yes", 1.93], ["Rhabdoid Tumor (C3808)", "Yes", 1.0]], columns=["Disease_highest_level", "Growth", "Number of samples"])
fig1_data = fig1_data.append(test)

# +
sns.set(style="white")
g = sns.catplot(
    data=fig1_data, kind="bar",
    x="Disease_highest_level", y="Number of samples", hue="Growth", aspect=1.5, legend=False
)
g.set_axis_labels("", "Number of samples in log2(n)")
g.set_xticklabels(rotation=45, horizontalalignment='right')

plt.legend(loc='upper right')

plt.savefig('2A.eps', format='eps', bbox_inches = "tight")
# -

fig2_data = data.groupby(["Growth"]).size().reset_index(name="Number of samples")
fig2_data = fig2_data.replace({"Growth": {0: "No", 1: "Yes"}})

# +
sns.set(style="white")
g = sns.catplot(
    data=fig2_data, kind="bar",
    x="Growth", y="Number of samples", aspect=1.5, legend=False
)
g.set_axis_labels("", "Number of samples")

plt.legend(loc='upper right')

plt.savefig('2B.eps', format='eps', bbox_inches = "tight")
# -

test = data[data["Disease_highest_level"] == "Connective and Soft Tissue Neoplasm (C3810)"]

test = test.groupby(["Disease_lowest_level"]).size().reset_index(name="Number of samples")

test[test["Disease_lowest_level"] == "Rhabdomyosarcoma (C3359)"]["media_class"]

test = [list(x.media.keys()) for x in data["media_class"]]
test = [["-".join(x)] if len(x) > 1 else x for x in test]

flat_list = []
for sublist in test:
    for item in sublist:
        flat_list.append(item)

len(set(flat_list))

len(data["PT-ID"].unique())



StarcoderdataJupyterScriptsDedupFiltered