| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var __asyncValues = (this && this.__asyncValues) || function (o) {
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
- var m = o[Symbol.asyncIterator], i;
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
- };
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.getGOterms = exports.getSymbol = void 0;
- const fs_1 = __importDefault(require("fs"));
- const readline_1 = __importDefault(require("readline"));
- const line$ = (path) => readline_1.default.createInterface({
- input: fs_1.default.createReadStream(path),
- crlfDelay: Infinity
- });
- // http://geneontology.org/docs/guide-go-evidence-codes/
- // http://wiki.geneontology.org/index.php/Category:Evidence_Codes
- const getSymbol = (symbol, goaPath, oboPath) => __awaiter(void 0, void 0, void 0, function* () {
- var e_1, _a;
- var _b;
- const header = [
- 'database', 'ID', 'Symbol', 'Qualifier',
- 'GO_Term', 'Evidence', 'Evidence_Code',
- 'With', 'From', 'Name', 'Alternative_symbols',
- 'Class', 'Taxon', 'Date', 'Origin'
- ];
- const tester = new RegExp('\t' + symbol + '\t');
- const separator = new RegExp('\\|');
- const results = [];
- try {
- for (var _c = __asyncValues(line$(goaPath)), _d; _d = yield _c.next(), !_d.done;) {
- const line = _d.value;
- if (tester.test(line))
- results.push(line.split('\t').reduce((p, c, i) => (Object.assign(Object.assign({}, p), { [header[i]]: separator.test(c) ? c.split('|') : c })), {}));
- }
- }
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
- finally {
- try {
- if (_d && !_d.done && (_a = _c.return)) yield _a.call(_c);
- }
- finally { if (e_1) throw e_1.error; }
- }
- const subTerms = results.map(e => e === null || e === void 0 ? void 0 : e.GO_Term);
- const cacheTerms = yield getGOterms(subTerms, oboPath);
- for (let index = 0; index < results.length; index++) {
- const goTerm = (_b = results[index]) === null || _b === void 0 ? void 0 : _b.GO_Term;
- results[index]['GO_Term'] = cacheTerms.filter(e => e.id === goTerm)[0];
- }
- return results;
- });
- exports.getSymbol = getSymbol;
- const getGOterms = (terms, oboPath) => __awaiter(void 0, void 0, void 0, function* () {
- var e_2, _e;
- const testerList = terms.map(e => new RegExp('id: ' + e));
- let delim = false;
- const results = [];
- let result = {};
- try {
- for (var _f = __asyncValues(line$(oboPath)), _g; _g = yield _f.next(), !_g.done;) {
- const line = _g.value;
- if (testerList.some(rx => rx.test(line)))
- delim = true;
- if (line === '' && delim) {
- delim = false;
- results.push(result);
- result = {};
- }
- if (delim)
- result[line.split(': ')[0]] = line.split(': ')[1];
- }
- }
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
- finally {
- try {
- if (_g && !_g.done && (_e = _f.return)) yield _e.call(_f);
- }
- finally { if (e_2) throw e_2.error; }
- }
- return results;
- });
- exports.getGOterms = getGOterms;
|