-
Notifications
You must be signed in to change notification settings - Fork 4
/
piped2.js
29 lines (26 loc) · 873 Bytes
/
piped2.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
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 concatStream = concat(function(array) {
console.log(array);
});
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(concatStream);