alignment.js
Version:
A suite of reusable [React](http://reactjs.org/) components for creating a variety of visualizations involving [multiple sequence alignments](https://en.wikipedia.org/wiki/Multiple_sequence_alignment). [View the live demo here](http://alignment.hyphy.org/
200 lines (163 loc) • 10.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _fasta = _interopRequireDefault(require("./../helpers/fasta"));
var _computeLabelWidth = _interopRequireDefault(require("../helpers/computeLabelWidth"));
var _BaseAlignment = _interopRequireDefault(require("./BaseAlignment.js"));
var _SiteAxis = _interopRequireDefault(require("./SiteAxis.js"));
var _SequenceAxis = _interopRequireDefault(require("./SequenceAxis.js"));
var _Scaffold = _interopRequireDefault(require("./Scaffold.js"));
var _scroll_broadcaster = _interopRequireDefault(require("./../helpers/scroll_broadcaster"));
var _format = _interopRequireDefault(require("../helpers/format"));
var _colors = require("./../helpers/colors");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var ScaffoldViewer = /*#__PURE__*/function (_Component) {
_inherits(ScaffoldViewer, _Component);
var _super = _createSuper(ScaffoldViewer);
function ScaffoldViewer(props) {
var _this;
_classCallCheck(this, ScaffoldViewer);
_this = _super.call(this, props);
_this.label_width = 200;
_this.initialize(_this.props);
return _this;
}
_createClass(ScaffoldViewer, [{
key: "setScrollingEvents",
value: function setScrollingEvents(props) {
if (props.fasta) {
var alignment_width = props.alignment_width,
alignment_height = props.alignment_height;
var full_pixel_width = this.full_pixel_width,
full_pixel_height = this.full_pixel_height;
this.scroll_broadcaster = new _scroll_broadcaster["default"]({
width: full_pixel_width,
height: full_pixel_height,
x_pad: alignment_width,
y_pad: alignment_height,
x_pixel: this.x_pixel,
y_pixel: this.y_pixel,
bidirectional: ["alignmentjs-reference-alignment", "alignmentjs-alignment", "alignmentjs-axis-div", "alignmentjs-labels-div", "alignmentjs-scaffold-div"]
});
}
}
}, {
key: "componentWillUpdate",
value: function componentWillUpdate(nextProps) {
this.initialize(nextProps);
}
}, {
key: "initialize",
value: function initialize(props) {
if (props.fasta) {
var fasta = props.fasta,
site_size = props.site_size;
this.sequence_data = (0, _fasta["default"])(fasta);
var sequence_data = this.sequence_data;
var label_padding = this.props.label_padding;
this.label_width = (0, _computeLabelWidth["default"])(sequence_data, label_padding);
this.full_pixel_width = site_size * sequence_data.number_of_sites;
this.full_pixel_height = site_size * (sequence_data.number_of_sequences - 1);
}
this.setScrollingEvents(props);
}
}, {
key: "render",
value: function render() {
if (!this.sequence_data) {
return /*#__PURE__*/_react["default"].createElement("div", {
style: container_style,
id: "alignmentjs-main-div"
});
}
var _this$props = this.props,
alignment_width = _this$props.alignment_width,
alignment_height = _this$props.alignment_height,
scaffold_width = _this$props.scaffold_width,
container_style = {
display: "grid",
gridTemplateColumns: (0, _format["default"])([this.label_width, alignment_width, scaffold_width]),
gridTemplateRows: (0, _format["default"])([20, 20, alignment_height])
},
reference_sequence_data = this.sequence_data.slice(0, 1),
remaining_sequence_data = this.sequence_data.slice(1);
return /*#__PURE__*/_react["default"].createElement("div", {
style: container_style,
id: "alignmentjs-main-div"
}, /*#__PURE__*/_react["default"].createElement("div", {
id: "alignmentjs-axis-placeholder1"
}), /*#__PURE__*/_react["default"].createElement(_SiteAxis["default"], {
width: alignment_width,
height: 20,
sequence_data: this.sequence_data,
scroll_broadcaster: this.scroll_broadcaster
}), /*#__PURE__*/_react["default"].createElement("div", {
id: "alignmentjs-axis-placeholder2"
}), /*#__PURE__*/_react["default"].createElement(_SequenceAxis["default"], {
width: this.label_width,
height: this.props.site_size,
sequence_data: reference_sequence_data,
site_size: this.props.site_size,
id: "alignmentjs-reference",
scroll_broadcaster: this.scroll_broadcaster
}), /*#__PURE__*/_react["default"].createElement(_BaseAlignment["default"], {
width: alignment_width,
height: this.props.site_size,
sequence_data: reference_sequence_data,
site_size: this.props.site_size,
id: "alignmentjs-reference",
disableVerticalScrolling: true,
scroll_broadcaster: this.scroll_broadcaster
}), /*#__PURE__*/_react["default"].createElement("div", {
id: "alignmentjs-reference-placeholder"
}), /*#__PURE__*/_react["default"].createElement(_SequenceAxis["default"], {
width: this.label_width,
height: 800,
sequence_data: remaining_sequence_data,
site_size: this.props.site_size,
y_pixel: this.y_pixel,
scroll_broadcaster: this.scroll_broadcaster
}), /*#__PURE__*/_react["default"].createElement(_BaseAlignment["default"], {
width: alignment_width,
height: 800,
sequence_data: remaining_sequence_data,
site_size: this.props.site_size,
scroll_broadcaster: this.scroll_broadcaster
}), /*#__PURE__*/_react["default"].createElement(_Scaffold["default"], {
width: scaffold_width,
height: 800,
sequence_data: remaining_sequence_data,
scroll_broadcaster: this.scroll_broadcaster
}));
}
}]);
return ScaffoldViewer;
}(_react.Component);
ScaffoldViewer.defaultProps = {
site_color: _colors.nucleotide_color,
text_color: _colors.nucleotide_text_color,
site_size: 20,
label_padding: 10,
axis_height: 20,
alignment_width: 600,
alignment_height: 800,
scaffold_width: 400
};
var _default = ScaffoldViewer;
exports["default"] = _default;