-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for NetMHCstabpan (GH Issue #64) #167
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ htmlcov/ | |
.cache | ||
nosetests.xml | ||
coverage.xml | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from .base_commandline_predictor import BaseCommandlinePredictor | ||
from .parsing import parse_netmhcstabpan | ||
|
||
class NetMHCstabpan(BaseCommandlinePredictor): | ||
def __init__( | ||
self, | ||
alleles, | ||
default_peptide_lengths=[], | ||
program_name="netMHCstabpan", | ||
process_limit=-1, | ||
flags=[]): | ||
""" | ||
Wrapper for NetMHCstabpan. | ||
""" | ||
BaseCommandlinePredictor.__init__( | ||
self, | ||
program_name=program_name, | ||
alleles=alleles, | ||
default_peptide_lengths=default_peptide_lengths, | ||
parse_output_fn=parse_netmhcstabpan, | ||
supported_alleles_flag="-listMHC", | ||
input_file_flag="-f", | ||
length_flag="-l", | ||
allele_flag="-a", | ||
extra_flags=flags, | ||
process_limit=process_limit) | ||
|
||
def predict_peptides(self, peptides): | ||
peptide_lengths = set(len(p) for p in peptides) | ||
if len(peptide_lengths) > 1: | ||
raise ValueError("All peptides must be the same length") | ||
return super().predict_peptides(peptides) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from .common import approx_ | ||
from mhctools import NetMHCstabpan | ||
|
||
|
||
DEFAULT_ALLELE = 'HLA-A*02:01' | ||
|
||
# Protein sequences to test with against known values of netMHCstabpan web server. | ||
protein_sequences = [ | ||
"ALDKNLHQL", | ||
"ALHEEVVCV", | ||
"ALPPTVYEV", | ||
"AVLGSFSYV", | ||
"EMASVLFKA", | ||
] | ||
|
||
web_server_predictions = [ | ||
4.6393, | ||
10.6011, | ||
11.8201, | ||
4.6722, | ||
1.8404, | ||
] | ||
|
||
# REMINDER: a program called "netMHCstabpan" MUST be installed and working for | ||
# this test suite to succeeed. Also all peptides must be the same length. | ||
|
||
|
||
def test_netmhc_stabpan_accuracy(): | ||
# Check that the netMHCstabpan program is working and returning th eexpected outputs. | ||
predictor = NetMHCstabpan( | ||
alleles=[DEFAULT_ALLELE], program_name='netMHCstabpan' | ||
) | ||
|
||
binding_predictions = predictor.predict_peptides(protein_sequences) | ||
stability_predictions = [p.score for p in binding_predictions] | ||
rank_predictions = [p.percentile_rank for p in binding_predictions] | ||
|
||
assert len(web_server_predictions) == len(binding_predictions) | ||
assert len(stability_predictions) == len(binding_predictions) | ||
|
||
for prank in rank_predictions: | ||
# Make sure that correct mapping is done by checking percentiles aren't above 100. | ||
assert prank < 100 | ||
|
||
for i, (expected, actual) in enumerate(zip(web_server_predictions, stability_predictions)): | ||
# Check to make sure that the stability predictions are within 0.01 of the webserver values. | ||
# This could be the result of different versions of dependencies or the nature of the ANN itself. | ||
approx_(expected, actual, tol=0.01, msg="Peptide %d: expected %f but got %f" % (i, expected, actual)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest using numpy.testing.assert_allclose here rather than writing your own function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dhuvik I've been mercilessly rolling my own testing helpers so might be setting a bad precedent but agree with Tim There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Tim! Will go ahead and make that change |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to oblige @timodonnell and call numpy.testing.assert_allclose here?