@staticmethod<EOL><INDENT>def make_network(<EOL>allele_encoding_dims,<EOL>kmer_size,<EOL>peptide_amino_acid_encoding,<EOL>embedding_input_dim,<EOL>embedding_output_dim,<EOL>allele_dense_layer_sizes,<EOL>peptide_dense_layer_sizes,<EOL>peptide_allele_merge_method,<EOL>peptide_allele_merge_activation,<EOL>layer_sizes,<EOL>dense_layer_l1_regularization,<EOL>dense_layer_l2_regularization,<EOL>activation,<EOL>init,<EOL>output_activation,<EOL>dropout_probability,<EOL>batch_normalization,<EOL>embedding_init_method,<EOL>locally_connected_layers):<DEDENT>
<EOL>from keras.layers import Input<EOL>import keras.layers<EOL>from keras.layers.core import Dense, Flatten, Dropout<EOL>from keras.layers.embeddings import Embedding<EOL>from keras.layers.normalization import BatchNormalization<EOL>if peptide_amino_acid_encoding == "<STR_LIT>":<EOL><INDENT>peptide_input = Input(<EOL>shape=(kmer_size,), dtype='<STR_LIT>', name='<STR_LIT>')<EOL>current_layer = Embedding(<EOL>input_dim=embedding_input_dim,<EOL>output_dim=embedding_output_dim,<EOL>input_length=kmer_size,<EOL>embeddings_initializer=embedding_init_method,<EOL>name="<STR_LIT>")(peptide_input)<EOL><DEDENT>else:<EOL><INDENT>peptide_input = Input(<EOL>shape=(<EOL>kmer_size,<EOL>vector_encoding_length(peptide_amino_acid_encoding)),<EOL>dtype='<STR_LIT>',<EOL>name='<STR_LIT>')<EOL>current_layer = peptide_input<EOL><DEDENT>inputs = [peptide_input]<EOL>kernel_regularizer = None<EOL>l1 = dense_layer_l1_regularization<EOL>l2 = dense_layer_l2_regularization<EOL>if l1 > <NUM_LIT:0> or l2 > <NUM_LIT:0>:<EOL><INDENT>kernel_regularizer = keras.regularizers.l1_l2(l1, l2)<EOL><DEDENT>for (i, locally_connected_params) in enumerate(locally_connected_layers):<EOL><INDENT>current_layer = keras.layers.LocallyConnected1D(<EOL>name="<STR_LIT>" % i,<EOL>**locally_connected_params)(current_layer)<EOL><DEDENT>current_layer = Flatten(name="<STR_LIT>")(current_layer)<EOL>for (i, layer_size) in enumerate(peptide_dense_layer_sizes):<EOL><INDENT>current_layer = Dense(<EOL>layer_size,<EOL>name="<STR_LIT>" % i,<EOL>kernel_regularizer=kernel_regularizer,<EOL>activation=activation)(current_layer)<EOL><DEDENT>if batch_normalization:<EOL><INDENT>current_layer = BatchNormalization(name="<STR_LIT>")(<EOL>current_layer)<EOL><DEDENT>if dropout_probability:<EOL><INDENT>current_layer = Dropout(dropout_probability, name="<STR_LIT>")(<EOL>current_layer)<EOL><DEDENT>if allele_encoding_dims:<EOL><INDENT>allele_input = Input(<EOL>shape=allele_encoding_dims,<EOL>dtype='<STR_LIT>',<EOL>name='<STR_LIT>')<EOL>inputs.append(allele_input)<EOL>allele_embedding_layer = Flatten(name="<STR_LIT>")(allele_input)<EOL>for (i, layer_size) in enumerate(allele_dense_layer_sizes):<EOL><INDENT>allele_embedding_layer = Dense(<EOL>layer_size,<EOL>name="<STR_LIT>" % i,<EOL>kernel_regularizer=kernel_regularizer,<EOL>activation=activation)(allele_embedding_layer)<EOL><DEDENT>if peptide_allele_merge_method == '<STR_LIT>':<EOL><INDENT>current_layer = keras.layers.concatenate([<EOL>current_layer, allele_embedding_layer<EOL>], name="<STR_LIT>")<EOL><DEDENT>elif peptide_allele_merge_method == '<STR_LIT>':<EOL><INDENT>current_layer = keras.layers.multiply([<EOL>current_layer, allele_embedding_layer<EOL>], name="<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>% peptide_allele_merge_method)<EOL><DEDENT>if peptide_allele_merge_activation:<EOL><INDENT>current_layer = keras.layers.Activation(<EOL>peptide_allele_merge_activation,<EOL>name="<STR_LIT>" %<EOL>peptide_allele_merge_activation)(current_layer)<EOL><DEDENT><DEDENT>for (i, layer_size) in enumerate(layer_sizes):<EOL><INDENT>current_layer = Dense(<EOL>layer_size,<EOL>activation=activation,<EOL>kernel_regularizer=kernel_regularizer,<EOL>name="<STR_LIT>" % i)(current_layer)<EOL>if batch_normalization:<EOL><INDENT>current_layer = BatchNormalization(name="<STR_LIT>" % i)(current_layer)<EOL><DEDENT>if dropout_probability > <NUM_LIT:0>:<EOL><INDENT>current_layer = Dropout(<EOL>dropout_probability, name="<STR_LIT>" % i)(current_layer)<EOL><DEDENT><DEDENT>output = Dense(<EOL><NUM_LIT:1>,<EOL>kernel_initializer=init,<EOL>activation=output_activation,<EOL>name="<STR_LIT>")(current_layer)<EOL>model = keras.models.Model(<EOL>inputs=inputs,<EOL>outputs=[output],<EOL>name="<STR_LIT>")<EOL>return model<EOL>
Helper function to make a keras network for class1 affinity prediction.