Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. from __future__ import print_function
  2. import argparse
  3.  
  4. import onecodex
  5.  
  6.  
  7. if __name__ == "__main__":
  8. parser = argparse.ArgumentParser(
  9. description=("Download a set of FASTA/Q files stored in One Codex with their sample IDs."))
  10. parser.add_argument('samples', metavar='sample ID', nargs='+',
  11. help='One Codex sample IDs to download')
  12. parser.add_argument('--api-key', default=None,
  13. help='One Codex API key (optional if a ~/.onecodex file exists)')
  14. args = parser.parse_args()
  15.  
  16. # Automatically fetch API key from ~/.onecodex file
  17. ocx = onecodex.Api(api_key=args.api_key)
  18.  
  19. # Check that the verison is OK (> 0.2.0)
  20. assert tuple(int(x) for x in onecodex.version.__version__.split('.')) > (0, 2, 0)
  21.  
  22. for ix, uuid in enumerate(args.samples):
  23. sample = ocx.Samples.get(uuid)
  24. if sample is None:
  25. raise Exception('Could not fetch sample {}. Double check that the Sample ID '
  26. 'is correct and that you are logged in with '
  27. '`onecodex login`.'.format(uuid))
  28. print('Downloading {} (sample {}/{})...'.format(sample.filename, ix + 1, len(args.samples)))
  29. sample.download()
  30.  
  31. print('Done!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement