annotate uniprot.py @ 9:468c71dac78a draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
author bgruening
date Wed, 22 May 2024 21:18:15 +0000
parents af5eccf83605
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
cd2a41c65447 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit fb201f32a92466c2bd8086e91bbf777401f1b489
bgruening
parents: 0
diff changeset
1 import argparse
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
2 import json
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
3 import re
1
cd2a41c65447 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit fb201f32a92466c2bd8086e91bbf777401f1b489
bgruening
parents: 0
diff changeset
4 import sys
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
5 import time
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
6 import zlib
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
7 from urllib.parse import (
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
8 parse_qs,
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
9 urlencode,
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
10 urlparse,
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
11 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
12 from xml.etree import ElementTree
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
13
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
14 import requests
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
15 from requests.adapters import (
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
16 HTTPAdapter,
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
17 Retry,
7
bfdc6a7ffd3a "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit ddbed5f0b0879b4a001d2da6a521b0c9a39c1e7b"
bgruening
parents: 5
diff changeset
18 )
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
19
1
cd2a41c65447 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit fb201f32a92466c2bd8086e91bbf777401f1b489
bgruening
parents: 0
diff changeset
20
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
21 POLLING_INTERVAL = 3
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
22 API_URL = "https://rest.uniprot.org"
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
23
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
24
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
25 retries = Retry(total=5, backoff_factor=0.25, status_forcelist=[500, 502, 503, 504])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
26 session = requests.Session()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
27 session.mount("https://", HTTPAdapter(max_retries=retries))
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
28
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
29
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
30 def check_response(response):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
31 try:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
32 response.raise_for_status()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
33 except requests.HTTPError:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
34 print(response.json())
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
35 raise
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
36
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
37
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
38 def submit_id_mapping(from_db, to_db, ids):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
39 print(f"{from_db} {to_db}")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
40 request = requests.post(
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
41 f"{API_URL}/idmapping/run",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
42 data={"from": from_db, "to": to_db, "ids": ",".join(ids)},
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
43 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
44 check_response(request)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
45 return request.json()["jobId"]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
46
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
47
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
48 def get_next_link(headers):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
49 re_next_link = re.compile(r'<(.+)>; rel="next"')
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
50 if "Link" in headers:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
51 match = re_next_link.match(headers["Link"])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
52 if match:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
53 return match.group(1)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
54
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
55
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
56 def check_id_mapping_results_ready(job_id):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
57 while True:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
58 request = session.get(f"{API_URL}/idmapping/status/{job_id}")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
59 check_response(request)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
60 j = request.json()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
61 if "jobStatus" in j:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
62 if j["jobStatus"] == "RUNNING":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
63 print(f"Retrying in {POLLING_INTERVAL}s")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
64 time.sleep(POLLING_INTERVAL)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
65 else:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
66 raise Exception(j["jobStatus"])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
67 else:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
68 return bool(j["results"] or j["failedIds"])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
69
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
70
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
71 def get_batch(batch_response, file_format, compressed):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
72 batch_url = get_next_link(batch_response.headers)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
73 while batch_url:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
74 batch_response = session.get(batch_url)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
75 batch_response.raise_for_status()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
76 yield decode_results(batch_response, file_format, compressed)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
77 batch_url = get_next_link(batch_response.headers)
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
78
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
79
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
80 def combine_batches(all_results, batch_results, file_format):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
81 if file_format == "json":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
82 for key in ("results", "failedIds"):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
83 if key in batch_results and batch_results[key]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
84 all_results[key] += batch_results[key]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
85 elif file_format == "tsv":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
86 return all_results + batch_results[1:]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
87 else:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
88 return all_results + batch_results
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
89 return all_results
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
90
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
91
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
92 def get_id_mapping_results_link(job_id):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
93 url = f"{API_URL}/idmapping/details/{job_id}"
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
94 request = session.get(url)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
95 check_response(request)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
96 return request.json()["redirectURL"]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
97
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
98
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
99 def decode_results(response, file_format, compressed):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
100 if compressed:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
101 decompressed = zlib.decompress(response.content, 16 + zlib.MAX_WBITS)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
102 if file_format == "json":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
103 j = json.loads(decompressed.decode("utf-8"))
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
104 return j
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
105 elif file_format == "tsv":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
106 return [line for line in decompressed.decode("utf-8").split("\n") if line]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
107 elif file_format == "xlsx":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
108 return [decompressed]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
109 elif file_format == "xml":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
110 return [decompressed.decode("utf-8")]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
111 else:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
112 return decompressed.decode("utf-8")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
113 elif file_format == "json":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
114 return response.json()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
115 elif file_format == "tsv":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
116 return [line for line in response.text.split("\n") if line]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
117 elif file_format == "xlsx":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
118 return [response.content]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
119 elif file_format == "xml":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
120 return [response.text]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
121 return response.text
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
122
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
123
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
124 def get_xml_namespace(element):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
125 m = re.match(r"\{(.*)\}", element.tag)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
126 return m.groups()[0] if m else ""
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
127
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
128
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
129 def merge_xml_results(xml_results):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
130 merged_root = ElementTree.fromstring(xml_results[0])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
131 for result in xml_results[1:]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
132 root = ElementTree.fromstring(result)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
133 for child in root.findall("{http://uniprot.org/uniprot}entry"):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
134 merged_root.insert(-1, child)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
135 ElementTree.register_namespace("", get_xml_namespace(merged_root[0]))
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
136 return ElementTree.tostring(merged_root, encoding="utf-8", xml_declaration=True)
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
137
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
138
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
139 def print_progress_batches(batch_index, size, total):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
140 n_fetched = min((batch_index + 1) * size, total)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
141 print(f"Fetched: {n_fetched} / {total}")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
142
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
143
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
144 def get_id_mapping_results_search(url):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
145 parsed = urlparse(url)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
146 query = parse_qs(parsed.query)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
147 file_format = query["format"][0] if "format" in query else "json"
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
148 if "size" in query:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
149 size = int(query["size"][0])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
150 else:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
151 size = 500
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
152 query["size"] = size
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
153 compressed = (
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
154 query["compressed"][0].lower() == "true" if "compressed" in query else False
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
155 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
156 parsed = parsed._replace(query=urlencode(query, doseq=True))
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
157 url = parsed.geturl()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
158 request = session.get(url)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
159 check_response(request)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
160 results = decode_results(request, file_format, compressed)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
161 total = int(request.headers["x-total-results"])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
162 print_progress_batches(0, size, total)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
163 for i, batch in enumerate(get_batch(request, file_format, compressed), 1):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
164 results = combine_batches(results, batch, file_format)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
165 print_progress_batches(i, size, total)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
166 if file_format == "xml":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
167 return merge_xml_results(results)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
168 return results
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
169
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
170
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
171 # print(results)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
172 # {'results': [{'from': 'P05067', 'to': 'CHEMBL2487'}], 'failedIds': ['P12345']}
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
173
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
174 if __name__ == "__main__":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
175 parser = argparse.ArgumentParser(description="retrieve uniprot mapping")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
176 subparsers = parser.add_subparsers(dest="tool")
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
177
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
178 mapping = subparsers.add_parser("map")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
179 mapping.add_argument("f", help="from")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
180 mapping.add_argument("t", help="to")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
181 mapping.add_argument(
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
182 "inp",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
183 nargs="?",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
184 type=argparse.FileType("r"),
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
185 default=sys.stdin,
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
186 help="input file (default: stdin)",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
187 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
188 mapping.add_argument(
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
189 "out",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
190 nargs="?",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
191 type=argparse.FileType("w"),
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
192 default=sys.stdout,
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
193 help="output file (default: stdout)",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
194 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
195 mapping.add_argument("--format", default="tab", help="output format")
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
196
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
197 retrieve = subparsers.add_parser("retrieve")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
198 retrieve.add_argument(
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
199 "inp",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
200 metavar="in",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
201 nargs="?",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
202 type=argparse.FileType("r"),
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
203 default=sys.stdin,
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
204 help="input file (default: stdin)",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
205 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
206 retrieve.add_argument(
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
207 "out",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
208 nargs="?",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
209 type=argparse.FileType("w"),
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
210 default=sys.stdout,
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
211 help="output file (default: stdout)",
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
212 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
213 retrieve.add_argument("-f", "--format", help="specify output format", default="txt")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
214 mapping = subparsers.add_parser("menu")
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
215
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
216 args = parser.parse_args()
7
bfdc6a7ffd3a "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit ddbed5f0b0879b4a001d2da6a521b0c9a39c1e7b"
bgruening
parents: 5
diff changeset
217
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
218 # code for auto generating the from - to conditional
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
219 if args.tool == "menu":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
220 from lxml import etree
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
221
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
222 request = session.get("https://rest.uniprot.org/configure/idmapping/fields")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
223 check_response(request)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
224 fields = request.json()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
225
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
226 tos = dict()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
227 from_cond = etree.Element("conditional", name="from_cond")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
228 from_select = etree.SubElement(
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
229 from_cond, "param", name="from", type="select", label="Source database:"
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
230 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
231
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
232 rules = dict()
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
233 for rule in fields["rules"]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
234 rules[rule["ruleId"]] = rule["tos"]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
235
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
236 for group in fields["groups"]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
237 group_name = group["groupName"]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
238 group_name = group_name.replace("databases", "DBs")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
239 for item in group["items"]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
240 if item["to"]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
241 tos[item["name"]] = f"{group_name} - {item['displayName']}"
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
242
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
243 for group in fields["groups"]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
244 group_name = group["groupName"]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
245 group_name = group_name.replace("databases", "DBs")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
246 for item in group["items"]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
247 if not item["from"]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
248 continue
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
249 option = etree.SubElement(from_select, "option", value=item["name"])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
250 option.text = f"{group_name} - {item['displayName']}"
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
251 when = etree.SubElement(from_cond, "when", value=item["name"])
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
252
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
253 to_select = etree.SubElement(
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
254 when, "param", name="to", type="select", label="Target database:"
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
255 )
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
256 ruleId = item["ruleId"]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
257 for to in rules[ruleId]:
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
258 option = etree.SubElement(to_select, "option", value=to)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
259 option.text = tos[to]
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
260 etree.indent(from_cond, space=" ")
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
261 print(etree.tostring(from_cond, pretty_print=True, encoding="unicode"))
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
262 sys.exit(0)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
263
7
bfdc6a7ffd3a "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit ddbed5f0b0879b4a001d2da6a521b0c9a39c1e7b"
bgruening
parents: 5
diff changeset
264 # get the IDs from the file as sorted list
bfdc6a7ffd3a "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit ddbed5f0b0879b4a001d2da6a521b0c9a39c1e7b"
bgruening
parents: 5
diff changeset
265 # (sorted is convenient for testing)
bfdc6a7ffd3a "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit ddbed5f0b0879b4a001d2da6a521b0c9a39c1e7b"
bgruening
parents: 5
diff changeset
266 query = set()
bfdc6a7ffd3a "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit ddbed5f0b0879b4a001d2da6a521b0c9a39c1e7b"
bgruening
parents: 5
diff changeset
267 for line in args.inp:
bfdc6a7ffd3a "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit ddbed5f0b0879b4a001d2da6a521b0c9a39c1e7b"
bgruening
parents: 5
diff changeset
268 query.add(line.strip())
bfdc6a7ffd3a "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit ddbed5f0b0879b4a001d2da6a521b0c9a39c1e7b"
bgruening
parents: 5
diff changeset
269 query = sorted(query)
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
270
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
271 if args.tool == "map":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
272 job_id = submit_id_mapping(from_db=args.f, to_db=args.t, ids=query)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
273 elif args.tool == "retrieve":
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
274 job_id = submit_id_mapping(
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
275 from_db="UniProtKB_AC-ID", to_db="UniProtKB", ids=query
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
276 )
0
48522382b6a4 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit 2b8ad1bbfe098129ae32cd8311a755dff58ae97b-dirty
bgruening
parents:
diff changeset
277
9
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
278 if check_id_mapping_results_ready(job_id):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
279 link = get_id_mapping_results_link(job_id)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
280 link = f"{link}?format={args.format}"
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
281 print(link)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
282 results = get_id_mapping_results_search(link)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
283
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
284 if not isinstance(results, str):
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
285 results = "\n".join(results)
468c71dac78a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/uniprot_rest_interface commit da476148d1c609f5c26e880a3e593f0fa71ff2f6
bgruening
parents: 8
diff changeset
286 args.out.write(f"{results}\n")