diff --git a/src/config.js b/src/config.js index 01f66f2..dd950af 100644 --- a/src/config.js +++ b/src/config.js @@ -1,34 +1,36 @@ exports.ONTOLOGIES = { - 'doid': { - 'name': 'doid', - 'url': 'http://purl.obolibrary.org/obo/doid.owl' + doid: { + name: "doid", + url: "http://purl.obolibrary.org/obo/doid.owl", }, - 'go': { - 'name': 'go', - 'url': 'http://purl.obolibrary.org/obo/go.owl' - }, - 'mondo': { - 'name': 'mondo', - 'url': 'http://purl.obolibrary.org/obo/mondo.owl' + go: { + name: "go", + url: "http://purl.obolibrary.org/obo/go.owl", }, - 'hp': { - 'name': 'hp', - 'url': 'http://purl.obolibrary.org/obo/hp.owl' + mondo: { + name: "mondo", + url: "http://purl.obolibrary.org/obo/mondo.owl", }, - 'chebi': { // not sure why but downloading chebi.owl using curl or node js fails - 'name': 'chebi', - 'url': 'https://ftp.ebi.ac.uk/pub/databases/chebi/ontology/chebi.owl' - }, - 'umls': { // manually processed from MRREL.REF file in UMLS dump - 'name': 'umls' - } -} + hp: { + name: "hp", + url: "http://purl.obolibrary.org/obo/hp.owl", + }, + chebi: { + // not sure why but downloading chebi.owl using curl or node js fails + name: "chebi", + url: "https://ftp.ebi.ac.uk/pub/databases/chebi/ontology/chebi.owl", + }, + umls: { + // manually processed from MRREL.REF file in UMLS dump + name: "umls", + }, +}; exports.CHILD_RELATIONS = { - 'is_a': true, + is_a: true, // 'http://purl.obolibrary.org/obo/BFO_0000050': true, // part of -} +}; exports.PARENT_RELATIONS = { - 'http://purl.obolibrary.org/obo/BFO_0000051': true, // has part -} + "http://purl.obolibrary.org/obo/BFO_0000051": true, // has part +}; diff --git a/src/download.js b/src/download.js index 493351c..a968c66 100644 --- a/src/download.js +++ b/src/download.js @@ -1,7 +1,7 @@ //find and download and parse -const { ONTOLOGIES } = require('./config'); -const { parseFile } = require('./parser'); -const child_process = require('child_process'); +const { ONTOLOGIES } = require("./config"); +const { parseFile } = require("./parser"); +const child_process = require("child_process"); //iterate over ontologies obj for (let ontology of Object.values(ONTOLOGIES)) { @@ -11,21 +11,22 @@ for (let ontology of Object.values(ONTOLOGIES)) { let download_process = child_process.exec(`curl -o ../data/${ontology.name}.owl -L ${url}`); download_process.stdout.pipe(process.stdout); download_process.stderr.pipe(process.stderr); - - download_process.on('close', (code) => { + + download_process.on("close", code => { if (code !== 0) { console.log(`Error downloading ${url}`); return; } console.log(`Done downloading ${url} with code ${code}`); - + // use robot to convert owl to json - child_process.execSync(`../robot convert -i ../data/${ontology.name}.owl --format json -o ../data/${ontology.name}.json`); + child_process.execSync( + `../robot convert -i ../data/${ontology.name}.owl --format json -o ../data/${ontology.name}.json`, + ); console.log(`Parsing ${url}`); parseFile(`../data/${ontology.name}.json`); console.log(`Cleaning up ${url}`); child_process.exec(`rm ../data/${ontology.name}.owl`); child_process.exec(`rm ../data/${ontology.name}.json`); }); - } diff --git a/src/index.js b/src/index.js index 4cf2482..ebec271 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ -const { ONTOLOGIES } = require('./config'); -const _ = require('lodash'); +const { ONTOLOGIES } = require("./config"); +const _ = require("lodash"); let data = {}; let loaded = false; @@ -13,12 +13,12 @@ const loadData = () => { for (let ontology in ONTOLOGIES) { const filename = `../data/${ontology}-parsed.json`; const ontologyData = require(filename); - data = {...data, ...ontologyData}; + data = { ...data, ...ontologyData }; } // const end = performance.now(); // console.log(`loadData took ${end - start} milliseconds.`); loaded = true; -} +}; //get all children of a list of curies exports.getDescendants = (curies, recursive = true) => { @@ -43,8 +43,7 @@ exports.getDescendants = (curies, recursive = true) => { children[curie] = _.uniq(children[curie]).slice(0, ENTITY_CAP); } return children; - } else - { + } else { return _.pick(data, curies); } -} +}; diff --git a/src/parser.js b/src/parser.js index ae6625c..3d904a9 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1,29 +1,26 @@ -var fs = require('fs'); -const { CHILD_RELATIONS, PARENT_RELATIONS } = require('./config'); +var fs = require("fs"); +const { CHILD_RELATIONS, PARENT_RELATIONS } = require("./config"); -const urltoCurie = (url) => { - if (url.startsWith('http://purl.obolibrary.org/obo/')) { - return url.replace('http://purl.obolibrary.org/obo/', '').replace('_', ':'); +const urltoCurie = url => { + if (url.startsWith("http://purl.obolibrary.org/obo/")) { + return url.replace("http://purl.obolibrary.org/obo/", "").replace("_", ":"); } -} +}; -const parseFile = (filename) => { - let f = JSON.parse(fs.readFileSync(filename, 'utf8')); +const parseFile = filename => { + let f = JSON.parse(fs.readFileSync(filename, "utf8")); let map_edges = {}; - for (let edge of f.graphs[0].edges) - { - if (CHILD_RELATIONS[edge.pred]) - { + for (let edge of f.graphs[0].edges) { + if (CHILD_RELATIONS[edge.pred]) { let obj = urltoCurie(edge.obj); let sub = urltoCurie(edge.sub); - if (!map_edges[obj]) - { + if (!map_edges[obj]) { map_edges[obj] = []; } map_edges[obj].push(sub); - } + } // else if (PARENT_RELATIONS[edge.pred]) { // let obj = urltoCurie(edge.sub); // let sub = urltoCurie(edge.obj); @@ -34,9 +31,9 @@ const parseFile = (filename) => { // map_edges[obj].push(sub); // } } - + //export map_edges into json file - fs.writeFileSync(filename.replace('.json', '-parsed.json'), JSON.stringify(map_edges)); -} + fs.writeFileSync(filename.replace(".json", "-parsed.json"), JSON.stringify(map_edges)); +}; exports.parseFile = parseFile;