@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
66 lines • 3.25 kB
JavaScript
import { Logo } from "../TrackGenerators/Logo";
import { Assertions } from "../Helpers/Assertions";
var assertElementListDefined = Assertions.assertElementListDefined;
export 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(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];
});
});
});
}
}
//# sourceMappingURL=GroupGapLessTransformer.js.map