annotate efetch.py @ 14:5107f3e96e09 draft default tip

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