Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first draft of FornaContainer component. #418

Merged
merged 65 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
14ff1d7
Add first draft of FornaContainer component.
Sep 18, 2019
7702d2e
Add first version of demo app.
Sep 18, 2019
71e872d
Fix Speck demo application argument names.
Aug 2, 2019
f4829e3
Change parameter names in demo apps.
Sep 18, 2019
112ec28
Add image for Forna Container.
Sep 18, 2019
ea1451c
Update version in package.
Sep 18, 2019
e25d12f
Update auto-generated files.
Sep 18, 2019
aaad47e
Update version in requirements.
Sep 18, 2019
a21bea9
Update Dash requirement.
Sep 18, 2019
3d126ea
Add fornac library to package.json requirements.
Sep 18, 2019
63d7224
Merge branch 'master' into add-forna-component
Sep 23, 2019
9a731d8
Restructure shouldComponentUpdate code.
Oct 4, 2019
fd272ea
Fix pylint errors.
Oct 4, 2019
d01a200
Fix flake8 errors.
Oct 4, 2019
524232d
Change PropTypes.shape to PropTypes.exact.
Oct 4, 2019
0cc040a
Avoid directly modifying 'options' object.
Oct 9, 2019
f8a4f1b
Add support for custom color schemes.
Oct 9, 2019
dba202a
Remove outline.
Oct 9, 2019
ed2005f
Add more detailed prop descriptions for custom color scheme.
Oct 9, 2019
5322933
Add custom colors to FornaContainer demo app.
Oct 9, 2019
ab35ecf
Update style for FornaContainer app.
Oct 9, 2019
f726054
Update Dash DAQ requirement.
Oct 9, 2019
56a44c8
Update requirements to latest version.
Oct 9, 2019
0654538
Add auto-generated files and linted FornaContainer code.
Oct 9, 2019
3537b31
Update package.json.
Oct 9, 2019
a965b1a
Always update color scheme.
Oct 10, 2019
32d3dcf
Small changes to the app.
Oct 10, 2019
82e6a48
Update version in package.
Oct 10, 2019
775dc78
Add auto-generated files.
Oct 10, 2019
b17d6f1
Update version in requirements.
Oct 10, 2019
4f91108
Fix width and height being backwards.
Oct 10, 2019
de68e61
Small changes and improvements.
Oct 10, 2019
040d781
Add better description of app and different initial colors.
Oct 10, 2019
07a1173
Check for existence of options before comparing them.
Oct 11, 2019
942daab
Remove unnecessary comma
Oct 11, 2019
39a25bd
Add tests for FornaContainer.
Oct 11, 2019
04dbdd5
Merge branch 'master' into add-forna-component
Oct 11, 2019
edf88d4
Use Ramda equals.
Oct 18, 2019
9b3527b
Move new sequence rendering to componentDidUpdate.
Oct 18, 2019
e1a6b24
Update tests/dashbio_demos/app_forna_container.py
Oct 18, 2019
7e3bc68
Use dcc.Markdown.
Oct 18, 2019
9411e5d
Add back renderNewSequences to componentDidMount.
Oct 18, 2019
ef225b1
Use ref instead of ID.
Oct 18, 2019
afbc06b
Change callbacks argument name and remove pylint statement.
Oct 18, 2019
3745fd9
Fix arguments for Circos app table.
Oct 18, 2019
9c5aedb
Merge branch 'master' into add-forna-component
Oct 18, 2019
b83ebe3
Merge branch 'master' into add-forna-component
Oct 18, 2019
04faf48
Use React.createRef().
Oct 18, 2019
a627320
Update version.
Oct 18, 2019
45c73c7
Update autogenerated files.
Oct 18, 2019
8f4f572
Update CHANGELOG.
Oct 18, 2019
7f5df65
Update description of FornaContainer component.
Oct 18, 2019
877f3e9
Ensure that colors are updated on initial render.
Oct 18, 2019
1aac6b3
Add test for initial color scheme.
Oct 18, 2019
7ecfc19
Update version.
Oct 18, 2019
52db7f0
Update autogenerated files.
Oct 18, 2019
4af466d
Merge branch 'master' into add-forna-component
Oct 18, 2019
b890bb5
Fix ordering and logic for color scheme changes.
Oct 21, 2019
2f6e424
Fix typo and correctly pass in allowPanningAndZooming option.
Oct 21, 2019
548260e
Update version and add auto-generated files.
Oct 21, 2019
f795f39
Fix more bugs related to nodeFillColor behaviour.
Oct 21, 2019
69dc7b1
Update version of react-docgen.
Oct 21, 2019
cf6bd8f
Update package version and all autogenerated files.
Oct 21, 2019
e1eb149
Update version of package.
Oct 22, 2019
7b267a4
Add new app to list of remotes.
Oct 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions src/lib/components/FornaContainer.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {FornaContainer as PreFornaContainer} from 'fornac';

