comparison eutils.py @ 5:e269b3b5185b 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:37:49 -0400
parents c26d1863f3f3
children 2ff5369b4b51
comparison
equal deleted inserted replaced
4:c26d1863f3f3 5:e269b3b5185b
41 } 41 }
42 42
43 def post(self, database, **payload): 43 def post(self, database, **payload):
44 return json.dumps(Entrez.read(Entrez.epost(database, **payload)), indent=4) 44 return json.dumps(Entrez.read(Entrez.epost(database, **payload)), indent=4)
45 45
46 def fetch(self, db, whole=False, **payload): 46 def fetch(self, db, ftype=None, **payload):
47 if whole: 47 os.makedirs("downloads")
48 if 'id' in payload:
49 summary = self.id_summary(db, payload['id'])
50 else:
51 summary = self.history_summary(db)
52 48
53 count = len(summary) 49 if 'id' in payload:
50 summary = self.id_summary(db, payload['id'])
51 else:
52 summary = self.history_summary(db)
54 53
55 payload['retmax'] = BATCH_SIZE 54 count = len(summary)
55 payload['retmax'] = BATCH_SIZE
56 56
57 # Print the first one 57 # This may be bad. I'm not sure yet. I think it will be ... but UGH.
58 print Entrez.efetch(db, **payload).read() 58 for i in range(0, count, BATCH_SIZE):
59 # Then write subsequent to files for <discover datasets> 59 payload['retstart'] = i
60 for i in range(BATCH_SIZE, count, BATCH_SIZE): 60 file_path = os.path.join('downloads', 'EFetch Results Chunk %s.%s' % (i, ftype))
61 payload['retstart'] = i 61 with open(file_path, 'w') as handle:
62 # TODO: output multiple files??? Collection? 62 handle.write(Entrez.efetch(db, **payload).read())
63 with open('%s.out' % i, 'w') as handle:
64 handle.write(Entrez.efetch(db, **payload).read())
65 else:
66 print Entrez.efetch(db, **payload).read()
67 63
68 def id_summary(self, db, id_list): 64 def id_summary(self, db, id_list):
69 payload = { 65 payload = {
70 'db': db, 66 'db': db,
71 'id': id_list, 67 'id': id_list,
106 102
107 def gquery(self, **kwargs): 103 def gquery(self, **kwargs):
108 return Entrez.egquery(**kwargs).read() 104 return Entrez.egquery(**kwargs).read()
109 105
110 def citmatch(self, **kwargs): 106 def citmatch(self, **kwargs):
111 return Entrez.ECitMatch(**kwargs).read() 107 return Entrez.ecitmatch(**kwargs).read()
112 108
113 @classmethod 109 @classmethod
114 def parse_ids(cls, id_list, id, history_file): 110 def parse_ids(cls, id_list, id, history_file):
115 """Parse IDs passed on --cli or in a file passed to the cli 111 """Parse IDs passed on --cli or in a file passed to the cli
116 """ 112 """