pack.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env node
  2. /**
  3. * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  4. *
  5. * Taken/adapted from DensityServer (https://github.com/dsehnal/DensityServer)
  6. *
  7. * @author David Sehnal <david.sehnal@gmail.com>
  8. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  9. */
  10. import * as argparse from 'argparse';
  11. import { pack } from './pack/main';
  12. import { VERSION } from './pack/version';
  13. type FileFormat = 'ccp4' | 'dsn6'
  14. interface Config {
  15. input: { name: string, filename: string }[],
  16. format: FileFormat,
  17. isPeriodic: boolean,
  18. outputFilename: string,
  19. blockSizeInMB: number
  20. }
  21. function getConfig(args: Args) {
  22. const config: Partial<Config> = {
  23. blockSizeInMB: args.blockSizeInMB,
  24. format: args.format,
  25. outputFilename: args.output
  26. };
  27. switch (args.mode) {
  28. case 'em':
  29. config.input = [
  30. { name: 'em', filename: args.inputEm }
  31. ];
  32. config.isPeriodic = false;
  33. break;
  34. case 'xray':
  35. config.input = [
  36. { name: '2Fo-Fc', filename: args.input2fofc },
  37. { name: 'Fo-Fc', filename: args.inputFofc }
  38. ];
  39. config.isPeriodic = true;
  40. break;
  41. }
  42. return config as Config;
  43. }
  44. interface GeneralArgs {
  45. blockSizeInMB: number
  46. format: FileFormat
  47. output: string
  48. }
  49. interface XrayArgs extends GeneralArgs {
  50. mode: 'xray'
  51. input2fofc: string
  52. inputFofc: string
  53. }
  54. interface EmArgs extends GeneralArgs {
  55. mode: 'em'
  56. inputEm: string
  57. }
  58. type Args = XrayArgs | EmArgs
  59. const parser = new argparse.ArgumentParser({
  60. add_help: true,
  61. description: `VolumeServer Packer ${VERSION}, (c) 2018-2019, Mol* contributors`
  62. });
  63. const subparsers = parser.add_subparsers({
  64. title: 'Packing modes',
  65. dest: 'mode'
  66. });
  67. function addGeneralArgs(parser: argparse.ArgumentParser) {
  68. parser.add_argument('output', { help: `Output path.` });
  69. parser.add_argument('--blockSizeInMB', { default: 96, help: `Maximum block size.`, metavar: 'SIZE' });
  70. parser.add_argument('--format', { default: 'ccp4', help: `Input file format.` });
  71. }
  72. const xrayParser = subparsers.add_parser('xray', { add_help: true });
  73. xrayParser.add_argument('input2fofc', { help: `Path to 2fofc file.`, metavar: '2FOFC' });
  74. xrayParser.add_argument('inputFofc', { help: `Path to fofc file.`, metavar: 'FOFC' });
  75. addGeneralArgs(xrayParser);
  76. const emParser = subparsers.add_parser('em', { add_help: true });
  77. emParser.add_argument('inputEm', { help: `Path to EM density file.`, metavar: 'EM' });
  78. addGeneralArgs(emParser);
  79. const args: Args = parser.parse_args();
  80. const config = getConfig(args);
  81. pack(config.input, config.blockSizeInMB, config.isPeriodic, config.outputFilename, config.format);