-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.js
executable file
·49 lines (42 loc) · 1.36 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
var through = require('through2')
var minimist = require('minimist')
var bionodeSAM = require('./')
var args = minimist(process.argv.slice(2))
var command = args._[0]
var lastArg = args._[args._.length - 1]
var wantsStdin = false
if (lastArg === '-') {
wantsStdin = true
args._.pop()
}
// if (args.length === 0) { throw Error('Please specify command and files') }
// else if (args.length === 1) { throw Error('Please provide a SRA file') }
// else if (args.length === 2) { srcDest = args[1] + ' .' }
// else if (args.length === 3) { srcDest = args.slice(args.length-2) }
// else if (args.length > 3) { throw Error('Too many arguments specified') }
var sam = bionodeSAM(command)
if (wantsStdin) {
process.stdin.setEncoding('utf8')
process.stdin.on('data', function (data) {
data = data.trim()
if (data === '') { return }
args._.push(data.trim())
var samStream = sam(args._)
samStream.pipe(JSONstringify()).pipe(process.stdout)
samStream.on('error', console.log)
})
} else {
var samStream = sam(args._)
samStream.pipe(JSONstringify()).pipe(process.stdout)
samStream.on('error', console.log)
}
function JSONstringify () {
var stream = through.obj(transform)
return stream
function transform (obj, enc, next) {
try { obj = JSON.stringify(obj) } catch (e) {}
if (obj !== '') { this.push(obj + '\n') }
next()
}
}