<jupyter_start><jupyter_text>Loading Data<jupyter_code>!gunzip -v ../data/K562_2000_merged_histones_init.csv.gz -c > ../data/K562_2000_merged_histones_init.csv
import pandas as pd
from repli1d.nn import load_signal,transform_norm,train_test_split,transform_seq
name="../data/GM06990_2000_merged_histones_init.csv"
marks = [ "H3K4me1", "H3K4me3", "H3K27me3", "H3K36me3",
                         "H3K9me3","H2A.Z","H3K79me2","H3K9ac","H3K4me2","H3K27ac","H4K20me1"]
data = load_signal(name,
                                marks=marks,
                                targets=["initiation"],
                                 t_norm=transform_norm, smm=5,wig=False)
XC = pd.read_csv(name)  # List of chromosome coordinates
traint = ["chr%i"%i for i in [3,4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] +[20, 21, 22, 23]]
testv= ["chr1"]
train, test = train_test_split(XC, traint, testv, data["notnan"])
#X_train_us, y_train_us = df , yinit
X_train_us, X_test_us, y_train_us, y_test_us = data["df"][train], data["df"][test], data["yinit"][train], data["yinit"][test]

window=101
vtrain = transform_seq(X_train_us, y_train_us, mask_borders=data["mask_borders"], stepsize=1, width=window)
vtest= transform_seq(X_test_us, y_test_us,  mask_borders=data["mask_borders"], stepsize=1, width=window)
del data
#print(vtrain[0].shape,vtrain[1].shape)
from repli1d.nn import load_signal,transform_norm,train_test_split,transform_seq,window_stack<jupyter_output><empty_output><jupyter_text>Loading the networkcommand line to train it:```python src/repli1d/nn.py  --noenrichment --targets initiation --root training_dir/nn_K562_2000/ --listfile data/K562_2000_merged_histones_init.csv  --window 101 --wig 0 --predict_files data/K562_2000_merged_histones_init.csv --marks H3K4me1 H3K4me3 H3K27me3 H3K36me3 H3K9me3 H2A.Z H3K79me2 H3K9ac H3K4me2 H3K27ac H4K20me1 --datafile```<jupyter_code>import keras

model = keras.models.load_model("../data/nn_K562_2000_correct_split_Noneweights.04-0.0677.hdf5")
model.summary()
vtrain[0].shape
!head ../../jax_based_agent/notebooks/min_max_outputs.csv
#for batch in range(len(vtrain[0]))

from repli1d.nn import inv_transform
def binary_cross_entropy(true,pred):
    return -np.mean(true*np.log(pred+1e-7) + (1-true)*np.log(1-pred+1e-7))

which=["train:","test:"]
for i,ds in enumerate([vtrain,vtest]):
    #print(len(ds[0]))
    n=None
    data_start = model.predict(ds[0][:n])

    f=57.1294
    #f=1
    print(f"{which[i]}")
    print("MSE",np.mean((f*data_start-f*ds[1][:n])**2))
    print("Binary loss",binary_cross_entropy(ds[1][:n],data_start))
f=57.124;
s=10000
figure(figsize=(20,5))
plot(ds[1][100:]*f,label="target")
plot(data_start[100:]*f,label="NN prediction")
print(np.mean((f*data_start[:s]*1.15-f*ds[1][:s])**2))
xlim(0,s)
#ylim(0,2)
legend()
figure(figsize=(20,10))
cov = pd.read_csv("../data/hg19_2000_coverage.csv")
data = pd.read_csv("../data/K562_2000_merged_histones_init.csv")
plot(data[data.chrom=="chr1"].initiation,label="initiation")
plot(cov[cov.chrom=="chr1"].signal*4,label="coverage *4")
legend()
xlabel("Genomic pos / 2000kb")

len(data),len(cov)
len(cov[cov.signal==0]) 
from repli1d.analyse_RFD import cut_larger_than
import numpy as np
cut_larger_than(np.array([0,0,1,1,1,0,1,0,0,0]))<jupyter_output>[False  True False False  True  True  True False False]
[ 0  2  5  6  7 10]
[True, -1, True, -1, 0]
[2 3 1 1 3]
{'fraction_non_alphanumeric': 0.1705150976909414, 'fraction_numerical': 0.08259325044404973, 'mean_word_length': 5.36346516007533, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '521235', 'license': 'MIT', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1406, 'n_words': 223, 'path': 'notebook_demo/Running NN on marks.ipynb', 'repo_name': 'amir-zeraati/repli1D', 'size': '3378'}