diff options
author | Brian Cully <bjc@kublai.com> | 2021-01-03 18:34:19 -0500 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2021-02-06 10:39:32 -0500 |
commit | e92ad9f4b19a0670a80cdd293970c3a08c27a8b4 (patch) | |
tree | e8659dcdbf5f7ba3c55a118909d82dd8f0d0bcbd /nucleotide.mjs | |
download | molsim-e92ad9f4b19a0670a80cdd293970c3a08c27a8b4.tar.gz molsim-e92ad9f4b19a0670a80cdd293970c3a08c27a8b4.zip |
Initial commit.
Diffstat (limited to 'nucleotide.mjs')
-rw-r--r-- | nucleotide.mjs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/nucleotide.mjs b/nucleotide.mjs new file mode 100644 index 0000000..d599fe1 --- /dev/null +++ b/nucleotide.mjs @@ -0,0 +1,79 @@ +import NucleotideSelector from './nucleotide-selector.mjs' + +class Nucleotide { + constructor(base) { + this.value = base + this._boundClickHandler = this.clickHandler.bind(this) + } + + get elt() { + if (this._elt === undefined) { + this._elt = document.createElement('li') + this._elt.classList.add('nucleotide') + } + return this._elt + } + + get valueElt() { + if (this._valueElt === undefined) { + this._valueElt = document.createElement('span') + this.elt.appendChild(this._valueElt) + } + return this._valueElt + } + + get value() { + return this.valueElt.innerText + } + + set value(val) { + this.valueElt.innerText = val + } + + get onClick() { + if (this._onClick !== undefined) { + return this._onClick + } + return () => {} + } + + set onClick(fn) { + this._onClick = fn + } + + lock() { + this.elt.removeEventListener('click', this._boundClickHandler) + } + + unlock() { + this.elt.addEventListener('click', this._boundClickHandler) + } + + select() { + this._elt.classList.add('selected') + } + + deselect() { + this._elt.classList.remove('selected') + } + + clickHandler(evt) { + this.onClick(this) + } +} +Nucleotide.translation = {'A': 'G', + 'C': 'T', + 'G': 'A', + 'T': 'C'} +Nucleotide.complementingTransversion = {'A': 'T', + 'C': 'G', + 'G': 'C', + 'T': 'A'} +Nucleotide.defaultTransversion = {'A': 'C', + 'C': 'A', + 'G': 'T', + 'T': 'G'} +Nucleotide.bases = Object.keys(Nucleotide.translation) + + +export default Nucleotide |