Mercurial > repos > iuc > ncbi_eutils_einfo
comparison elink.py @ 0:32ac58827a97 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
author | iuc |
---|---|
date | Thu, 07 Jul 2016 02:40:06 -0400 |
parents | |
children | 5b1dc5936af2 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:32ac58827a97 |
---|---|
1 #!/usr/bin/env python | |
2 import argparse | |
3 import json | |
4 | |
5 import eutils | |
6 | |
7 | |
8 if __name__ == '__main__': | |
9 parser = argparse.ArgumentParser(description='EFetch', epilog='') | |
10 parser.add_argument('db', help='Database to use, sometimes "none" (e.g. *check)') | |
11 parser.add_argument('dbfrom', help='Database containing input UIDs') | |
12 parser.add_argument('cmd', choices=['neighbor', 'neighbor_score', | |
13 'neighbor_history', 'acheck', 'ncheck', 'lcheck', | |
14 'llinks', 'llinkslib', 'prlinks'], | |
15 help='ELink command mode') | |
16 # Only used in case of neighbor_history | |
17 parser.add_argument('--history_out', type=argparse.FileType('w'), | |
18 help='Output history file', default='-') | |
19 | |
20 parser.add_argument('--user_email', help="User email") | |
21 parser.add_argument('--admin_email', help="Admin email") | |
22 # ID Sources | |
23 parser.add_argument('--id_list', help='list of ids') | |
24 parser.add_argument('--id', help='Comma separated individual IDs') | |
25 parser.add_argument('--history_file', help='Fetch results from previous query') | |
26 | |
27 # TODO: dates, linkname, term, holding | |
28 # neighbor or neighbor_history and dbfrom is pubmed | |
29 # parser.add_argument('--datetype', help='Date type') | |
30 # parser.add_argument('--reldate', help='In past N days') | |
31 # parser.add_argument('--mindate', help='Minimum date') | |
32 # parser.add_argument('--maxdate', help='maximum date') | |
33 | |
34 # Output | |
35 args = parser.parse_args() | |
36 | |
37 c = eutils.Client(history_file=args.history_file, user_email=args.user_email, admin_email=args.admin_email) | |
38 merged_ids = c.parse_ids(args.id_list, args.id, args.history_file) | |
39 | |
40 payload = { | |
41 'dbfrom': args.dbfrom, | |
42 'cmd': args.cmd, | |
43 } | |
44 if args.history_file is not None: | |
45 payload.update(c.get_history()) | |
46 else: | |
47 payload['id'] = ','.join(merged_ids) | |
48 | |
49 # DB can be 'none' in a few cases. | |
50 if args.db != "none": | |
51 payload['db'] = args.db | |
52 | |
53 results = c.link(**payload) | |
54 | |
55 if args.cmd == "neighbor_history": | |
56 history = c.extract_history(results) | |
57 args.history_out.write(json.dumps(history, indent=4)) | |
58 | |
59 print results |