diff --git a/mhcflurry/class1_affinity_prediction/class1_affinity_predictor.py b/mhcflurry/class1_affinity_prediction/class1_affinity_predictor.py index 69615774a2b1f4b0ac7642948241bd0782441ec8..a3861cb263428836e469fabe4505caac8e791c23 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 336e20b903ae2975b90f77609f5e667216d5ff44..8738ba02affde9130a7a47de39b0d5da339825cb 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 757af4268dcdedeaf01b97c2da943f96541f2099..d1773b9a4097667b2f28faafd88b79ec886ee611 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 42f50f456e7681ccd930fdeec785af26ea4d2e17..1770e5366b23031d063710d0aadf2bee10049c4c 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