-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetBed.js
More file actions
executable file
·79 lines (71 loc) · 1.8 KB
/
getBed.js
File metadata and controls
executable file
·79 lines (71 loc) · 1.8 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
var through2 = require('through2');
var byline = require('byline');
var fs = require('fs');
var argv = require('minimist')(process.argv.slice(2));
var url = argv.swagger || 'http://data.gramene.org/swagger';
var feature = argv.feature || 'gene';
var combiner = argv.combiner || 'canonical';
var idFile = argv.ids;
var batchSize = argv.batchSize || 100;
global.gramene = {defaultServer: url};
var gramene = require('gramene-search-client').client.grameneClient;
if (idFile) {
var reader = byline(fs.createReadStream(idFile));
var ids = [];
var batcher = function batcher(batchSize) {
var transform = function (line, enc, done) {
if (ids.length === batchSize) {
var batch = ids;
this.push(batch);
ids = [];
}
ids.push(line);
done();
};
var flush = function(done) {
this.push(ids);
done();
}
return through2.obj(transform,flush);
};
var fetcher = through2.obj(function(ids, enc, done) {
var that = this;
gramene.then(function(client) {
var params = {
rows: batchSize,
wt: 'bed',
bedFeature: feature,
bedCombiner: combiner,
idList: ids
};
if (argv.taxon_id) {
params.taxon_id = argv.taxon_id;
}
client['Data access'].genes(params, function(res) {
that.push(res.data);
done();
})
})
});
reader
.pipe(batcher(batchSize))
.pipe(fetcher)
.pipe(process.stdout);
}
else if (argv.taxon_id) {
gramene.then(function(client) {
client['Data access'].genes(
{
wt: 'bed',
rows: -1,
bedFeature: feature,
bedCombiner: combiner,
taxon_id: argv.taxon_id,
db_type: 'core'
}, function(res) {
console.log(res.data);
}
)
})
}