| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- const chalk_1 = __importDefault(require("chalk"));
- const _1 = require(".");
- const blessed_1 = __importDefault(require("blessed"));
- const figlet_1 = __importDefault(require("figlet"));
- const fs_1 = __importDefault(require("fs"));
- const formatSeq = (seq) => {
- return seq.split('').map(c => {
- let r;
- switch (c) {
- case 'A':
- r = chalk_1.default.green(c);
- break;
- case 'T':
- r = chalk_1.default.red(c);
- break;
- case 'C':
- r = chalk_1.default.blue(c);
- break;
- case 'G':
- r = chalk_1.default.yellow(c);
- break;
- case '.':
- //r = chalk.hex('#FF0000').bgBlue(' ')
- // r = chalk.bgHex('#DEADED').underline(' ')
- // break;
- r = c;
- default:
- r = c;
- break;
- }
- return r;
- }).join('');
- };
- const combineSTr = (strings, lineN) => {
- const splittedSts = [];
- const r = new RegExp(".{1," + lineN + "}", "g");
- for (const s of strings) {
- const tmpLines = s.match(r) || [];
- const resLines = [];
- for (const line of tmpLines)
- resLines.push(line.length < lineN ? line + ' '.repeat(lineN - line.length) : line);
- splittedSts.push(resLines);
- }
- const firstLines = splittedSts.shift() || [];
- return firstLines.map((e, i) => formatSeq(e.toUpperCase()) + formatSeq(splittedSts.map(ee => ee[i]).join(''))).join('');
- };
- (() => __awaiter(void 0, void 0, void 0, function* () {
- var _a;
- const arg = process.argv.slice(2);
- console.log(chalk_1.default.blue('Welcome to gbffParser!'));
- if (arg.length === 0 || arg.length > 1) {
- console.log(chalk_1.default.red('Usage : cli.js <Accession>'));
- }
- else {
- const screen = blessed_1.default.screen({
- smartCSR: true,
- dockBorders: true,
- autoPadding: true
- });
- screen.title = 'gbffParser';
- const mainBox = blessed_1.default.box({
- top: '15%',
- left: '10%',
- width: '90%',
- height: '85%',
- content: '',
- tags: true,
- border: {
- type: 'line'
- },
- scrollable: true,
- scrollbar: {
- style: { bg: 'blue' },
- },
- keys: true,
- mouse: false,
- style: {
- fg: 'white',
- border: {
- fg: '#f0f0f0'
- }
- }
- });
- const topBox = blessed_1.default.box({
- top: 0,
- left: 0,
- width: '100%',
- height: '15%',
- content: 'top',
- tags: true,
- border: {
- type: 'line'
- },
- scrollable: false,
- keys: true,
- mouse: false,
- style: {
- fg: 'white',
- border: {
- fg: '#f0f0f0'
- }
- }
- });
- const leftBox = blessed_1.default.box({
- top: '15%',
- left: 0,
- width: '10%',
- height: '85%',
- content: 'left',
- tags: true,
- border: {
- type: 'line'
- },
- scrollable: false,
- keys: true,
- mouse: false,
- style: {
- fg: 'white',
- border: {
- fg: '#f0f0f0'
- }
- }
- });
- screen.append(topBox);
- screen.append(leftBox);
- screen.append(mainBox);
- screen.key(['escape', 'q', 'C-c'], (ch, key) => process.exit(0));
- const dbPath = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(n => '/home/thomas/NGS/ref/ncbi/RNA/human.' + n + '.rna.gbff');
- const result = yield (0, _1.getFromAcc)(arg[0], dbPath);
- if (result) {
- yield fs_1.default.promises.writeFile('tmp.json', JSON.stringify(result));
- const title = ((_a = result.features.filter(feature => feature.type === 'gene')[0]) === null || _a === void 0 ? void 0 : _a.name) || arg[0];
- topBox.setContent(figlet_1.default.textSync(title));
- mainBox.setContent(result.sequence);
- mainBox.focus();
- const lineN = mainBox.getScreenLines()[0].length;
- mainBox.setContent(combineSTr([result.sequence, result.sequence.split('').map(e => '.').join('')], lineN));
- screen.render();
- }
- }
- }))();
|