<commit_before>/*
 * Copyright 2015-present 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 "../file-preview.js";
import "../../commons/forms/data-form.js";
import "../../sample/sample-files-view.js";
import UtilsNew from "../../../core/utilsNew.js";

export default class FileQcAscatMetrics extends LitElement {

    constructor() {
        super();

        this._init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            opencgaSession: {
                type: Object,
            },
            sampleId: {
                type: String,
            },
            config: {
                type: Object,
            },
        };
    }

    _init() {
        this._prefix = UtilsNew.randomString(8);

        this._ascatMetrics = null;
        this._ascatImages = [];
        this._config = this.getDefaultConfig();
    }

    connectedCallback() {
        super.connectedCallback();

        this._config = {...this.getDefaultConfig(), ...this.config};
    }

    update(changedProperties) {
        if (changedProperties.has("sampleId")) {
            this.sampleIdObserver();
        }

        if (changedProperties.has("config")) {
            this._config = {...this.getDefaultConfig(), ...this.config};
        }

        super.update(changedProperties);
    }

    sampleIdObserver() {
        if (this.opencgaSession && this.sampleId) {
            this.opencgaSession.opencgaClient.files().search({
                format: "VCF",
                sampleIds: this.sampleId,
                softwareName: "ascat",
                study: this.opencgaSession.study.fqn,
            }).then(response => {
                const file = response.responses[0].results[0];
                this._ascatMetrics = file.qualityControl.variant.ascatMetrics;
                this._ascatMetrics.file = file.name;
                const images = file.qualityControl.variant.ascatMetrics.images.join(",");
                return this.opencgaSession.opencgaClient.files().info(images, {
                    study: this.opencgaSession.study.fqn,
                });
            }).then(response => {
                this._ascatImages = response.responses[0].results;
                this.requestUpdate();
            }).catch(error => {
                console.error(error);
            });
        }
    }

    getDefaultConfig() {
        return {
            title: "",
            icon: "",
            display: {
                collapsable: true,
                showTitle: false,
                labelWidth: 2,
                defaultValue: "-",
                defaultLayout: "horizontal",
            },<commit_msg>:hammer: wc: fixed ascat metrics files field  #266<commit_after>/*
 * Copyright 2015-present 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 "../file-preview.js";
import "../../commons/forms/data-form.js";
import "../../sample/sample-files-view.js";
import UtilsNew from "../../../core/utilsNew.js";

export default class FileQcAscatMetrics extends LitElement {

    constructor() {
        super();

        this._init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            opencgaSession: {
                type: Object,
            },
            sampleId: {
                type: String,
            },
            config: {
                type: Object,
            },
        };
    }

    _init() {
        this._prefix = UtilsNew.randomString(8);

        this._ascatMetrics = null;
        this._ascatImages = [];
        this._config = this.getDefaultConfig();
    }

    connectedCallback() {
        super.connectedCallback();

        this._config = {...this.getDefaultConfig(), ...this.config};
    }

    update(changedProperties) {
        if (changedProperties.has("sampleId")) {
            this.sampleIdObserver();
        }

        if (changedProperties.has("config")) {
            this._config = {...this.getDefaultConfig(), ...this.config};
        }

        super.update(changedProperties);
    }

    sampleIdObserver() {
        if (this.opencgaSession && this.sampleId) {
            this.opencgaSession.opencgaClient.files().search({
                format: "VCF",
                sampleIds: this.sampleId,
                softwareName: "ascat",
                study: this.opencgaSession.study.fqn,
            }).then(response => {
                const file = response.responses[0].results[0];
                this._ascatMetrics = file.qualityControl.variant.ascatMetrics;
                this._ascatMetrics.file = file.name;
                const images = file.qualityControl.variant.ascatMetrics.files.join(",");
                return this.opencgaSession.opencgaClient.files().info(images, {
                    study: this.opencgaSession.study.fqn,
                });
            }).then(response => {
                this._ascatImages = response.responses[0].results;
                this.requestUpdate();
            }).catch(error => {
                console.error(error);
            });
        }
    }

    getDefaultConfig() {
        return {
            title: "",
            icon: "",
            display: {
                collapsable: true,
                showTitle: false,
                labelWidth: 2,
                defaultValue: "-",
                defaultLayout: "horizontal",
            },
{'fraction_non_alphanumeric': 0.11960844294891404, 'fraction_numerical': 0.004435607219333129, 'mean_word_length': 1.7348389795064827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3012640', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1661, 'n_words': 393}