Mercurial > repos > galaxyp > iedb_netmhcpan
annotate nextgen_iedb_api.py @ 0:4fb283cf23a5 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:02 +0000 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 0 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 2 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 3 """ | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 7 """ | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 8 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 9 import argparse | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 10 import json | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 12 import re | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 13 import sys | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 14 import time | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 17 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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'] | 
| 
4fb283cf23a5
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'] | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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} | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 24 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 30 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 31 | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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.""" | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 34 alleles = [] | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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() | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 39 return alleles | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 40 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 41 | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 44 | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 46 """ | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 47 aapat = '^[ABCDEFGHIKLMNPQRSTVWY]+$' | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 48 sequences = [] | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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()) | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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}') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 55 else: | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 57 else: | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 59 break | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 60 return sequences | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 61 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 62 | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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.""" | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 66 response = None | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 67 try: | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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. \ | 
| 
4fb283cf23a5
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}') | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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}') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 75 return None | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 76 | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 83 | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 88 else: | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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}') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 91 | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 93 return None | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 94 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 95 | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 99 | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 101 """ | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 102 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 104 input_parameters = { | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 105 'alleles': alleles, | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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], | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 109 } | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 110 | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 113 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 114 stage = { | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 119 } | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 120 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 121 params = { | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 122 'pipeline_id': "", | 
| 
4fb283cf23a5
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], | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 124 'stages': [stage] | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 125 } | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 126 | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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)) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 131 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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.') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 136 return None | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 137 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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}") | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 147 return None | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 148 | 
| 
4fb283cf23a5
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}') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 150 | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 152 if errors: | 
| 
4fb283cf23a5
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}') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 154 return None | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 155 | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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.') | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 159 return None | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 160 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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': | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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.') | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 169 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 173 return None | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 175 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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.') | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 182 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 183 | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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") | 
| 
4fb283cf23a5
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() | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 189 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 190 | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 193 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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_'. | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 196 """ | 
| 
4fb283cf23a5
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 = [] | 
| 
4fb283cf23a5
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': | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 199 i = 0 | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 201 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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] | 
| 
4fb283cf23a5
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] != '>': | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 207 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 210 seq = '' | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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] | 
| 
4fb283cf23a5
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] == '>': | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 214 break | 
| 
4fb283cf23a5
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] | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 216 j += 1 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 217 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 221 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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_') | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 225 | 
| 
4fb283cf23a5
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] | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 228 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 230 i = j | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 231 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 233 else: | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 235 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 236 # Reverse seq | 
| 
4fb283cf23a5
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]}' | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 238 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 242 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 244 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 245 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 246 def __main__(): | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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() | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 251 default='mhci', | 
| 
4fb283cf23a5
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(), | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 255 action="append", | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 256 required=True, | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 260 required=True, | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 265 type=int, | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 266 default=None, | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 269 required=True, | 
| 
4fb283cf23a5
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 ' | 
| 
4fb283cf23a5
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)') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 273 default=None, | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 276 required=True, | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 279 type=int, | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 280 default=600, | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 283 type=int, | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 284 default=5, | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 287 type=int, | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 288 default=300, | 
| 
4fb283cf23a5
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') | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
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', | 
| 
4fb283cf23a5
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.') | 
| 
4fb283cf23a5
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() | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 295 | 
| 
4fb283cf23a5
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)) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 297 | 
| 
4fb283cf23a5
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(',')] | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 299 | 
| 
4fb283cf23a5
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' | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 301 | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 303 try: | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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() | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 308 | 
| 
4fb283cf23a5
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() | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 310 | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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')) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 317 else: | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 319 else: | 
| 
4fb283cf23a5
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)) | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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')) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 323 else: | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 325 | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 328 | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 336 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 337 try: | 
| 
4fb283cf23a5
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] | 
| 
4fb283cf23a5
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'] | 
| 
4fb283cf23a5
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'] | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 341 | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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): | 
| 
4fb283cf23a5
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 #': | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 348 break | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 351 | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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 | 
| 
4fb283cf23a5
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']) | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 357 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 358 # Write data | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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: | 
| 
4fb283cf23a5
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] | 
| 
4fb283cf23a5
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, | 
| 
4fb283cf23a5
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. | 
| 
4fb283cf23a5
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() | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 365 else: | 
| 
4fb283cf23a5
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' | 
| 
4fb283cf23a5
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]) | 
| 
4fb283cf23a5
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) | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 369 | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 370 | 
| 
4fb283cf23a5
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__": | 
| 
4fb283cf23a5
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/iedb_netmhcpan commit 0ac7534c8d9f5bfea21b998286f822784e62da08
 galaxyp parents: diff
changeset | 372 __main__() | 
