Mercurial > repos > galaxyp > dbbuilder
annotate uniprotkb.py @ 11:8e637098a8ab 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:22:04 +0000 |
parents | |
children |
rev | line source |
---|---|
11
8e637098a8ab
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 |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
2 |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
3 import argparse |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
4 import sys |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
5 |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
6 import requests |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
7 |
8e637098a8ab
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=' |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
9 |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
10 |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
11 def __main__(): |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
12 parser = argparse.ArgumentParser( |
8e637098a8ab
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') |
8e637098a8ab
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") |
8e637098a8ab
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") |
8e637098a8ab
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') |
8e637098a8ab
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') |
8e637098a8ab
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() |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
19 if args.url: |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
20 url = args.url |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
21 else: |
8e637098a8ab
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 |
8e637098a8ab
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: |
8e637098a8ab
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() |
8e637098a8ab
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): |
8e637098a8ab
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) |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
27 |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
28 |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
29 if __name__ == "__main__": |
8e637098a8ab
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/dbbuilder commit 16ba4570b04301b774ee0420694f379cc640744b
galaxyp
parents:
diff
changeset
|
30 __main__() |