-
Notifications
You must be signed in to change notification settings - Fork 4
/
collect-seqs.js
41 lines (33 loc) · 995 Bytes
/
collect-seqs.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
var fs = require('fs');
// return array of uids of proteins with title containing `mbp1`
function filter(proteins, cb) {
var num = 0;
var filtered = [];
var check = function(err, data) {
if (err) cb(err);
num+= 1;
var obj = JSON.parse(data);
if (obj.title !== undefined && obj.title.toUpperCase().indexOf('MBP1') >= 0) {
filtered.push(obj.uid);
}
tryFinish();
};
var tryFinish = function() {
if (num === proteins.length) {
cb(null, filtered);
}
};
proteins.forEach(function(protein) {
fs.readFile('data/' + protein, check);
});
}
filter(fs.readdirSync('data'), function(err, mbp1s) {
if (err) console.error(err);
mbp1s.forEach(function(uid) {
fs.readFile('data/' + uid + '.json', function(err, data) {
if (err) console.error(err);
var obj = JSON.parse(data);
console.log(obj.title);
});
});
});