-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from shamseen/external-api
Calls ENA search endpoint via fixed search
- Loading branch information
Showing
5 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const ENADataService = require('../dataServices/enaDataService'); | ||
const ena = new ENADataService(); | ||
|
||
// TEST GET! | ||
router.get('/', async (req, res) => { | ||
|
||
try { | ||
const found = ena.enaData; | ||
res.status(200).json(found); | ||
|
||
} catch (err) { | ||
console.log(err); | ||
res.status(400).json({ | ||
msg: err.message | ||
}); | ||
} | ||
}); | ||
|
||
// | ||
router.get('/:query', async (req, res) => { | ||
// const filter = { [req.params.prop]: req.params.val }; | ||
// TODO: parse query, search mongo too | ||
|
||
try { | ||
const found = []; | ||
// const found = await enaService.search(); | ||
res.status(200).json(found); | ||
|
||
} catch (err) { | ||
res.status(400).json({ | ||
msg: err.message | ||
}); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// structure from https://www.codementor.io/@evanbechtol/node-service-oriented-architecture-12vjt9zs9i | ||
|
||
/* -------------------------------------------------------------- */ | ||
// European Nucleotide Archive (ENA): database of sequences | ||
// The European Bioinformatics Institute exposes an API to access ENA | ||
// In ENA, record IDs are called accessions | ||
/* -------------------------------------------------------------- */ | ||
const axios = require('axios') | ||
|
||
|
||
class ENADataService { | ||
/* - populating with fixed search on instantiation - */ | ||
constructor() { | ||
this.searchENA(); | ||
} | ||
|
||
/* -- variables for JOINs -- */ | ||
// static baseURL = 'https://www.ebi.ac.uk/ena/portal/api/search?dataPortal=ena&query='; | ||
// static resultLimit = 10; | ||
|
||
/* -- API Calls -- */ | ||
// BLOCKED: ena POST endpoint docs are missing, waiting to hear back | ||
|
||
// using a custom rule i made on their side instead | ||
async searchENA() { | ||
try { | ||
const response = await axios.get('https://www.ebi.ac.uk/ena/portal/api/search?rule=8624c855-9921-4b98-b763-ac0d79b6a567'); | ||
|
||
this.enaData = response.data; // axios returns JSON already | ||
return this.enaData; | ||
|
||
} catch (error) { | ||
// console.log(error); | ||
|
||
return error.message; | ||
} | ||
} | ||
|
||
/* -- Search Functionality -- */ | ||
|
||
filterByAccession(accType, value, arr) { | ||
|
||
} | ||
|
||
filterByKeyword(keyword, arr) { | ||
|
||
} | ||
|
||
search(seq_accession, study_accession, keyword) { | ||
let results = [...this.enaData]; | ||
|
||
if (seq_accession !== '') | ||
results = this.filterByAccession('accession', seq_accession, results); | ||
|
||
if (study_accession !== '') | ||
results = this.filterByAccession('study_accession', study_accession, results); | ||
|
||
if (keyword !== '') | ||
results = this.filterByKeyword(keyword, results); | ||
|
||
return results; | ||
} | ||
|
||
/* Returns array of: | ||
{ | ||
"accession": "CP034527", | ||
"study_accession": "PRJNA504496", | ||
"scientific_name": "eukaryotic synthetic construct", | ||
"cell_type": "", | ||
"dataclass": "STD", | ||
"description": "Eukaryotic synthetic construct chromosome 3.", | ||
"mol_type": "other DNA", | ||
"plasmid": "", | ||
"keywords": "" | ||
} | ||
*/ | ||
} | ||
|
||
module.exports = ENADataService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,13 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" | ||
integrity sha1-ml9pkFGx5wczKPKgCJaLZOopVdI= | ||
|
||
axios@^0.21.1: | ||
version "0.21.1" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" | ||
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== | ||
dependencies: | ||
follow-redirects "^1.10.0" | ||
|
||
bl@^2.2.1: | ||
version "2.2.1" | ||
resolved "https://registry.yarnpkg.com/bl/-/bl-2.2.1.tgz#8c11a7b730655c5d56898cdc871224f40fd901d5" | ||
|
@@ -212,6 +219,11 @@ finalhandler@~1.1.2: | |
statuses "~1.5.0" | ||
unpipe "~1.0.0" | ||
|
||
follow-redirects@^1.10.0: | ||
version "1.14.1" | ||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43" | ||
integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg== | ||
|
||
forwarded@~0.1.2: | ||
version "0.1.2" | ||
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84" | ||
|