UNPKG

molstar

Version:

A comprehensive macromolecular library.

79 lines 2.67 kB
#!/usr/bin/env node /** * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __awaiter, __generator } from "tslib"; import * as argparse from 'argparse'; import * as util from 'util'; import * as fs from 'fs'; import * as zlib from 'zlib'; import { convert } from './converter'; require('util.promisify').shim(); function process(srcPath, outPath, configPath, filterPath) { return __awaiter(this, void 0, void 0, function () { var config, filter, res; return __generator(this, function (_a) { switch (_a.label) { case 0: config = configPath ? JSON.parse(fs.readFileSync(configPath, 'utf8')) : void 0; filter = filterPath ? fs.readFileSync(filterPath, 'utf8') : void 0; return [4 /*yield*/, convert(srcPath, false, config, filter)]; case 1: res = _a.sent(); return [4 /*yield*/, write(outPath, res)]; case 2: _a.sent(); return [2 /*return*/]; } }); }); } var zipAsync = util.promisify(zlib.gzip); function write(outPath, res) { return __awaiter(this, void 0, void 0, function () { var isGz; return __generator(this, function (_a) { switch (_a.label) { case 0: isGz = /\.gz$/i.test(outPath); if (!isGz) return [3 /*break*/, 2]; return [4 /*yield*/, zipAsync(res)]; case 1: res = _a.sent(); _a.label = 2; case 2: fs.writeFileSync(outPath, res); return [2 /*return*/]; } }); }); } function run(args) { process(args.src, args.out, args.config, args.filter); } var parser = new argparse.ArgumentParser({ add_help: true, description: 'Convert any CIF file to a BCIF file' }); parser.add_argument('src', { help: 'Source CIF path' }); parser.add_argument('out', { help: 'Output BCIF path' }); parser.add_argument('-c', '--config', { help: 'Optional encoding strategy/precision config path', required: false }); parser.add_argument('-f', '--filter', { help: 'Optional filter whitelist/blacklist path', required: false }); var args = parser.parse_args(); if (args) { run(args); } //# sourceMappingURL=index.js.map