Mercurial > repos > galaxyp > iedb_netmhcpan
annotate nextgen_iedb_api.py @ 0:88e44dab2988 draft default tip
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
author | galaxyp |
---|---|
date | Wed, 09 Jul 2025 12:56:30 +0000 |
parents | |
children |
rev | line source |
---|---|
0
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
1 #!/usr/bin/env python |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
2 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
3 """ |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
4 This file was adapted from the iedb_apy.py file of the iedb_api tool. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
5 It uses the newer "Next-Generation" IEDB API, and is constrained to |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
6 the mhci and mhcii tool groups. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
7 """ |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
8 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
9 import argparse |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
10 import json |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
11 import os.path |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
12 import re |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
13 import sys |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
14 import time |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
15 import urllib.request |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
16 from urllib.error import HTTPError |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
17 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
18 # IEDB tool groups and predictor methods |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
19 mhci_methods = ['netmhcpan_el', 'netmhcpan_ba'] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
20 mhcii_methods = ['netmhciipan_el', 'netmhciipan_ba'] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
21 tool_group_methods = {'mhci': mhci_methods, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
22 'mhcii': mhcii_methods} |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
23 all_methods = set(mhci_methods + mhcii_methods) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
24 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
25 # Values for polling backoff |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
26 max_backoff_count = 25 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
27 init_poll_sleep = 10 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
28 poll_retries = 50 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
29 requests_before_backoff = 5 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
30 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
31 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
32 def parse_alleles(allelefile): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
33 """Returns a dictionary with alleles from input file.""" |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
34 alleles = [] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
35 with open(allelefile, 'r') as fh: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
36 for line in fh: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
37 allele = line.strip() |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
38 alleles.append(allele) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
39 return alleles |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
40 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
41 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
42 def parse_sequence_column(sequence_file_lines, col): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
43 """Sequences may come from a specific column in a TSV file. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
44 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
45 Parse these sequences out while checking each against a regex for validity. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
46 """ |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
47 aapat = '^[ABCDEFGHIKLMNPQRSTVWY]+$' |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
48 sequences = [] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
49 for i, line in enumerate(sequence_file_lines): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
50 fields = line.split('\t') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
51 if len(fields) > col: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
52 seq = re.sub('[_*]', '', fields[col].strip()) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
53 if not re.match(aapat, seq): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
54 warn_err(f'Line {i}, Not a peptide: {seq}') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
55 else: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
56 sequences.append(seq) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
57 else: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
58 warn_err('Invalid value for -c/--column') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
59 break |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
60 return sequences |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
61 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
62 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
63 def iedb_request(req, timeout, retries, error_retry_sleep, response_fn=None, req_data=None): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
64 """Handles HTTP request and exceptions. Allows for a callback to parse IEDB response.""" |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
65 for retry in range(1, retries + 1): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
66 response = None |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
67 try: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
68 response = urllib.request.urlopen(req, req_data, timeout=timeout) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
69 except HTTPError as e: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
70 warn_err(f'{retry} of {retries} Error connecting to IEDB server. \ |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
71 HTTP status code: {e.code}') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
72 time.sleep(error_retry_sleep) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
73 except Exception as e: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
74 warn_err(f'Error getting results from IEDB server: {e}') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
75 return None |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
76 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
77 if response and response.getcode() == 200: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
78 # If no callback, return results |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
79 if not response_fn: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
80 response_string = response.read().decode('utf-8') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
81 response_json = json.loads(response_string) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
82 return response_json |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
83 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
84 # Retry if response_fn callback deems necessary, i.e. results from job are not ready. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
85 response_json = response_fn(response, retry) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
86 if response_json: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
87 return response_json |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
88 else: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
89 code = response.getcode() if response else 1 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
90 warn_err(f'Error connecting to IEDB server. HTTP status code: {code}') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
91 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
92 warn_err(f'No successful response from IEDB in {retries} retries') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
93 return None |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
94 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
95 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
96 def pipeline_request(url, tool_group, sequence_text, alleles, length_range, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
97 methods, peptide_shift, timeout=300, retries=3, error_retry_sleep=300): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
98 """Submits job to IEDB pipeline and polls API until results are ready. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
99 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
100 Returns response JSON from IEDB. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
101 """ |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
102 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
103 # Set up input parameters for IEDB NetMHCPan or NetMHCIIPan job |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
104 input_parameters = { |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
105 'alleles': alleles, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
106 'peptide_length_range': length_range, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
107 'predictors': [{'type': 'binding', 'method': m} for m in methods], |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
108 'peptide_shift': peptide_shift |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
109 } |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
110 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
111 if peptide_shift: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
112 input_parameters['peptide_shift'] = peptide_shift |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
113 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
114 stage = { |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
115 'stage_number': 1, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
116 'tool_group': tool_group, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
117 'input_sequence_text': sequence_text, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
118 'input_parameters': input_parameters |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
119 } |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
120 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
121 params = { |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
122 'pipeline_id': "", |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
123 'run_stage_range': [1, 1], |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
124 'stages': [stage] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
125 } |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
126 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
127 req = urllib.request.Request(url, method='POST') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
128 req_data = json.dumps(params).encode('utf-8') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
129 req.add_header('Content-Type', 'application/json; charset=utf-8') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
130 req.add_header('Content-Length', len(req_data)) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
131 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
132 # Make an initial request to submit job |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
133 response_json = iedb_request(req, timeout, retries, error_retry_sleep, req_data=req_data) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
134 if not response_json: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
135 warn_err('Initial request failed.') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
136 return None |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
137 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
138 # Check response from job submission |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
139 warnings = response_json.get('warnings') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
140 if warnings and len(warnings) > 0: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
141 invalid_alleles = False |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
142 for warning in warnings: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
143 if 'cannot predict binding for allele' in warning: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
144 warn_err(f"Error: Bad allelle input. {warning}") |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
145 invalid_alleles = True |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
146 if invalid_alleles: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
147 return None |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
148 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
149 warn_err(f'Warnings from IEDB: {warnings}') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
150 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
151 errors = response_json.get('errors') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
152 if errors: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
153 warn_err(f'Errors from IEDB: {errors}') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
154 return None |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
155 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
156 results_uri = response_json.get('results_uri') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
157 if not results_uri: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
158 warn_err('No results URI provided from IEDB.') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
159 return None |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
160 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
161 # Callback function to rate-limit poll requests |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
162 def poll_response_fn(response, retry): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
163 response_string = response.read().decode('utf-8') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
164 response_json = json.loads(response_string) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
165 if response_json['status'] != 'done': |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
166 if retry == poll_retries: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
167 warn_err('Job not finished in maximum allowed time.') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
168 backoff_count = min(retry, max_backoff_count) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
169 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
170 # Double sleep every requests_before_backoff requests |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
171 sleep_duration = init_poll_sleep * 2 ** (backoff_count // requests_before_backoff) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
172 time.sleep(sleep_duration) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
173 return None |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
174 return response_json |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
175 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
176 # Submit polling for results |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
177 response_json = iedb_request(results_uri, timeout, poll_retries, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
178 error_retry_sleep, response_fn=poll_response_fn) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
179 if not response_json: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
180 warn_err('Retrieving results failed.') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
181 return response_json |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
182 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
183 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
184 def warn_err(msg, exit_code=None): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
185 sys.stderr.write(f"{msg}\n") |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
186 sys.stderr.flush() |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
187 if exit_code: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
188 sys.exit(exit_code) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
189 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
190 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
191 def add_reversed_sequences(file_lines, file_format): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
192 """Adds a reversed sequence after each input sequence. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
193 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
194 Takes a plain list of sequences, or FASTA file. Each reversed FASTA sequence has |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
195 the same header prefixed with 'reversed_'. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
196 """ |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
197 sequences_with_reversed = [] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
198 if file_format == 'fasta': |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
199 i = 0 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
200 while i < len(file_lines): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
201 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
202 # Validate header from next sequence |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
203 seq_header = file_lines[i] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
204 if seq_header[0] != '>': |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
205 print('Invalid FASTA. Exiting.', file=sys.stderr) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
206 sys.exit(1) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
207 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
208 # Aggregate sequence into a single line |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
209 j = i + 1 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
210 seq = '' |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
211 while j < len(file_lines): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
212 next_line = file_lines[j] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
213 if next_line[0] == '>': |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
214 break |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
215 seq = seq + file_lines[j] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
216 j += 1 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
217 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
218 # Add non-reversed sequence |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
219 sequences_with_reversed.append(seq_header) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
220 sequences_with_reversed.append(seq) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
221 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
222 # Add reversed header and sequence |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
223 rev_header = seq_header.replace('>', '>reversed_') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
224 sequences_with_reversed.append(rev_header) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
225 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
226 rev_seq = seq[::-1] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
227 sequences_with_reversed.append(rev_seq) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
228 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
229 # Advance index to what should be the next sequence header |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
230 i = j |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
231 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
232 # If not FASTA, should be a simple list of peptides to reverse sequentially |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
233 else: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
234 for seq in file_lines: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
235 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
236 # Reverse seq |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
237 rev_seq = f'{seq[::-1]}' |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
238 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
239 # Add original and reversed sequences |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
240 sequences_with_reversed.append(seq) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
241 sequences_with_reversed.append(rev_seq) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
242 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
243 return sequences_with_reversed |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
244 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
245 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
246 def __main__(): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
247 # Parse Command Line |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
248 parser = argparse.ArgumentParser() |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
249 parser.add_argument('-T', '--tool-group', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
250 dest='tool_group', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
251 default='mhci', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
252 choices=tool_group_methods.keys(), |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
253 help='IEDB API Tool Group') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
254 parser.add_argument('-m', '--method', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
255 action="append", |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
256 required=True, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
257 choices=all_methods, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
258 help='prediction method') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
259 parser.add_argument('-A', '--allelefile', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
260 required=True, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
261 help='File of HLA alleles') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
262 parser.add_argument('-l', '--lengthrange', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
263 help='length range for which to make predictions for alleles') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
264 parser.add_argument('-P', '--peptide_shift', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
265 type=int, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
266 default=None, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
267 help='Peptide Shift') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
268 parser.add_argument('-i', '--input', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
269 required=True, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
270 help='Input file for peptide sequences ' |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
271 + '(fasta or tabular)') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
272 parser.add_argument('-c', '--column', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
273 default=None, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
274 help='Zero-indexed peptide column in a tabular input file') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
275 parser.add_argument('-o', '--output', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
276 required=True, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
277 help='Output file for query results') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
278 parser.add_argument('-t', '--timeout', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
279 type=int, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
280 default=600, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
281 help='Seconds to wait for server response') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
282 parser.add_argument('-r', '--retries', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
283 type=int, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
284 default=5, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
285 help='Number of times to retry failed server query') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
286 parser.add_argument('-S', '--sleep', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
287 type=int, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
288 default=300, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
289 help='Seconds to wait between failed server query retries') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
290 parser.add_argument('-R', '--add-reversed', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
291 dest='add_reversed', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
292 action='store_true', |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
293 help='Input has every other sequence reversed. Identify in output.') |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
294 args = parser.parse_args() |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
295 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
296 allele_string = ','.join(parse_alleles(args.allelefile)) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
297 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
298 length_range = [int(i) for i in args.lengthrange.split(',')] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
299 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
300 pipeline_url = 'https://api-nextgen-tools.iedb.org/api/v1/pipeline' |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
301 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
302 # If sequences submitted as a file, parse out sequences. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
303 try: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
304 with open(args.input) as inf: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
305 sequence_file_contents = inf.read() |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
306 except Exception as e: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
307 warn_err(f'Unable to open input file: {e}', exit_code=1) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
308 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
309 sequence_file_lines = sequence_file_contents.splitlines() |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
310 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
311 # Pick out sequences if input file has multiple columns, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
312 # otherwise submit list of sequences as-is. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
313 if not args.column: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
314 # IEDB may take FASTA files directly, so input contents as-is |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
315 if args.add_reversed: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
316 sequence_text = '\n'.join(add_reversed_sequences(sequence_file_lines, 'fasta')) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
317 else: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
318 sequence_text = sequence_file_contents |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
319 else: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
320 sequences = parse_sequence_column(sequence_file_lines, int(args.column)) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
321 if args.add_reversed: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
322 sequence_text = '\n'.join(add_reversed_sequences(sequences, 'tsv')) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
323 else: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
324 sequence_text = '\n'.join(sequences) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
325 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
326 if len(sequence_text) == 0: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
327 warn_err('Error parsing sequences', exit_code=1) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
328 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
329 # Submit job and return results |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
330 results = pipeline_request(pipeline_url, args.tool_group, sequence_text, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
331 allele_string, length_range, args.method, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
332 peptide_shift=args.peptide_shift, timeout=args.timeout, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
333 retries=args.retries, error_retry_sleep=args.sleep) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
334 if not results: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
335 warn_err('Job failed. Exiting.', exit_code=1) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
336 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
337 try: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
338 peptide_table = [t for t in results['data']['results'] if t['type'] == 'peptide_table'][0] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
339 peptide_table_data = peptide_table['table_data'] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
340 peptide_table_columns = peptide_table['table_columns'] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
341 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
342 # If we reversed peptides prior to IEDB input, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
343 # find column index of sequence number so we can identify which come from reversed input. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
344 if args.add_reversed: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
345 for i, column in enumerate(peptide_table_columns): |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
346 if column['display_name'] == 'seq #': |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
347 seq_num_index = i |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
348 break |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
349 except (KeyError, IndexError) as e: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
350 warn_err(f'Error parsing IEDB results: {e}', exit_code=1) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
351 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
352 output_path = os.path.abspath(args.output) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
353 with open(output_path, 'w') as output_file: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
354 # Write column names |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
355 display_names = '\t'.join([c['display_name'] for c in peptide_table_columns] + ['reversed']) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
356 print(display_names, file=output_file) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
357 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
358 # Write data |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
359 for values in peptide_table_data: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
360 if args.add_reversed: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
361 seq_number = values[seq_num_index] |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
362 # Every original input sequence is followed by its reversed sequence, |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
363 # so we know even sequence numbers are reversed. |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
364 reversed_val = str(seq_number % 2 == 0).lower() |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
365 else: |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
366 reversed_val = 'false' |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
367 values = '\t'.join([str(v) for v in values] + [reversed_val]) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
368 print(values, file=output_file) |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
369 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
370 |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
371 if __name__ == "__main__": |
88e44dab2988
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
galaxyp
parents:
diff
changeset
|
372 __main__() |