<commit_before>/*
 * Copyright 2015-2016 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {LitElement, html} from "lit";
import LitUtils from "../../commons/utils/lit-utils.js";
import "../../commons/forms/data-form.js";

export default class VariantInterpreterGridConfig extends LitElement {

    constructor() {
        super();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            // FIXME Temporary object used to check CellBase version and hide RefSeq filter
            opencgaSession: {
                type: Object
            },
            config: {
                type: Object
            }
        };
    }

    connectedCallback() {
        super.connectedCallback();
    }

    update(changedProperties) {
        super.update(changedProperties);
    }

    onFieldChange(e) {
        switch (e.detail.param) {
            case "genotype.type":
                this.config.genotype.type = e.detail.value;
                break;
            case "showHgvs":
                this.config.showHgvs = e.detail.value;
                break;
            case "geneSet.ensembl":
            case "geneSet.refseq":
            case "consequenceType.all":
            case "consequenceType.maneTranscript":
            case "consequenceType.ensemblCanonicalTranscript":
            case "consequenceType.gencodeBasicTranscript":
            case "consequenceType.ccdsTranscript":
            case "consequenceType.lrgTranscript":
            case "consequenceType.ensemblTslTranscript":
            case "consequenceType.illuminaTSO500Transcript":
            case "consequenceType.eglhHaemoncTranscript":
            case "consequenceType.proteinCodingTranscript":
            case "consequenceType.highImpactConsequenceTypeTranscript":
            case "consequenceType.showNegativeConsequenceTypes":
                const fields = e.detail.param.split(".");
                if (!this.config[fields[0]]) {
                    this.config[fields[0]] = {};
                }
                this.config[fields[0]][fields[1]] = e.detail.value;

                if (e.detail.param === "consequenceType.all") {
                    // we need to refresh the form to display disabled checkboxes
                    this.requestUpdate();
                }
                break;
            case "activeHighlights":
                this.config.activeHighlights = (e.detail.value || "").split(",").filter(v => v.length > 0);
                break;
        }

        LitUtils.dispatchCustomEvent(this, "configChange", this.config);
    }

    render() {
        return html`
            <data-form
                .data="${this.config}"
                .config="${this.getConfigForm()}"
                @fieldChange="${e => this.onFieldChange(e)}">
            </data-form>
        `;
    }

    getConfigForm() {
        return {
            id: "interpreter-grid-config",
            title: "",
            icon: "fas fa-user-md",
            type: "pills",
            validation: {
                validate: data => {
                    return data.geneSet?.ensembl || data.geneSet?.refseq;
                }
            },
            display: {
                width: 10,
                titleVisible: false,
                titleAlign: "left",
                titleWidth: 4,
                defaultLayout: "vertical",
                buttonsVisible: false
            },
            sections: [
                {
                    id: "gt",
                    title: "General Settings",
                    description: "Select some general options",
                    display: {
                        titleHeader: "h4",
                        titleStyle: "margin: 5px 5px",
                        descriptionClassName: "help-block",
                        descriptionStyle: "margin: 0px 10px",
                        visible: () => !!this.config?.genotype?.type
                    },
                    elements: [
                        {
                            title: "Select how genotypes are displayed",
                            field: "genotype.type",
                            type: "select",
                            allowedValues: ["ALLELES", "VCF_CALL", "ZYGOSITY", "VAF", "ALLELE_FREQUENCY", "CIRCLE"],
                            display: {
                                width: 6,
                            }
                        },
                        {
                            title: "Show HGVS column",
                            field: "showHgvs",
                            type: "checkbox",
                            text: "Show HGVS",
                            display: {
                                width: 6,
                            }
                        }
                    ]
                },
                {
                    title: "Transcript Filter",
                    // description: "Select which transcripts and consequence types are displayed in the variant grid",
                    display: {
                        titleHeader: "h4",
                        titleStyle: "margin: 5px 5px",
                        descriptionClassName: "help-block",
                        descriptionStyle: "margin: 0px 10px"
                    },
                    elements: [
                        {
                            type: "text",
                            text: "Select the Gene Set to be displayed",
                            display: {
                                containerStyle: "margin: 5px 5px 5px 0px",
                                visible: () => this.opencgaSession?.project?.internal?.cellbase?.version === "v5"
                            }
                        },
                        {
                            field: "geneSet.ensembl",
                            type: "checkbox",
                            text: "Ensembl",
                            display: {
                                containerStyle: "margin: 10px 5px",
                                visible: () => this.opencgaSession?.project?.internal?.cellbase?.version === "v5"
                            }
                        },
                        {
                            field: "geneSet.refseq",
                            type: "checkbox",
                            text: "RefSeq",
                            display: {
                                containerStyle: "margin: 10px 5px",
                                visible: () => this.opencgaSession?.project?.internal?.cellbase?.version === "v5"
                            }
                        },
                        {<commit_msg>wc: fix cellbase version check<commit_after>/*
 * Copyright 2015-2016 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {LitElement, html} from "lit";
import LitUtils from "../../commons/utils/lit-utils.js";
import "../../commons/forms/data-form.js";

export default class VariantInterpreterGridConfig extends LitElement {

    constructor() {
        super();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            // FIXME Temporary object used to check CellBase version and hide RefSeq filter
            opencgaSession: {
                type: Object
            },
            config: {
                type: Object
            }
        };
    }

    connectedCallback() {
        super.connectedCallback();
    }

    update(changedProperties) {
        super.update(changedProperties);
    }

    onFieldChange(e) {
        switch (e.detail.param) {
            case "genotype.type":
                this.config.genotype.type = e.detail.value;
                break;
            case "showHgvs":
                this.config.showHgvs = e.detail.value;
                break;
            case "geneSet.ensembl":
            case "geneSet.refseq":
            case "consequenceType.all":
            case "consequenceType.maneTranscript":
            case "consequenceType.ensemblCanonicalTranscript":
            case "consequenceType.gencodeBasicTranscript":
            case "consequenceType.ccdsTranscript":
            case "consequenceType.lrgTranscript":
            case "consequenceType.ensemblTslTranscript":
            case "consequenceType.illuminaTSO500Transcript":
            case "consequenceType.eglhHaemoncTranscript":
            case "consequenceType.proteinCodingTranscript":
            case "consequenceType.highImpactConsequenceTypeTranscript":
            case "consequenceType.showNegativeConsequenceTypes":
                const fields = e.detail.param.split(".");
                if (!this.config[fields[0]]) {
                    this.config[fields[0]] = {};
                }
                this.config[fields[0]][fields[1]] = e.detail.value;

                if (e.detail.param === "consequenceType.all") {
                    // we need to refresh the form to display disabled checkboxes
                    this.requestUpdate();
                }
                break;
            case "activeHighlights":
                this.config.activeHighlights = (e.detail.value || "").split(",").filter(v => v.length > 0);
                break;
        }

        LitUtils.dispatchCustomEvent(this, "configChange", this.config);
    }

    render() {
        return html`
            <data-form
                .data="${this.config}"
                .config="${this.getConfigForm()}"
                @fieldChange="${e => this.onFieldChange(e)}">
            </data-form>
        `;
    }

    getConfigForm() {
        return {
            id: "interpreter-grid-config",
            title: "",
            icon: "fas fa-user-md",
            type: "pills",
            validation: {
                validate: data => {
                    return data.geneSet?.ensembl || data.geneSet?.refseq;
                }
            },
            display: {
                width: 10,
                titleVisible: false,
                titleAlign: "left",
                titleWidth: 4,
                defaultLayout: "vertical",
                buttonsVisible: false
            },
            sections: [
                {
                    id: "gt",
                    title: "General Settings",
                    description: "Select some general options",
                    display: {
                        titleHeader: "h4",
                        titleStyle: "margin: 5px 5px",
                        descriptionClassName: "help-block",
                        descriptionStyle: "margin: 0px 10px",
                        visible: () => !!this.config?.genotype?.type
                    },
                    elements: [
                        {
                            title: "Select how genotypes are displayed",
                            field: "genotype.type",
                            type: "select",
                            allowedValues: ["ALLELES", "VCF_CALL", "ZYGOSITY", "VAF", "ALLELE_FREQUENCY", "CIRCLE"],
                            display: {
                                width: 6,
                            }
                        },
                        {
                            title: "Show HGVS column",
                            field: "showHgvs",
                            type: "checkbox",
                            text: "Show HGVS",
                            display: {
                                width: 6,
                            }
                        }
                    ]
                },
                {
                    title: "Transcript Filter",
                    // description: "Select which transcripts and consequence types are displayed in the variant grid",
                    display: {
                        titleHeader: "h4",
                        titleStyle: "margin: 5px 5px",
                        descriptionClassName: "help-block",
                        descriptionStyle: "margin: 0px 10px"
                    },
                    elements: [
                        {
                            type: "text",
                            text: "Select the Gene Set to be displayed",
                            display: {
                                containerStyle: "margin: 5px 5px 5px 0px",
                                visible: () => this.opencgaSession?.project?.internal?.cellbase?.version.startsWith("v5")
                            }
                        },
                        {
                            field: "geneSet.ensembl",
                            type: "checkbox",
                            text: "Ensembl",
                            display: {
                                containerStyle: "margin: 10px 5px",
                                visible: () => this.opencgaSession?.project?.internal?.cellbase?.version.startsWith("v5")
                            }
                        },
                        {
                            field: "geneSet.refseq",
                            type: "checkbox",
                            text: "RefSeq",
                            display: {
                                containerStyle: "margin: 10px 5px",
                                visible: () => this.opencgaSession?.project?.internal?.cellbase?.version.startsWith("v5")
                            }
                        },
                        {
{'fraction_non_alphanumeric': 0.09608884596813133, 'fraction_numerical': 0.00689797889218459, 'mean_word_length': 1.0993339125398205, 'pattern_counts': {'":': 34, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4047196', 'n_tokens_mistral': 3507, 'n_tokens_neox': 3249, 'n_words': 765}