annotate eutils.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
1 import os
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
2 import json
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
3 import StringIO
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
4 from Bio import Entrez
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
5 Entrez.tool = "GalaxyEutils_1_0"
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
6 BATCH_SIZE = 200
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
7
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
8
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
9 class Client(object):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
10
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
11 def __init__(self, history_file=None, user_email=None, admin_email=None):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
12 self.using_history = False
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
13
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
14 if user_email is not None and admin_email is not None:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
15 Entrez.email = ';'.join((admin_email, user_email))
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
16 elif user_email is not None:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
17 Entrez.email = user_email
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
18 elif admin_email is not None:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
19 Entrez.email = admin_email
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
20 else:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
21 Entrez.email = os.environ.get('NCBI_EUTILS_CONTACT', None)
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
22
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
23 if Entrez.email is None:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
24 raise Exception("Cannot continue without an email; please set "
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
25 "administrator email in NCBI_EUTILS_CONTACT")
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
26
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
27 if history_file is not None:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
28 with open(history_file, 'r') as handle:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
29 data = json.loads(handle.read())
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
30 self.query_key = data['QueryKey']
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
31 self.webenv = data['WebEnv']
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
32 self.using_history = True
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
33
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
34 def get_history(self):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
35 if not self.using_history:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
36 return {}
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
37 else:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
38 return {
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
39 'query_key': self.query_key,
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
40 'WebEnv': self.webenv,
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
41 }
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
42
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
43 def post(self, database, **payload):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
44 return json.dumps(Entrez.read(Entrez.epost(database, **payload)), indent=4)
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
45
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
46 def fetch(self, db, whole=False, **payload):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
47 if whole:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
48 if 'id' in payload:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
49 summary = self.id_summary(db, payload['id'])
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
50 else:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
51 summary = self.history_summary(db)
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
52
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
53 count = len(summary)
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
54
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
55 payload['retmax'] = BATCH_SIZE
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
56
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
57 # Print the first one
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
58 print Entrez.efetch(db, **payload).read()
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
59 # Then write subsequent to files for <discover datasets>
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
60 for i in range(BATCH_SIZE, count, BATCH_SIZE):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
61 payload['retstart'] = i
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
62 # TODO: output multiple files??? Collection?
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
63 with open('%s.out' % i, 'w') as handle:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
64 handle.write(Entrez.efetch(db, **payload).read())
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
65 else:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
66 print Entrez.efetch(db, **payload).read()
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
67
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
68 def id_summary(self, db, id_list):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
69 payload = {
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
70 'db': db,
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
71 'id': id_list,
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
72 }
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
73 return Entrez.read(Entrez.esummary(**payload))
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
74
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
75 def history_summary(self, db):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
76 if not self.using_history:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
77 raise Exception("History must be available for this method")
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
78
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
79 payload = {
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
80 'db': db,
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
81 'query_key': self.query_key,
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
82 'WebEnv': self.webenv,
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
83 }
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
84 return Entrez.read(Entrez.esummary(**payload))
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
85
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
86 def summary(self, **payload):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
87 return Entrez.esummary(**payload).read()
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
88
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
89 def link(self, **payload):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
90 return Entrez.elink(**payload).read()
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
91
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
92 def extract_history(self, xml_data):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
93 parsed_data = Entrez.read(StringIO.StringIO(xml_data))
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
94 history = {}
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
95 for key in ('QueryKey', 'WebEnv'):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
96 if key in parsed_data:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
97 history[key] = parsed_data[key]
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
98
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
99 return history
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
100
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
101 def search(self, **payload):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
102 return Entrez.esearch(**payload).read()
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
103
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
104 def info(self, **kwargs):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
105 return Entrez.einfo(**kwargs).read()
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
106
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
107 def gquery(self, **kwargs):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
108 return Entrez.egquery(**kwargs).read()
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
109
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
110 def citmatch(self, **kwargs):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
111 return Entrez.ECitMatch(**kwargs).read()
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
112
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
113 @classmethod
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
114 def parse_ids(cls, id_list, id, history_file):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
115 """Parse IDs passed on --cli or in a file passed to the cli
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
116 """
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
117 merged_ids = []
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
118 if id is not None:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
119 for pid in id.replace('__cn__', ',').replace('\n', ',').split(','):
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
120 if pid is not None and len(pid) > 0:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
121 merged_ids.append(pid)
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
122
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
123 if id_list is not None:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
124 with open(id_list, 'r') as handle:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
125 merged_ids += [x.strip() for x in handle.readlines()]
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
126
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
127 # Exception hanlded here for uniformity
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
128 if len(merged_ids) == 0 and history_file is None:
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
129 raise Exception("Must provide history file or IDs")
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
130
22fed2340d2b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 780c9984a9c44d046aadf1e316a668d1e53aa1f0
iuc
parents:
diff changeset
131 return merged_ids