Mercurial > repos > iuc > ncbi_eutils_esummary
annotate efetch.py @ 4:ff3a5e980fab draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 25545b698cffc9999cde0079b3be176f55e17803"
author | iuc |
---|---|
date | Mon, 04 Jan 2021 11:45:16 +0000 |
parents | 254f40d3ae2b |
children | 7fe990069458 |
rev | line source |
---|---|
0
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
3
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
2 |
0
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
3 import argparse |
3
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
4 import glob |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
5 import json |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
6 import logging |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
7 import os |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
8 |
1
c8d4ea6376a7
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit a4b0969b33a68a0ea9ba12291f6694aec24f13ed
iuc
parents:
0
diff
changeset
|
9 |
0
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
10 import eutils |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
11 |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
12 |
3
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
13 logging.basicConfig(level=logging.INFO) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
14 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
15 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
16 def handleEfetchException(e, db, payload): |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
17 logging.error('No results returned. This could either be due to no records matching the supplied IDs for the query database or it could be an error due to invalid parameters. The reported exception was "%s".\n\nPayload used for the efetch query to database "%s"\n\n%s', e, db, json.dumps(payload, indent=4)) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
18 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
19 # Create a file in the downloads folder so that the user can access run information |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
20 current_directory = os.getcwd() |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
21 final_directory = os.path.join(current_directory, r'downloads') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
22 if not os.path.exists(final_directory): |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
23 os.makedirs(final_directory) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
24 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
25 print('The following files were downloaded:') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
26 print(os.listdir(final_directory)) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
27 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
28 file_path = os.path.join('downloads', 'no_results.txt') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
29 with open(file_path, 'w') as handle: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
30 handle.write('No results') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
31 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
32 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
33 def localFetch(db, gformat, newname, **payload): |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
34 problem = None |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
35 try: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
36 c.fetch(db, **payload) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
37 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
38 for chunk, file in enumerate(glob.glob('downloads/EFetch *')): |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
39 os.rename(file, '%s%s.%s' % (newname, chunk + 1, gformat)) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
40 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
41 except Exception as e: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
42 problem = e |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
43 handleEfetchException(e, db, payload) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
44 else: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
45 print('The following files were downloaded:') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
46 print(os.listdir('downloads')) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
47 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
48 return problem |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
49 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
50 |
0
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
51 if __name__ == '__main__': |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
52 parser = argparse.ArgumentParser(description='EFetch', epilog='') |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
53 parser.add_argument('db', help='Database to use') |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
54 parser.add_argument('--user_email', help="User email") |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
55 parser.add_argument('--admin_email', help="Admin email") |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
56 |
3
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
57 parser.add_argument('--version', action='version', version=eutils.Client.getVersion(), help='Version (reports Biopython version)') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
58 |
0
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
59 # ID source |
3
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
60 parser.add_argument('--id_json', help='list of ids in a json file as returned by esearch or elink') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
61 parser.add_argument('--id_xml', help='list of ids in an xml file as returned by esearch or elink') |
0
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
62 parser.add_argument('--id_list', help='list of ids') |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
63 parser.add_argument('--id', help='Comma separated individual IDs') |
3
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
64 parser.add_argument('--history_file', help='Fetch results from previous query (JSON)') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
65 parser.add_argument('--history_xml', help='Fetch results from previous query (XML)') |
0
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
66 |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
67 # Output |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
68 parser.add_argument('--retmode', help='Retmode') |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
69 parser.add_argument('--rettype', help='Rettype') |
3
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
70 parser.add_argument('--galaxy_format', help='Galaxy format') |
0
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
71 args = parser.parse_args() |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
72 |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
73 c = eutils.Client(history_file=args.history_file, user_email=args.user_email, admin_email=args.admin_email) |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
74 |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
75 payload = {} |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
76 for attr in ('retmode', 'rettype'): |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
77 if getattr(args, attr, None) is not None: |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
78 payload[attr] = getattr(args, attr) |
92bd8a680b9d
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
iuc
parents:
diff
changeset
|
79 |
3
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
80 if args.history_file is not None or args.history_xml is not None: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
81 if args.history_file is not None: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
82 input_histories = c.get_histories() |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
83 else: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
84 input_histories = c.extract_histories_from_xml_file(args.history_xml) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
85 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
86 problem = None |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
87 for hist in input_histories: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
88 qkey = hist['query_key'] |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
89 tmp_payload = payload |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
90 tmp_payload.update(hist) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
91 newname = 'downloads/EFetch-%s-%s-querykey%s-chunk' % (args.rettype, args.retmode, qkey) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
92 problem = localFetch(args.db, args.galaxy_format, newname, **tmp_payload) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
93 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
94 if os.path.exists('downloads'): |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
95 os.rename('downloads', 'downloads-qkey%s' % (qkey)) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
96 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
97 if not os.path.exists('downloads'): |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
98 os.makedirs('downloads') |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
99 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
100 for relpath in glob.glob('downloads-qkey*/*'): |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
101 file = os.path.basename(relpath) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
102 os.rename(relpath, 'downloads/%s' % (file)) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
103 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
104 if problem is not None: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
105 raise(problem) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
106 |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
107 else: |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
108 merged_ids = c.parse_ids(args.id_list, args.id, args.history_file, args.id_xml, args.id_json) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
109 payload['id'] = ','.join(merged_ids) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
110 newname = 'downloads/EFetch-%s-%s-chunk' % (args.rettype, args.retmode) |
254f40d3ae2b
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
iuc
parents:
1
diff
changeset
|
111 localFetch(args.db, args.galaxy_format, newname, **payload) |