UNPKG

@rcsb/rcsb-saguaro-app

Version:
70 lines (69 loc) 3.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GroupGapLessTransformer = void 0; const Logo_1 = require("../TrackGenerators/Logo"); const Assertions_1 = require("../Helpers/Assertions"); var assertElementListDefined = Assertions_1.Assertions.assertElementListDefined; class GroupGapLessTransformer { constructor() { this.gapLessReference = []; } processAlignments(alignment) { var _a, _b; if (this.gapLessReference.length > 0 || !alignment.alignment_logo) return; const querySequenceLogo = new Array(); if (alignment.alignment_length && alignment.alignment_length != ((_a = alignment.alignment_logo) === null || _a === void 0 ? void 0 : _a.length)) throw new Error("ERROR Alignment length and logo should match"); (_b = alignment.alignment_logo) === null || _b === void 0 ? void 0 : _b.forEach(al => { assertElementListDefined(al); querySequenceLogo.push(new Logo_1.Logo(al)); }); let newIndex = 1; this.gapLessReference[0] = -1; querySequenceLogo.forEach((sl, n) => { if ((sl.get("-") / sl.total()) == 1) { this.gapLessReference[n + 1] = -1; } else { this.gapLessReference[n + 1] = newIndex++; } }); this.refLength = newIndex - 1; } gapLessAlignments(alignments) { var _a, _b; this.processAlignments(alignments); if (this.gapLessReference.length == 0) return; (_a = alignments.target_alignments) === null || _a === void 0 ? void 0 : _a.forEach(ta => { var _a; (_a = ta === null || ta === void 0 ? void 0 : ta.aligned_regions) === null || _a === void 0 ? void 0 : _a.forEach(region => { if (region === null || region === void 0 ? void 0 : region.query_begin) region.query_begin = this.gapLessReference[region.query_begin]; if (region === null || region === void 0 ? void 0 : region.query_end) region.query_end = this.gapLessReference[region.query_end]; }); }); alignments.alignment_logo = (_b = alignments.alignment_logo) === null || _b === void 0 ? void 0 : _b.filter((al, n) => this.gapLessReference[n + 1] != -1); if (alignments.alignment_length) alignments.alignment_length = this.refLength; } gapLessFeatures(annotations) { if (this.gapLessReference.length == 0) return; annotations.forEach(ann => { var _a; (_a = ann.features) === null || _a === void 0 ? void 0 : _a.forEach(feature => { var _a; (_a = feature === null || feature === void 0 ? void 0 : feature.feature_positions) === null || _a === void 0 ? void 0 : _a.forEach(position => { if (position === null || position === void 0 ? void 0 : position.beg_seq_id) position.beg_seq_id = this.gapLessReference[position.beg_seq_id]; if (position === null || position === void 0 ? void 0 : position.end_seq_id) position.end_seq_id = this.gapLessReference[position.end_seq_id]; }); }); }); } } exports.GroupGapLessTransformer = GroupGapLessTransformer;