Skip to content
Snippets Groups Projects
Commit 94f4c437 authored by Tim O'Donnell's avatar Tim O'Donnell
Browse files

update requirements

parent a9abf6a5
No related branches found
No related tags found
No related merge requests found
...@@ -16,42 +16,6 @@ from ..downloads import get_path ...@@ -16,42 +16,6 @@ from ..downloads import get_path
from .class1_neural_network import Class1NeuralNetwork 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): class Class1AffinityPredictor(object):
def __init__( def __init__(
self, self,
...@@ -339,4 +303,40 @@ class Class1AffinityPredictor(object): ...@@ -339,4 +303,40 @@ class Class1AffinityPredictor(object):
columns = [ columns = [
c for c in df.columns if c not in df_predictions.columns c for c in df.columns if c not in df_predictions.columns
] ]
return df[columns] return df[columns]
\ No newline at end of file
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
...@@ -257,6 +257,7 @@ class Class1NeuralNetwork(object): ...@@ -257,6 +257,7 @@ class Class1NeuralNetwork(object):
peptides : EncodableSequences or list of string peptides : EncodableSequences or list of string
affinities : list of float affinities : list of float
nM affinities. Must be same length of as peptides.
allele_pseudosequences : EncodableSequences or list of string, optional allele_pseudosequences : EncodableSequences or list of string, optional
If not specified, the model will be a single-allele predictor. If not specified, the model will be a single-allele predictor.
...@@ -407,15 +408,18 @@ class Class1NeuralNetwork(object): ...@@ -407,15 +408,18 @@ class Class1NeuralNetwork(object):
def predict(self, peptides, allele_pseudosequences=None): def predict(self, peptides, allele_pseudosequences=None):
""" """
Predict affinities
Parameters Parameters
---------- ----------
peptides peptides : EncodableSequences or list of string
allele_pseudosequences
allele_pseudosequences : EncodableSequences or list of string, optional
Only required when this model is a pan-allele model
Returns Returns
------- -------
numpy.array of nM affinity predictions
""" """
x_dict = { x_dict = {
'peptide': self.peptides_to_network_input(peptides) 'peptide': self.peptides_to_network_input(peptides)
...@@ -428,6 +432,9 @@ class Class1NeuralNetwork(object): ...@@ -428,6 +432,9 @@ class Class1NeuralNetwork(object):
return to_ic50(predictions) return to_ic50(predictions)
def compile(self): def compile(self):
"""
Compile the keras model. Used internally.
"""
self.network.compile( self.network.compile(
**self.compile_hyperparameter_defaults.subselect( **self.compile_hyperparameter_defaults.subselect(
self.hyperparameters)) self.hyperparameters))
...@@ -450,7 +457,9 @@ class Class1NeuralNetwork(object): ...@@ -450,7 +457,9 @@ class Class1NeuralNetwork(object):
batch_normalization, batch_normalization,
embedding_init_method, embedding_init_method,
locally_connected_layers): locally_connected_layers):
"""
Helper function to make a keras network for class1 affinity prediction.
"""
if use_embedding: if use_embedding:
peptide_input = Input( peptide_input = Input(
shape=(kmer_size,), dtype='int32', name='peptide') shape=(kmer_size,), dtype='int32', name='peptide')
......
...@@ -57,9 +57,8 @@ if __name__ == '__main__': ...@@ -57,9 +57,8 @@ if __name__ == '__main__':
'scikit-learn', 'scikit-learn',
'h5py', 'h5py',
'typechecks', 'typechecks',
'pepdata',
'bottle',
'six', 'six',
'mhcnames',
] ]
if PY2: if PY2:
# concurrent.futures is a standard library in Py3 but Py2 # concurrent.futures is a standard library in Py3 but Py2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment