annotate elink.py @ 1:5b1dc5936af2 draft

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