rebuildContainer()

in client/client/modules/render/tracks/blast/renderer.js [71:187]


    rebuildContainer(viewport, cache) {
        super.rebuildContainer(viewport, cache);
        this.dataContainer.removeChildren();
        this._hoveringGraphics.clear();
        this._hoveringGraphics = new PIXI.Graphics();
        if (
            cache.data !== null &&
            cache.data !== undefined &&
            cache.data.length > 0
        ) {
            const alignments = cache.data;
            const featureCoords = this.blastContext.featureCoords;
            const levels = [];
            let maxLevels = 0;
            const height = this.config.sequence.height;
            const levelHeight = height + 2 * this.config.sequence.margin;
            for (let i = 0; i < alignments.length; i++) {
                const alignment = alignments[i];
                const {
                    queryLength,
                    sequenceStrandView
                } = alignment;
                let {
                    sequenceStart,
                    sequenceEnd,
                    queryStart,
                    queryEnd,
                } = alignment;
                if (!sequenceStart || !sequenceEnd) {
                    continue;
                }
                const positiveStrand = !sequenceStrandView || sequenceStrandView === '+';
                if (!positiveStrand) {
                    const temp = queryStart;
                    queryStart = queryLength - queryEnd + 1;
                    queryEnd = queryLength - temp + 1;
                }
                queryStart = queryStart - 1;
                queryEnd = queryLength - queryEnd;
                if (featureCoords) {
                    sequenceStart = featureCoords.start;
                    sequenceEnd = featureCoords.end;
                }
                const start = Math.min(sequenceStart, sequenceEnd);
                const end = Math.max(sequenceStart, sequenceEnd);
                let startPx = viewport.project.brushBP2pixel(start);
                let endPx = viewport.project.brushBP2pixel(end);
                if (queryStart > 0) {
                    startPx -= (
                        this.config.sequence.notAligned.width +
                        this.config.sequence.notAligned.margin +
                        PixiTextSize.getTextSize(
                            `${queryStart}`,
                            this.config.sequence.notAligned.label
                        ).width
                    );
                }
                if (queryEnd > 0) {
                    endPx += (
                        this.config.sequence.notAligned.width +
                        this.config.sequence.notAligned.margin +
                        PixiTextSize.getTextSize(
                            `${queryEnd}`,
                            this.config.sequence.notAligned.label
                        ).width
                    );
                }
                if (positiveStrand) {
                    endPx += this.config.strandMarker.width;
                } else {
                    startPx -= this.config.strandMarker.width;
                }
                startPx -= this.config.sequence.margin;
                endPx += this.config.sequence.margin;
                const size = endPx - startPx;
                const intersections = levels.filter(level => {
                    const {
                        start: levelStart,
                        end: levelEnd
                    } = level;
                    const levelSize = levelEnd - levelStart;
                    const s = Math.min(levelStart, startPx);
                    const e = Math.max(levelEnd, endPx);
                    return (e - s) < levelSize + size;
                });
                const minimumLevel = Math.min(
                    ...intersections.map(intersection => intersection.level),
                    -1
                );
                const maximumLevel = Math.max(
                    ...intersections.map(intersection => intersection.level),
                    -1
                );
                let level = maximumLevel + 1;
                if (minimumLevel > 0) {
                    level = minimumLevel - 1;
                }
                levels.push({
                    start: startPx,
                    end: endPx,
                    level,
                    y1: level * levelHeight,
                    y2: (level + 1) * levelHeight,
                    alignment
                });
                maxLevels = Math.max(maxLevels, level);
                this.renderAlignment(viewport, alignment, level, cache.isProtein);
            }
            this.renderingInfo = levels.slice();
            this._actualHeight = levelHeight * (maxLevels + 1);
        } else {
            this.renderingInfo = [];
            this._actualHeight = this._height;
        }
        this.dataContainer.addChild(this._hoveringGraphics);
        this.scroll(viewport, null);
    }