Skip to content
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

Add netmhciipan 4.3 interface #96

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading