UNPKG

1.09 kBJavaScriptView Raw
1'use strict';
2
3var grameneClient = require('gramene-search-client').client.grameneClient;
4var validateFactory = require('gramene-search-client').client.validate;
5var Q = require('q');
6var taxonomy = require('./taxonomy');
7
8module.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']};
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
36function justTheData(json) {
37 return Q(json.obj);
38}
39
40function taxonomyPromise(data) {
41 return Q.fcall(taxonomy.tree, data);
42}