import React from 'react'; import _ from 'underscore'; import HitsOverview from './hits_overview'; import LengthDistribution from './length_distribution'; // length distribution of hits import Utils from './utils'; // to use as mixin in HitsTable /** * Query component displays query defline, graphical overview, length * distribution, and hits table. */ export default React.createClass({ // Kind of public API // /** * Returns the id of query. */ domID: function () { return 'Query_' + this.props.query.number; }, queryLength: function () { return this.props.query.length; }, /** * Returns number of hits. */ numhits: function () { return this.props.query.hits.length; }, // Life cycle methods // render: function () { return (
{ this.headerJSX() } { this.numhits() && this.hitsListJSX() || this.noHitsJSX() }
); }, headerJSX: function () { var meta = `length: ${this.queryLength().toLocaleString()}`; if (this.props.showQueryCrumbs) { meta = `query ${this.props.query.number}, ` + meta; } return

Query= {this.props.query.id}  {this.props.query.title}

{ meta }
; }, hitsListJSX: function () { return
; }, noHitsJSX: function () { return
****** No hits found ******
; }, // Each update cycle will cause all previous queries to be re-rendered. // We avoid that by implementing shouldComponentUpdate life-cycle hook. // The trick is to simply check if the components has recieved props // before. shouldComponentUpdate: function () { // If the component has received props before, query property will // be set on it. If it is, we return false so that the component // is not re-rendered. If the query property is not set, we return // true: this must be the first time react is trying to render the // component. return !this.props.query; } }); /** * Renders summary of all hits per query in a tabular form. */ var HitsTable = React.createClass({ mixins: [Utils], render: function () { var hasName = _.every(this.props.query.hits, function(hit) { return hit.sciname !== ''; }); // Width of sequence column is 55% when species name is not shown and // query coverage is. var seqwidth = 55; // If we are going to show species name, then reduce the width of // sequence column by the width of species column. if (hasName) seqwidth -= 15; // If we are not going to show query coverage (i.e. for imported XML), // then increase the width of sequence column by the width of coverage // column. if (this.props.imported_xml) seqwidth += 15; return (

  Summary table of hits

{hasName && } {!this.props.imported_xml && } { _.map(this.props.query.hits, _.bind(function (hit) { return ( {hasName && } {!this.props.imported_xml && } ); }, this)) }
# Similar sequencesSpeciesQuery coverage (%)Total score E value Identity (%)
{hit.number + '.'} {hit.id} {hit.title} {hit.sciname} {hit.qcovs}{hit.score} {this.inExponential(hit.hsps[0].evalue)} {hit.identity}
); } });