UNPKG

generic-sequence-panel

Version:

read feature and sequence data and produce highlighted fasta

73 lines (72 loc) 3.75 kB
"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.default = fetchTranscripts; const generic_filehandle2_1 = require("generic-filehandle2"); const nclist_1 = __importDefault(require("@gmod/nclist")); // Create transcriptList function this function is called by the SeqPanel // component when it needs to fetch a list of transcripts for a given gene it // should return an array of transcript names (see @gmod/nclist for more info) // // it is called with five arguments: // - nclistbaseurl: the base URL of the NCList file // - urltemplate: the URL template for the NCList file // - refseq: the reference sequence (name, like "chr1") // - start: the start of the range (in interbase coordinates) // - end: the end of the range (in interbase coordinates) // - gene: the name of the gene function fetchTranscripts(_a) { return __awaiter(this, arguments, void 0, function* ({ nclistbaseurl, urltemplate, refseq, start, end, gene, }) { var _b, e_1, _c, _d; var _e; if (refseq == "NC_045512.2") { throw new Error("Unfortunately, Sequence Details doesn't yet support fetching viral sequences; sorry."); } const store = new nclist_1.default({ urlTemplate: urltemplate, baseUrl: nclistbaseurl, readFile: (url) => new generic_filehandle2_1.RemoteFile(url).readFile(), }); try { for (var _f = true, _g = __asyncValues(store.getFeatures({ refName: refseq, start: start, end: end, })), _h; _h = yield _g.next(), _b = _h.done, !_b; _f = true) { _d = _h.value; _f = false; const feature = _d; const f = feature; if (f.get("name") === gene) { return (_e = f.get("subfeatures")) !== null && _e !== void 0 ? _e : []; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_f && !_b && (_c = _g.return)) yield _c.call(_g); } finally { if (e_1) throw e_1.error; } } return []; }); }