|
|
@@ -26,11 +26,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
};
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
-exports.getSymbol = exports.getFromAcc = void 0;
|
|
|
+exports.makeRefSeqFromReg = exports.getSymbol = exports.getFromAcc = void 0;
|
|
|
const fs_1 = __importDefault(require("fs"));
|
|
|
+const os_1 = __importDefault(require("os"));
|
|
|
+const path_1 = __importDefault(require("path"));
|
|
|
+const child_process_1 = require("child_process");
|
|
|
const readline_1 = __importDefault(require("readline"));
|
|
|
const buffer_1 = require("buffer");
|
|
|
const genbank_parser_1 = __importDefault(require("genbank-parser"));
|
|
|
+const aligner_1 = require("aligner");
|
|
|
+const async_exec = (prog, args, onData) => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const child = (0, child_process_1.spawn)(prog, args, { shell: true });
|
|
|
+ child.stdout.on('data', data => onData(data.toString().trim()));
|
|
|
+ child.stderr.on('data', data => onData(data.toString().trim()));
|
|
|
+ child.on('error', err => reject(err));
|
|
|
+ child.on('exit', code => resolve(code));
|
|
|
+ });
|
|
|
+};
|
|
|
const line$ = (path) => readline_1.default.createInterface({
|
|
|
input: fs_1.default.createReadStream(path),
|
|
|
crlfDelay: Infinity
|
|
|
@@ -125,15 +138,7 @@ const getOffset = (indexPath, acc) => __awaiter(void 0, void 0, void 0, function
|
|
|
const getFromAcc = (accession, dbPath, indexPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
dbPath = Array.isArray(dbPath) ? dbPath : [dbPath];
|
|
|
if (!indexPath) {
|
|
|
- indexPath = [];
|
|
|
- for (const p of dbPath) {
|
|
|
- const iP = p + '.jsi';
|
|
|
- if (!fs_1.default.existsSync(iP)) {
|
|
|
- console.log('Writing index: ' + iP);
|
|
|
- yield makeGbffIndex(p);
|
|
|
- }
|
|
|
- indexPath.push(iP);
|
|
|
- }
|
|
|
+ indexPath = yield getJSI(dbPath);
|
|
|
}
|
|
|
else {
|
|
|
indexPath = Array.isArray(indexPath) ? indexPath : [indexPath];
|
|
|
@@ -207,3 +212,63 @@ rnaDBPath // wget ftp://ftp.ncbi.nlm.nih.gov/refseq/H_sapiens/mRNA_Prot/human.[1
|
|
|
return allFeatures;
|
|
|
});
|
|
|
exports.getSymbol = getSymbol;
|
|
|
+const getJSI = (dbPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
+ dbPath = Array.isArray(dbPath) ? dbPath : [dbPath];
|
|
|
+ const indexPath = [];
|
|
|
+ for (const p of dbPath) {
|
|
|
+ const iP = p + '.jsi';
|
|
|
+ if (!fs_1.default.existsSync(iP)) {
|
|
|
+ console.log('Writing index: ' + iP);
|
|
|
+ yield makeGbffIndex(p);
|
|
|
+ }
|
|
|
+ indexPath.push(iP);
|
|
|
+ }
|
|
|
+ return indexPath;
|
|
|
+});
|
|
|
+// Todo: add progress
|
|
|
+const makeRefSeqFromReg = (dbPath, reg, distFile) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
+ var e_3, _g;
|
|
|
+ dbPath = Array.isArray(dbPath) ? dbPath : [dbPath];
|
|
|
+ const jsiFiles = yield getJSI(dbPath);
|
|
|
+ const tmpDir = path_1.default.join(os_1.default.tmpdir(), 'parser-' + Math.random());
|
|
|
+ yield fs_1.default.promises.mkdir(tmpDir);
|
|
|
+ const createdFiles = [];
|
|
|
+ for (const jsiFile of jsiFiles) {
|
|
|
+ try {
|
|
|
+ for (var _h = (e_3 = void 0, __asyncValues(line$(jsiFile))), _j; _j = yield _h.next(), !_j.done;) {
|
|
|
+ const line = _j.value;
|
|
|
+ if (line.match(reg)) {
|
|
|
+ const [accession, from, to] = line.split('\t');
|
|
|
+ const res = yield getFromAcc(accession, jsiFile.split('.jsi')[0]);
|
|
|
+ if (res === null || res === void 0 ? void 0 : res.sequence) {
|
|
|
+ try {
|
|
|
+ const file = path_1.default.join(tmpDir, (res === null || res === void 0 ? void 0 : res.version) || res.accession + '.fa');
|
|
|
+ yield (0, aligner_1.writeSequence)((res === null || res === void 0 ? void 0 : res.version) || res.accession, res === null || res === void 0 ? void 0 : res.sequence, file);
|
|
|
+ createdFiles.push(file);
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
|
+ finally {
|
|
|
+ try {
|
|
|
+ if (_j && !_j.done && (_g = _h.return)) yield _g.call(_h);
|
|
|
+ }
|
|
|
+ finally { if (e_3) throw e_3.error; }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(createdFiles.length + ' sequences');
|
|
|
+ if (fs_1.default.existsSync(distFile))
|
|
|
+ yield fs_1.default.promises.rm(distFile);
|
|
|
+ for (const createdFile of createdFiles) {
|
|
|
+ const tmp = yield fs_1.default.promises.readFile(createdFile);
|
|
|
+ yield fs_1.default.promises.appendFile(distFile, tmp.toString() + '\n');
|
|
|
+ }
|
|
|
+ yield fs_1.default.promises.rm(tmpDir, { recursive: true });
|
|
|
+ yield async_exec('bwa', ['index', distFile], () => console.log);
|
|
|
+});
|
|
|
+exports.makeRefSeqFromReg = makeRefSeqFromReg;
|