|
@@ -6,39 +6,44 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
import * as React from 'react'
|
|
import * as React from 'react'
|
|
-import { StructureSelection, StructureQuery } from '../../../mol-model/structure';
|
|
|
|
import { PluginUIComponent } from '../base';
|
|
import { PluginUIComponent } from '../base';
|
|
import { Interactivity } from '../../util/interactivity';
|
|
import { Interactivity } from '../../util/interactivity';
|
|
import { MarkerAction } from '../../../mol-util/marker-action';
|
|
import { MarkerAction } from '../../../mol-util/marker-action';
|
|
import { ButtonsType, ModifiersKeys, getButtons, getModifiers } from '../../../mol-util/input/input-observer';
|
|
import { ButtonsType, ModifiersKeys, getButtons, getModifiers } from '../../../mol-util/input/input-observer';
|
|
import { ValueBox } from '../../../mol-util';
|
|
import { ValueBox } from '../../../mol-util';
|
|
-import { createResidueQuery, markResidue, StructureSeq } from './util';
|
|
|
|
import { Residue } from './residue';
|
|
import { Residue } from './residue';
|
|
|
|
+import { SequenceWrapper } from './util';
|
|
|
|
|
|
-type BaseSequenceProps = { structureSeq: StructureSeq, markerArray: Uint8Array }
|
|
|
|
-type BaseSequenceState = { markerData: ValueBox<Uint8Array> }
|
|
|
|
|
|
+type SequenceProps = { sequenceWrapper: SequenceWrapper.Any }
|
|
|
|
+type SequenceState = { markerData: ValueBox<Uint8Array> }
|
|
|
|
+
|
|
|
|
+function getState(markerData: ValueBox<Uint8Array>) {
|
|
|
|
+ return { markerData: ValueBox.withValue(markerData, markerData.value) }
|
|
|
|
+}
|
|
|
|
|
|
// TODO: this is really inefficient and should be done using a canvas.
|
|
// TODO: this is really inefficient and should be done using a canvas.
|
|
-export class BaseSequence extends PluginUIComponent<BaseSequenceProps, BaseSequenceState> {
|
|
|
|
|
|
+export class Sequence<P extends SequenceProps> extends PluginUIComponent<P, SequenceState> {
|
|
state = {
|
|
state = {
|
|
- markerData: ValueBox.create(new Uint8Array(this.props.markerArray))
|
|
|
|
|
|
+ markerData: ValueBox.create(this.props.sequenceWrapper.markerArray)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private setMarkerData(markerData: ValueBox<Uint8Array>) {
|
|
|
|
+ this.setState(getState(markerData))
|
|
}
|
|
}
|
|
|
|
|
|
private lociHighlightProvider = (loci: Interactivity.Loci, action: MarkerAction) => {
|
|
private lociHighlightProvider = (loci: Interactivity.Loci, action: MarkerAction) => {
|
|
- const { markerData } = this.state;
|
|
|
|
- const changed = markResidue(loci.loci, this.props.structureSeq, markerData.value, action)
|
|
|
|
- if (changed) this.setState({ markerData: ValueBox.withValue(markerData, markerData.value) })
|
|
|
|
|
|
+ const changed = this.props.sequenceWrapper.markResidue(loci.loci, action)
|
|
|
|
+ if (changed) this.setMarkerData(this.state.markerData)
|
|
}
|
|
}
|
|
|
|
|
|
private lociSelectionProvider = (loci: Interactivity.Loci, action: MarkerAction) => {
|
|
private lociSelectionProvider = (loci: Interactivity.Loci, action: MarkerAction) => {
|
|
- const { markerData } = this.state;
|
|
|
|
- const changed = markResidue(loci.loci, this.props.structureSeq, markerData.value, action)
|
|
|
|
- if (changed) this.setState({ markerData: ValueBox.withValue(markerData, markerData.value) })
|
|
|
|
|
|
+ const changed = this.props.sequenceWrapper.markResidue(loci.loci, action)
|
|
|
|
+ if (changed) this.setMarkerData(this.state.markerData)
|
|
}
|
|
}
|
|
|
|
|
|
- static getDerivedStateFromProps(nextProps: BaseSequenceProps, prevState: BaseSequenceState): BaseSequenceState | null {
|
|
|
|
- if (prevState.markerData.value !== nextProps.markerArray) {
|
|
|
|
- return { markerData: ValueBox.create(nextProps.markerArray) }
|
|
|
|
|
|
+ static getDerivedStateFromProps(nextProps: SequenceProps, prevState: SequenceState): SequenceState | null {
|
|
|
|
+ if (prevState.markerData.value !== nextProps.sequenceWrapper.markerArray) {
|
|
|
|
+ return getState(ValueBox.create(nextProps.sequenceWrapper.markerArray))
|
|
}
|
|
}
|
|
return null
|
|
return null
|
|
}
|
|
}
|
|
@@ -53,16 +58,10 @@ export class BaseSequence extends PluginUIComponent<BaseSequenceProps, BaseSeque
|
|
this.plugin.interactivity.lociSelections.removeProvider(this.lociSelectionProvider)
|
|
this.plugin.interactivity.lociSelections.removeProvider(this.lociSelectionProvider)
|
|
}
|
|
}
|
|
|
|
|
|
- getLoci(seqId: number) {
|
|
|
|
- const { structure, seq } = this.props.structureSeq
|
|
|
|
- const query = createResidueQuery(seq.entityId, seqId);
|
|
|
|
- return StructureSelection.toLoci2(StructureQuery.run(query, structure));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
highlight(seqId?: number, modifiers?: ModifiersKeys) {
|
|
highlight(seqId?: number, modifiers?: ModifiersKeys) {
|
|
const ev = { current: Interactivity.Loci.Empty, modifiers }
|
|
const ev = { current: Interactivity.Loci.Empty, modifiers }
|
|
if (seqId !== undefined) {
|
|
if (seqId !== undefined) {
|
|
- const loci = this.getLoci(seqId);
|
|
|
|
|
|
+ const loci = this.props.sequenceWrapper.getLoci(seqId);
|
|
if (loci.elements.length > 0) ev.current = { loci };
|
|
if (loci.elements.length > 0) ev.current = { loci };
|
|
}
|
|
}
|
|
this.plugin.behaviors.interaction.highlight.next(ev)
|
|
this.plugin.behaviors.interaction.highlight.next(ev)
|
|
@@ -71,7 +70,7 @@ export class BaseSequence extends PluginUIComponent<BaseSequenceProps, BaseSeque
|
|
click(seqId: number | undefined, buttons: ButtonsType, modifiers: ModifiersKeys) {
|
|
click(seqId: number | undefined, buttons: ButtonsType, modifiers: ModifiersKeys) {
|
|
const ev = { current: Interactivity.Loci.Empty, buttons, modifiers }
|
|
const ev = { current: Interactivity.Loci.Empty, buttons, modifiers }
|
|
if (seqId !== undefined) {
|
|
if (seqId !== undefined) {
|
|
- const loci = this.getLoci(seqId);
|
|
|
|
|
|
+ const loci = this.props.sequenceWrapper.getLoci(seqId);
|
|
if (loci.elements.length > 0) ev.current = { loci };
|
|
if (loci.elements.length > 0) ev.current = { loci };
|
|
}
|
|
}
|
|
this.plugin.behaviors.interaction.click.next(ev)
|
|
this.plugin.behaviors.interaction.click.next(ev)
|
|
@@ -89,8 +88,8 @@ export class BaseSequence extends PluginUIComponent<BaseSequenceProps, BaseSeque
|
|
|
|
|
|
render() {
|
|
render() {
|
|
const { markerData } = this.state;
|
|
const { markerData } = this.state;
|
|
- const { seq } = this.props.structureSeq;
|
|
|
|
- const { offset, sequence } = seq.sequence;
|
|
|
|
|
|
+ const { label } = this.props.sequenceWrapper
|
|
|
|
+ const { offset, sequence } = this.props.sequenceWrapper.sequence;
|
|
|
|
|
|
const elems: JSX.Element[] = [];
|
|
const elems: JSX.Element[] = [];
|
|
for (let i = 0, _i = sequence.length; i < _i; i++) {
|
|
for (let i = 0, _i = sequence.length; i < _i; i++) {
|
|
@@ -102,7 +101,7 @@ export class BaseSequence extends PluginUIComponent<BaseSequenceProps, BaseSeque
|
|
onContextMenu={this.contextMenu}
|
|
onContextMenu={this.contextMenu}
|
|
onMouseDown={this.mouseDown}
|
|
onMouseDown={this.mouseDown}
|
|
>
|
|
>
|
|
- <span style={{ fontWeight: 'bold' }}>{seq.entityId}:{offset} </span>
|
|
|
|
|
|
+ <span style={{ fontWeight: 'bold' }}>{label}:{offset} </span>
|
|
{elems}
|
|
{elems}
|
|
</div>;
|
|
</div>;
|
|
}
|
|
}
|