|
@@ -1,106 +1,92 @@
|
|
|
/**
|
|
|
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
*
|
|
|
* Taken/adapted from DensityServer (https://github.com/dsehnal/DensityServer)
|
|
|
*
|
|
|
* @author David Sehnal <david.sehnal@gmail.com>
|
|
|
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
|
*/
|
|
|
|
|
|
+import * as argparse from 'argparse'
|
|
|
import pack from './pack/main'
|
|
|
import VERSION from './pack/version'
|
|
|
|
|
|
+type FileFormat = 'ccp4' | 'dsn6'
|
|
|
+
|
|
|
interface Config {
|
|
|
input: { name: string, filename: string }[],
|
|
|
- format: 'ccp4' | 'dsn6',
|
|
|
+ format: FileFormat,
|
|
|
isPeriodic: boolean,
|
|
|
outputFilename: string,
|
|
|
blockSizeInMB: number
|
|
|
}
|
|
|
|
|
|
-let config: Config = {
|
|
|
- input: [],
|
|
|
- format: 'ccp4',
|
|
|
- isPeriodic: false,
|
|
|
- outputFilename: '',
|
|
|
- blockSizeInMB: 96
|
|
|
-};
|
|
|
-
|
|
|
-function getFormat(format: string): Config['format'] {
|
|
|
- switch (format.toLowerCase()) {
|
|
|
- case 'ccp4': return 'ccp4'
|
|
|
- case 'dsn6': return 'dsn6'
|
|
|
+function getConfig(args: Args) {
|
|
|
+ const config: Partial<Config> = {
|
|
|
+ blockSizeInMB: args.blockSizeInMB,
|
|
|
+ format: args.format,
|
|
|
+ outputFilename: args.output
|
|
|
+ }
|
|
|
+ switch (args.mode) {
|
|
|
+ case 'em':
|
|
|
+ config.input = [
|
|
|
+ { name: 'em', filename: args.inputEm }
|
|
|
+ ];
|
|
|
+ config.isPeriodic = false;
|
|
|
+ break
|
|
|
+ case 'xray':
|
|
|
+ config.input = [
|
|
|
+ { name: '2Fo-Fc', filename: args.input2fofc },
|
|
|
+ { name: 'Fo-Fc', filename: args.inputFofc }
|
|
|
+ ];
|
|
|
+ config.isPeriodic = true;
|
|
|
+ break
|
|
|
}
|
|
|
- throw new Error(`unsupported format '${format}'`)
|
|
|
+ return config as Config
|
|
|
}
|
|
|
|
|
|
-function printHelp() {
|
|
|
- let help = [
|
|
|
- `VolumeServer Packer ${VERSION}, (c) 2016 - now, David Sehnal`,
|
|
|
- ``,
|
|
|
- `The input data must be CCP4/MAP mode 2 (32-bit floats) files.`,
|
|
|
- ``,
|
|
|
- `Usage: `,
|
|
|
- ``,
|
|
|
- ` node pack -v`,
|
|
|
- ` Print version.`,
|
|
|
- ``,
|
|
|
- ` node pack -xray main.ccp4 diff.ccp4 output.mdb [-blockSize 96]`,
|
|
|
- ` Pack main and diff density into a single block file.`,
|
|
|
- ` Optionally specify maximum block size.`,
|
|
|
- ``,
|
|
|
- ` node pack -em density.map output.mdb [-blockSize 96]`,
|
|
|
- ` Pack single density into a block file.`,
|
|
|
- ` Optionally specify maximum block size.`
|
|
|
- ];
|
|
|
- console.log(help.join('\n'));
|
|
|
+interface GeneralArgs {
|
|
|
+ blockSizeInMB: number
|
|
|
+ format: FileFormat
|
|
|
+ output: string
|
|
|
+}
|
|
|
+interface XrayArgs extends GeneralArgs {
|
|
|
+ mode: 'xray'
|
|
|
+ input2fofc: string
|
|
|
+ inputFofc: string
|
|
|
+}
|
|
|
+interface EmArgs extends GeneralArgs {
|
|
|
+ mode: 'em'
|
|
|
+ inputEm: string
|
|
|
}
|
|
|
+type Args = XrayArgs | EmArgs
|
|
|
|
|
|
-function parseInput() {
|
|
|
- let input = false;
|
|
|
+const parser = new argparse.ArgumentParser({
|
|
|
+ addHelp: true,
|
|
|
+ description: `VolumeServer Packer ${VERSION}, (c) 2018-2019, Mol* contributors`
|
|
|
+});
|
|
|
|
|
|
- if (process.argv.length <= 2) {
|
|
|
- printHelp();
|
|
|
- process.exit();
|
|
|
- return false;
|
|
|
- }
|
|
|
+const subparsers = parser.addSubparsers({
|
|
|
+ title: 'Packing modes',
|
|
|
+ dest: 'mode'
|
|
|
+});
|
|
|
|
|
|
- for (let i = 2; i < process.argv.length; i++) {
|
|
|
- switch (process.argv[i].toLowerCase()) {
|
|
|
- case '-blocksize':
|
|
|
- config.blockSizeInMB = +process.argv[++i];
|
|
|
- break;
|
|
|
- case '-format':
|
|
|
- config.format = getFormat(process.argv[++i]);
|
|
|
- break;
|
|
|
- case '-xray':
|
|
|
- input = true;
|
|
|
- config.input = [
|
|
|
- { name: '2Fo-Fc', filename: process.argv[++i] },
|
|
|
- { name: 'Fo-Fc', filename: process.argv[++i] }
|
|
|
- ];
|
|
|
- config.isPeriodic = true;
|
|
|
- config.outputFilename = process.argv[++i];
|
|
|
- break;
|
|
|
- case '-em':
|
|
|
- input = true;
|
|
|
- config.input = [
|
|
|
- { name: 'em', filename: process.argv[++i] }
|
|
|
- ];
|
|
|
- config.outputFilename = process.argv[++i];
|
|
|
- break;
|
|
|
- case '-v':
|
|
|
- console.log(VERSION);
|
|
|
- process.exit();
|
|
|
- return false;
|
|
|
- default:
|
|
|
- printHelp();
|
|
|
- process.exit();
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return input;
|
|
|
+function addGeneralArgs(parser: argparse.ArgumentParser) {
|
|
|
+ parser.addArgument(['output'], { help: `Output path.` })
|
|
|
+ parser.addArgument(['--blockSizeInMB'], { defaultValue: 96, help: `Maximum block size.`, metavar: 'SIZE' })
|
|
|
+ parser.addArgument(['--format'], { defaultValue: 'ccp4', help: `Input file format.` })
|
|
|
}
|
|
|
|
|
|
-if (parseInput()) {
|
|
|
- pack(config.input, config.blockSizeInMB, config.isPeriodic, config.outputFilename, config.format);
|
|
|
-}
|
|
|
+const xrayParser = subparsers.addParser('xray', { addHelp: true })
|
|
|
+xrayParser.addArgument(['input2fofc'], { help: `Path to 2fofc file.`, metavar: '2FOFC' })
|
|
|
+xrayParser.addArgument(['inputFofc'], { help: `Path to fofc file.`, metavar: 'FOFC' })
|
|
|
+addGeneralArgs(xrayParser)
|
|
|
+
|
|
|
+const emParser = subparsers.addParser('em', { addHelp: true })
|
|
|
+emParser.addArgument(['inputEm'], { help: `Path to EM density file.`, metavar: 'EM' })
|
|
|
+addGeneralArgs(emParser)
|
|
|
+
|
|
|
+const args: Args = parser.parseArgs();
|
|
|
+const config = getConfig(args)
|
|
|
+
|
|
|
+pack(config.input, config.blockSizeInMB, config.isPeriodic, config.outputFilename, config.format);
|