comparison esearch.py @ 0:92bd8a680b9d 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:41:02 -0400
parents
children c8d4ea6376a7
comparison
equal deleted inserted replaced
-1:000000000000 0:92bd8a680b9d
1 #!/usr/bin/env python
2 import json
3 import argparse
4 import eutils
5
6
7 if __name__ == '__main__':
8 parser = argparse.ArgumentParser(description='ESearch', epilog='')
9 parser.add_argument('db', help='Database to use')
10 parser.add_argument('term', help='Query')
11 parser.add_argument('--history_file', help='Filter existing history')
12 parser.add_argument('--datetype', help='Date type')
13 parser.add_argument('--reldate', help='In past N days')
14 parser.add_argument('--mindate', help='Minimum date')
15 parser.add_argument('--maxdate', help='maximum date')
16 # History
17 parser.add_argument('--history_out', type=argparse.FileType('w'),
18 help='Output history file')
19 parser.add_argument('--user_email', help="User email")
20 parser.add_argument('--admin_email', help="Admin email")
21 args = parser.parse_args()
22
23 c = eutils.Client(history_file=args.history_file, user_email=args.user_email, admin_email=args.admin_email)
24
25 payload = {
26 'db': args.db,
27 'term': args.term,
28 'retstart': 0,
29 'retmax': 20,
30 # hmmm @ retmax
31 }
32 if args.history_file is not None:
33 payload.update(c.get_history())
34 if args.history_out is not None:
35 payload['usehistory'] = 'y'
36
37 for attr in ('datetype', 'reldate', 'mindate', 'maxdate'):
38 if getattr(args, attr, None) is not None:
39 payload[attr] = getattr(args, attr)
40
41 results = c.search(**payload)
42
43 if args.history_out is not None:
44 history = c.extract_history(results)
45 args.history_out.write(json.dumps(history, indent=4))
46
47 print results