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