annotate iedb_api.py @ 0:991424605492 draft

"planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
author jjohnson
date Mon, 17 Feb 2020 16:04:07 -0500
parents
children 4a89ba6cfc63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
1 #!/usr/bin/env python
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
2 """
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
3 """
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
4 import sys
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
5 import os.path
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
6 import re
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
7 import optparse
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
8 import urllib
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
9 import urllib2
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
10 from optparse import OptionParser
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
11
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
12 mhci_methods = ['recommended','consensus','netmhcpan','ann','smmpmbec','smm','comblib_sidney2008','netmhccons','pickpocket']
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
13 mhcii_methods = ['recommended','consensus3','NetMHCIIpan','nn_align','smm_align','comblib','tepitope']
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
14 processing_methods = ['recommended','consensus','netmhcpan','ann','smmpmbec','smm','comblib_sidney2008']
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
15 mhcnp_methods = ['mhcnp']
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
16 bcell_methods = ['Bepipred','Chou-FasmanEmini','Karplus-Schulz','Kolaskar-Tongaonkar','Parker']
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
17 prediction_methods = {'mhci':mhci_methods,'mhcii':mhcii_methods,'processing':processing_methods,'mhcnp':mhcnp_methods,'bcell':bcell_methods}
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
18
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
19 def warn_err(msg,exit_code=1):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
20 sys.stderr.write(msg)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
21 if exit_code:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
22 sys.exit(exit_code)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
23
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
24
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
25 def __main__():
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
26 #Parse Command Line
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
27 parser = optparse.OptionParser()
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
28 parser.add_option( '-p', '--prediction', dest='prediction', default='mhci', choices=['mhci','mhcii','processing','mhcnp','bcell'], help='IEDB API prediction service' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
29 parser.add_option( '-s', '--sequence', dest='sequence', action="append", default=None, help='Peptide Sequence' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
30 parser.add_option( '-m', '--method', dest='method', default='recommended', choices=['recommended','consensus','netmhcpan','ann','smmpmbec','smm','comblib_sidney2008','netmhccons','pickpocket' ], help='prediction method' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
31 parser.add_option( '-a', '--allele', dest='allele', action="append", default=[], help='Alleles for which to make predictions' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
32 parser.add_option( '-l', '--length', dest='length', action="append", default=[], choices=['8', '9', '10', '11', '12', '13', '14', '15'], help='lengths for which to make predictions, 1 per allele' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
33 parser.add_option( '-i', '--input', dest='input', default=None, help='Input file for peptide sequences (fasta or tabular)' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
34 parser.add_option( '-c', '--column', dest='column', default=None, help='Peptide Column in a tabular input file' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
35 parser.add_option( '-C', '--id_column', dest='id_column', default=None, help='ID Column in a tabular input file' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
36 parser.add_option( '-o', '--output', dest='output', default=None, help='Output file for query results' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
37 parser.add_option( '-d', '--debug', dest='debug', action='store_true', default=False, help='Turn on wrapper debugging to stderr' )
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
38 (options, args) = parser.parse_args()
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
39
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
40 aapat = '^[ABCDEFGHIKLMNPQRSTVWY]+$'
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
41
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
42 if not options.allele and options.prediction != 'bcell':
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
43 warn_err('-a allele required\n', exit_code=1)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
44
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
45 if not (options.sequence or options.input):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
46 warn_err('NO Sequences given: either -s sequence or -i input_file is required\n', exit_code=1)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
47
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
48 if options.output != None:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
49 try:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
50 outputPath = os.path.abspath(options.output)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
51 outputFile = open(outputPath, 'w')
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
52 except Exception, e:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
53 warn_err("Unable to open output file: %s\n" % e, exit_code=1)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
54 else:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
55 outputFile = sys.stdout
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
56
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
57 url = 'http://tools-api.iedb.org/tools_api/%s/' % options.prediction
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
58
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
59 #TODO parse alleles from the options.alleles file
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
60 alleles = ','.join(options.allele)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
61 lengths = ','.join(options.length)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
62 method = options.method
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
63
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
64 results = []
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
65 global header
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
66 header = None
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
67
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
68 sequence_text = []
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
69 def add_seq(seqid,seq):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
70 sequence_text.append(">%s\n%s" % (seqid if seqid else "peptide%d" % len(sequence_text),seq))
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
71
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
72 def query(url,seq,allele,length,seqid=None,method='recommended'):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
73 global header
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
74 params = dict()
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
75 if method:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
76 params['method'] = method
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
77 params['sequence_text'] = seq
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
78 params['allele'] = allele
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
79 params['length'] = length
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
80 data = urllib.urlencode(params)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
81 request = urllib2.Request(url, data)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
82 if options.debug:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
83 print >> sys.stderr, "url %s %s %s" % (request.get_full_url(), seqid if seqid else "None", seq)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
84 response = None
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
85 response = urllib2.urlopen(request)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
86 if response and response.getcode() == 200:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
87 resp_data = response.readlines()
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
88 for line in resp_data:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
89 if line.find('eptide') > 0:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
90 header = "#%s%s" % ("ID\t" if seqid else "", line)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
91 continue
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
92 if seqid:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
93 results.append("%s\t%s" % (seqid,line))
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
94 else:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
95 results.append(line)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
96 elif not response:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
97 warn_err("NO response from IEDB server\n", exit_code=3)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
98 else:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
99 warn_err("Error connecting to IEDB server\n", exit_code=response.getcode())
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
100
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
101 if options.sequence:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
102 for i,seq in enumerate(options.sequence):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
103 query(url,seq,alleles,lengths,seqid=None,method=method)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
104 if options.input:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
105 try:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
106 fh = open(options.input,'r')
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
107 if options.column: ## tabular
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
108 col = int(options.column)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
109 idcol = int(options.id_column) if options.id_column else None
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
110 for i,line in enumerate(fh):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
111 fields = line.split('\t')
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
112 if len(fields) > col:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
113 seq = re.sub('[_*]','',fields[col])
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
114 if re.match(aapat,seq):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
115 seqid = fields[idcol] if idcol != None and idcol < len(fields) else None
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
116 query(url,seq,alleles,lengths,seqid=seqid,method=method)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
117 else:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
118 warn_err('Line %d, Not a peptide: %s\n' % (i,seq),exit_code=None)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
119 else: ## fasta
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
120 seqid = None
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
121 seq = ''
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
122 for i,line in enumerate(fh):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
123 if line.startswith('>'):
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
124 if seqid and len(seq) > 0:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
125 query(url,seq,alleles,lengths,seqid=seqid,method=method)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
126 seqid = line[1:].strip()
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
127 seq = ''
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
128 else:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
129 seq += line.strip()
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
130 if seqid and len(seq) > 0:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
131 query(url,seq,alleles,lengths,seqid=seqid,method=method)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
132 fh.close()
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
133 except Exception, e:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
134 warn_err("Unable to open input file: %s\n" % e, exit_code=1)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
135
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
136 if header:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
137 outputFile.write(header)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
138 for line in results:
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
139 outputFile.write(line)
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
140
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
141 if __name__ == "__main__": __main__()
991424605492 "planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/iedb_api commit bbca4d5248b883344319e7a9f42c82d20a11cf0d"
jjohnson
parents:
diff changeset
142