cli.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. var __importDefault = (this && this.__importDefault) || function (mod) {
  12. return (mod && mod.__esModule) ? mod : { "default": mod };
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. const chalk_1 = __importDefault(require("chalk"));
  16. const _1 = require(".");
  17. const blessed_1 = __importDefault(require("blessed"));
  18. const figlet_1 = __importDefault(require("figlet"));
  19. const fs_1 = __importDefault(require("fs"));
  20. const formatSeq = (seq) => {
  21. return seq.split('').map(c => {
  22. let r;
  23. switch (c) {
  24. case 'A':
  25. r = chalk_1.default.green(c);
  26. break;
  27. case 'T':
  28. r = chalk_1.default.red(c);
  29. break;
  30. case 'C':
  31. r = chalk_1.default.blue(c);
  32. break;
  33. case 'G':
  34. r = chalk_1.default.yellow(c);
  35. break;
  36. case '.':
  37. //r = chalk.hex('#FF0000').bgBlue(' ')
  38. // r = chalk.bgHex('#DEADED').underline(' ')
  39. // break;
  40. r = c;
  41. default:
  42. r = c;
  43. break;
  44. }
  45. return r;
  46. }).join('');
  47. };
  48. const combineSTr = (strings, lineN) => {
  49. const splittedSts = [];
  50. const r = new RegExp(".{1," + lineN + "}", "g");
  51. for (const s of strings) {
  52. const tmpLines = s.match(r) || [];
  53. const resLines = [];
  54. for (const line of tmpLines)
  55. resLines.push(line.length < lineN ? line + ' '.repeat(lineN - line.length) : line);
  56. splittedSts.push(resLines);
  57. }
  58. const firstLines = splittedSts.shift() || [];
  59. return firstLines.map((e, i) => formatSeq(e.toUpperCase()) + formatSeq(splittedSts.map(ee => ee[i]).join(''))).join('');
  60. };
  61. (() => __awaiter(void 0, void 0, void 0, function* () {
  62. var _a;
  63. const arg = process.argv.slice(2);
  64. console.log(chalk_1.default.blue('Welcome to gbffParser!'));
  65. if (arg.length === 0 || arg.length > 1) {
  66. console.log(chalk_1.default.red('Usage : cli.js <Accession>'));
  67. }
  68. else {
  69. const screen = blessed_1.default.screen({
  70. smartCSR: true,
  71. dockBorders: true,
  72. autoPadding: true
  73. });
  74. screen.title = 'gbffParser';
  75. const mainBox = blessed_1.default.box({
  76. top: '15%',
  77. left: '10%',
  78. width: '90%',
  79. height: '85%',
  80. content: '',
  81. tags: true,
  82. border: {
  83. type: 'line'
  84. },
  85. scrollable: true,
  86. scrollbar: {
  87. style: { bg: 'blue' },
  88. },
  89. keys: true,
  90. mouse: false,
  91. style: {
  92. fg: 'white',
  93. border: {
  94. fg: '#f0f0f0'
  95. }
  96. }
  97. });
  98. const topBox = blessed_1.default.box({
  99. top: 0,
  100. left: 0,
  101. width: '100%',
  102. height: '15%',
  103. content: 'top',
  104. tags: true,
  105. border: {
  106. type: 'line'
  107. },
  108. scrollable: false,
  109. keys: true,
  110. mouse: false,
  111. style: {
  112. fg: 'white',
  113. border: {
  114. fg: '#f0f0f0'
  115. }
  116. }
  117. });
  118. const leftBox = blessed_1.default.box({
  119. top: '15%',
  120. left: 0,
  121. width: '10%',
  122. height: '85%',
  123. content: 'left',
  124. tags: true,
  125. border: {
  126. type: 'line'
  127. },
  128. scrollable: false,
  129. keys: true,
  130. mouse: false,
  131. style: {
  132. fg: 'white',
  133. border: {
  134. fg: '#f0f0f0'
  135. }
  136. }
  137. });
  138. screen.append(topBox);
  139. screen.append(leftBox);
  140. screen.append(mainBox);
  141. screen.key(['escape', 'q', 'C-c'], (ch, key) => process.exit(0));
  142. const dbPath = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(n => '/home/thomas/NGS/ref/ncbi/RNA/human.' + n + '.rna.gbff');
  143. const result = yield (0, _1.getFromAcc)(arg[0], dbPath);
  144. if (result) {
  145. yield fs_1.default.promises.writeFile('tmp.json', JSON.stringify(result));
  146. const title = ((_a = result.features.filter(feature => feature.type === 'gene')[0]) === null || _a === void 0 ? void 0 : _a.name) || arg[0];
  147. topBox.setContent(figlet_1.default.textSync(title));
  148. mainBox.setContent(result.sequence);
  149. mainBox.focus();
  150. const lineN = mainBox.getScreenLines()[0].length;
  151. mainBox.setContent(combineSTr([result.sequence, result.sequence.split('').map(e => '.').join('')], lineN));
  152. screen.render();
  153. }
  154. }
  155. }))();