Skip to content

Commit

Permalink
Merge pull request #96 from jonasscheid/add_netmhciipan4.3_interface
Browse files Browse the repository at this point in the history
Add netmhciipan 4.3 interface
  • Loading branch information
christopher-mohr authored Dec 5, 2023
2 parents 48b22f4 + 1b730d4 commit 952cbad
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion epytope/EpitopePrediction/External.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ class NetMHCIIpan_4_2(NetMHCIIpan_4_1):
__alleles = getattr(__import__("epytope.Data.supportedAlleles.external." + __allele_import_name,
fromlist=[__allele_import_name])
, __allele_import_name)

__command = "netMHCIIpan -f {peptides} -inptype 1 -a {alleles} {options} -xls -xlsfile {out}"


Expand All @@ -1625,6 +1625,53 @@ def command(self):
return self.__command


class NetMHCIIpan_4_3(NetMHCIIpan_4_2):
"""
Implementation of NetMHCIIpan 4.3 adapter.
"""
__name = "netmhcIIpan"
__version = "4.3"
__supported_length = frozenset(list(range(9,57)))

__command = "netMHCIIpan -f {peptides} -inptype 1 -a {alleles} {options} -xls -xlsfile {out}"

@property
def version(self):
"""The version of the predictor"""
return self.__version

@property
def command(self):
"""
Defines the commandline call for external tool
"""
return self.__command

def parse_external_result(self, file):
"""
Parses external results and returns the result containing the predictors string representation
of alleles and peptides.
:param str file: The file path or the external prediction results
:return: A dictionary containing the prediction results
:rtype: dict
"""
f = csv.reader(open(file, "r"), delimiter='\t')
scores = defaultdict(defaultdict)
ranks = defaultdict(defaultdict)
alleles = [x for x in set([x for x in next(f) if x != ""])]
next(f)
for row in f:
pep_seq = row[PeptideIndex.NETMHCIIPAN_4_3]
for i, a in enumerate(alleles):
scores[a][pep_seq] = float(row[ScoreIndex.NETMHCIIPAN_4_3 + i * Offset.NETMHCIIPAN_4_3])
ranks[a][pep_seq] = float(row[RankIndex.NETMHCIIPAN_4_3 + i * Offset.NETMHCIIPAN_4_3])
# Create dictionary with hierarchy: {'Allele1': {'Score': {'Pep1': Score1, 'Pep2': Score2,..}, 'Rank': {'Pep1': RankScore1, 'Pep2': RankScore2,..}}, 'Allele2':...}
result = {allele: {metric:(list(scores.values())[j] if metric == "Score" else list(ranks.values())[j]) for metric in ["Score", "Rank"]} for j, allele in enumerate(alleles)}

return result


class PickPocket_1_1(AExternalEpitopePrediction):
"""
Implementation of PickPocket adapter.
Expand Down Expand Up @@ -1914,6 +1961,7 @@ class PeptideIndex(IntEnum):
NETMHCIIPAN_3_1 = 1
NETMHCIIPAN_4_0 = 1
NETMHCIIPAN_4_1 = 1
NETMHCIIPAN_4_3 = 1
PICKPOCKET_1_1 = 2
NETCTLPAN_1_1 = 3

Expand All @@ -1935,6 +1983,7 @@ class ScoreIndex(IntEnum):
NETMHCIIPAN_3_1 = 3
NETMHCIIPAN_4_0 = 4
NETMHCIIPAN_4_1 = 5
NETMHCIIPAN_4_3 = 6
PICKPOCKET_1_1 = 4
NETCTLPAN_1_1 = 7

Expand All @@ -1952,6 +2001,7 @@ class RankIndex(IntEnum):
NETMHCIIPAN_3_1 = 5
NETMHCIIPAN_4_0 = 5
NETMHCIIPAN_4_1 = 6
NETMHCIIPAN_4_3 = 7

class Offset(IntEnum):
"""
Expand All @@ -1969,6 +2019,7 @@ class Offset(IntEnum):
NETMHCIIPAN_3_1 = 3
NETMHCIIPAN_4_0 = 2
NETMHCIIPAN_4_1 = 3
NETMHCIIPAN_4_3 = 3

class HLAIndex(IntEnum):
"""
Expand Down

0 comments on commit 952cbad

Please sign in to comment.