Skip to content

Commit

Permalink
style: prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Oct 20, 2023
1 parent 4d0769c commit fb02845
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 58 deletions.
52 changes: 27 additions & 25 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -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
};
17 changes: 9 additions & 8 deletions src/download.js
Original file line number Diff line number Diff line change
@@ -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)) {
Expand All @@ -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`);
});

}
13 changes: 6 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ONTOLOGIES } = require('./config');
const _ = require('lodash');
const { ONTOLOGIES } = require("./config");
const _ = require("lodash");

let data = {};
let loaded = false;
Expand All @@ -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) => {
Expand All @@ -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);
}
}
};
33 changes: 15 additions & 18 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;

0 comments on commit fb02845

Please sign in to comment.