annotate iedb_api.py @ 3:e95d3221b7f0 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
author iuc
date Fri, 11 Sep 2020 21:02:34 +0000
parents 6cf84410cb2e
children 7ed6dda64a81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
2
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
3 import argparse
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
4 import os.path
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
5 import re
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
6 import sys
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
7 import time
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
8 from urllib.error import HTTPError
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
9 from urllib.parse import unquote, urlencode
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
10 from urllib.request import urlopen
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
11
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
12 mhci_methods = ['recommended', 'consensus',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
13 'netmhcpan_ba', 'netmhcpan_el',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
14 'ann', 'smmpmbec', 'smm',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
15 'comblib_sidney2008', 'netmhccons',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
16 'pickpocket', 'netmhcstabpan']
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
17 mhcii_methods = ['recommended', 'consensus', 'NetMHCIIpan',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
18 'nn_align', 'smm_align', 'comblib', 'tepitope']
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
19 processing_methods = ['recommended', 'netmhcpan', 'ann',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
20 'smmpmbec', 'smm', 'comblib_sidney2008',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
21 'netmhccons', 'pickpocket']
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
22 mhcnp_methods = ['mhcnp', 'netmhcpan']
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
23 bcell_methods = ['Bepipred', 'Chou-Fasman', 'Emini', 'Karplus-Schulz',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
24 'Kolaskar-Tongaonkar', 'Parker', 'Bepipred-2.0']
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
25 prediction_methods = {'mhci': mhci_methods,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
26 'mhcii': mhcii_methods,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
27 'processing': processing_methods,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
28 'mhcnp': mhcnp_methods,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
29 'bcell': bcell_methods}
1
6cf84410cb2e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 848c47fb29e9f1d319056a94a7dbd90129a4aafc"
iuc
parents: 0
diff changeset
30 all_methods = set(mhci_methods + mhcii_methods + mhcnp_methods + bcell_methods)
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
31 prediction_lengths = {'mhci': range(8, 16),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
32 'mhcii': range(11, 31),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
33 'processing': range(8, 15),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
34 'mhcnp': range(8, 12),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
35 'bcell': range(8, 16)}
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
36
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
37
3
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
38 def parse_alleles(allelefile, query_lengths):
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
39 alleles = []
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
40 lengths = []
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
41 with open(allelefile, 'r') as fh:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
42 for i, line in enumerate(fh):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
43 fields = line.strip().split(',')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
44 allele = fields[0].strip()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
45 if allele:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
46 if len(fields) > 1:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
47 for alen in fields[1:]:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
48 alleles.append(allele)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
49 lengths.append(alen)
3
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
50 elif query_lengths:
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
51 lens = []
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
52 for ql in query_lengths:
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
53 lens.extend(str(ql).split(','))
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
54 for alen in lens:
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
55 alleles.append(allele)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
56 lengths.append(alen)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
57 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
58 alleles.append(allele)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
59 return (alleles, lengths)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
60
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
61
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
62 def query(url, prediction, seq, allele, length, results,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
63 seqid=None, method='recommended', proteasome=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
64 timeout=300, retries=3, sleep=300, debug=False):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
65 params = dict()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
66 if method:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
67 params['method'] = method.encode()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
68 if proteasome:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
69 params['proteasome'] = proteasome.encode()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
70 params['sequence_text'] = seq.strip().encode()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
71 if allele is not None:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
72 params['allele'] = allele.encode()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
73 if length is not None:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
74 if prediction == 'bcell':
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
75 params['window_size'] = str(length).encode()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
76 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
77 params['length'] = str(length).encode()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
78 req_data = urlencode(params)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
79 if debug:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
80 print('url %s %s' % (url, unquote(req_data)), file=sys.stderr)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
81 retries = max(0, retries) + 1
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
82 for retry in range(1, retries):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
83 response = None
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
84 try:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
85 response = urlopen(url, data=req_data.encode('utf-8'),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
86 timeout=timeout)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
87 if response and response.getcode() == 200:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
88 data = [line.decode() for line in response.readlines()]
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
89 if debug:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
90 print(data, file=sys.stderr)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
91 rslts = results['prediction']['entries']
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
92 for ln, line in enumerate(data):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
93 if 'invalid' in line.lower() or 'tools_api.html' in line:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
94 msg = '%s %s\n%s' % (url, unquote(req_data),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
95 ''.join(data))
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
96 warn_err(msg, exit_code=1)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
97 if line.find('eptide') > 0:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
98 results['prediction']['header'] = "#%s%s" %\
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
99 ("ID\t" if seqid else "", line)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
100 continue
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
101 elif method == 'Bepipred' and line.find('Residue') > 0:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
102 results['detail']['header'] = "#%s%s" %\
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
103 ("ID\t" if seqid else "", line)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
104 rslts = results['detail']['entries']
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
105 continue
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
106 if seqid:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
107 rslts.extend("%s\t%s" % (seqid, line))
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
108 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
109 rslts.extend(line)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
110 break
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
111 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
112 code = response.getcode() if response else 1
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
113 warn_err("Error connecting to IEDB server\n",
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
114 exit_code=code)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
115 except HTTPError as e:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
116 code = None if retry < retries else e.code
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
117 warn_err("%d of %d Error connecting to IEDB server %s\n" %
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
118 (retry, retries, e),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
119 exit_code=code)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
120 time.sleep(sleep)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
121 except Exception as e:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
122 warn_err("Error connecting to IEDB server %s\n" % e,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
123 exit_code=3)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
124 return results
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
125
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
126
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
127 def warn_err(msg, exit_code=1):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
128 sys.stderr.write(msg)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
129 sys.stderr.flush()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
130 if exit_code:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
131 sys.exit(exit_code)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
132
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
133
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
134 def __main__():
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
135 # Parse Command Line
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
136 parser = argparse.ArgumentParser(description='', epilog='')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
137 parser.add_argument('-p', '--prediction',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
138 default='mhci',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
139 choices=prediction_methods.keys(),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
140 help='IEDB API prediction service')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
141 parser.add_argument('-s', '--sequence',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
142 action="append",
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
143 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
144 help='Peptide Sequence')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
145 parser.add_argument('-m', '--method',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
146 default='recommended',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
147 choices=all_methods,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
148 help='prediction method')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
149 parser.add_argument('-P', '--proteasome',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
150 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
151 choices=['immuno', 'constitutive'],
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
152 help='IEDB processing proteasome type')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
153 parser.add_argument('-a', '--allele',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
154 action="append",
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
155 default=[],
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
156 help='Alleles for which to make predictions')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
157 parser.add_argument('-A', '--allelefile',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
158 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
159 help='File of HLA alleles')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
160 parser.add_argument('-l', '--length',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
161 action="append",
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
162 default=[],
3
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
163 help='lengths for which to make predictions for alleles')
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
164 parser.add_argument('-w', '--window_size',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
165 type=int,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
166 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
167 help='window_size for bcell prediction')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
168 parser.add_argument('-i', '--input',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
169 default=None,
1
6cf84410cb2e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 848c47fb29e9f1d319056a94a7dbd90129a4aafc"
iuc
parents: 0
diff changeset
170 help='Input file for peptide sequences '
3
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
171 + '(fasta or tabular)')
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
172 parser.add_argument('-c', '--column',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
173 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
174 help='Peptide Column in a tabular input file')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
175 parser.add_argument('-C', '--id_column',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
176 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
177 help='ID Column in a tabular input file')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
178 parser.add_argument('-o', '--output',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
179 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
180 help='Output file for query results')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
181 parser.add_argument('-O', '--output2',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
182 default='iedb_results2',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
183 help='Output file for secondary query results')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
184 parser.add_argument('-t', '--timeout',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
185 type=int,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
186 default=600,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
187 help='Seconds to wait for server response')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
188 parser.add_argument('-r', '--retries',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
189 type=int,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
190 default=5,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
191 help='Number of times to retry server query')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
192 parser.add_argument('-S', '--sleep',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
193 type=int,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
194 default=300,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
195 help='Seconds to wait between retries')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
196 parser.add_argument('-d', '--debug',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
197 action='store_true',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
198 default=False,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
199 help='Turn on wrapper debugging to stderr')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
200 args = parser.parse_args()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
201
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
202 aapat = '^[ABCDEFGHIKLMNPQRSTVWY]+$'
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
203
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
204 if args.prediction != 'bcell':
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
205 if not args.allele and not args.allelefile:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
206 warn_err('-a allele or -A allelefile required\n', exit_code=1)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
207
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
208 if not (args.sequence or args.input):
1
6cf84410cb2e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 848c47fb29e9f1d319056a94a7dbd90129a4aafc"
iuc
parents: 0
diff changeset
209 warn_err('NO Sequences given: '
3
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
210 + 'either -s sequence or -i input_file is required\n',
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
211 exit_code=1)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
212
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
213 if args.output is not None:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
214 try:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
215 outputPath = os.path.abspath(args.output)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
216 outputFile = open(outputPath, 'w')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
217 except Exception as e:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
218 warn_err("Unable to open output file: %s\n" % e, exit_code=1)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
219 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
220 outputFile = sys.stdout
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
221
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
222 # params
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
223 alleles = []
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
224 lengths = []
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
225 if args.prediction == 'bcell' and args.window_size is not None:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
226 lengths.append(str(args.window_size))
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
227 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
228 if args.allelefile:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
229 (alleles, lengths) = parse_alleles(args.allelefile, args.length)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
230 if args.allele:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
231 for i, allele in enumerate(args.allele):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
232 alleles.append(allele)
3
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
233 alen = args.length[i] if i < len(args.length)\
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
234 else args.length[-1]
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
235 lengths.append(alen)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
236 allele = ','.join(alleles) if alleles else None
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
237 length = ','.join(lengths) if lengths else None
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
238 method = args.method
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
239 proteasome = args.proteasome if args.prediction == 'processcing' else None
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
240 url = 'http://tools-cluster-interface.iedb.org/tools_api/%s/' %\
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
241 args.prediction
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
242
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
243 # results
3
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
244 results = {'prediction': {'header': None, 'entries': []},
e95d3221b7f0 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 863578373c7dadc5880633115b0c348f73dac782"
iuc
parents: 1
diff changeset
245 'detail': {'header': None, 'entries': []}}
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
246
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
247 if args.sequence:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
248 for i, seq in enumerate(args.sequence):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
249 seqid = 'pep_%d' % i
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
250 query(url, args.prediction, seq, allele, length, results,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
251 seqid=seqid, method=method, proteasome=proteasome,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
252 timeout=args.timeout, retries=args.retries,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
253 sleep=args.sleep, debug=args.debug)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
254 if args.input:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
255 try:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
256 fh = open(args.input, 'r')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
257 if args.column: # tabular
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
258 col = int(args.column)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
259 idcol = int(args.id_column) if args.id_column else None
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
260 for i, line in enumerate(fh):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
261 fields = line.rstrip('\r\n').split('\t')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
262 if len(fields) > col:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
263 seq = re.sub('[_*]', '', fields[col].strip())
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
264 if re.match(aapat, seq):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
265 if idcol is not None and idcol < len(fields):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
266 seqid = fields[idcol]
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
267 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
268 seqid = 'pep_%d' % i
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
269 query(url, args.prediction, seq, allele, length,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
270 results, seqid=seqid,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
271 method=method, proteasome=proteasome,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
272 timeout=args.timeout, retries=args.retries,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
273 sleep=args.sleep, debug=args.debug)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
274 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
275 warn_err('Line %d, Not a peptide: %s\n' % (i, seq),
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
276 exit_code=None)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
277 else: # fasta
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
278 seqid = None
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
279 seq = ''
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
280 for i, line in enumerate(fh):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
281 if line.startswith('>'):
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
282 if seqid and len(seq) > 0:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
283 query(url, args.prediction, seq, allele, length,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
284 results, seqid=seqid,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
285 method=method, proteasome=proteasome,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
286 timeout=args.timeout, retries=args.retries,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
287 sleep=args.sleep, debug=args.debug)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
288 seqid = line[1:].strip()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
289 seq = ''
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
290 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
291 seq += line.strip()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
292 if seqid and len(seq) > 0:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
293 query(url, args.prediction, seq, allele, length,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
294 results, seqid=seqid,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
295 method=method, proteasome=proteasome,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
296 timeout=args.timeout, retries=args.retries,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
297 sleep=args.sleep, debug=args.debug)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
298 fh.close()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
299 except Exception as e:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
300 warn_err("Unable to open input file: %s\n" % e, exit_code=1)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
301
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
302 if results['prediction']['header']:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
303 outputFile.write(results['prediction']['header'])
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
304 for line in results['prediction']['entries']:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
305 outputFile.write(line)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
306 if results['detail']['entries']:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
307 if args.output2:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
308 try:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
309 outPath = os.path.abspath(args.output2)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
310 outFile = open(outPath, 'w')
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
311 except Exception as e:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
312 warn_err("Unable to open output file: %s\n" % e, exit_code=1)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
313 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
314 outFile = sys.stdout
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
315 if results['detail']['header']:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
316 outFile.write(results['detail']['header'])
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
317 for line in results['detail']['entries']:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
318 outFile.write(line)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
319
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
320
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
321 if __name__ == "__main__":
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
322 __main__()