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

optimization

parent b4f63aea
No related branches found
No related tags found
No related merge requests found
...@@ -848,20 +848,29 @@ class Class1AffinityPredictor(object): ...@@ -848,20 +848,29 @@ class Class1AffinityPredictor(object):
(min_peptide_length, max_peptide_length) = ( (min_peptide_length, max_peptide_length) = (
self.supported_peptide_lengths) self.supported_peptide_lengths)
df["supported_peptide_length"] = (
(df.peptide.str.len() >= min_peptide_length) & if (peptides.min_length < min_peptide_length or
(df.peptide.str.len() <= max_peptide_length)) peptides.max_length > max_peptide_length):
if (~df.supported_peptide_length).any(): # Only compute this if needed
msg = ( all_peptide_lengths_supported = False
"%d peptides have lengths outside of supported range [%d, %d]: " df["supported_peptide_length"] = (
"%s" % ( (df.sequence_length.len() >= min_peptide_length) &
(~df.supported_peptide_length).sum(), (df.sequence_length.len() <= max_peptide_length))
min_peptide_length, if (~df.supported_peptide_length).any():
max_peptide_length, msg = (
str(df.ix[~df.supported_peptide_length].peptide.unique()))) "%d peptides have lengths outside of supported range [%d, %d]: "
logging.warning(msg) "%s" % (
if throw: (~df.supported_peptide_length).sum(),
raise ValueError(msg) min_peptide_length,
max_peptide_length,
str(df.ix[~df.supported_peptide_length].peptide.unique())))
logging.warning(msg)
if throw:
raise ValueError(msg)
else:
# Handle common case efficiently.
df["supported_peptide_length"] = True
all_peptide_lengths_supported = True
if self.class1_pan_allele_models: if self.class1_pan_allele_models:
unsupported_alleles = [ unsupported_alleles = [
...@@ -904,12 +913,16 @@ class Class1AffinityPredictor(object): ...@@ -904,12 +913,16 @@ class Class1AffinityPredictor(object):
logging.warning(msg) logging.warning(msg)
if throw: if throw:
raise ValueError(msg) raise ValueError(msg)
for allele in query_alleles: for allele in query_alleles:
models = self.allele_to_allele_specific_models.get(allele, []) models = self.allele_to_allele_specific_models.get(allele, [])
mask = ( if len(query_alleles) == 1 and all_peptide_lengths_supported:
(df.normalized_allele == allele) & mask = None
df.supported_peptide_length).values else:
if mask.all(): mask = (
(df.normalized_allele == allele) &
df.supported_peptide_length).values
if mask is None or mask.all():
# Common case optimization # Common case optimization
for (i, model) in enumerate(models): for (i, model) in enumerate(models):
df["model_single_%d" % i] = model.predict(peptides) df["model_single_%d" % i] = model.predict(peptides)
......
...@@ -39,6 +39,8 @@ class EncodableSequences(object): ...@@ -39,6 +39,8 @@ class EncodableSequences(object):
"sequence": numpy.array(sequences), "sequence": numpy.array(sequences),
"sequence_length": numpy.array(sequences), "sequence_length": numpy.array(sequences),
}) })
self.min_length = self.sequences_df.sequence_length.min()
self.max_length = self.sequences_df.sequence_length.max()
self.sequences = self.sequences_df.sequence.values self.sequences = self.sequences_df.sequence.values
self.encoding_cache = {} self.encoding_cache = {}
self.fixed_sequence_length = None self.fixed_sequence_length = None
......
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