<commit_before>(function( $, undefined ) { 
    $.KBWidget({ 
        name: "KBaseGenomeOverview", 
        parent: "kbaseWidget", 
        version: "1.0.0",

        options: {
            genomeID: null,
            workspaceID: null,
            loadingImage: "../../widgets/images/ajax-loader.gif",
            kbCache: null,
            isInCard: false,
        },

        token: null,
        cdmiURL: "https://kbase.us/services/cdmi_api",
        $infoTable: null,
        noContigs: "No Contigs",

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

            this.$messagePane = $("<div/>")
                                .addClass("kbwidget-message-pane")
                                .hide();
            this.$elem.append(this.$messagePane);

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

            return this;
        },

        render: function() {
            var self = this;

            this.$infoPanel = $("<div>");
            this.$infoPanel.append($("<button>")
                           .addClass("btn btn-primary")
                           .append("Show Description")
                           .attr("type", "button")
                           .on("click", 
                               function(event) {
                                   self.trigger("showGenomeDescription", 
                                       {
                                           genomeID: self.options.genomeID,
                                           workspaceID: self.options.workspaceID,
                                           kbCache: self.options.kbCache,
                                           event: event
                                       }
                                   );
                               })
                           );
            this.$infoTable = $("<table>")
                              .addClass("table table-striped table-bordered");
            this.$infoPanel.append($("<div>").append(this.$infoTable));

            this.$contigSelect = $("<select>")
                                 .addClass("form-control")
                                 .css({"width":"60%", "margin-right":"5px"})
                                 .append($("<option>")
                                         .attr("id", this.noContigs)
                                         .append(this.noContigs));

            var self = this;
            this.$contigButton = $("<button>")
                                 .addClass("btn btn-primary")
                                 .append("Show Contig")
                                 .click(function(event) {
                                    self.$elem.find("select option:selected").each(function() {
                                        var contigId = $(this).attr("id");
                                        if (contigId !== self.noContigs) {
                                            self.trigger("showContig", 
                                                { 
                                                    contig: $(this).attr("id"), 
                                                    workspaceId: self.options.workspaceID,
                                                    genomeId: self.options.genomeID,
                                                    kbCache: self.options.kbCache,
                                                    event: event,
                                                }
                                            );
                                        }
                                    })
                                 });

            this.$infoPanel.append($("<div>")
                              .addClass("form-inline")
                              .append(this.$contigSelect)
                              .append(this.$contigButton));

            this.$infoPanel.hide();
            this.$elem.append(this.$infoPanel);
        },

        addInfoRow: function(a, b) {
            return "<tr><td>" + a + "</td><td>" + b + "</td></tr>";
        },

        renderCentralStore: function() {
            this.cdmiClient = new CDMI_API(this.cdmiURL);
            this.entityClient = new CDMI_EntityAPI(this.cdmiURL);

            this.$infoPanel.hide();
            this.showMessage("<img src='" + this.options.loadingImage + "'>");
            /**
             * Fields to show:
             * ID
             * Workspace (if from a workspace)
             * Owner (KBase Central Store vs. username)
             * Scientific Name
             * Domain
             * Complete
             * Size in bp
             * GC content (do we need this?)
             * # contigs
             * # features
             * # genes - PEGs
             * # RNA feats
             * Taxonomy
             */

            var self = this;
            this.entityClient.get_entity_Genome([this.options.genomeID],
                ['id', 'scientific_name', 'domain', 'complete', 'dna_size', 'source_id', 
                 'contigs', 'gc_content', 'pegs', 'rnas'],

                $.proxy(function(genome) {
                    genome = genome[this.options.genomeID];
                    this.genome = genome; // store it for now.

                    if (!genome) {
                        this.renderError("Genome '" + this.options.genomeID + "' not found in the KBase Central Store.");
                        return;
                    }

                    this.$infoTable.empty()
                                   .append(this.addInfoRow("ID", genome.id))
                                   .append(this.addInfoRow("Name", genome.scientific_name))
                                   .append(this.addInfoRow("Domain", genome.domain))
                                   .append(this.addInfoRow("Complete?", (genome.complete ? "Yes" : "No")))
                                   .append(this.addInfoRow("DNA Length", genome.dna_size))
                                   .append(this.addInfoRow("Source ID", genome.source_id))
                                   .append(this.addInfoRow("Number of Contigs", genome.contigs))
                                   .append(this.addInfoRow("GC Content", Number(genome.gc_content).toFixed(2) + " %"))
                                   .append(this.addInfoRow("Protein Encoding Genes", genome.pegs))
                                   .append(this.addInfoRow("RNAs", genome.rnas));

                    /*
                     * Here we go. Chain of callbacks.
                     * Get list of contigs, then get their lengths.<commit_msg>committing genomeoverview<commit_after>(function( $, undefined ) { 
    $.KBWidget({ 
        name: "KBaseGenomeOverview", 
        parent: "kbaseWidget", 
        version: "1.0.0",

        options: {
            genomeID: null,
            workspaceID: null,
            loadingImage: "../../widgets/images/ajax-loader.gif",
            kbCache: null,
            isInCard: false,
        },

        token: null,
        cdmiURL: "https://kbase.us/services/cdmi_api",
        $infoTable: null,
        noContigs: "No Contigs",

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

            this.$messagePane = $("<div/>")
                                .addClass("kbwidget-message-pane")
                                .hide();
            this.$elem.append(this.$messagePane);

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

            return this;
        },

        render: function() {
            var self = this;

            this.$infoPanel = $("<div>");
            this.$infoPanel.append($("<button>")
                           .addClass("btn btn-primary")
                           .append("Show Description")
                           .attr("type", "button")
                           .on("click", 
                               function(event) {
                                   self.trigger("showGenomeDescription", 
                                       {
                                           genomeID: self.options.genomeID,
                                           workspaceID: self.options.workspaceID,
                                           kbCache: self.options.kbCache,
                                           event: event
                                       }
                                   );
                               })
                           );
			
			this.$infoPanel.append($("<button>")
                                 .addClass("btn btn-primary")
                                 .append("Literature Search")
								 .attr("type", "button")
								 .on("click",
									function(event) {
										self.entityClient = new CDMI_EntityAPI(self.cdmiURL)
										self.entityClient.get_entity_Genome([self.options.genomeID],
										['id', 'scientific_name', 'domain', 'complete', 'dna_size', 'source_id', 
										 'contigs', 'gc_content', 'pegs', 'rnas'],

										$.proxy(function(genome) {
											genome = genome[self.options.genomeID];
											self.genome = genome; // store it for now.

											if (!genome) {
												self.renderError("Genome '" + self.options.genomeID + "' not found in the KBase Central Store.");
												return;
											}
											
											self.pubmedQuery = genome.scientific_name
											console.log(self.pubmedQuery)
											// pubmedQuery = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term='+genome.scientific_name
											var literature = $.get('http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term='+self.pubmedQuery,
												function(data) {
													self.trigger("showLitWidget", 
														{ 
															literature: data, 
															workspaceId: self.options.workspaceID,
															genomeId: self.options.genomeID,
															kbCache: self.options.kbCache,
															event: event,
														}
													);
												})
											
										}, self),
										self.renderError
									);
                                 })
							);
								 
            this.$infoTable = $("<table>")
                              .addClass("table table-striped table-bordered");
            this.$infoPanel.append($("<div>").append(this.$infoTable));

            this.$contigSelect = $("<select>")
                                 .addClass("form-control")
                                 .css({"width":"60%", "margin-right":"5px"})
                                 .append($("<option>")
                                         .attr("id", this.noContigs)
                                         .append(this.noContigs));

            var self = this;
            this.$contigButton = $("<button>")
                                 .addClass("btn btn-primary")
                                 .append("Show Contig")
                                 .click(function(event) {
                                    self.$elem.find("select option:selected").each(function() {
                                        var contigId = $(this).attr("id");
                                        if (contigId !== self.noContigs) {
                                            self.trigger("showContig", 
                                                { 
                                                    contig: $(this).attr("id"), 
                                                    workspaceId: self.options.workspaceID,
                                                    genomeId: self.options.genomeID,
                                                    kbCache: self.options.kbCache,
                                                    event: event,
                                                }
                                            );
                                        }
                                    })
                                 });
			
            this.$infoPanel.append($("<div>")
                              .addClass("form-inline")
                              .append(this.$contigSelect)
                              .append(this.$contigButton));

            this.$infoPanel.hide();
            this.$elem.append(this.$infoPanel);
			
			// self.pubmedQuery = ""
			console.log(self.pubmedQuery)

        },

        addInfoRow: function(a, b) {
            return "<tr><td>" + a + "</td><td>" + b + "</td></tr>";
        },

        renderCentralStore: function() {
            this.cdmiClient = new CDMI_API(this.cdmiURL);
            this.entityClient = new CDMI_EntityAPI(this.cdmiURL);

            this.$infoPanel.hide();
            this.showMessage("<img src='" + this.options.loadingImage + "'>");
            /**
             * Fields to show:
             * ID
             * Workspace (if from a workspace)
             * Owner (KBase Central Store vs. username)
             * Scientific Name
             * Domain
             * Complete
             * Size in bp
             * GC content (do we need this?)
             * # contigs
             * # features
             * # genes - PEGs
             * # RNA feats
             * Taxonomy
             */

            var self = this;
            this.entityClient.get_entity_Genome([this.options.genomeID],
                ['id', 'scientific_name', 'domain', 'complete', 'dna_size', 'source_id', 
                 'contigs', 'gc_content', 'pegs', 'rnas'],

                $.proxy(function(genome) {
                    genome = genome[this.options.genomeID];
                    this.genome = genome; // store it for now.

                    if (!genome) {
                        this.renderError("Genome '" + this.options.genomeID + "' not found in the KBase Central Store.");
                        return;
                    }
					
					self.pubmedQuery = genome.scientific_name
					
                    this.$infoTable.empty()
                                   .append(this.addInfoRow("ID", genome.id))
                                   .append(this.addInfoRow("Name", genome.scientific_name))
                                   .append(this.addInfoRow("Domain", genome.domain))
                                   .append(this.addInfoRow("Complete?", (genome.complete ? "Yes" : "No")))
                                   .append(this.addInfoRow("DNA Length", genome.dna_size))
                                   .append(this.addInfoRow("Source ID", genome.source_id))
                                   .append(this.addInfoRow("Number of Contigs", genome.contigs))
                                   .append(this.addInfoRow("GC Content", Number(genome.gc_content).toFixed(2) + " %"))
                                   .append(this.addInfoRow("Protein Encoding Genes", genome.pegs))
                                   .append(this.addInfoRow("RNAs", genome.rnas));

                    /*
                     * Here we go. Chain of callbacks.
                     * Get list of contigs, then get their lengths.
{'fraction_non_alphanumeric': 0.11527768798086248, 'fraction_numerical': 0.0009051529061873667, 'mean_word_length': 0.9540171803941384, 'pattern_counts': {'":': 4, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 118, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5515269', 'n_tokens_mistral': 4034, 'n_tokens_neox': 3403, 'n_words': 596}