UNPKG

@rcsb/rcsb-saguaro-app

Version:
743 lines (742 loc) 38.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RcsbFvChromosome = void 0; const tslib_1 = require("tslib"); const rxjs_1 = require("rxjs"); const RcsbDataManager_1 = require("@rcsb/rcsb-saguaro/lib/RcsbDataManager/RcsbDataManager"); const RcsbFvAbstractModule_1 = require("./RcsbFvAbstractModule"); const GqlTypes_1 = require("@rcsb/rcsb-api-tools/lib/RcsbGraphQL/Types/Borrego/GqlTypes"); const RcsbAnnotationConstants_1 = require("../../RcsbAnnotationConfig/RcsbAnnotationConstants"); const RcsbFvAlignmentCollectorQueue_1 = require("../RcsbFvWorkers/RcsbFvAlignmentCollectorQueue"); const NcbiGenomeSequenceData_1 = require("../../ExternalResources/NcbiData/NcbiGenomeSequenceData"); const NcbiSummary_1 = require("../../ExternalResources/NcbiData/NcbiSummary"); const ideogram_1 = tslib_1.__importDefault(require("ideogram")); const ObservableHelper_1 = require("../../RcsbUtils/Helpers/ObservableHelper"); const RcsbClient_1 = require("../../RcsbGraphQL/RcsbClient"); const Assertions_1 = require("../../RcsbUtils/Helpers/Assertions"); var assertElementListDefined = Assertions_1.Assertions.assertElementListDefined; var assertDefined = Assertions_1.Assertions.assertDefined; function sequenceDisplayDynamicUpdate(reference, ranges, trackWidth) { return (where) => { const delta = trackWidth ? trackWidth / (where.to - where.from) : 1000 / (where.to - where.from); if (delta > 4) { const ids = new Array(); ranges.forEach((id, r) => { if (!(r[0] > where.to || r[1] < where.from)) ids.push(id); }); return Promise.all(ids.map(id => { return RcsbClient_1.rcsbClient.requestAlignment({ queryId: id, from: reference, to: GqlTypes_1.SequenceReference.NcbiGenome }); })).then((alignments) => { const out = new RcsbDataManager_1.RcsbFvTrackData(); alignments.forEach((a, n) => { var _c; if (a.query_sequence == null) return; const sequence = a.query_sequence.split(""); (_c = a.target_alignments) === null || _c === void 0 ? void 0 : _c.forEach(ta => { var _c; if (!ta) return; const orientation = ta.orientation; if (!orientation) return; (_c = ta.aligned_regions) === null || _c === void 0 ? void 0 : _c.forEach(r => { if (!r) return; const targetIndex = r.target_begin; const queryIndex = r.query_begin; const length = r.query_end - r.query_begin + 1; for (let i = 0; i < length; i++) { out.push({ begin: targetIndex + orientation * (1 + 3 * i), label: sequence[queryIndex - 1 + i], oriBegin: queryIndex + i, source: reference.toString(), sourceId: ids[n] }); } }); }); }); return out; }); } else { return new Promise((resolve, reject) => { resolve([]); }); } }; } //TODO This class needs a lot of improvements //TODO this Module is not collecting alignments through AlignmentCollector class RcsbFvChromosome extends RcsbFvAbstractModule_1.RcsbFvAbstractModule { constructor() { super(...arguments); this.targetAlignmentList = new Map([ [GqlTypes_1.SequenceReference.NcbiProtein, new Array()], [GqlTypes_1.SequenceReference.Uniprot, new Array()], [GqlTypes_1.SequenceReference.PdbEntity, new Array()] ]); this.maxRange = 0; this.minRange = Number.MAX_SAFE_INTEGER; this.alignmentCollectorQueue = new RcsbFvAlignmentCollectorQueue_1.RcsbFvAlignmentCollectorQueue(12); this.nTasks = 0; this.completeTasks = 0; this.batchSize = 10000000; this.beginView = 0; this.endView = 0; this.entityBegin = 0; this.entityEnd = 0; this.nonExonConfigData = new Array(); this.featuresConfigData = new Array(); this.targetCoverages = new Map(); this.chrSet = new Array(); this.targetFilterFlag = true; this.IDEOGRAM_DIV_ID = "chrIdeogramDiv"; this.TITLE_CHR_DIV_ID = "chrTitleDiv"; this.TITLE_CHR_REGION_ID = "chrTitleRegion"; this.currentDisplayedChrId = ""; this.buildSubject = new rxjs_1.Subject(); this.targetsSubject = new rxjs_1.Subject(); } buildPdbGenomeFv(pdbEntityId, chrId) { this.entityId = pdbEntityId; Promise.all([GqlTypes_1.SequenceReference.NcbiProtein, GqlTypes_1.SequenceReference.Uniprot].map(to => { return RcsbClient_1.rcsbClient.requestAlignment({ queryId: pdbEntityId, from: GqlTypes_1.SequenceReference.PdbEntity, to: to }); })).then((result) => { result.forEach(a => { var _c; if (!a) return; (_c = a.target_alignments) === null || _c === void 0 ? void 0 : _c.forEach(ta => { if ((ta === null || ta === void 0 ? void 0 : ta.target_id) && (ta === null || ta === void 0 ? void 0 : ta.coverage)) this.targetCoverages.set(ta.target_id, ta.coverage); }); }); this.alignmentCollectorQueue.sendTask({ queryId: pdbEntityId, from: GqlTypes_1.SequenceReference.PdbEntity, to: GqlTypes_1.SequenceReference.NcbiGenome, }, (e) => tslib_1.__awaiter(this, void 0, void 0, function* () { const ar = e; yield this.collectPdbWorkerResults(ar, pdbEntityId, chrId); })); }); } buildFullGenomeRangeFv(chrId) { this.plotChromosomeTitle(chrId); this.targetFilterFlag = false; this.genomeSequenceTracks(chrId); this.collectChromosomeAlignments(chrId, GqlTypes_1.SequenceReference.PdbEntity); this.collectChromosomeAlignments(chrId, GqlTypes_1.SequenceReference.Uniprot); this.collectChromosomeAlignments(chrId, GqlTypes_1.SequenceReference.NcbiProtein); } collectPdbWorkerResults(ar, pdbEntityId, chrId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _c, _d; assertElementListDefined(ar.target_alignments); const exonTracks = this.collectExons(ar.target_alignments, "target", RcsbAnnotationConstants_1.RcsbAnnotationConstants.provenanceColorCode.rcsbPdb, RcsbAnnotationConstants_1.RcsbAnnotationConstants.provenanceColorCode.rcsbPdb, GqlTypes_1.SequenceReference.PdbEntity, chrId); this.pdbEntityTrack = this.mergeExonTracks(exonTracks, GqlTypes_1.SequenceReference.PdbEntity)[0]; (_d = (_c = this.pdbEntityTrack.displayConfig) === null || _c === void 0 ? void 0 : _c[0].displayData) === null || _d === void 0 ? void 0 : _d.forEach(d => { d.description = [pdbEntityId]; }); this.addSequences([this.pdbEntityTrack], GqlTypes_1.SequenceReference.PdbEntity); this.pdbEntityTrack.rowTitle = { visibleTex: pdbEntityId, style: { fontWeight: "bold" } }; this.pdbEntityTrack.hideEmptyTrackFlag = false; yield this.buildChromosomeFv(chrId !== null && chrId !== void 0 ? chrId : this.chrSet[0]); }); } buildChromosomeFv(chrId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { this.plotChromosomeTitle(chrId); this.genomeSequenceTracks(chrId); this.nonExonConfigData.push(this.pdbEntityTrack); yield this.plot(); this.collectChromosomeEntityRegion(chrId); }); } plotChromosomeTitle(chrId) { var _c, _d; (_c = document.getElementById(this.IDEOGRAM_DIV_ID)) === null || _c === void 0 ? void 0 : _c.remove(); (_d = document.getElementById(this.TITLE_CHR_DIV_ID)) === null || _d === void 0 ? void 0 : _d.remove(); this.currentDisplayedChrId = chrId; NcbiSummary_1.NcbiSummary.requestChromosomeData(chrId).then(ncbiChrResult => { var _c, _d; if (chrId == this.currentDisplayedChrId) { const ideogramDiv = document.createElement("div"); ideogramDiv.id = this.IDEOGRAM_DIV_ID; const titleDiv = document.createElement("div"); titleDiv.style.display = "inline-block"; titleDiv.style.marginLeft = "20px"; titleDiv.id = this.TITLE_CHR_DIV_ID; const title = document.createElement("span"); title.innerHTML = ncbiChrResult.title; titleDiv.append(title); const region = document.createElement("span"); region.id = this.TITLE_CHR_REGION_ID; region.innerHTML = " / Region: [" + this.entityBegin + " - " + this.entityEnd + "]"; region.style.color = "#666"; titleDiv.append(region); (_c = document.getElementById(this.elementSelectId)) === null || _c === void 0 ? void 0 : _c.insertAdjacentElement("afterend", titleDiv); (_d = document.getElementById(this.elementId)) === null || _d === void 0 ? void 0 : _d.insertAdjacentElement("beforebegin", ideogramDiv); this.plotIdeogram(ncbiChrResult); } }); } updateChromosomeTitleRegion() { const region = document.getElementById(this.TITLE_CHR_REGION_ID); if (region != null) region.innerHTML = " / Region: [" + this.beginView + " - " + this.endView + "]"; } plotIdeogram(ncbiChrResult) { NcbiSummary_1.NcbiSummary.requestTaxonomyData(ncbiChrResult.taxid.toString()).then(ncbiTaxResult => { if (ncbiChrResult.ncbiId == this.currentDisplayedChrId) { const chrName = ncbiChrResult.subname.includes("|") ? ncbiChrResult.subname.split("|").filter(n => { return (n.match(/^([\dXYxy]+)$/) != null); })[0] : ncbiChrResult.subname; const ideogram = new ideogram_1.default({ rotatable: false, chrHeight: 1080, chrWidth: 20, organism: ncbiTaxResult.scientificname, chromosomes: [chrName], orientation: 'horizontal', container: '#' + this.IDEOGRAM_DIV_ID, annotationHeight: 8, showBandLabels: true, annotations: [{ name: this.entityId, chr: chrName, start: this.entityBegin, stop: this.entityEnd }], onLoad: () => { var _c, _d; if (!(((_c = ideogram.chromosomesArray) === null || _c === void 0 ? void 0 : _c.length) > 0)) { (_d = document.getElementById(this.IDEOGRAM_DIV_ID)) === null || _d === void 0 ? void 0 : _d.remove(); } else { const e = document.getElementById("_ideogram"); if (e != null) e.style.padding = "0 0 0 0"; } } }); } }); } genomeSequenceTracks(chrId) { var _c, _d, _e, _f; this.nonExonConfigData.push({ trackId: "mainSequenceTrack_5_" + chrId, displayType: "sequence" /* RcsbFvDisplayTypes.SEQUENCE */, trackColor: "#F9F9F9", displayColor: "#000000", nonEmptyDisplay: true, rowPrefix: chrId + " ", rowTitle: { visibleTex: "5'", style: { fontWeight: "bold" }, }, titleFlagColor: RcsbAnnotationConstants_1.RcsbAnnotationConstants.provenanceColorCode.external, updateDataOnMove: NcbiGenomeSequenceData_1.NcbiGenomeSequenceData.update(chrId, 1, false, (_d = (_c = this.rcsbFv) === null || _c === void 0 ? void 0 : _c.getBoardConfig()) === null || _d === void 0 ? void 0 : _d.trackWidth) }); this.nonExonConfigData.push({ trackId: "mainSequenceTrack_3_" + chrId, displayType: "sequence" /* RcsbFvDisplayTypes.SEQUENCE */, trackColor: "#F9F9F9", displayColor: "#000000", rowPrefix: "", nonEmptyDisplay: true, rowTitle: { visibleTex: "3'", style: { fontWeight: "bold" }, }, titleFlagColor: RcsbAnnotationConstants_1.RcsbAnnotationConstants.provenanceColorCode.external, updateDataOnMove: NcbiGenomeSequenceData_1.NcbiGenomeSequenceData.update(chrId, 2, true, (_f = (_e = this.rcsbFv) === null || _e === void 0 ? void 0 : _e.getBoardConfig()) === null || _f === void 0 ? void 0 : _f.trackWidth) }); } collectChromosomeEntityRegion(chrId) { var _c, _d, _e, _f; const begin = (_d = (_c = this.pdbEntityTrack.displayConfig) === null || _c === void 0 ? void 0 : _c[0].displayData) === null || _d === void 0 ? void 0 : _d[0].begin; const end = (_f = (_e = this.pdbEntityTrack.displayConfig) === null || _e === void 0 ? void 0 : _e[0].displayData) === null || _f === void 0 ? void 0 : _f[0].end; if (begin && end) { const range = [Math.max(1, begin - 5000000), end + 5000000]; this.collectChromosomeAlignments(chrId, GqlTypes_1.SequenceReference.Uniprot, range, 0); this.collectChromosomeAlignments(chrId, GqlTypes_1.SequenceReference.NcbiProtein, range, 0); } } collectChromosomeAlignments(chrId, to, range, index) { if (range != null) { this.nTasks++; this.alignmentCollectorQueue.sendTask({ queryId: chrId, from: GqlTypes_1.SequenceReference.NcbiGenome, to: to, range: range }, (e) => tslib_1.__awaiter(this, void 0, void 0, function* () { const ar = e; if (typeof index === "number") yield this.collectChromosomeWorkerResults(index, to, ar, false); })); } else { for (let i = 0; i < 30; i++) { this.nTasks++; this.alignmentCollectorQueue.sendTask({ queryId: chrId, from: GqlTypes_1.SequenceReference.NcbiGenome, to: to, range: [i * this.batchSize, (i + 1) * this.batchSize] }, (e) => tslib_1.__awaiter(this, void 0, void 0, function* () { const ar = e; yield this.collectChromosomeWorkerResults(i, to, ar, false); })); } } } collectChromosomeWorkerResults(index, reference, alignment, forcePlot) { return tslib_1.__awaiter(this, void 0, void 0, function* () { this.completeTasks++; const e = this.targetAlignmentList.get(reference); assertDefined(e); assertElementListDefined(alignment.target_alignments); e[index] = alignment.target_alignments; console.log("Completed " + Math.floor(this.completeTasks / this.nTasks * 100) + "%"); if (forcePlot) { yield this.plot(); } else if (this.nTasks == this.completeTasks) { console.log("All Tasks Completed. Starting Rendering"); this.alignmentCollectorQueue.terminateWorkers(); yield this.plot(); } }); } collectExons(targetAlignmentList, member, blockColor, flagTitleColor, reference, chrId) { const exonTrackList = new Array(); targetAlignmentList.forEach((targetAlignment, i) => { var _c; if (!targetAlignment.target_id) return; if (((_c = targetAlignment.aligned_regions) === null || _c === void 0 ? void 0 : _c.length) == 0 || (member == "query" && this.targetFilterFlag && !this.targetCoverages.has(targetAlignment.target_id)) || (member == "target" && chrId != null && chrId != targetAlignment.target_id)) return; exonTrackList.push({ data: [this.normalizeTargetAlignment(targetAlignment, member)], id: targetAlignment.target_id }); }); const lightTracks = this.simplifyExonTracks(exonTrackList.sort((_a, _b) => { var _c, _d, _e, _f; const a = _a.data; const b = _b.data; if (a[0].begin != b[0].begin) return a[0].begin - b[0].begin; if (b[0].end && a[0].end && b[0].end != a[0].end) return b[0].end - a[0].end; return ((_d = (_c = a[0].gaps) === null || _c === void 0 ? void 0 : _c.map(g => g.end - g.begin).reduce((a, b) => a + b, 0)) !== null && _d !== void 0 ? _d : 0) - ((_f = (_e = b[0].gaps) === null || _e === void 0 ? void 0 : _e.map(g => g.end - g.begin).reduce((a, b) => a + b, 0)) !== null && _f !== void 0 ? _f : 0); }).map(a => { if (member == "target" && !this.chrSet.includes(a.id)) this.chrSet.push(a.id); return a.data; }), member, reference); return lightTracks.map((t, index) => { return { trackId: "pdbTracks_" + Math.random().toString(36).substring(2), displayType: "composite" /* RcsbFvDisplayTypes.COMPOSITE */, trackColor: "#F9F9F9", rowTitle: "", titleFlagColor: flagTitleColor, overlap: true, displayConfig: [{ displayType: "block" /* RcsbFvDisplayTypes.BLOCK */, displayData: t, displayColor: blockColor, selectDataInRangeFlag: true, hideEmptyTrackFlag: true, minRatio: 1 / 5000 }] }; }); } normalizeTargetAlignment(targetAlignment, member) { const beginMember = member === "query" ? "query_begin" : "target_begin"; const endMember = member === "query" ? "query_end" : "target_end"; const ar = targetAlignment.aligned_regions; assertElementListDefined(ar); assertDefined(targetAlignment.target_id), assertDefined(targetAlignment.orientation); const out = { begin: Math.min(ar[0][beginMember], ar[ar.length - 1][endMember]), end: Math.max(ar[0][beginMember], ar[ar.length - 1][endMember]), gaps: [], description: [targetAlignment.target_id], openBegin: targetAlignment.orientation < 0, openEnd: targetAlignment.orientation > 0 }; if (targetAlignment.orientation > 0) { if (member == "query" && ar[ar.length - 1][endMember] > this.maxRange) this.maxRange = ar[ar.length - 1][endMember]; if (member == "query" && ar[0][beginMember] < this.minRange) this.minRange = ar[0][beginMember]; ar.forEach((currentExon, n) => { var _c, _d, _e, _f, _g, _h; if ((n + 1) < ar.length) { const nextExon = ar[n + 1]; let beginGap = currentExon[endMember]; let endGap = nextExon[beginMember]; const exonShift = currentExon.exon_shift ? currentExon.exon_shift.map(e => { if (!e) throw new Error(`Undefined exon`); return e; }) : []; if ((exonShift === null || exonShift === void 0 ? void 0 : exonShift.length) == 1) { if (Math.abs(exonShift[0] - endGap) == 1) { endGap = exonShift[0]; } else { (_c = out.gaps) === null || _c === void 0 ? void 0 : _c.push({ end: exonShift[0], begin: beginGap, isConnected: true }); endGap = exonShift[0]; } } else if ((exonShift === null || exonShift === void 0 ? void 0 : exonShift.length) == 2) { if (Math.abs(exonShift[1] - endGap) == 1 && Math.abs(exonShift[1] - exonShift[0]) == 1) { endGap = exonShift[0]; } else if (Math.abs(exonShift[1] - endGap) == 1) { (_d = out.gaps) === null || _d === void 0 ? void 0 : _d.push({ end: exonShift[0], begin: beginGap, isConnected: true }); beginGap = exonShift[0]; endGap = exonShift[1]; } else if (Math.abs(exonShift[1] - exonShift[0]) == 1) { (_e = out.gaps) === null || _e === void 0 ? void 0 : _e.push({ end: exonShift[0], begin: beginGap, isConnected: true }); beginGap = exonShift[1]; } else { (_f = out.gaps) === null || _f === void 0 ? void 0 : _f.push({ end: exonShift[0], begin: beginGap, isConnected: true }); beginGap = exonShift[0]; (_g = out.gaps) === null || _g === void 0 ? void 0 : _g.push({ end: exonShift[1], begin: beginGap, isConnected: true }); beginGap = exonShift[1]; } } (_h = out.gaps) === null || _h === void 0 ? void 0 : _h.push({ begin: beginGap, end: endGap, isConnected: true }); } }); } else { if (member == "query" && ar[0][beginMember] > this.maxRange) this.maxRange = ar[0][beginMember]; if (member == "query" && ar[ar.length - 1][endMember] < this.minRange) this.minRange = ar[ar.length - 1][endMember]; ar.reverse().forEach((currentExon, n) => { var _c, _d, _e, _f, _g, _h; if ((n + 1) < ar.length) { const nextExon = ar[n + 1]; let beginGap = currentExon[beginMember]; let endGap = nextExon[endMember]; const exonShift = nextExon.exon_shift ? nextExon.exon_shift.map(e => { if (!e) throw new Error(`Undefined exon`); return e; }) : []; if ((exonShift === null || exonShift === void 0 ? void 0 : exonShift.length) == 1) { if (Math.abs(exonShift[0] - beginGap) == 1) { beginGap = exonShift[0]; } else { (_c = out.gaps) === null || _c === void 0 ? void 0 : _c.push({ end: exonShift[0], begin: beginGap, isConnected: true }); beginGap = exonShift[0]; } } else if ((exonShift === null || exonShift === void 0 ? void 0 : exonShift.length) == 2) { if (Math.abs(exonShift[1] - beginGap) == 1 && Math.abs(exonShift[1] - exonShift[0]) == 1) { beginGap = exonShift[0]; } else if (Math.abs(exonShift[1] - beginGap) == 1) { beginGap = exonShift[1]; (_d = out.gaps) === null || _d === void 0 ? void 0 : _d.push({ end: exonShift[0], begin: beginGap, isConnected: true }); beginGap = exonShift[0]; } else if (Math.abs(exonShift[1] - exonShift[0]) == 1) { (_e = out.gaps) === null || _e === void 0 ? void 0 : _e.push({ end: exonShift[0], begin: beginGap, isConnected: true }); beginGap = exonShift[1]; } else { (_f = out.gaps) === null || _f === void 0 ? void 0 : _f.push({ end: exonShift[0], begin: beginGap, isConnected: true }); beginGap = exonShift[0]; (_g = out.gaps) === null || _g === void 0 ? void 0 : _g.push({ end: exonShift[1], begin: beginGap, isConnected: true }); beginGap = exonShift[1]; } } (_h = out.gaps) === null || _h === void 0 ? void 0 : _h.push({ end: endGap, begin: beginGap, isConnected: true }); } }); } return out; } simplifyExonTracks(tracks, member, reference) { const lightTracks = new Array(); tracks.forEach(t => { var _c, _d, _e, _f, _g; const trackBegin = t[0].begin; const trackEnd = t[0].end; if (lightTracks.length == 0) { if ((this.entityBegin > 0 && this.entityEnd > 0) && !(trackBegin > this.entityEnd || (trackEnd && trackEnd < this.entityBegin))) { if (trackBegin < this.beginView) this.beginView = trackBegin; if (trackEnd && trackEnd > this.endView) this.endView = trackEnd; } lightTracks.push(t); } else { const N = lightTracks.length - 1; const begin = lightTracks[N][0].begin; const end = lightTracks[N][0].end; const trackHash = trackBegin + "." + ((_c = t[0].gaps) === null || _c === void 0 ? void 0 : _c.map((b) => { return b.begin + "." + b.end; }).join(".")) + "." + trackEnd; const ltHash = begin + "." + ((_d = lightTracks[N][0].gaps) === null || _d === void 0 ? void 0 : _d.map((b) => { return b.begin + "." + b.end; }).join(".")) + "." + end; if (trackHash != ltHash) { if ((this.entityBegin > 0 && this.entityEnd > 0) && !(trackBegin > this.entityEnd || (trackEnd && trackEnd < this.entityBegin))) { if (trackBegin < this.beginView) this.beginView = trackBegin; if (trackEnd && trackEnd > this.endView) this.endView = trackEnd; } lightTracks.push(t); } else { (_e = lightTracks[N][0].description) === null || _e === void 0 ? void 0 : _e.push((_g = (_f = t[0].description) === null || _f === void 0 ? void 0 : _f[0]) !== null && _g !== void 0 ? _g : "N/A"); } } }); return lightTracks; } mergeExonTracks(tracks, reference) { const lightTracks = new Array(); tracks.forEach(t => { var _c, _d, _e, _f, _g, _h, _j; if (lightTracks.length == 0) { lightTracks.push(t); } else { const trackBegin = (_d = (_c = t.displayConfig) === null || _c === void 0 ? void 0 : _c[0].displayData) === null || _d === void 0 ? void 0 : _d[0].begin; let index = -1; lightTracks.forEach((lT, n) => { var _c; const d = (_c = lT.displayConfig) === null || _c === void 0 ? void 0 : _c[0].displayData; if (!d) return; const N = d.length - 1; const end = d[N].end; if (trackBegin && end && trackBegin > end && index == -1) { index = n; } }); if (index >= 0 && ((_f = (_e = t.displayConfig) === null || _e === void 0 ? void 0 : _e[0].displayData) === null || _f === void 0 ? void 0 : _f[0])) { (_h = (_g = lightTracks[index].displayConfig) === null || _g === void 0 ? void 0 : _g[0].displayData) === null || _h === void 0 ? void 0 : _h.push((_j = t.displayConfig) === null || _j === void 0 ? void 0 : _j[0].displayData[0]); } else if (index == -1) { lightTracks.push(t); } } }); this.addSequences(lightTracks, reference); return lightTracks; } addSequences(lightTracks, reference) { lightTracks.forEach(t => { var _c, _d, _e, _f, _g; const ids = new Map(); (_d = (_c = t.displayConfig) === null || _c === void 0 ? void 0 : _c[0].displayData) === null || _d === void 0 ? void 0 : _d.forEach(d => { if (d.end && d.description) ids.set([d.begin, d.end], d.description[0]); }); (_e = t.displayConfig) === null || _e === void 0 ? void 0 : _e.push({ displayType: "sequence" /* RcsbFvDisplayTypes.SEQUENCE */, updateDataOnMove: sequenceDisplayDynamicUpdate(reference, ids, (_g = (_f = this.rcsbFv) === null || _f === void 0 ? void 0 : _f.getBoardConfig()) === null || _g === void 0 ? void 0 : _g.trackWidth), displayData: [], hideEmptyTrackFlag: true, minRatio: 1 / 1000 }); }); } setDisplayView() { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _c, _d, _e, _f, _g, _h, _j; if (this.entityBegin == 0 && this.entityEnd == 0 && ((_e = (_d = (_c = this.pdbEntityTrack) === null || _c === void 0 ? void 0 : _c.displayConfig) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) > 0) { const d = (_f = this.pdbEntityTrack.displayConfig) === null || _f === void 0 ? void 0 : _f[0].displayData; if (!d) return; const lastIndex = d[d.length - 1].end; if (!lastIndex) return; this.entityBegin = d[0].begin; this.entityEnd = lastIndex; this.beginView = d[0].begin; this.endView = lastIndex; const begin = this.beginView; const end = this.endView; const length = end - begin; this.boardConfigData.range = { min: begin - Math.ceil(0.05 * length), max: end + Math.ceil(+0.05 * length) }; } else if (((_j = (_h = (_g = this.pdbEntityTrack) === null || _g === void 0 ? void 0 : _g.displayConfig) === null || _h === void 0 ? void 0 : _h.length) !== null && _j !== void 0 ? _j : 0) > 0) { this.beginView = this.minRange; this.endView = this.maxRange; const begin = this.beginView; const end = this.endView; const length = end - begin; this.boardConfigData.range = { min: begin - Math.ceil(0.05 * length), max: end + Math.ceil(+0.05 * length) }; this.updateChromosomeTitleRegion(); } yield this.display(); return void 0; }); } plot() { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _c, _d, _e, _f; console.log("PROCESSING"); let tracks = new Array(); let ncbiTracks = new Array(); (_c = this.targetAlignmentList.get(GqlTypes_1.SequenceReference.NcbiProtein)) === null || _c === void 0 ? void 0 : _c.forEach((tA, index) => { if (tA.length > 0) { ncbiTracks = ncbiTracks.concat(this.collectExons(tA, "query", "#69b3a2", "#69b3a2", GqlTypes_1.SequenceReference.NcbiProtein)); } }); ncbiTracks = this.mergeExonTracks(ncbiTracks, GqlTypes_1.SequenceReference.NcbiProtein); let uniprotTracks = new Array(); (_d = this.targetAlignmentList.get(GqlTypes_1.SequenceReference.Uniprot)) === null || _d === void 0 ? void 0 : _d.forEach((tA, index) => { if (tA.length > 0) uniprotTracks = uniprotTracks.concat(this.collectExons(tA, "query", "#cc99ff", "#cc99ff", GqlTypes_1.SequenceReference.Uniprot)); }); uniprotTracks = this.mergeExonTracks(uniprotTracks, GqlTypes_1.SequenceReference.Uniprot); let entityTracks = new Array(); (_e = this.targetAlignmentList.get(GqlTypes_1.SequenceReference.PdbEntity)) === null || _e === void 0 ? void 0 : _e.forEach((tA, index) => { if (tA.length > 0) entityTracks = entityTracks.concat(this.collectExons(tA, "query", RcsbAnnotationConstants_1.RcsbAnnotationConstants.provenanceColorCode.rcsbPdb, RcsbAnnotationConstants_1.RcsbAnnotationConstants.provenanceColorCode.rcsbPdb, GqlTypes_1.SequenceReference.PdbEntity)); }); entityTracks = this.mergeExonTracks(entityTracks, GqlTypes_1.SequenceReference.PdbEntity); if (ncbiTracks.length > 0) { tracks = tracks.concat(ncbiTracks); ncbiTracks[0].rowTitle = "NCBI PROTEINS"; } if (uniprotTracks.length > 0) { tracks = tracks.concat(uniprotTracks); uniprotTracks[0].rowTitle = "UNIPROT PROTEINS"; } if (entityTracks.length > 0) { tracks = tracks.concat(entityTracks); entityTracks[0].rowTitle = "PDB ENTITIES"; } const headerTracks = ((_f = this.featuresConfigData) === null || _f === void 0 ? void 0 : _f.length) > 0 ? this.nonExonConfigData.concat(this.featuresConfigData) : this.nonExonConfigData; if (tracks.length > 0) this.rowConfigData = headerTracks.concat(tracks); else this.rowConfigData = headerTracks; console.log("RENDERING"); this.boardConfigData.hideInnerBorder = true; this.boardConfigData.length = Math.floor(this.maxRange + 0.01 * this.maxRange); this.boardConfigData.includeAxis = true; yield this.setDisplayView(); this.buildSubject.next(void 0); this.targetsSubject.next(this.chrSet); return void 0; }); } protectedBuild() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const buildConfig = this.buildConfig; return new Promise(((resolve, reject) => { ObservableHelper_1.ObservableHelper.oneTimeSubscription(resolve, this.buildSubject); if (buildConfig.elementSelectId) this.elementSelectId = buildConfig.elementSelectId; if (buildConfig.entityId != null) this.buildPdbGenomeFv(buildConfig.entityId, buildConfig.chrId); else if (buildConfig.chrId != null) this.buildFullGenomeRangeFv(buildConfig.chrId); })); }); } getTargets() { return tslib_1.__awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { if (this.chrSet.length > 0) resolve(this.chrSet); else ObservableHelper_1.ObservableHelper.oneTimeSubscription(resolve, this.targetsSubject); }); }); } concatAlignmentAndAnnotationTracks() { } } exports.RcsbFvChromosome = RcsbFvChromosome;