-
Notifications
You must be signed in to change notification settings - Fork 4
/
piped3.js
28 lines (26 loc) · 902 Bytes
/
piped3.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
var ncbi = require('bionode-ncbi');
var es = require('event-stream');
var filter = require('through2-filter');
var concat = require('concat-stream');
var tool = require('tool-stream');
var species = [];
ncbi.search('protein', 'mbp1')
.pipe(filter.obj(function (obj) {
return obj.title.match(/^mbp1p?.*\[.*\]$/i);
}))
.pipe(filter.obj(function (obj) {
var specieName = obj.title.substring(obj.title.indexOf('[') + 1, obj.title.length-1);
specieName = specieName.split(' ').slice(0,1).join(' ');
if (species.indexOf(specieName) >= 0) {
return false;
} else {
species.push(specieName);
return true;
}
}))
.pipe(tool.extractProperty('gi'))
.pipe(ncbi.fetch('protein'))
.pipe(es.through(function(obj) {
this.emit('data', JSON.stringify(obj) + '\n');
}))
.pipe(process.stdout);