<commit_before>/**
 * Shows taxonomic lineage.
 *
 */
define([
    'jquery',
    'kb_common/html',
    'kb_service/client/workspace',
    'kb_service/client/trees',

    'kb_widget/legacy/authenticatedWidget'
], function(
    $,
    html,
    Workspace,
    KBaseTrees) {
    'use strict';
    $.KBWidget({
        name: 'KBaseGenomeLineage',
        parent: 'kbaseAuthenticatedWidget',
        version: '1.0.0',
        options: {
            genomeID: null,
            workspaceID: null,
            objVer: null,
            width: 600,
            //isInCard: false,
            genomeInfo: null
        },
        token: null,
        $infoTable: null,
        pref: null,
        init: function(options) {

            this._super(options);

            if (this.options.genomeID === null) {
                //throw an error
                return;
            }

            this.pref = this.uuid();

            this.$messagePane = $('<div/>').hide();
            this.$elem.append(this.$messagePane);

            this.render();
            if (this.options.workspaceID === null) {
                this.renderCentralStore();
            } else {
                this.renderWorkspace();
            }

            return this;
        },
        render: function() {
            this.$infoPanel = $('<div>');

            this.$infoTable = $('<table>').addClass('table table-striped table-bordered');
            this.$infoPanel.append($('<div>').append(this.$infoTable));

            this.$infoPanel.hide();
            this.$elem.append(this.$infoPanel);
        },
        renderCentralStore: function() {
            var self = this;

            this.$infoPanel.hide();
            this.showMessage(html.loading('loading...'));

            // Fields to show:
            // ID
            // Workspace (if from a workspace)
            // Owner (KBase Central Store vs. username)
            // Scientific Name
            // Taxonomy
            // Taxonomy
            this.entityClient.get_entity_Genome(
                [this.options.genomeID], ['id', 'scientific_name', 'domain', 'taxonomy'],
                $.proxy(
                    function(genome) {
                        genome = genome[0].data;
                        self.showData(genome);
                    },
                    this
                ),
                this.renderError
            );
        },
        renderWorkspace: function() {
            var self = this;
            this.showMessage(html.loading('loading...'));
            this.$infoPanel.hide();
            if (self.options.genomeInfo) {
                self.showData(self.options.genomeInfo.data);
            } else {
                var obj = this.getObjectIdentity(this.options.workspaceID, this.options.genomeID);
                obj.included = ['/taxonomy', '/scientific_name'];

                var workspace = new Workspace(this.runtime.config('services.workspace.url'), {
                    token: this.runtime.service('session').getAuthToken()
                });

                workspace.get_object_subset([obj],
                    function(data) {
                        if (data[0]) {
                            var genome = data[0].data;
                            self.showData(genome);
                        }
                    },
                    function(error) {
                        var obj = self.buildObjectIdentity(self.options.workspaceID, self.options.genomeID);
                        obj.included = ['/scientific_name'];
                        workspace.get_object_subset([obj], function(data) {
                                if (data[0]) {
                                    var genome = data[0].data;
                                    self.showData(genome);
                                }
                            },
                            function(error) {
                                self.renderError(error);
                            });
                    });
            }
        },
        showData: function(genome) {
            var self = this;

            this.$infoTable.empty()
                .append(this.addInfoRow('Name', genome.scientific_name))
                .append('<tr><th>Taxonomic Lineage</th><td id="tax_td_' + this.pref + '"/></tr>');

            self.hideMessage();
            this.$infoPanel.show();
            this.showLinage(genome.taxonomy);
        },
        showLinage: function(taxonomy) {
            var self = this;
            var finaltax = '';
            var needGuess = this.options.workspaceID !== null;
            if (taxonomy) {
                var splittax = taxonomy.replace('/ /g', '');
                splittax = splittax.split(';');
                if (splittax.length >= 2) {
                    needGuess = false;
                }
                finaltax += '<pre style="white-space: pre-wrap">';
                var a, b, pad, searchtax, str;
                for (a = 0; a < splittax.length; a += 1) {
                    pad = '';
                    for (b = 0; b < a; b += 1) {
                        pad += ' ';
                    }
                    //http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?name=drosophila+miranda<commit_msg>testing hooks in generated html<commit_after>/**
 * Shows taxonomic lineage.
 *
 */
define([
    'jquery',
    'kb_common/html',
    'kb_service/client/workspace',
    'kb_service/client/trees',

    'kb_widget/legacy/authenticatedWidget'
], function(
    $,
    html,
    Workspace,
    KBaseTrees) {
    'use strict';
    $.KBWidget({
        name: 'KBaseGenomeLineage',
        parent: 'kbaseAuthenticatedWidget',
        version: '1.0.0',
        options: {
            genomeID: null,
            workspaceID: null,
            objVer: null,
            width: 600,
            //isInCard: false,
            genomeInfo: null
        },
        token: null,
        $infoTable: null,
        pref: null,
        init: function(options) {

            this._super(options);

            if (this.options.genomeID === null) {
                //throw an error
                return;
            }

            this.pref = this.uuid();

            this.$messagePane = $('<div/>').hide();
            this.$elem.append(this.$messagePane);

            this.render();
            if (this.options.workspaceID === null) {
                this.renderCentralStore();
            } else {
                this.renderWorkspace();
            }

            return this;
        },
        render: function() {
            this.$infoPanel = $('<div>');

            this.$infoTable = $('<table>').addClass('table table-striped table-bordered');
            this.$infoPanel.append($('<div>').append(this.$infoTable));

            this.$infoPanel.hide();
            this.$elem.append(this.$infoPanel);
        },
        renderCentralStore: function() {
            var self = this;

            this.$infoPanel.hide();
            this.showMessage(html.loading('loading...'));

            // Fields to show:
            // ID
            // Workspace (if from a workspace)
            // Owner (KBase Central Store vs. username)
            // Scientific Name
            // Taxonomy
            // Taxonomy
            this.entityClient.get_entity_Genome(
                [this.options.genomeID], ['id', 'scientific_name', 'domain', 'taxonomy'],
                $.proxy(
                    function(genome) {
                        genome = genome[0].data;
                        self.showData(genome);
                    },
                    this
                ),
                this.renderError
            );
        },
        renderWorkspace: function() {
            var self = this;
            this.showMessage(html.loading('loading...'));
            this.$infoPanel.hide();
            if (self.options.genomeInfo) {
                self.showData(self.options.genomeInfo.data);
            } else {
                var obj = this.getObjectIdentity(this.options.workspaceID, this.options.genomeID);
                obj.included = ['/taxonomy', '/scientific_name'];

                var workspace = new Workspace(this.runtime.config('services.workspace.url'), {
                    token: this.runtime.service('session').getAuthToken()
                });

                workspace.get_object_subset([obj],
                    function(data) {
                        if (data[0]) {
                            var genome = data[0].data;
                            self.showData(genome);
                        }
                    },
                    function(error) {
                        var obj = self.buildObjectIdentity(self.options.workspaceID, self.options.genomeID);
                        obj.included = ['/scientific_name'];
                        workspace.get_object_subset([obj], function(data) {
                                if (data[0]) {
                                    var genome = data[0].data;
                                    self.showData(genome);
                                }
                            },
                            function(error) {
                                self.renderError(error);
                            });
                    });
            }
        },
        showData: function(genome) {
            var self = this;

            this.$infoTable.empty()
                .append('<tr><th>' + 'Name' + '</th><td data-field="scientific-name">' + genome.scientific_name + '</td></tr>')
                .append('<tr><th>Taxonomic Lineage</th><td id="tax_td_' + this.pref + '"/></tr>');

            self.hideMessage();
            this.$infoPanel.show();
            this.showLinage(genome.taxonomy);
        },
        showLinage: function(taxonomy) {
            var self = this;
            var finaltax = '';
            var needGuess = this.options.workspaceID !== null;
            if (taxonomy) {
                var splittax = taxonomy.replace('/ /g', '');
                splittax = splittax.split(';');
                if (splittax.length >= 2) {
                    needGuess = false;
                }
                finaltax += '<pre style="white-space: pre-wrap">';
                var a, b, pad, searchtax, str;
                for (a = 0; a < splittax.length; a += 1) {
                    pad = '';
                    for (b = 0; b < a; b += 1) {
                        pad += ' ';
                    }
                    //http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?name=drosophila+miranda
{'fraction_non_alphanumeric': 0.12895906211591188, 'fraction_numerical': 0.003025432542308783, 'mean_word_length': 1.1796826705130847, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3311893', 'n_tokens_mistral': 2856, 'n_tokens_neox': 2625, 'n_words': 471}