|
|
@@ -61,12 +61,26 @@ const templateGTnode = (args) => {
|
|
|
const templateEdge = (from, to) => {
|
|
|
return `MATCH (from:GoTerm {id: '${from}'})
|
|
|
MATCH (to:GoTerm {id: '${to}'})
|
|
|
- CREATE (from)-[rel:is_a]->(to)`;
|
|
|
+ MERGE (from)-[rel:is_a]->(to)`;
|
|
|
};
|
|
|
-const insert = (oboPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
+const templateSymbol = (args) => {
|
|
|
+ let tmp = 'CREATE (sy:Symbol {';
|
|
|
+ Object.keys(args).forEach((dd, ii) => {
|
|
|
+ const delim = ii === 0 ? '' : ', ';
|
|
|
+ tmp += `${delim}${dd}: "${args[dd]}"`;
|
|
|
+ });
|
|
|
+ tmp += `})`;
|
|
|
+ return tmp;
|
|
|
+};
|
|
|
+const templateEdgeGoa = (fromSymbol, toGoTerm, relName, args) => {
|
|
|
+ const tmpArgs = Object.keys(args).reduce((p, c) => p += `${c}: "${args[c]}", `, "").slice(0, -2);
|
|
|
+ return `MATCH (from:Symbol {name: '${fromSymbol}'})
|
|
|
+ MATCH (to:GoTerm {id: '${toGoTerm}'})
|
|
|
+ MERGE (from)-[rel:${relName} {${tmpArgs}}]->(to)`;
|
|
|
+};
|
|
|
+const readObo = (oboPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
var e_1, _a;
|
|
|
let delim = false;
|
|
|
- const results = [];
|
|
|
const vertexes = [];
|
|
|
const edges = [];
|
|
|
let result = {};
|
|
|
@@ -85,7 +99,6 @@ const insert = (oboPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
}
|
|
|
}
|
|
|
result = {};
|
|
|
- results.push(result);
|
|
|
}
|
|
|
else if (delim)
|
|
|
result[line.split(': ')[0]] = line.split(': ')[1].replace("\"", "");
|
|
|
@@ -100,6 +113,53 @@ const insert = (oboPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
}
|
|
|
return { vertexes, edges };
|
|
|
});
|
|
|
+const readGoa = (goaPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
+ var e_2, _d;
|
|
|
+ const header = [
|
|
|
+ 'database', 'ID', 'Symbol', 'Qualifier',
|
|
|
+ 'GO_Term', 'Evidence', 'Evidence_Code',
|
|
|
+ 'With', 'From', 'Name', 'Alternative_symbols',
|
|
|
+ 'Class', 'Taxon', 'Date', 'Origin'
|
|
|
+ ];
|
|
|
+ const vertexes = [];
|
|
|
+ const edges = [];
|
|
|
+ const allSymbols = {};
|
|
|
+ try {
|
|
|
+ for (var _e = __asyncValues(line$(goaPath)), _f; _f = yield _e.next(), !_f.done;) {
|
|
|
+ const line = _f.value;
|
|
|
+ if (/^[^!]/.test(line)) {
|
|
|
+ const obj = line.split('\t').filter((e) => e).reduce((p, c, i) => (Object.assign(Object.assign({}, p), { [header[i]]: /*separator.test(c) ? c.split('|') :*/ c })), {});
|
|
|
+ if (typeof allSymbols[obj.Symbol] === 'undefined') {
|
|
|
+ vertexes.push(templateSymbol({
|
|
|
+ name: obj.Symbol,
|
|
|
+ class: obj.Class,
|
|
|
+ fullName: obj.Name,
|
|
|
+ alternativeName: obj.Alternative_symbols,
|
|
|
+ taxon: obj.Taxon,
|
|
|
+ goaID: obj.ID,
|
|
|
+ goaDB: obj.Origin
|
|
|
+ }));
|
|
|
+ allSymbols[obj.Symbol] = '';
|
|
|
+ }
|
|
|
+ edges.push(templateEdgeGoa(obj.Symbol, obj.GO_Term, obj.Qualifier.replace("|", "_or_"), {
|
|
|
+ goaEvidence: obj.Evidence,
|
|
|
+ goaEvidenceCode: obj.Evidence_Code,
|
|
|
+ goaWith: obj.With,
|
|
|
+ goaFrom: obj.From,
|
|
|
+ goaDate: obj.Date
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
|
+ finally {
|
|
|
+ try {
|
|
|
+ if (_f && !_f.done && (_d = _e.return)) yield _d.call(_e);
|
|
|
+ }
|
|
|
+ finally { if (e_2) throw e_2.error; }
|
|
|
+ }
|
|
|
+ return { vertexes, edges };
|
|
|
+});
|
|
|
const runNeo = (session, sql) => {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
try {
|
|
|
@@ -112,16 +172,30 @@ const runNeo = (session, sql) => {
|
|
|
};
|
|
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
const oboPath = '/home/thomas/NGS/ref/GO/go-basic.obo';
|
|
|
+ const goaPath = '/home/thomas/NGS/ref/GO/goa_human.gaf';
|
|
|
var driver = neo4j.driver('neo4j://localhost', neo4j.auth.basic('neo4j', '123456'));
|
|
|
var session = driver.session();
|
|
|
- console.log(session);
|
|
|
- const rr = yield insert(oboPath);
|
|
|
- // const rr = await getGOterms('GO:0008150', oboPath)
|
|
|
- console.log(rr.edges[0]);
|
|
|
+ // OBO
|
|
|
+ /*
|
|
|
+ const rr = await readObo(oboPath)
|
|
|
for (const v of rr.vertexes) {
|
|
|
- yield runNeo(session, v);
|
|
|
+ console.log('Inserting OBO vertexes...');
|
|
|
+ await runNeo(session, v)
|
|
|
}
|
|
|
for (const e of rr.edges) {
|
|
|
+ console.log('Inserting OBO edges...');
|
|
|
+ await runNeo(session, e)
|
|
|
+ }
|
|
|
+ */
|
|
|
+ // GOA
|
|
|
+ const goaAll = yield readGoa(goaPath);
|
|
|
+ console.log(goaAll.edges[0]);
|
|
|
+ // for (const v of goaAll.vertexes) {
|
|
|
+ // console.log('Inserting GOA vertexes...');
|
|
|
+ // await runNeo(session, v)
|
|
|
+ // }
|
|
|
+ for (const e of goaAll.edges) {
|
|
|
+ // console.log('Inserting GOA edges...');
|
|
|
yield runNeo(session, e);
|
|
|
}
|
|
|
yield driver.close();
|