Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bionode-fasta

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bionode-fasta - npm Package Compare versions

Comparing version 0.5.5 to 0.5.6

7

cli.js
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var minimist = require('minimist')

@@ -16,3 +15,3 @@ var fasta = require('./')

if (argv.help) {
return console.log(
console.log(
'Usage: bionode-fasta <options> <fasta file [required]> <output file>\n\n' +

@@ -36,6 +35,6 @@ 'You can also use fasta files compressed with gzip\n' +

process.stdin.setEncoding('utf8');
process.stdin.setEncoding('utf8')
if (!process.stdin.isTTY) {
process.stdin.on('data', function(data) {
process.stdin.on('data', function (data) {
if (data.trim() === '') { return }

@@ -42,0 +41,0 @@ parser.write(data)

@@ -1,1 +0,1 @@

module.exports = require('./lib/bionode-fasta')
module.exports = require('./lib/bionode-fasta')

@@ -81,3 +81,3 @@ // # bionode-fasta

module.exports.obj = function(arg1, arg2, arg3) {
module.exports.obj = function (arg1, arg2, arg3) {
var params = paramsParser(arg1, arg2, arg3)

@@ -89,13 +89,12 @@ params.options.objectMode = true

module.exports.write = function() {
module.exports.write = function () {
var stream = through.obj(transform)
return pumpify.obj(split(), stream)
function transform(obj, enc, next) {
function transform (obj, enc, next) {
try {
obj = JSON.parse(obj)
var fastaString = '>'+obj.id+'\n' + obj.seq.match(/.{1,80}/g).join('\n')+'\n'
var fastaString = '>' + obj.id + '\n' + obj.seq.match(/.{1,80}/g).join('\n') + '\n'
this.push(fastaString)
}
catch(e) {}
} catch (e) {}
next()

@@ -105,12 +104,9 @@ }

function fasta(arg1, arg2, arg3) {
var self = this
function fasta (arg1, arg2, arg3) {
var params = paramsParser(arg1, arg2, arg3)
var jsparse
var contentParser
if (params.options.objectMode) {
contentParser = pumpify.obj(fastaParser(), jsParse())
}
else {
} else {
contentParser = fastaParser()

@@ -120,5 +116,5 @@ }

var filesParser = through.obj(transform)
function transform(obj, enc, next){
function transform (obj, enc, next) {
var self = this
var unzip = 'gz' === obj.split('.').pop() ? zlib.Gunzip() : through()
var unzip = obj.split('.').pop() === 'gz' ? zlib.Gunzip() : through()
var includepath = params.options.includePath ? includePath(obj) : through()

@@ -128,6 +124,5 @@

if (params.options.objectMode) {
jsparse = jsParse()
jsparse = jsParse()
pumpit = pumpify.obj
}
else {
} else {
jsparse = through()

@@ -146,5 +141,5 @@ pumpit = pumpify

pipeline
.on('error', function(error) { self.emit('error', error) })
.on('data', function(data) { self.push(data) })
.on('end', function() { self.push(null) })
.on('error', function (error) { self.emit('error', error) })
.on('data', function (data) { self.push(data) })
.on('end', function () { self.push(null) })

@@ -154,7 +149,7 @@ next()

stream = params.filename || params.options.filenameMode ? filesParser : contentParser
var stream = params.filename || params.options.filenameMode ? filesParser : contentParser
if (params.filename) { stream.write(params.filename) }
if (params.callback) {
stream.on('error', params.callback)
stream.pipe(concat(function(data) { params.callback(null, data) }))
stream.pipe(concat(function (data) { params.callback(null, data) }))
}

@@ -165,10 +160,9 @@

function includePath(path) {
function includePath (path) {
var stream = through(transform)
return stream
function transform(buf, enc, next) {
var openEnd = buf.slice(0, buf.length-2)
var pathBuf = new Buffer(',"path":"' + path + '"}\n')
var totalLen = buf.length-2 + pathBuf.length
function transform (buf, enc, next) {
var openEnd = buf.slice(0, buf.length - 2)
var pathBuf = Buffer.from(',"path":"' + path + '"}\n')
var totalLen = buf.length - 2 + pathBuf.length
var newBuf = Buffer.concat([openEnd, pathBuf], totalLen)

@@ -180,8 +174,7 @@ this.push(newBuf)

function jsParse() {
function jsParse () {
var stream = through.obj(transform, flush)
return stream
function transform(obj, enc, next) {
if (typeof obj === 'Buffer') { obj = obj.toString() }
function transform (obj, enc, next) {
if (Buffer.isBuffer(obj)) { obj = obj.toString() }
JSON.parse(obj)

@@ -191,6 +184,6 @@ this.push(JSON.parse(obj))

}
function flush() { this.push(null) }
function flush () { this.push(null) }
}
function paramsParser(arg1, arg2, arg3) {
function paramsParser (arg1, arg2, arg3) {
var params = {}

@@ -205,4 +198,3 @@ if (typeof arg1 === 'object') {

}
}
else if (typeof arg1 === 'string') {
} else if (typeof arg1 === 'string') {
params.options = {}

@@ -213,4 +205,3 @@ params.filename = arg1

}
}
else {
} else {
params.options = {}

@@ -217,0 +208,0 @@ }

{
"name": "bionode-fasta",
"description": "Streamable FASTA parser",
"version": "0.5.5",
"version": "0.5.6",
"homepage": "http://bionode.io",

@@ -16,23 +16,24 @@ "repository": {

"dependencies": {
"concat-stream": "~1.4.6",
"concat-stream": "~1.6.0",
"fasta-parser": "0.1.0",
"minimist": "~1.1.0",
"pumpify": "~1.3.0",
"split2": "^2.0.1",
"through2": "~0.6.0"
"minimist": "~1.2.0",
"pumpify": "~1.3.5",
"split2": "^2.1.1",
"through2": "~2.0.3"
},
"devDependencies": {
"async": "~0.9.0",
"beefy": "^2.1.0",
"async": "~2.3.0",
"beefy": "^2.1.8",
"browserify": "git+https://github.com/bmpvieira/node-browserify#3.46.1/http-browserify-1.6.0-pull-53-61-62",
"browserify-fs": "~1.0.0",
"contributor": "~0.1.22",
"coveralls": "~2.11.1",
"docco": "~0.6.3",
"istanbul": "~0.3.0",
"request": "~2.40.0",
"tap-spec": "~0.2.0",
"tape": "~2.14.0",
"contributor": "~0.1.25",
"coveralls": "~2.13.0",
"docco": "~0.7.0",
"istanbul": "~0.4.5",
"request": "~2.81.0",
"standard": "^10.0.2",
"tap-spec": "~4.1.1",
"tape": "~4.6.3",
"testling": "^1.7.1",
"uglify-js": "~2.4.15"
"uglify-js": "~2.8.22"
},

@@ -58,3 +59,3 @@ "keywords": [

"scripts": {
"test": "node test/bionode-fasta.js | tap-spec",
"test": "standard && node test/bionode-fasta.js | tap-spec",
"test-browser": "browserify test/bionode-fasta.js | testling -x 'open -a \"Google Chrome\"' | tap-spec",

@@ -61,0 +62,0 @@ "coverage": "istanbul cover test/bionode-fasta.js --report lcovonly -- | tap-spec && rm -rf ./coverage",

@@ -7,7 +7,3 @@ var fs = require('fs')

var data = require('./data')
var zlib = require('zlib')
var through = require('through2')
var buffer = require('buffer')
// Node.js fs is implemented in the browser by browserify-fs using leveldb.

@@ -20,7 +16,7 @@ // So we need to fetch the file and save it locally (server) or in leveldb (client) with fs.

function download(file, callback) {
function download (file, callback) {
var proxy = 'http://cors.inb.io/'
var rooturl = 'https://raw.githubusercontent.com/bionode/bionode-fasta/master/test/'
fs.mkdir('test', gotDir)
function gotDir() {
function gotDir () {
var get = request(proxy + rooturl + file, {encoding: null})

@@ -33,7 +29,6 @@ var write = fs.createWriteStream('test/' + file)

function startTests() {
function startTests () {
test('Read a fasta file and pipe content to parser.', function (t) {
t.plan(3)
var msg
var pushFunc

@@ -49,4 +44,3 @@ msg = 'should return a Buffer for each sequence'

function testPipeParser(msg, parser, jsparse) {
function testPipeParser (msg, parser, jsparse) {
var result = []

@@ -57,5 +51,5 @@

.on('data', pushResult)
.on('end', function() { t.deepEqual(result, data.fasta, msg) })
.on('end', function () { t.deepEqual(result, data.fasta, msg) })
function pushResult(data) {
function pushResult (data) {
if (jsparse) { data = JSON.parse(data.toString()) }

@@ -72,20 +66,20 @@ result.push(data)

function testFilename(file, includePath) {
function testFilename (file, includePath) {
var solution = JSON.parse(JSON.stringify(data.fasta))
var extramsg = ''
if (includePath) {
extramsg = ' (add path to results)'
solution.forEach(addPath)
function addPath(obj, i) {
obj.path = file
solution[i] = obj
}
}
if ('gz' === file.split('.').pop()) {
function addPath (obj, i) {
obj.path = file
solution[i] = obj
}
if (file.split('.').pop() === 'gz') {
extramsg += ' (read gzipped file)'
}
test('Use parser to read file by passing filename' + extramsg, function (t) {

@@ -95,3 +89,2 @@ t.plan(3)

var parser
var pushFunc

@@ -112,8 +105,8 @@ msg = 'should return a Buffer for each sequence'

function testFilenamePipe(msg, parser, jsparse) {
function testFilenamePipe (msg, parser, jsparse) {
var result = []
parser
.on('data', pushResult)
.on('end', function() { t.deepEqual(result, solution, msg) })
function pushResult(data) {
.on('end', function () { t.deepEqual(result, solution, msg) })
function pushResult (data) {
if (jsparse) { data = JSON.parse(data.toString()) }

@@ -125,3 +118,2 @@ result.push(data)

test('Use parser to read file by passing filename and get results with callback' + extramsg, function (t) {

@@ -132,11 +124,10 @@ t.plan(6)

fasta({ includePath: true }, file, callback1)
}
else {
} else {
fasta(file, callback1)
}
function callback1(err, result) {
function callback1 (err, result) {
t.error(err, 'callback error should be null')
var objects = []
result.toString().split('\n').forEach(pushObject)
function pushObject(obj) {
function pushObject (obj) {
if (obj !== '') {

@@ -150,6 +141,5 @@ objects.push(JSON.parse(obj))

var options = { objectMode: true }
if (includePath) { options.includePath = true }
fasta(options, file, function(err, result) {
fasta(options, file, function (err, result) {
t.error(err, 'callback error should be null')

@@ -160,10 +150,8 @@ var msg = 'should return an array of Objects'

if (includePath) {
fasta.obj({ includePath: true }, file, callback2)
}
else {
} else {
fasta.obj(file, callback2)
}
function callback2(err, result) {
function callback2 (err, result) {
t.error(err, 'callback error should be null')

@@ -176,9 +164,8 @@ var msg = 'should return an array of Objects'

test('Errors should be caught', function(t) {
test('Errors should be caught', function (t) {
t.plan(1)
var msg = 'should return a ENOENT error for non-existing path'
fasta('./nosuchfile.fasta')
.on('error', function(error) { t.equal(error.code, 'ENOENT', msg) })
.on('error', function (error) { t.equal(error.code, 'ENOENT', msg) })
})
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc