<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Getting started with concise
Become familiar with Keras
In order to successfully use Concise, please make sure you are familiar with Keras. I strongly advise everyone to read the excellent Keras documentation first. As a Keras extension, Concise closely follows the Keras API.
Modules overview
Pre-processing functions
Encoding different objects into modeling-ready numpy arrays
concise.preprocessing
Custom Keras components
concise.layers
concise.initializers
concise.regularizers
concise.losses
concise.metrics
Hyper-parameter tuning
concise.hyopt
concise.eval_metrics
SNP-effect prediction
concise.effects
Other utilities
concise.utils
Example
Step1:  Concise is fully compatible with Keras; we can save and load the Keras models (note
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import matplotlib.pyplot as plt
import concise.layers as cl
import keras.layers as kl
import concise.initializers as ci
import concise.regularizers as cr
from keras.callbacks import EarlyStopping
from concise.preprocessing import encodeDNA
from keras.models import Model, load_model
# get the data
def load(split="train", st=None):
    dt = pd.read_csv("../data/RBP/PUM2_{0}.csv".format(split))
    # DNA/RNA sequence
    xseq = encodeDNA(dt.seq) # list of sequences -> np.ndarray
    # response variable
    y = dt.binding_site.as_matrix().reshape((-1, 1)).astype("float")
    return {"seq": xseq}, y
train, valid, test = load("train"), load("valid"), load("test")
# extract sequence length
seq_length = train[0]["seq"].shape[1]
# get the PWM list for initialization
from concise.data import attract
dfa = attract.get_metadata() # table with PWM meta-info
dfa_pum2 = dfa[dfa.Gene_name.str.match("PUM2") & \
               dfa.Organism.str.match("Homo_sapiens") & \
               (dfa.Experiment_description == "genome-wide in vivo immunoprecipitation")]
pwm_list = attract.get_pwm_list(dfa_pum2.PWM_id.unique()) # retrieve the PWM by id
print(pwm_list)
# specify the model
in_dna = cl.InputDNA(seq_length=seq_length, name="seq") # Convenience wrapper around keras.layers.Input()
x = cl.ConvDNA(filters=4, # Convenience wrapper around keras.layers.Conv1D()
               kernel_size=8, 
               kernel_initializer=ci.PSSMKernelInitializer(pwm_list), # intialize the filters on the PWM values
               activation="relu",
               name="conv1")(in_dna)
x = kl.AveragePooling1D(pool_size=4)(x)
x = kl.Flatten()(x)
x = kl.Dense(units=1)(x)
m = Model(in_dna, x)
m.compile("adam", loss="binary_crossentropy", metrics=["acc"])
# train the model
m.fit(train[0], train[1], epochs=5);
Explanation: Getting started with concise
Become familiar with Keras
In order to successfully use Concise, please make sure you are familiar with Keras. I strongly advise everyone to read the excellent Keras documentation first. As a Keras extension, Concise closely follows the Keras API.
Modules overview
Pre-processing functions
Encoding different objects into modeling-ready numpy arrays
concise.preprocessing
Custom Keras components
concise.layers
concise.initializers
concise.regularizers
concise.losses
concise.metrics
Hyper-parameter tuning
concise.hyopt
concise.eval_metrics
SNP-effect prediction
concise.effects
Other utilities
concise.utils
Example: RBP binding model in concise
Here we will show a simple use-case with Concise. We will predict the eCLIP binding peaks of the RNA-binding protein (RBP) PUM2.
eCLIP raw data ENCODE
eCLIP paper Van Nostrand et al, Nature Meth. 2016
paper also using this data: Avsec et al, Bioarxiv 2017
End of explanation
# save the model
m.save("/tmp/model.h5")
# load the model
m2 = load_model("/tmp/model.h5")
# Convenience layers extend the base class (here keras.layers.Conv1D) with .plot_weights for filter visualization
m.get_layer("conv1").plot_weights(plot_type="motif_pwm_info", figsize=(4, 6));
Explanation: Concise is fully compatible with Keras; we can save and load the Keras models (note: concise package needs to be imported before loading: import concise...).
End of explanation
<END_TASK>