Mercurial > repos > iuc > ncbi_eutils_egquery
diff eutils.py @ 5:20a86bfb54eb 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:38:00 -0400 |
| parents | 484b84b30c75 |
| children | 2d54a753d1f1 |
line wrap: on
line diff
--- a/eutils.py Fri Jun 10 15:03:27 2016 -0400 +++ b/eutils.py Thu Jul 07 02:38:00 2016 -0400 @@ -43,27 +43,23 @@ def post(self, database, **payload): return json.dumps(Entrez.read(Entrez.epost(database, **payload)), indent=4) - def fetch(self, db, whole=False, **payload): - if whole: - if 'id' in payload: - summary = self.id_summary(db, payload['id']) - else: - summary = self.history_summary(db) + def fetch(self, db, ftype=None, **payload): + os.makedirs("downloads") - count = len(summary) - - payload['retmax'] = BATCH_SIZE + if 'id' in payload: + summary = self.id_summary(db, payload['id']) + else: + summary = self.history_summary(db) - # Print the first one - print Entrez.efetch(db, **payload).read() - # Then write subsequent to files for <discover datasets> - for i in range(BATCH_SIZE, count, BATCH_SIZE): - payload['retstart'] = i - # TODO: output multiple files??? Collection? - with open('%s.out' % i, 'w') as handle: - handle.write(Entrez.efetch(db, **payload).read()) - else: - print Entrez.efetch(db, **payload).read() + count = len(summary) + payload['retmax'] = BATCH_SIZE + + # This may be bad. I'm not sure yet. I think it will be ... but UGH. + for i in range(0, count, BATCH_SIZE): + payload['retstart'] = i + file_path = os.path.join('downloads', 'EFetch Results Chunk %s.%s' % (i, ftype)) + with open(file_path, 'w') as handle: + handle.write(Entrez.efetch(db, **payload).read()) def id_summary(self, db, id_list): payload = { @@ -108,7 +104,7 @@ return Entrez.egquery(**kwargs).read() def citmatch(self, **kwargs): - return Entrez.ECitMatch(**kwargs).read() + return Entrez.ecitmatch(**kwargs).read() @classmethod def parse_ids(cls, id_list, id, history_file):
