From 94f4c43719192f08047b433be735086d803f5620 Mon Sep 17 00:00:00 2001 From: Tim O'Donnell <timodonnell@gmail.com> Date: Mon, 22 May 2017 21:56:21 -0400 Subject: [PATCH] update requirements --- .../class1_affinity_predictor.py | 74 +++++++++---------- .../class1_neural_network.py | 17 ++++- requirements.txt | 2 +- setup.py | 3 +- 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/mhcflurry/class1_affinity_prediction/class1_affinity_predictor.py b/mhcflurry/class1_affinity_prediction/class1_affinity_predictor.py index 69615774..a3861cb2 100644 --- a/mhcflurry/class1_affinity_prediction/class1_affinity_predictor.py +++ b/mhcflurry/class1_affinity_prediction/class1_affinity_predictor.py @@ -16,42 +16,6 @@ from ..downloads import get_path from .class1_neural_network import Class1NeuralNetwork -class LazyLoadingClass1NeuralNetwork(object): - @classmethod - def wrap(cls, instance): - if isinstance(instance, cls): - return instance - elif isinstance(instance, Class1NeuralNetwork): - return cls(model=instance) - raise TypeError("Unsupported type: %s" % instance) - - @classmethod - def wrap_list(cls, lst): - return [ - cls.wrap(instance) - for instance in lst - ] - - def __init__(self, model=None, config=None, weights_filename=None): - if model is None: - assert config is not None - assert weights_filename is not None - else: - assert config is None - assert weights_filename is None - - self.model = model - self.config = config - self.weights_filename = weights_filename - - @property - def instance(self): - if self.model is None: - self.model = Class1NeuralNetwork.from_config(self.config) - self.model.restore_weights(self.weights_filename) - return self.model - - class Class1AffinityPredictor(object): def __init__( self, @@ -339,4 +303,40 @@ class Class1AffinityPredictor(object): columns = [ c for c in df.columns if c not in df_predictions.columns ] - return df[columns] \ No newline at end of file + return df[columns] + + +class LazyLoadingClass1NeuralNetwork(object): + @classmethod + def wrap(cls, instance): + if isinstance(instance, cls): + return instance + elif isinstance(instance, Class1NeuralNetwork): + return cls(model=instance) + raise TypeError("Unsupported type: %s" % instance) + + @classmethod + def wrap_list(cls, lst): + return [ + cls.wrap(instance) + for instance in lst + ] + + def __init__(self, model=None, config=None, weights_filename=None): + if model is None: + assert config is not None + assert weights_filename is not None + else: + assert config is None + assert weights_filename is None + + self.model = model + self.config = config + self.weights_filename = weights_filename + + @property + def instance(self): + if self.model is None: + self.model = Class1NeuralNetwork.from_config(self.config) + self.model.restore_weights(self.weights_filename) + return self.model \ No newline at end of file diff --git a/mhcflurry/class1_affinity_prediction/class1_neural_network.py b/mhcflurry/class1_affinity_prediction/class1_neural_network.py index 336e20b9..8738ba02 100644 --- a/mhcflurry/class1_affinity_prediction/class1_neural_network.py +++ b/mhcflurry/class1_affinity_prediction/class1_neural_network.py @@ -257,6 +257,7 @@ class Class1NeuralNetwork(object): peptides : EncodableSequences or list of string affinities : list of float + nM affinities. Must be same length of as peptides. allele_pseudosequences : EncodableSequences or list of string, optional If not specified, the model will be a single-allele predictor. @@ -407,15 +408,18 @@ class Class1NeuralNetwork(object): def predict(self, peptides, allele_pseudosequences=None): """ + Predict affinities Parameters ---------- - peptides - allele_pseudosequences + peptides : EncodableSequences or list of string + + allele_pseudosequences : EncodableSequences or list of string, optional + Only required when this model is a pan-allele model Returns ------- - + numpy.array of nM affinity predictions """ x_dict = { 'peptide': self.peptides_to_network_input(peptides) @@ -428,6 +432,9 @@ class Class1NeuralNetwork(object): return to_ic50(predictions) def compile(self): + """ + Compile the keras model. Used internally. + """ self.network.compile( **self.compile_hyperparameter_defaults.subselect( self.hyperparameters)) @@ -450,7 +457,9 @@ class Class1NeuralNetwork(object): batch_normalization, embedding_init_method, locally_connected_layers): - + """ + Helper function to make a keras network for class1 affinity prediction. + """ if use_embedding: peptide_input = Input( shape=(kmer_size,), dtype='int32', name='peptide') diff --git a/requirements.txt b/requirements.txt index 757af426..d1773b9a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,8 +6,8 @@ keras scikit-learn h5py typechecks -pepdata joblib cherrypy bottle six +mhcnames diff --git a/setup.py b/setup.py index 42f50f45..1770e536 100644 --- a/setup.py +++ b/setup.py @@ -57,9 +57,8 @@ if __name__ == '__main__': 'scikit-learn', 'h5py', 'typechecks', - 'pepdata', - 'bottle', 'six', + 'mhcnames', ] if PY2: # concurrent.futures is a standard library in Py3 but Py2 -- GitLab