Mercurial > repos > bgruening > uniprot_rest_interface
annotate uniprot.py @ 0:48522382b6a4 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
author | bgruening |
---|---|
date | Fri, 09 Oct 2015 16:42:22 -0400 |
parents | |
children | cd2a41c65447 |
rev | line source |
---|---|
0
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
2 """ |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
3 uniprot python interface |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
4 to access the uniprot database |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
5 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
6 Based on work from Jan Rudolph: https://github.com/jdrudolph/uniprot |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
7 available services: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
8 map |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
9 retrieve |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
10 """ |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
11 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
12 import requests |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
13 import sys, argparse |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
14 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
15 url = 'http://www.uniprot.org/' |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
16 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
17 def _retrieve(query, format='txt'): |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
18 """_retrieve is not meant for use with the python interface, use `retrieve` |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
19 instead""" |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
20 tool = 'batch/' |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
21 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
22 query = list(set(query.split('\n'))) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
23 queries = [query[i:i+100] for i in range(0, len(query), 100)] |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
24 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
25 data = {'format':format} |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
26 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
27 responses = [requests.post(url + tool, data=data, files={'file':' '.join(query)}) for query in queries] |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
28 page = ''.join([response.text for response in responses]) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
29 return page |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
30 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
31 def retrieve(ids, format='txt'): |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
32 """ request entries by uniprot acc using batch retrieval |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
33 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
34 Args: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
35 query: list of ids to retrieve |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
36 format: txt by default |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
37 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
38 Help: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
39 possible formats: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
40 txt, xml, rdf, fasta, gff""" |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
41 if type(ids) is not list: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
42 ids = [ids] |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
43 return _retrieve(' '.join(ids), format) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
44 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
45 def _map(query, f, t, format='tab'): |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
46 """ _map is not meant for use with the python interface, use `map` instead |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
47 """ |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
48 tool = 'mapping/' |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
49 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
50 data = { |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
51 'from':f, |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
52 'to':t, |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
53 'format':format, |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
54 'query': query |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
55 } |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
56 response = requests.post(url + tool, data=data) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
57 page = response.text |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
58 return page |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
59 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
60 def map(ids, f, t, format='tab'): |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
61 """ map a list of ids from one format onto another using uniprots mapping api |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
62 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
63 Args: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
64 query: id or list of ids to be mapped |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
65 f: from ACC | P_ENTREZGENEID | ... |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
66 t: to ... |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
67 format: tab by default |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
68 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
69 Help: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
70 for a list of all possible mappings visit |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
71 'http://www.uniprot.org/faq/28' |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
72 """ |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
73 if type(ids) is not list: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
74 ids = [ids] |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
75 page = _map(' '.join(ids), f, t, format) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
76 result = dict() |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
77 for row in page.splitlines()[1:]: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
78 key, value = row.split('\t') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
79 if key in result: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
80 result[key].add(value) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
81 else: |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
82 result[key] = set([value]) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
83 return result |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
84 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
85 if __name__ == '__main__': |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
86 import argparse |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
87 import sys |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
88 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
89 parser = argparse.ArgumentParser(description='retrieve uniprot mapping') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
90 subparsers = parser.add_subparsers(dest='tool') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
91 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
92 mapping = subparsers.add_parser('map') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
93 mapping.add_argument('f', help='from') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
94 mapping.add_argument('t', help='to') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
95 mapping.add_argument('inp', nargs='?', type=argparse.FileType('r'), |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
96 default=sys.stdin, help='input file (default: stdin)') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
97 mapping.add_argument('out', nargs='?', type=argparse.FileType('w'), |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
98 default=sys.stdout, help='output file (default: stdout)') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
99 mapping.add_argument('--format', default='tab', help='output format') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
100 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
101 retrieve = subparsers.add_parser('retrieve') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
102 retrieve.add_argument('inp', metavar = 'in', nargs='?', type=argparse.FileType('r'), |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
103 default=sys.stdin, help='input file (default: stdin)') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
104 retrieve.add_argument('out', nargs='?', type=argparse.FileType('w'), |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
105 default=sys.stdout, help='output file (default: stdout)') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
106 retrieve.add_argument('-f', '--format', help='specify output format', default='txt') |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
107 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
108 args = parser.parse_args() |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
109 query = args.inp.read() |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
110 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
111 if args.tool == 'map': |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
112 args.out.write(_map(query, args.f, args.t, args.format)) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
113 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
114 elif args.tool == 'retrieve': |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
115 args.out.write(_retrieve(query, format=args.format)) |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
116 |
48522382b6a4
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff
changeset
|
117 |