summaryrefslogtreecommitdiffstats
path: root/nucleotide.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2021-02-17 21:40:03 -0500
committerBrian Cully <bjc@kublai.com>2021-02-17 21:40:28 -0500
commit4bb133a3515fa54be34b8ec50b80d6dcbe3a0b3d (patch)
tree35c929036f31e9e1c641ea1b007432aedf373166 /nucleotide.mjs
downloadmolsim2-4bb133a3515fa54be34b8ec50b80d6dcbe3a0b3d.tar.gz
molsim2-4bb133a3515fa54be34b8ec50b80d6dcbe3a0b3d.zip
Initial commit.
Diffstat (limited to 'nucleotide.mjs')
-rw-r--r--nucleotide.mjs79
1 files changed, 79 insertions, 0 deletions
diff --git a/nucleotide.mjs b/nucleotide.mjs
new file mode 100644
index 0000000..13ed1b6
--- /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.transition = {'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.transition)
+
+
+export default Nucleotide