Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import argparse
- import onecodex
- if __name__ == "__main__":
- parser = argparse.ArgumentParser(
- description=("Download a set of FASTA/Q files stored in One Codex with their sample IDs."))
- parser.add_argument('samples', metavar='sample ID', nargs='+',
- help='One Codex sample IDs to download')
- parser.add_argument('--api-key', default=None,
- help='One Codex API key (optional if a ~/.onecodex file exists)')
- args = parser.parse_args()
- # Automatically fetch API key from ~/.onecodex file
- ocx = onecodex.Api(api_key=args.api_key)
- # Check that the verison is OK (> 0.2.0)
- assert tuple(int(x) for x in onecodex.version.__version__.split('.')) > (0, 2, 0)
- for ix, uuid in enumerate(args.samples):
- sample = ocx.Samples.get(uuid)
- if sample is None:
- raise Exception('Could not fetch sample {}. Double check that the Sample ID '
- 'is correct and that you are logged in with '
- '`onecodex login`.'.format(uuid))
- print('Downloading {} (sample {}/{})...'.format(sample.filename, ix + 1, len(args.samples)))
- sample.download()
- print('Done!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement