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