| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- 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 <Accession>'))
- } 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();
- }
-
- }
- })()
|