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 count = 0,
hasName = _.every(this.props.query.hits, function(hit) {
return hit.sciname !== '';
});
return (
Summary table of hits
# |
Similar sequences |
{hasName && Species | }
{!this.props.imported_xml && Query coverage (%) | }
Total score |
E value |
Identity (%)
|
{
_.map(this.props.query.hits, _.bind(function (hit) {
return (
{hit.number + '.'} |
{hit.id}
|
{hasName && {hit.sciname} | }
{!this.props.imported_xml && {hit.qcovs} | }
{hit.score} |
{this.inExponential(hit.hsps[0].evalue)} |
{hit.identity} |
);
}, this))
}
);
}
});