From d9d9cb2794051567ea12e2a8abf937c2f5600703 Mon Sep 17 00:00:00 2001 From: e-dorigatti Date: Fri, 10 Jan 2020 17:08:09 +0100 Subject: [PATCH 1/4] updated pcm cleavage scores --- Fred2/Data/pssms/pcm/mat/pcm_6.py | 2 +- Fred2/test/TestEpitopeAssembly.py | 4 ++-- Fred2/test/TestSpacerDesign.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Fred2/Data/pssms/pcm/mat/pcm_6.py b/Fred2/Data/pssms/pcm/mat/pcm_6.py index 0c40d4a5..7b97436a 100644 --- a/Fred2/Data/pssms/pcm/mat/pcm_6.py +++ b/Fred2/Data/pssms/pcm/mat/pcm_6.py @@ -1 +1 @@ -pcm_6 = {0: {'A': 0.4731237565819792, 'C': -0.5025268209512956, 'E': -0.21691300156357377, 'D': -0.5025268209512956, 'G': -2.2537949288246137, 'F': -0.3495574761698686, 'I': 0.004987541511038968, 'H': 1.1647120903726331, 'K': -0.3495574761698686, 'M': 0.004987541511038968, 'L': 0.09984533496971612, 'N': 0.18647956694261839, 'Q': -0.6831968497067774, 'P': -0.3495574761698686, 'S': 0.2662030407746567, 'R': 0.2662030407746567, 'T': -0.21691300156357377, 'W': -0.903868211875598, 'V': 0.004987541511038968, 'Y': 0.2662030407746567}, 1: {'A': 0.4731237565819792, 'C': -0.5025268209512956, 'E': -0.0998203352822109, 'D': -0.0998203352822109, 'G': -5.298317366548036, 'F': -0.5025268209512956, 'I': -0.0998203352822109, 'H': 0.7907275088988094, 'K': -0.21691300156357377, 'M': -0.21691300156357377, 'L': 0.2662030407746567, 'N': 0.7907275088988094, 'Q': -0.903868211875598, 'P': -0.5025268209512956, 'S': 0.2662030407746567, 'R': 0.2662030407746567, 'T': -0.3495574761698686, 'W': -0.903868211875598, 'V': -0.3495574761698686, 'Y': 0.5335651107354802}, 2: {'A': 0.5335651107354802, 'C': 0.004987541511038968, 'E': 0.18647956694261839, 'D': -0.6831968497067774, 'G': -2.2537949288246137, 'F': 0.40879289820083897, 'I': 0.09984533496971612, 'H': 1.1002775679871708, 'K': -0.6831968497067774, 'M': -1.1874435023747254, 'L': -0.21691300156357377, 'N': 0.3400373027857091, 'Q': -0.6831968497067774, 'P': -0.0998203352822109, 'S': -1.1874435023747254, 'R': 0.4731237565819792, 'T': 0.004987541511038968, 'W': -2.2537949288246137, 'V': -0.0998203352822109, 'Y': 0.40879289820083897}, 3: {'A': 0.7443154671343447, 'C': 0.09984533496971612, 'E': -0.903868211875598, 'D': 0.3400373027857091, 'G': -5.298317366548036, 'F': -0.21691300156357377, 'I': 0.2662030407746567, 'H': 0.5335651107354802, 'K': -0.5025268209512956, 'M': -0.3495574761698686, 'L': 0.6444820085786643, 'N': -0.3495574761698686, 'Q': -0.6831968497067774, 'P': 0.004987541511038968, 'S': -0.903868211875598, 'R': -0.3495574761698686, 'T': -0.6831968497067774, 'W': -0.0998203352822109, 'V': 0.3400373027857091, 'Y': 0.5905605917848442}, 4: {'A': 0.8775499035577246, 'C': 0.004987541511038968, 'E': 0.18647956694261839, 'D': -0.21691300156357377, 'G': -5.298317366548036, 'F': -0.21691300156357377, 'I': -0.0998203352822109, 'H': 1.0314035389746596, 'K': -0.6831968497067774, 'M': -1.584745299843729, 'L': 0.004987541511038968, 'N': 0.40879289820083897, 'Q': -0.5025268209512956, 'P': -2.2537949288246137, 'S': 0.2662030407746567, 'R': 0.4731237565819792, 'T': 0.004987541511038968, 'W': -0.6831968497067774, 'V': 0.18647956694261839, 'Y': -0.6831968497067774}, 5: {'A': 0.3400373027857091, 'C': -0.21691300156357377, 'E': 0.5905605917848442, 'D': 0.3400373027857091, 'G': -5.298317366548036, 'F': 0.18647956694261839, 'I': 0.004987541511038968, 'H': 0.9182887345368281, 'K': -0.21691300156357377, 'M': 0.004987541511038968, 'L': 0.40879289820083897, 'N': -0.903868211875598, 'Q': -1.584745299843729, 'P': -0.21691300156357377, 'S': -0.3495574761698686, 'R': -0.21691300156357377, 'T': 0.18647956694261839, 'W': -0.5025268209512956, 'V': -0.21691300156357377, 'Y': 0.004987541511038968}} \ No newline at end of file +pcm_6 = {0: {'A': -0.07, 'R': -0.31, 'N': -0.24, 'D': -0.34, 'C': 0.16, 'Q': -0.17, 'E': -0.03, 'G': 0.32, 'H': 0.12, 'I': 0.05, 'L': -0.2, 'K': -0.23, 'M': 0.22, 'F': 0.13, 'P': 0.22, 'S': 0.04, 'T': -0.12, 'W': 0.31, 'Y': 0.27, 'V': -0.14}, 1: {'A': -0.18, 'R': -0.31, 'N': -0.12, 'D': -0.23, 'C': -5.49, 'Q': -0.08, 'E': -0.03, 'G': -0.09, 'H': 0.12, 'I': -0.04, 'L': 0.13, 'K': 0.42, 'M': 0.22, 'F': 0.01, 'P': -0.02, 'S': -0.16, 'T': -0.23, 'W': 0.31, 'Y': 0.05, 'V': 0.18}, 2: {'A': -0.01, 'R': 0.38, 'N': 0.24, 'D': -0.81, 'C': 0.16, 'Q': 0.43, 'E': 0.04, 'G': 0.22, 'H': -0.16, 'I': -0.73, 'L': -0.42, 'K': 0.04, 'M': 0.22, 'F': 0.23, 'P': -1.29, 'S': 0.2, 'T': 0.28, 'W': -1.29, 'Y': 0.16, 'V': 0.13}, 3: {'A': 0.22, 'R': 0.29, 'N': -0.71, 'D': 0.41, 'C': -5.49, 'Q': 0.07, 'E': 0.16, 'G': -0.29, 'H': -0.01, 'I': -0.27, 'L': 0.38, 'K': -0.85, 'M': 0.37, 'F': 0.33, 'P': -1.29, 'S': -0.71, 'T': -0.48, 'W': 1.0, 'Y': 0.8, 'V': 0.18}, 4: {'A': 0.3, 'R': 0.2, 'N': 0.16, 'D': -0.34, 'C': -5.49, 'Q': -0.08, 'E': -0.27, 'G': 0.22, 'H': -0.16, 'I': -1.64, 'L': -0.27, 'K': -0.02, 'M': 0.63, 'F': -0.96, 'P': 0.18, 'S': 0.34, 'T': 0.14, 'W': 0.31, 'Y': 0.53, 'V': -0.96}, 5: {'A': -0.18, 'R': -0.02, 'N': 0.57, 'D': 0.28, 'C': -5.49, 'Q': 0.14, 'E': -0.18, 'G': 0.08, 'H': 0.44, 'I': 0.05, 'L': 0.22, 'K': -1.4, 'M': -0.47, 'F': 0.41, 'P': -0.34, 'S': -0.4, 'T': 0.14, 'W': 0.64, 'Y': 0.16, 'V': -0.2}} diff --git a/Fred2/test/TestEpitopeAssembly.py b/Fred2/test/TestEpitopeAssembly.py index e1d63575..75477bdc 100644 --- a/Fred2/test/TestEpitopeAssembly.py +++ b/Fred2/test/TestEpitopeAssembly.py @@ -22,7 +22,7 @@ def test_simple_assembly(self): pred = CleavageSitePredictorFactory("PCM") assembler = EpitopeAssembly(self.peptides, pred, solver="cbc", verbosity=0) r = assembler.solve() - self.assertEqual(r, [Peptide("YLYDHLAPM"), Peptide("ALYDVVSTL"), Peptide("KLLPRLPGV")]) + self.assertEqual(r, [Peptide("KLLPRLPGV"), Peptide("ALYDVVSTL"), Peptide("YLYDHLAPM")]) @@ -53,4 +53,4 @@ def test_pareto_front_assembly(self): r = assembler.paretosolve() print r - #print assembler.solve(eps=2.0) \ No newline at end of file + #print assembler.solve(eps=2.0) diff --git a/Fred2/test/TestSpacerDesign.py b/Fred2/test/TestSpacerDesign.py index 41196a74..b1ff94a2 100644 --- a/Fred2/test/TestSpacerDesign.py +++ b/Fred2/test/TestSpacerDesign.py @@ -33,7 +33,7 @@ def test_standart_functions(self): sbws = EpitopeAssemblyWithSpacer(self.epis, cl_pred, epi_pred, self.alleles, solver="cbc") sol = sbws.solve() print sol - assert all(i == str(j) for i, j in zip(["GHRMAWDMM", "HH", "VYEADDVIL"], sol)) + assert all(i == str(j) for i, j in zip(["GHRMAWDMM", "WWQW", "VYEADDVIL"], sol)) def test_unsupported_allele_length_combination(self): """ @@ -47,7 +47,7 @@ def test_unsupported_allele_length_combination(self): sbws = EpitopeAssemblyWithSpacer(self.epis, cl_pred, epi_pred, alleles, solver="cbc") sol = sbws.solve() print sol - assert all(i == str(j) for i, j in zip(["GHRMAWDMM", "HH", "VYEADDVIL"], sol)) + assert all(i == str(j) for i, j in zip(["GHRMAWDMM", "WWQW", "VYEADDVIL"], sol)) def test_unsupported_allele_length_combination_exception(self): """ From 8fcdae76576ba5938f8477b553afea67ee308f87 Mon Sep 17 00:00:00 2001 From: Christopher Mohr Date: Thu, 16 Jan 2020 13:33:48 +0100 Subject: [PATCH 2/4] Fix returned data frame of mhcnuggets predictions --- Fred2/EpitopePrediction/ANN.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Fred2/EpitopePrediction/ANN.py b/Fred2/EpitopePrediction/ANN.py index f59aa932..16fbba7f 100644 --- a/Fred2/EpitopePrediction/ANN.py +++ b/Fred2/EpitopePrediction/ANN.py @@ -147,13 +147,15 @@ def predict(self, peptides, alleles=None, binary=False, **kwargs): # filter for supported alleles alleles = filter(lambda a: a in self.supportedAlleles, alleles) - # fetch peptides as strings - peptides = [str(peptide) for peptide in peptides] + # keep input peptide objects for later use + peptide_objects = {} + for peptide in peptides: + peptide_objects[str(peptide)] = peptide # write peptides temporarily, new line separated tmp_input_file = tempfile.NamedTemporaryFile().name with open(tmp_input_file, 'wb') as file: - for peptide in peptides: + for peptide in peptide_objects.keys(): file.write(peptide + "\n") alleles = self.convert_alleles(alleles) @@ -177,7 +179,8 @@ def predict(self, peptides, alleles=None, binary=False, **kwargs): # assign binding affinities for row in reader: content = row[0].split(',') - peptide = content[0] + # get original peptide object + peptide = peptide_objects[content[0]] binding_affinity = content[1] if binary: if binding_affinity <= 500: @@ -294,15 +297,17 @@ def predict(self, peptides, alleles=None, binary=False, **kwargs): # filter for supported alleles alleles = filter(lambda a: a in self.supportedAlleles, alleles) - # fetch peptides as strings - peptides = [str(peptide) for peptide in peptides] + # keep input peptide objects for later + peptide_objects = {} + for peptide in peptides: + peptide_objects[str(peptide)] = peptide alleles = self.convert_alleles(alleles) # write peptides temporarily, new line separated tmp_input_file = tempfile.NamedTemporaryFile().name with open(tmp_input_file, 'wb') as file: - for peptide in peptides: + for peptide in peptide_objects.keys(): file.write(peptide + "\n") result = {} @@ -325,7 +330,8 @@ def predict(self, peptides, alleles=None, binary=False, **kwargs): for row in reader: content = row[0].split(',') - peptide = content[0] + # get original peptide object + peptide = peptide_objects[content[0]] binding_affinity = content[1] if binary: if binding_affinity <= 500: From 02c97ffc6090d98a27b87834a14ca8d4ffa1731f Mon Sep 17 00:00:00 2001 From: Kasapovic Date: Mon, 3 Feb 2020 16:21:09 +0100 Subject: [PATCH 3/4] add netmhcpan 4.0 support to External.py --- Fred2/EpitopePrediction/External.py | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Fred2/EpitopePrediction/External.py b/Fred2/EpitopePrediction/External.py index efa45b59..8026aa3f 100755 --- a/Fred2/EpitopePrediction/External.py +++ b/Fred2/EpitopePrediction/External.py @@ -1445,6 +1445,43 @@ def parse_external_result(self, file): return result + +class NetMHCpan_4_0(NetMHCpan_3_0): + """ + Implements the NetMHC binding version 4.0 + Supported MHC alleles currently only restricted to HLA alleles. + """ + __version = "4.0" + __command = "netMHCpan -p {peptides} -a {alleles} {options} -xls -xlsfile {out}" + @property + def version(self): + return self.__version + + @property + def command(self): + return self.__command + + def parse_external_result(self, file): + """ + Parses external results and returns the result + + :param str file: The file path or the external prediction results + :return: A dictionary containing the prediction results + :rtype: dict + """ + result = defaultdict(defaultdict) + f = csv.reader(open(file, "r"), delimiter='\t') + alleles = list(filter(lambda x: x != "", f.next())) + f.next() + ic_pos = 5 + for row in f: + pep_seq = row[1] + for i, a in enumerate(alleles): + result[a][pep_seq] = float(row[ic_pos + i * 5]) + return result + + + class NetMHCstabpan_1_0(AExternalEpitopePrediction): """ Implements a wrapper to NetMHCstabpan 1.0 From f70712f9f341dd3982293106543a41700a291fc5 Mon Sep 17 00:00:00 2001 From: Christopher Mohr Date: Fri, 7 Feb 2020 13:11:01 +0100 Subject: [PATCH 4/4] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b005f3b0..bf7fc1d0 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ name='Fred2', # Version: - version='2.0.5', + version='2.0.6', description='A Framework for Epitope Detection and Vaccine Design', long_description=readme,