import chalk from 'chalk'; import { getFromAcc } from '.' import blessed from 'blessed' import figlet from 'figlet' import fs from 'fs' const formatSeq = (seq:string) => { return seq.split('').map(c => { let r switch (c) { case 'A': r = chalk.green(c) break; case 'T': r = chalk.red(c) break; case 'C': r = chalk.blue(c) break; case 'G': r = chalk.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: string[], lineN:number) => { const splittedSts: RegExpMatchArray[] = [] 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('') } (async()=>{ const arg = process.argv.slice(2) console.log(chalk.blue('Welcome to gbffParser!')) if (arg.length === 0 || arg.length > 1) { console.log(chalk.red('Usage : cli.js ')) } else { const screen = blessed.screen({ smartCSR: true, dockBorders: true, autoPadding: true }) screen.title = 'gbffParser' const mainBox = blessed.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.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.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 = await getFromAcc(arg[0], dbPath) if (result) { await fs.promises.writeFile('tmp.json', JSON.stringify(result)) const title = result.features.filter(feature => feature.type === 'gene')[0]?.name || arg[0] topBox.setContent(figlet.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(); } } })()