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

# +
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.metrics import mean_squared_error
from sklearn.utils import shuffle
import keras

marks = ["H3K4me1", "H3K4me3", "H3K27me3", "H3K36me3",
         "H3K9me3", "H2A.Z", "H3K79me2", "H3K9ac", "H3K4me2", "H3K27ac", "H4K20me1"]
df = pd.read_csv(
    '../data/K562_2000_merged_histones_init.csv.gz', compression='gzip')
masks = pd.read_csv('../data/hg19_2000_no_N_inside.csv')
print('Number of NANs is {}'.format(masks['signal'].sum()))
df.loc[~masks['signal'].astype(bool)] = np.nan
df = df.dropna()
print(df)
for i in marks:
    df[i] = df[i] + np.min(df[i][(df[i] != 0)])
    df[i] = np.log10(df[i])
X = df.loc[:, marks].to_numpy()

X_train = df.loc[df['chrom'] != 'chr1', marks].to_numpy()
print(X_train.shape)
y_train = df.loc[df['chrom'] != 'chr1', ['initiation']].to_numpy()
print(y_train.shape)
X_test = df.loc[df['chrom'] == 'chr1', marks].to_numpy()
y_test = df.loc[df['chrom'] == 'chr1', ['initiation']].to_numpy()
print(X)
model = keras.models.load_model("../development/log to raw FCNNFCNN_K562_marks.mdl_wts.hdf5")
predicted = model.predict(X_train)
print(mean_squared_error(predicted, y_train))
print(mean_squared_error(model.predict(X_test), y_test))
# predicted1 = regr.predict(X)
# dfp = pd.DataFrame(predicted1, index=df.index, columns=['predicted'])
# df['predicted'] = predicted1
# print(dfp.shape, df.shape)
# fig = go.Figure()
# fig.add_trace(go.Scatter(x=list(df.index[df['chrom'] == 'chr1']*2000),
#     y=list(df.loc[df['chrom'] == 'chr1', 'initiation']), name='PODLS'))
# fig.add_trace(go.Scatter(x=list(df.index[df['chrom'] == 'chr1']*2000),
#     y=list(df.loc[df['chrom'] == 'chr1', 'predicted']), name='Predictions from RF'))
# fig.add_trace(go.Scatter(x=list(df.index[df['chrom'] == 'chr1']*2000), 
#     y=list(np.abs(df.loc[df['chrom'] == 'chr1', 'predicted'].to_numpy()-df.loc[df['chrom'] == 'chr1',
#         'initiation'].to_numpy())), name='Absolute error'))

StarcoderdataJupyterScriptsDedupFiltered