Skip to content
Snippets Groups Projects
Commit 884cb0d9 authored by Alexander Rose's avatar Alexander Rose
Browse files

sequence widget refactoring

parent ef1ccd42
No related branches found
No related tags found
No related merge requests found
...@@ -8,11 +8,24 @@ import { StructureSelection, StructureQuery, Structure, Queries, StructureProper ...@@ -8,11 +8,24 @@ import { StructureSelection, StructureQuery, Structure, Queries, StructureProper
import { SequenceWrapper } from './util'; import { SequenceWrapper } from './util';
import { OrderedSet, Interval } from '../../../mol-data/int'; import { OrderedSet, Interval } from '../../../mol-data/int';
import { Loci } from '../../../mol-model/loci'; import { Loci } from '../../../mol-model/loci';
import { Sequence } from '../../../mol-model/sequence';
import { Color } from '../../../mol-util/color';
export type StructureUnit = { structure: Structure, unit: Unit } export type StructureUnit = { structure: Structure, unit: Unit }
export class PolymerSequenceWrapper extends SequenceWrapper<StructureUnit> { export class PolymerSequenceWrapper extends SequenceWrapper<StructureUnit> {
private readonly location = StructureElement.create() private readonly location: StructureElement
private readonly sequence: Sequence
seqId(i: number) {
return this.sequence.offset + i + 1
}
residueLabel(i: number) {
return this.sequence.sequence[i]
}
residueColor(i: number) {
return Color(0)
}
eachResidue(loci: Loci, apply: (interval: Interval) => boolean) { eachResidue(loci: Loci, apply: (interval: Interval) => boolean) {
let changed = false let changed = false
...@@ -47,15 +60,15 @@ export class PolymerSequenceWrapper extends SequenceWrapper<StructureUnit> { ...@@ -47,15 +60,15 @@ export class PolymerSequenceWrapper extends SequenceWrapper<StructureUnit> {
return StructureSelection.toLoci2(StructureQuery.run(query, this.data.structure)); return StructureSelection.toLoci2(StructureQuery.run(query, this.data.structure));
} }
constructor(readonly data: StructureUnit) { constructor(data: StructureUnit) {
super() const l = StructureElement.create(data.unit, data.unit.elements[0])
const sequence = data.unit.model.sequence.byEntityKey[SP.entity.key(l)].sequence
const markerArray = new Uint8Array(sequence.sequence.length)
const l = this.location super(data, markerArray, sequence.sequence.length)
l.unit = data.unit
l.element = data.unit.elements[0]
this.sequence = data.unit.model.sequence.byEntityKey[SP.entity.key(l)].sequence this.sequence = sequence
this.markerArray = new Uint8Array(this.sequence.sequence.length) this.location = StructureElement.create()
} }
} }
......
...@@ -9,8 +9,9 @@ import * as React from 'react' ...@@ -9,8 +9,9 @@ import * as React from 'react'
import { PurePluginUIComponent } from '../base'; import { PurePluginUIComponent } from '../base';
import { getButtons, getModifiers } from '../../../mol-util/input/input-observer'; import { getButtons, getModifiers } from '../../../mol-util/input/input-observer';
import { Sequence } from './sequence'; import { Sequence } from './sequence';
import { Color } from '../../../mol-util/color';
export class Residue extends PurePluginUIComponent<{ seqId: number, letter: string, parent: Sequence<any>, marker: number }> { export class Residue extends PurePluginUIComponent<{ seqId: number, label: string, parent: Sequence<any>, marker: number, color: Color }> {
mouseEnter = (e: React.MouseEvent) => { mouseEnter = (e: React.MouseEvent) => {
const modifiers = getModifiers(e.nativeEvent) const modifiers = getModifiers(e.nativeEvent)
...@@ -41,8 +42,11 @@ export class Residue extends PurePluginUIComponent<{ seqId: number, letter: stri ...@@ -41,8 +42,11 @@ export class Residue extends PurePluginUIComponent<{ seqId: number, letter: stri
onMouseEnter={this.mouseEnter} onMouseEnter={this.mouseEnter}
onMouseLeave={this.mouseLeave} onMouseLeave={this.mouseLeave}
onMouseDown={this.mouseDown} onMouseDown={this.mouseDown}
style={{ backgroundColor: this.getBackgroundColor() }}> style={{
{this.props.letter} color: Color.toStyle(this.props.color),
backgroundColor: this.getBackgroundColor()
}}>
{this.props.label}
</span>; </span>;
} }
} }
\ No newline at end of file
...@@ -88,11 +88,18 @@ export class Sequence<P extends SequenceProps> extends PluginUIComponent<P, Sequ ...@@ -88,11 +88,18 @@ export class Sequence<P extends SequenceProps> extends PluginUIComponent<P, Sequ
render() { render() {
const { markerData } = this.state; const { markerData } = this.state;
const { offset, sequence } = this.props.sequenceWrapper.sequence; const sw = this.props.sequenceWrapper
const elems: JSX.Element[] = []; const elems: JSX.Element[] = [];
for (let i = 0, _i = sequence.length; i < _i; i++) { for (let i = 0, il = sw.length; i < il; ++i) {
elems[elems.length] = <Residue seqId={offset + i + 1} letter={sequence[i]} parent={this} marker={markerData.value[i]} key={i} />; elems[elems.length] = <Residue
seqId={sw.seqId(i)}
label={sw.residueLabel(i)}
parent={this}
marker={markerData.value[i]}
color={sw.residueColor(i)}
key={i}
/>;
} }
return <div return <div
......
...@@ -8,15 +8,15 @@ import { Interval } from '../../../mol-data/int'; ...@@ -8,15 +8,15 @@ import { Interval } from '../../../mol-data/int';
import { Loci } from '../../../mol-model/loci'; import { Loci } from '../../../mol-model/loci';
import { MarkerAction, applyMarkerAction } from '../../../mol-util/marker-action'; import { MarkerAction, applyMarkerAction } from '../../../mol-util/marker-action';
import { StructureElement } from '../../../mol-model/structure'; import { StructureElement } from '../../../mol-model/structure';
import { Sequence } from '../../../mol-model/sequence'; import { Color } from '../../../mol-util/color';
export { SequenceWrapper } export { SequenceWrapper }
abstract class SequenceWrapper<D> { abstract class SequenceWrapper<D> {
label: string abstract seqId(i: number): number
data: D abstract residueLabel(i: number): string
markerArray: Uint8Array abstract residueColor(i: number): Color
sequence: Sequence
abstract eachResidue(loci: Loci, apply: (interval: Interval) => boolean): boolean abstract eachResidue(loci: Loci, apply: (interval: Interval) => boolean): boolean
abstract getLoci(seqId: number): StructureElement.Loci abstract getLoci(seqId: number): StructureElement.Loci
...@@ -25,6 +25,10 @@ abstract class SequenceWrapper<D> { ...@@ -25,6 +25,10 @@ abstract class SequenceWrapper<D> {
return applyMarkerAction(this.markerArray, i, action) return applyMarkerAction(this.markerArray, i, action)
}) })
} }
constructor(readonly data: D, readonly markerArray: Uint8Array, readonly length: number) {
}
} }
namespace SequenceWrapper { namespace SequenceWrapper {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment