async loadVariations()

in client/client/app/shared/projectContext/index.js [2386:2498]


    async loadVariations(page) {
        const filter = this.getVcfRequestFilter(page);
        if (!this.variationsPointer || this.variationsPointerPage + 1 !== page) {
            this.variationsPointer = null;
            this.variationsPointerPage = null;
        }
        this._variantsPageLoading = true;
        this.dispatcher.emit('variants:page:loading:started');
        let data = await this.projectDataService.getVcfVariationLoad(filter);
        if (data.error) {
            this._totalPagesCountVariations = 0;
            this._variationsPointer = null;
            this._variationsPointerPage = null;
            this._currentPageVariations = FIRST_PAGE;
            this._lastPageVariations = FIRST_PAGE;
            this._firstPageVariations = FIRST_PAGE;
            this._hasMoreVariations = true;
            this._variantsPageLoading = false;
            this._variantsPageError = data.message;
            this.dispatcher.emit('variants:page:loading:finished');
            return [];
        } else {
            this._variantsPageError = null;
        }
        if (data.totalPagesCount === 0) {
            data.totalPagesCount = undefined;
        }

        if (!data.entries && (data.totalPagesCount !== undefined && data.totalPagesCount < page)) {
            filter.page = data.totalPagesCount;
            filter.pointer = null;
            this.variationsPointer = null;
            this.variationsPointerPage = null;
            this.currentPageVariations = data.totalPagesCount || FIRST_PAGE;
            this.firstPageVariations = data.totalPagesCount || FIRST_PAGE;
            this.lastPageVariations = data.totalPagesCount || FIRST_PAGE;
            if (data.totalPagesCount > 0) {
                data = await this.projectDataService.getVcfVariationLoad(filter);
                if (data.error) {
                    this._totalPagesCountVariations = 0;
                    this._variationsPointer = null;
                    this._variationsPointerPage = null;
                    this._currentPageVariations = FIRST_PAGE;
                    this._lastPageVariations = FIRST_PAGE;
                    this._firstPageVariations = FIRST_PAGE;
                    this._hasMoreVariations = true;
                    this._variantsPageLoading = false;
                    this._variantsPageError = data.message;
                    this.dispatcher.emit('variants:page:loading:finished');
                    return [];
                } else {
                    this._variantsPageError = null;
                }
                if (data.totalPagesCount === 0) {
                    data.totalPagesCount = undefined;
                }
            }
        } else if (!data.entries && data.totalPagesCount === undefined) {
            this._hasMoreVariations = false;
        }

        const infoFieldsObj = {};
        this._infoFields && this._infoFields.forEach(f => infoFieldsObj[f] = null);

        const vcfTrackToProjectId = {};
        for (let i = 0; i < this.vcfTracks.length; i++) {
            const vcfTrack = this.vcfTracks[i];
            vcfTrackToProjectId[`${vcfTrack.id}`] = {
                name: vcfTrack.projectId,
                projectIdNumber: vcfTrack.project.id,
            };
        }

        this.totalPagesCountVariations = data.totalPagesCount;
        this.variationsPointer = data.pointer;
        this.variationsPointerPage = filter.page;
        const entries = data.entries ? data.entries : [];
        this._variantsPageLoading = false;
        this.dispatcher.emit('variants:page:loading:finished');

        return entries.map(item => {
            this.highlightProfileConditions.forEach(profile => {
                if (!item.highlightColor && highlightCondition.isHighlighted(item.info, profile.parsedCondition)) {
                    item.highlightColor = `#${profile.highlightColor}`;
                }
            });
            const sampleNames = (item.sampleNames || []).map(name => (
                this._vcfSampleInfo[item.featureFileId][name] || name
            ));
            return Object.assign({},
                {
                    chrId: item.chromosome.id,
                    chrName: item.chromosome.name,
                    chromosome: {
                        id: item.chromosome.id,
                        name: item.chromosome.name
                    },
                    endIndex: item.endIndex,
                    geneNames: item.geneNames,
                    highlightColor: item.highlightColor,
                    projectId: vcfTrackToProjectId[`${item.featureFileId}`].name,
                    projectIdNumber: vcfTrackToProjectId[`${item.featureFileId}`].projectIdNumber,
                    quality: item.quality,
                    startIndex: item.startIndex,
                    variantId: item.featureId,
                    variationType: item.variationType,
                    vcfFileId: item.featureFileId,
                    sampleNames: sampleNames
                },
                {...infoFieldsObj, ...item.info},
            );
        });
    }