/**
* This is a FornaContainer component.
*/
export default class FornaContainer extends Component {
constructor(props) {
super(props);
this.renderNewSequences = this.renderNewSequences.bind(this);
}

componentDidMount() {
const {id, height, width} = this.props;

this._fornaContainer = new PreFornaContainer('#' + id, {
initialSize: [height, width],
});

this.renderNewSequences();
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
}

renderNewSequences() {
const {sequences} = this.props;

if (this._fornaContainer) {
this._fornaContainer.clearNodes();

sequences.forEach(seq => {
const unpackedOptions = Object.assign(
seq.options ? seq.options : {},
{sequence: seq.sequence, structure: seq.structure}
);
console.warn(unpackedOptions);
this._fornaContainer.addRNA(seq.structure, unpackedOptions);
});
}
}

shouldComponentUpdate(nextProps) {
const {sequences, nodeFillColor, colorScheme} = this.props;

// update the component if the actual sequences have changed
if (
(sequences && !nextProps.sequences) ||
(!sequences && nextProps.sequences) ||
sequences.length !== nextProps.sequences.length ||
sequences.some(
(seq, i) =>
sequences[i].sequence !== nextProps.sequences[i].sequence ||
sequences[i].structure !==
nextProps.sequences[i].structure ||
(sequences[i].options && !nextProps.sequences[i].options) ||
(!sequences[i].options && nextProps.sequences[i].options) ||
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
(sequences[i].options &&
nextProps.sequences[i].options &&
Object.keys(seq.options).some(
optionName =>
(sequences[i].options[optionName] &&
!nextProps.sequences[i].options[
optionName
]) ||
(!sequences[i].options[optionName] &&
nextProps.sequences[i].options[
optionName
]) ||
sequences[i].options[optionName] !==
nextProps.sequences[i].options[optionName]
))
)
) {
return true;
}

// only change node fill color/color scheme if these props have changed
if (nodeFillColor !== nextProps.nodeFillColor) {
this._fornaContainer.setOutlineColor(nextProps.nodeFillColor);
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
}
if (colorScheme !== nextProps.colorScheme) {
this._fornaContainer.changeColorScheme(nextProps.colorScheme);
}

return false;
}

render() {
this.renderNewSequences();
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
return <div id={this.props.id} />;
}
}

FornaContainer.propTypes = {
/**
* The ID of this component, used to identify dash components in
* callbacks. The ID needs to be unique across all of the
* components in an app.
*/
id: PropTypes.string.isRequired,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this right, FornaContainer can accept either a selector string or a DOM node (it's just getting passed to d3.select). If you use a ref and pass that instead of '#' + id, then id becomes optional, making it easier to use and more robust.


/**
* The height (in px) of the container in which the molecules will
* be displayed.
*/
height: PropTypes.number,

/**
* The width (in px) of the container in which the molecules will
* be displayed.
*/
width: PropTypes.number,

/**
* The molecules that will be displayed.
*/
sequences: PropTypes.arrayOf(
PropTypes.shape({
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
/**
* A string representing the RNA nucleotide sequence of
* the RNA molecule.
*/
sequence: PropTypes.string.isRequired,

/**
* A dot-bracket string
* (https://software.broadinstitute.org/software/igv/RNAsecStructure)
* that specifies the secondary structure of the RNA
* molecule.
*/
structure: PropTypes.string.isRequired,

/**
* Additional options to be applied to the rendering of
* the RNA molecule.
*/
options: PropTypes.shape({
/**
* Indicate whether the force-directed layout will be
* applied to the displayed molecule. Enabling this
* option allows users to change the layout of the
* molecule by selecting and dragging the individual
* nucleotide nodes. True by default.
*/
applyForce: PropTypes.bool,

/**
* This only makes sense in connection with the
* applyForce argument. If it's true, the external
* loops will be arranged in a nice circle. If false,
* they will be allowed to flop around as the force
* layout dictates. True by default.
*/
circularizeExternal: PropTypes.bool,

/**
* Change how often nucleotide numbers are labelled
* with their number. 10 by default.
*/
labelInterval: PropTypes.number,

/**
* The molecule name; this is used in custom color
* scales.
*/
name: PropTypes.string,

/**
* Whether or not this molecule should "avoid" other
* molecules in the map.
*/
avoidOthers: PropTypes.bool,
}),
})
),

/**
* The fill color for all of the nodes. This will override any
* color scheme defined in colorScheme.
*/
nodeFillColor: PropTypes.string,

/**
* The color scheme that is used to color the nodes.
*/
colorScheme: PropTypes.oneOf(['sequence', 'structure', 'positions']),

/**
* Allow users to zoom in and pan the display. If this is enabled,
* then pressing the 'c' key on the keyboard will center the view.
*/
allowPanningAndZooming: PropTypes.bool,

/**
* Dash-assigned callback that gets fired when the value changes.
*/
setProps: PropTypes.func,
};

FornaContainer.defaultProps = {
height: 500,
width: 300,
sequences: [],
allowPanningandZooming: true,
labelInterval: 10,
colorScheme: 'sequence',
};
2 changes: 2 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import AlignmentChart from './components/AlignmentChart.react';
import AlignmentViewer from './components/AlignmentViewer.react';
import Circos from './components/Circos.react';
import FornaContainer from './components/FornaContainer.react';
import Ideogram from './components/Ideogram.react';
import Molecule2dViewer from './components/Molecule2dViewer.react';
import Molecule3dViewer from './components/Molecule3dViewer';
Expand All @@ -14,6 +15,7 @@ export {
AlignmentChart,
AlignmentViewer,
Circos,
FornaContainer,
Ideogram,
Molecule2dViewer,
Molecule3dViewer,
Expand Down