1 | 'use strict';
|
2 |
|
3 | var grameneClient = require('gramene-search-client').client.grameneClient;
|
4 | var validateFactory = require('gramene-search-client').client.validate;
|
5 | var Q = require('q');
|
6 | var taxonomy = require('./taxonomy');
|
7 |
|
8 | module.exports = {
|
9 | get: function (local) {
|
10 | var src;
|
11 | if(local) {
|
12 | src = Q(require('../spec/support/taxonomyFixture'));
|
13 | }
|
14 | else {
|
15 | src = grameneClient.then(function(client) {
|
16 | var deferred, params;
|
17 | deferred = Q.defer();
|
18 | params = {
|
19 | rows: -1,
|
20 | subset: 'gramene',
|
21 | fl: ['_id', 'is_a', 'property_value', 'name', 'synonym', 'num_genes', 'reactomePrefix']};
|
22 | client['Data access'].taxonomy(params, function(response) {
|
23 | response.client = client;
|
24 | deferred.resolve(response);
|
25 | });
|
26 | return deferred.promise;
|
27 | });
|
28 | }
|
29 | return src
|
30 | .then(validateFactory('TaxonomyResponse'))
|
31 | .then(justTheData)
|
32 | .then(taxonomyPromise);
|
33 | }
|
34 | };
|
35 |
|
36 | function justTheData(json) {
|
37 | return Q(json.obj);
|
38 | }
|
39 |
|
40 | function taxonomyPromise(data) {
|
41 | return Q.fcall(taxonomy.tree, data);
|
42 | }
|