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

bionode-ncbi

Package Overview
Dependencies
Maintainers
3
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bionode-ncbi - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

115

lib/bionode-ncbi.js

@@ -227,3 +227,3 @@ // # bionode-ncbi

if (srcUID) { stream.write(srcUID); stream.end() }
if (cb) { stream.pipe(concat(cb)) }
if (cb) { stream.on('data', cb) }
else { return stream }

@@ -234,2 +234,3 @@ }

var stream = through.obj(transform)
if (srcDB === 'tax') { srcDB = 'taxonomy' }
return stream

@@ -261,21 +262,53 @@

}
xml2js(obj.body, function(err, data) {
if (err) { self.emit('error', err) }
if (data.eLinkResult.LinkSet[0].LinkSetDb) {
data.eLinkResult.LinkSet[0].LinkSetDb.forEach(getMatch)
function getMatch(link) {
if (link.LinkName[0] === query.dbfrom + '_' + query.db) {
link.Link.forEach(pushLink)
function pushLink(link){
result.destUID = link.Id[0]
self.push(result)
}
}
}
}
xml2js(obj.body, gotParsed)
function gotParsed (err, data) {
if (err) { self.emit('error', err); return next() }
if (!data.eLinkResult.LinkSet[0].LinkSetDb) { return next() }
data.eLinkResult.LinkSet[0].LinkSetDb.forEach(getMatch)
self.push(result)
next()
})
}
function getMatch(link) {
var linkName = query.dbfrom + '_' + query.db
if (link.LinkName[0] !== linkName) { return }
destUIDs = []
link.Link.forEach(getLink)
function getLink (link) { destUIDs.push(link.Id[0]) }
result.destUIDs = destUIDs
}
}
}
// ## Property link (Plink)
// Similar to Link but taked the srcID from a property of the Streamed object
// and attached the result to a property with the name of the destination DB.
//
// ncbi.search('genome', 'arthropoda')
// .pipe(ncbi.expand('tax'))
// .pipe(ncbi.plink('tax', 'sra')
ncbi.plink = function (property, destDB) {
var srcDB = property.split('.').pop()
var destProperty = destDB+'id'
var stream = through.obj(transform)
return stream
function transform(obj, enc, next) {
var self = this
var id = tool.getValue(obj, property+'id')
if (!id) {
self.push(obj)
return next()
}
if (!obj[destProperty]) { obj[destProperty] = [] }
var link = ncbi.link(srcDB, destDB, id, gotData)
function gotData(data) {
// console.log(data)
if (data.destUIDs) { obj[destProperty] = data.destUIDs }
self.push(obj)
next()
}
}
}
// ## Download

@@ -493,1 +526,51 @@ // Takes a NCBI database string and a optional search term and downloads the datasets/sequence files.

}
// ## Expand
// Takes a property (e.g., biosample) and optional destination property
// (e.g., sample) and looks for a field named property+id (biosampleid)
// in the Streamed object. Then it will do a ncbi.search for that id and save
// the result under Streamed object.property.
//
// ncbi.search('genome', 'arthropoda').pipe(ncbi.expand('assembly'))
ncbi.expand = function(property, destProperty) {
var destProperty = destProperty || property
var db = property.split('.').pop()
if (db === 'tax') { db = 'taxonomy' }
var stream = through.obj(transform)
return stream
function transform(obj, enc, next) {
var self = this
var ids = tool.getValue(obj, property+'id')
if (!ids) {
self.push(obj)
return next()
}
// Taxonomy doesn't work just with ID number
if (db === 'taxonomy') { ids = ids+'[uid]' }
if (Array.isArray(ids)) {
async.map(ids, search, gotData)
} else {
search(ids, gotData)
}
function search(term, cb) {
var search = ncbi.search(db)
search.write(term)
search.on('data', function (data) { cb(null, data) })
search.on('end', next)
}
function gotData(err, data) {
if (err) { throw new Error(err) }
obj[destProperty] = data
self.push(obj)
next()
}
}
}

2

package.json
{
"name": "bionode-ncbi",
"description": "Node.js module for working with the NCBI API (aka e-utils) using Streams.",
"version": "1.0.4",
"version": "1.1.0",
"homepage": "http://github.com/bionode/bionode-ncbi",

@@ -6,0 +6,0 @@ "repository": {

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

test('Search', function(t) {
t.plan(5)
t.plan(3)

@@ -97,21 +97,22 @@ ncbi.search('assembly', 'Guillardia theta')

var start1 = Date.now()
ncbi.search({ db: 'sra', term: 'human', limit: 500, throughput: 500 })
.on('data', function(data) {})
.on('end', function() {
var msg = 'get 500 objects fast from sra using throughput of 500 per request'
var seconds = (Date.now() - start1) / 1000
var fast = seconds < 10
t.ok(fast, msg)
})
var start2 = Date.now()
ncbi.search({ db: 'sra', term: 'human', limit: 500, throughput: 5 })
.on('data', function(data) {})
.on('end', function() {
var msg = 'get 500 objects slowly from sra using throughput of 5 per request'
var seconds = (Date.now() - start2) / 1000
var slow = seconds > 10
t.ok(slow, msg)
})
// These tests fail randomly on Travis because of network speed
// var start1 = Date.now()
// ncbi.search({ db: 'sra', term: 'human', limit: 500, throughput: 500 })
// .on('data', function(data) {})
// .on('end', function() {
// var msg = 'get 500 objects fast from sra using throughput of 500 per request'
// var seconds = (Date.now() - start1) / 1000
// var fast = seconds < 10
// t.ok(fast, msg)
// })
//
// var start2 = Date.now()
// ncbi.search({ db: 'sra', term: 'human', limit: 500, throughput: 5 })
// .on('data', function(data) {})
// .on('end', function() {
// var msg = 'get 500 objects slowly from sra using throughput of 5 per request'
// var seconds = (Date.now() - start2) / 1000
// var slow = seconds > 10
// t.ok(slow, msg)
// })
})

@@ -135,4 +136,4 @@

var msg = 'same as previous, but doing bioproject->assembly instead of sra->assembly to try get same assembly UID as Search'
t.deepEqual(data.destUID, testData.assembly['guillardia-theta'].search.uid, msg)
t.deepEqual(data.destUIDs[0], testData.assembly['guillardia-theta'].search.uid, msg)
})
})

@@ -239,3 +239,3 @@ {

"srcUID" : "35533",
"destUID" : "53577",
"destUIDs" : ["53577"],
"destDB" : "bioproject"

@@ -250,3 +250,3 @@ }

"srcUID" : "53577",
"destUID" : "503988",
"destUIDs" : ["503988"],
"destDB" : "assembly"

@@ -253,0 +253,0 @@ }

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