Skip to content

Commit

Permalink
Merge pull request #1028 from griffithlab/revert-988-mhcflurry
Browse files Browse the repository at this point in the history
Revert "Run MHCflurry in code instead of from the command line"
  • Loading branch information
susannasiebert authored Sep 26, 2023
2 parents 8ac2846 + d35552b commit 71ac9b2
Show file tree
Hide file tree
Showing 3 changed files with 2,810 additions and 2,814 deletions.
46 changes: 21 additions & 25 deletions pvactools/lib/prediction_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
from Bio import SeqIO
import random
import uuid
from mhcflurry.downloads import get_default_class1_presentation_models_dir
from mhcflurry.class1_presentation_predictor import Class1PresentationPredictor
import numpy

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

class IEDB(metaclass=ABCMeta):
@classmethod
Expand Down Expand Up @@ -323,28 +318,29 @@ def predict(self, input_file, allele, epitope_length, iedb_executable_path, iedb

all_epitopes = list(set(all_epitopes))
if len(all_epitopes) > 0:
models_dir = get_default_class1_presentation_models_dir(test_exists=True)
predictor = Class1PresentationPredictor.load(models_dir)
df = predictor.predict(
peptides=numpy.array(all_epitopes, dtype='object'),
n_flanks=None,
c_flanks=None,
alleles={allele: [allele]},
throw=True,
include_affinity_percentile=True,
verbose=0
)
tmp_output_file = tempfile.NamedTemporaryFile('r', dir=tmp_dir, delete=False)
arguments = ["mhcflurry-predict", "--alleles", allele, "--out", tmp_output_file.name, "--peptides"]
arguments.extend(all_epitopes)
stderr_fh = tempfile.NamedTemporaryFile('w', dir=tmp_dir, delete=False)
try:
response = run(arguments, check=True, stdout=DEVNULL, stderr=stderr_fh)
except:
stderr_fh.close()
with open(stderr_fh.name, 'r') as fh:
err = fh.read()
os.unlink(stderr_fh.name)
raise Exception("An error occurred while calling MHCflurry:\n{}".format(err))
stderr_fh.close()
os.unlink(stderr_fh.name)
tmp_output_file.close()
df = pd.read_csv(tmp_output_file.name)
os.unlink(tmp_output_file.name)
df.rename(columns={
'prediction': 'ic50',
'affinity': 'ic50',
'prediction_percentile': 'percentile',
'affinity_percentile': 'percentile',
'processing_score': 'mhcflurry_processing_score',
'presentation_score': 'mhcflurry_presentation_score',
'presentation_percentile': 'mhcflurry_presentation_percentile',
'best_allele': 'allele',
'mhcflurry_prediction': 'ic50',
'mhcflurry_affinity': 'ic50',
'mhcflurry_prediction_percentile': 'percentile',
'mhcflurry_affinity_percentile': 'percentile'
}, inplace=True)
df.drop(labels='peptide_num', axis=1, inplace=True)
for record in SeqIO.parse(input_file, "fasta"):
seq_num = record.id
peptide = str(record.seq)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_call_iedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def test_mhcflurry_method_generates_expected_files(self):
])
if sys.platform == 'darwin':
expected_output_file = os.path.join(self.test_data_dir, 'output_mhcflurry_osx.tsv')
expected_df = pd.read_csv(expected_output_file, sep="\t", index_col=[0,8,9])
actual_df = pd.read_csv(call_iedb_output_file.name, sep="\t", index_col=[0,8,9])
expected_df = pd.read_csv(expected_output_file, sep="\t", index_col=[1,7,8])
actual_df = pd.read_csv(call_iedb_output_file.name, sep="\t", index_col=[1,7,8])
pd.testing.assert_frame_equal(expected_df, actual_df, check_like=True, check_exact=False, rtol=0.05)

def test_mhcnuggetsi_method_generates_expected_files(self):
Expand Down
Loading

0 comments on commit 71ac9b2

Please sign in to comment.