diff --git a/package-lock.json b/package-lock.json index b307d9d..266b4da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -695,6 +695,11 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "figlet": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.2.0.tgz", + "integrity": "sha1-bEZTc3j6tkkUa1phQ92gGbQwtBA=" + }, "figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", diff --git a/package.json b/package.json index 89f6dea..f3e005b 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "nyc": "^11.3.0" }, "dependencies": { + "figlet": "^1.2.0", "through2": "^2.0.3" } } diff --git a/src/Genes.js b/src/Genes.js index d464f7b..82380bd 100644 --- a/src/Genes.js +++ b/src/Genes.js @@ -57,11 +57,13 @@ class Genes extends NodeMist3 { return gene.aseq_id === item.id })[0] if (!gene.ai) { - this.log.warn(`Aseq ${gene.aseq_id} not found`) if (options.keepGoing === false) { this.log.error(`Aseq ${gene.aseq_id} not found`) throw Error(`Aseq ${gene.aseq_id} not found`) } + else { + this.log.warn(`Aseq ${gene.aseq_id} not found`) + } } } else { @@ -157,12 +159,12 @@ class Genes extends NodeMist3 { }) } - byGenome(version) { + byGenomeVersion(version) { const allGenes = [] let page = 1 const getGenes = (v, p) => { return new Promise((resolve, rejectg) => { - this.byGenomePerPage(v, p) + this.byGenomeVersionPerPage(v, p) .then((newGenes) => { if (newGenes.length !== 0) { newGenes.forEach((gene) => { @@ -180,7 +182,7 @@ class Genes extends NodeMist3 { return getGenes(version, page) } - byGenomePerPage(version, page = 1) { + byGenomeVersionPerPage(version, page = 1) { const genes = [] const genesPerPage = 100 this.httpOptions.method = 'GET' diff --git a/src/Genes.tests.js b/src/Genes.tests.js index c88b7e1..2b069b4 100644 --- a/src/Genes.tests.js +++ b/src/Genes.tests.js @@ -14,13 +14,13 @@ const should = chai.should() const Genes = require('./Genes') describe('Genes', function() { - describe('byGenomes', function() { + describe('byGenomeVersion', function() { it('should pass', function() { this.timeout(14000) const genes = new Genes() const expectedNumberOfGenes = 736 const genome = 'GCF_000701865.1' // 'GCF_000006765.1' - return genes.byGenome(genome).then((items) => { + return genes.byGenomeVersion(genome).then((items) => { expect(items.length).eql(expectedNumberOfGenes) }) }) @@ -29,41 +29,41 @@ describe('Genes', function() { describe('info', function() { it('should pass', function() { const genes = new Genes() - const geneVersion = 'GCF_000302455.1-A994_RS01985' - return genes.info(geneVersion).then((item) => { - expect(item.stable_id).eql(geneVersion) + const stableId = 'GCF_000302455.1-A994_RS01985' + return genes.info(stableId).then((item) => { + expect(item.stable_id).eql(stableId) }) }) it('should throw error when fed with invalid id', function() { const genes = new Genes() - const geneVersion = 'GCF_000302455.1-A994_RS0198' - return genes.info(geneVersion).should.be.rejectedWith(Error) + const stableId = 'GCF_000302455.1-A994_RS0198' + return genes.info(stableId).should.be.rejectedWith(Error) }) it.skip('should throw error when fed with empty id', function() { const genes = new Genes() - const geneVersion = '' - return genes.info(geneVersion).should.be.rejectedWith(Error) + const stableId = '' + return genes.info(stableId).should.be.rejectedWith(Error) }) }) describe('infoAll', function() { it('should pass', function() { const genes = new Genes() - const geneVersions = ['GCF_000302455.1-A994_RS01985', 'GCF_000302455.1-A994_RS00010'] - return genes.infoAll(geneVersions).then((items) => { + const stableIds = ['GCF_000302455.1-A994_RS01985', 'GCF_000302455.1-A994_RS00010'] + return genes.infoAll(stableIds).then((items) => { items.forEach((item, i) => { - expect(item.stable_id).eql(geneVersions[i]) + expect(item.stable_id).eql(stableIds[i]) }) }) }) it('should be rejected with invalid stable id', function() { const genes = new Genes() - const geneVersions = ['GCF_000302455.1-A994_RS01985', 'xxxGCF_000302455.1-A994_RS00010'] - return genes.infoAll(geneVersions).should.be.rejectedWith('Not Found') + const stableIds = ['GCF_000302455.1-A994_RS01985', 'xxxGCF_000302455.1-A994_RS00010'] + return genes.infoAll(stableIds).should.be.rejectedWith('Not Found') }) it('should pass with bunch', function() { this.timeout(14000) const genes = new Genes() - const geneVersions = [ + const stableIds = [ 'GCF_000006765.1-PA1072', 'GCF_000006765.1-PA1073', 'GCF_000006765.1-PA1074', @@ -230,9 +230,9 @@ describe('Genes', function() { 'GCF_000196175.1-BD_RS15605', 'GCF_000196175.1-BD_RS15610' ] - return genes.infoAll(geneVersions).then((items) => { + return genes.infoAll(stableIds).then((items) => { items.forEach((item, i) => { - expect(item.stable_id).eql(geneVersions[i]) + expect(item.stable_id).eql(stableIds[i]) }) }) }) @@ -267,8 +267,8 @@ describe('Genes', function() { describe('addAseqInfo', function() { it('should pass', function() { const genes = new Genes() - const geneVersion = 'GCF_000302455.1-A994_RS01985' - return genes.info(geneVersion).then((gene) => { + const stableId = 'GCF_000302455.1-A994_RS01985' + return genes.info(stableId).then((gene) => { return genes.addAseqInfo([gene]).then((result) => { expect(result[0].ai).to.not.be.null expect(result.length).eql(1) @@ -277,24 +277,24 @@ describe('Genes', function() { }) it('should reject if gene is not found', function() { const genes = new Genes() - const geneVersion = 'GCF_000302455.1-A994_RS01985' - return genes.info(geneVersion).then((gene) => { + const stableId = 'GCF_000302455.1-A994_RS01985' + return genes.info(stableId).then((gene) => { gene.aseq_id = 'wTCio8ibKOlaJ_LDGhkSVA' return genes.addAseqInfo([gene], {keepGoing: false}).should.be.rejectedWith('not found') }) }) it('should reject if aseq is null', function() { const genes = new Genes() - const geneVersion = 'GCF_000302455.1-A994_RS01985' - return genes.info(geneVersion).then((gene) => { + const stableId = 'GCF_000302455.1-A994_RS01985' + return genes.info(stableId).then((gene) => { gene.aseq_id = null return genes.addAseqInfo([gene], {keepGoing: false}).should.be.rejectedWith('has null aseq') }) }) it('should pass (with warning) null if aseq_id is null and told to keep going', function() { const genes = new Genes() - const geneVersion = 'GCF_000302455.1-A994_RS01985' - return genes.info(geneVersion).then((gene) => { + const stableId = 'GCF_000302455.1-A994_RS01985' + return genes.info(stableId).then((gene) => { gene.aseq_id = null return genes.addAseqInfo([gene], {keepGoing: true}).then((results) => { expect(results[0].ai).to.be.null @@ -303,8 +303,8 @@ describe('Genes', function() { }) it('should warns if gene is not found and asked to not throw error in options', function() { const genes = new Genes() - const geneVersion = 'GCF_000302455.1-A994_RS01985' - return genes.info(geneVersion).then((gene) => { + const stableId = 'GCF_000302455.1-A994_RS01985' + return genes.info(stableId).then((gene) => { gene.aseq_id = 'wTCio8ibKOlaJ_LDGhkSVA' return genes.addAseqInfo([gene], {keepGoing: true}).then((results) => { expect(results[0].ai).to.be.undefined diff --git a/src/NodeMist3Abstract.js b/src/NodeMist3Abstract.js index 8c32fd0..12de18b 100644 --- a/src/NodeMist3Abstract.js +++ b/src/NodeMist3Abstract.js @@ -1,9 +1,13 @@ 'use strict' -let httpDefaultOptions = { - method: 'GET', - hostname: 'api.mistdb.com', - port: 5000, +const https = require('https') + +const apiHostnameList = [ + 'api.mistdb.com', + 'api.mistdb.caltech.edu' +] + +const httpsDefaultOptions = { headers: {}, agent: false } @@ -11,6 +15,21 @@ let httpDefaultOptions = { module.exports = class NodeMist3 { constructor(options) { - this.httpOptions = options ? options : httpDefaultOptions + this.httpsOptions = options ? options : httpsDefaultOptions + } + + init() { + httpsDefaultOptions.method = 'HEAD' + const requests = [] + for (const apiHostname of apiHostnameList) { + httpsDefaultOptions.hostname = apiHostname + requests.push(https.request(httpsDefaultOptions)) + } + return Promise.all(requests).then((responses) => { + for (const response of responses) { + console.log(response.statusCode) + } + return + }) } } diff --git a/src/NodeMist3Abstract.tests.js b/src/NodeMist3Abstract.tests.js new file mode 100644 index 0000000..d86fb2d --- /dev/null +++ b/src/NodeMist3Abstract.tests.js @@ -0,0 +1,18 @@ +'use strict' + +const chai = require('chai') +const chaiAsPromised = require('chai-as-promised') + +chai.use(chaiAsPromised) + +const expect = chai.expect +const should = chai.should() + +const NodeMist3Abstract = require('./NodeMist3Abstract') + +describe.only('NodeMist3Abstract', function() { + it('init should work', function() { + const abstract = new NodeMist3Abstract() + return abstract.init() + }) +})