annotate uniprotkb.py @ 8:3f6354b7eb94 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
author galaxyp
date Tue, 27 Sep 2022 13:21:28 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
2
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
3 import argparse
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
4 import sys
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
5
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
6 import requests
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
7
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
8 uniprotkb_url = 'https://rest.uniprot.org/uniprotkb/stream?compressed=true&format=fasta&query='
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
9
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
10
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
11 def __main__():
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
12 parser = argparse.ArgumentParser(
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
13 description='Retrieve Uniprot data using streaming')
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
14 parser.add_argument('-u', '--url', help="Uniprot rest api URL")
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
15 parser.add_argument('-q', '--query', help="UniprotKB Query")
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
16 parser.add_argument('-o', '--output', type=argparse.FileType('wb'), default=sys.stdout, help='data')
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
17 parser.add_argument('-d', '--debug', action='store_true', help='Debug')
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
18 args = parser.parse_args()
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
19 if args.url:
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
20 url = args.url
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
21 else:
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
22 url = uniprotkb_url + args.query
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
23 with requests.get(url, stream=True) as request:
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
24 request.raise_for_status()
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
25 for chunk in request.iter_content(chunk_size=2**20):
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
26 args.output.write(chunk)
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
27
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
28
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
29 if __name__ == "__main__":
3f6354b7eb94 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff changeset
30 __main__()