annotate iedb_api.py @ 4:7ed6dda64a81 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
author iuc
date Sat, 13 Feb 2021 00:06:36 +0000
parents e95d3221b7f0
children
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()
4
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
76 elif length == 'asis':
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
77 params['length'] = str(length).encode()
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
78 else:
4
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
79 slen = len(seq)
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
80 alleles = []
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
81 lengths = []
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
82 for i in zip(length.split(','), allele.split(',')):
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
83 if int(i[0]) <= slen:
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
84 lengths.append(i[0])
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
85 alleles.append(i[1])
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
86 if lengths:
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
87 params['length'] = str(','.join(lengths)).encode()
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
88 params['allele'] = str(','.join(alleles)).encode()
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
89 else:
7ed6dda64a81 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 6aeacd9ee8abb962fd7037cc374598caa87e63b3"
iuc
parents: 3
diff changeset
90 return results
0
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
91 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
92 if debug:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
93 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
94 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
95 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
96 response = None
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
97 try:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
98 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
99 timeout=timeout)
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
100 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
101 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
102 if debug:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
103 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
104 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
105 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
106 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
107 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
108 ''.join(data))
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
109 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
110 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
111 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
112 ("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
113 continue
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
114 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
115 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
116 ("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
117 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
118 continue
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
119 if seqid:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
120 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
121 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
122 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
123 break
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
124 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
125 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
126 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
127 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
128 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
129 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
130 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
131 (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
132 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
133 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
134 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
135 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
136 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
137 return results
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
138
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
139
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
140 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
141 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
142 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
143 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
144 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
145
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
146
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
147 def __main__():
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
148 # 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
149 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
150 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
151 default='mhci',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
152 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
153 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
154 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
155 action="append",
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
156 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
157 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
158 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
159 default='recommended',
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
160 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
161 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
162 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
163 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
164 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
165 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
166 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
167 action="append",
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
168 default=[],
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
169 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
170 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
171 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
172 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
173 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
174 action="append",
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
175 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
176 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
177 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
178 type=int,
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='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
181 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
182 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
183 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
184 + '(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
185 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
186 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
187 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
188 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
189 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
190 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
191 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
192 default=None,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
193 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
194 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
195 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
196 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
197 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
198 type=int,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
199 default=600,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
200 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
201 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
202 type=int,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
203 default=5,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
204 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
205 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
206 type=int,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
207 default=300,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
208 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
209 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
210 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
211 default=False,
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
212 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
213 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
214
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
215 aapat = '^[ABCDEFGHIKLMNPQRSTVWY]+$'
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
216
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
217 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
218 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
219 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
220
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
221 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
222 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
223 + '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
224 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
225
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
226 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
227 try:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
228 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
229 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
230 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
231 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
232 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
233 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
234
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
235 # params
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
236 alleles = []
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
237 lengths = []
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
238 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
239 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
240 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
241 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
242 (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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254 args.prediction
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
255
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
256 # 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
257 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
258 '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
259
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
260 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
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 try:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
269 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
270 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
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 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
279 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
280 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
281 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
282 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
283 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
284 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
285 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
286 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
287 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
288 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
289 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
290 else: # fasta
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
291 seqid = None
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
292 seq = ''
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 seq = ''
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
303 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 fh.close()
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
312 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
313 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
314
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['prediction']['header']:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
316 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
317 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
318 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
319 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
320 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
321 try:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
322 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
323 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
324 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
325 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
326 else:
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
327 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
328 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
329 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
330 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
331 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
332
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
333
fe3c43451319 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/iedb_api commit 9aaa7c6c7241db52681b12939ebd908902830ef1"
iuc
parents:
diff changeset
334 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
335 __main__()