diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 5c90981e..00000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,17 +0,0 @@ -extends: cheminfo -env: - amd: true - browser: true - jest: true -parserOptions: - sourceType: module - ecmaVersion: '2018' - -rules: - import/no-amd: 0 - import/unambiguous: 0 - import/no-unresolved: 0 - import/no-extraneous-dependencies: 0 - import/default: 0 - import/no-named-as-default: 0 - import/no-named-as-default-member: 0 diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 00000000..fee873d7 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,16 @@ +name: Node.js CI + +on: + push: + branches: + - main + pull_request: + +jobs: + nodejs: + uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1 + with: + node-version: '24.x' + node-version-matrix: '[24]' + disable-test-package: true + upload-coverage: false diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..5f11b1c1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +tiles/font-awesome +util/aesjs.js +util/cloneDeepLimitArray.js +util/md5.js +util/yamlParser.js, +spectra-data/conrec.js diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d6b81871..00000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: node_js -node_js: - - node diff --git a/ChemEquilibrium/AcidModel.js b/ChemEquilibrium/AcidModel.js index c0ec6cbd..ad7d48c9 100644 --- a/ChemEquilibrium/AcidModel.js +++ b/ChemEquilibrium/AcidModel.js @@ -1,5 +1,151 @@ - -var pkas = [{ ha: 'HIO3', a: 'IO3-', pka: 0.8, specie: { label: 'IO3-', number: 1, pka: 0.8 } }, { ha: 'H3PO4', a: 'H2PO4-', pka: 2.16, specie: { label: 'PO4---', number: 3, pka: 21.69 } }, { ha: 'H2PO4-', a: 'HPO4--', pka: 7.21, specie: { label: 'PO4---', number: 2, pka: 19.53 } }, { ha: 'HPO4--', a: 'PO4---', pka: 12.32, specie: { label: 'PO4---', number: 1, pka: 12.32 } }, { ha: 'HF', a: 'F-', pka: 3.2, specie: { label: 'F-', number: 1, pka: 3.2 } }, { ha: 'HNO2', a: 'NO2-', pka: 3.25, specie: { label: 'NO2-', number: 1, pka: 3.25 } }, { ha: 'HOCN', a: 'OCN-', pka: 3.48, specie: { label: 'OCN-', number: 1, pka: 3.48 } }, { ha: 'H2CO3', a: 'HCO3-', pka: 6.35, specie: { label: 'CO3--', number: 2, pka: 16.68 } }, { ha: 'HCO3-', a: 'CO3--', pka: 10.33, specie: { label: 'CO3--', number: 1, pka: 10.33 } }, { ha: 'H2S', a: 'HS-', pka: 7.05, specie: { label: 'S--', number: 2, pka: 19.14 } }, { ha: 'HS-', a: 'S--', pka: 12.09, specie: { label: 'S--', number: 1, pka: 12.09 } }, { ha: 'HClO', a: 'ClO-', pka: 7.4, specie: { label: 'ClO-', number: 1, pka: 7.4 } }, { ha: 'HBrO', a: 'BrO-', pka: 8.6, specie: { label: 'BrO-', number: 1, pka: 8.6 } }, { ha: 'HCN', a: 'CN-', pka: 9.21, specie: { label: 'CN-', number: 1, pka: 9.21 } }, { ha: 'NH4+', a: 'NH3', pka: 9.25, specie: { label: 'NH3', number: 1, pka: 9.25 } }, { ha: 'CH2ClCOOH', a: 'CH2ClCOO-', pka: 2.89, specie: { label: 'CH2ClCOO-', number: 1, pka: 2.89 } }, { ha: 'HCOOH', a: 'HCOO-', pka: 3.75, specie: { label: 'HCOO-', number: 1, pka: 3.75 } }, { ha: 'C6H5COOH', a: 'C6H5COO-', pka: 4.2, specie: { label: 'C6H5COO-', number: 1, pka: 4.2 } }, { ha: 'C66H5NH3+', a: 'C66H5NH2', pka: 4.6, specie: { label: 'C66H5NH2', number: 1, pka: 4.6 } }, { ha: 'CH3COOH', a: 'CH3COO-', pka: 4.75, specie: { label: 'CH3COO-', number: 1, pka: 4.75 } }, { ha: 'C2H5COOH', a: 'C2H5COO-', pka: 4.87, specie: { label: 'C2H5COO-', number: 1, pka: 4.87 } }, { ha: 'C5H5NH+', a: 'C5H5N', pka: 5.25, specie: { label: 'C5H5N', number: 1, pka: 5.25 } }, { ha: 'CH3NH3+', a: 'CH3NH2', pka: 10.66, specie: { label: 'CH3NH2', number: 1, pka: 10.66 } }, { ha: '(C2H5)3NH+', a: '(C2H5)3N', pka: 10.75, specie: { label: '(C2H5)3N', number: 1, pka: 10.75 } }, { ha: 'C2H5NH3+', a: 'C2H5NH2', pka: 10.8, specie: { label: 'C2H5NH2', number: 1, pka: 10.8 } }, { ha: 'HCl', a: 'Cl-', pka: 1, specie: { label: 'Cl-', number: 1, pka: 1 } }]; +let pkas = [ + { + ha: 'HIO3', + a: 'IO3-', + pka: 0.8, + specie: { label: 'IO3-', number: 1, pka: 0.8 }, + }, + { + ha: 'H3PO4', + a: 'H2PO4-', + pka: 2.16, + specie: { label: 'PO4---', number: 3, pka: 21.69 }, + }, + { + ha: 'H2PO4-', + a: 'HPO4--', + pka: 7.21, + specie: { label: 'PO4---', number: 2, pka: 19.53 }, + }, + { + ha: 'HPO4--', + a: 'PO4---', + pka: 12.32, + specie: { label: 'PO4---', number: 1, pka: 12.32 }, + }, + { ha: 'HF', a: 'F-', pka: 3.2, specie: { label: 'F-', number: 1, pka: 3.2 } }, + { + ha: 'HNO2', + a: 'NO2-', + pka: 3.25, + specie: { label: 'NO2-', number: 1, pka: 3.25 }, + }, + { + ha: 'HOCN', + a: 'OCN-', + pka: 3.48, + specie: { label: 'OCN-', number: 1, pka: 3.48 }, + }, + { + ha: 'H2CO3', + a: 'HCO3-', + pka: 6.35, + specie: { label: 'CO3--', number: 2, pka: 16.68 }, + }, + { + ha: 'HCO3-', + a: 'CO3--', + pka: 10.33, + specie: { label: 'CO3--', number: 1, pka: 10.33 }, + }, + { + ha: 'H2S', + a: 'HS-', + pka: 7.05, + specie: { label: 'S--', number: 2, pka: 19.14 }, + }, + { + ha: 'HS-', + a: 'S--', + pka: 12.09, + specie: { label: 'S--', number: 1, pka: 12.09 }, + }, + { + ha: 'HClO', + a: 'ClO-', + pka: 7.4, + specie: { label: 'ClO-', number: 1, pka: 7.4 }, + }, + { + ha: 'HBrO', + a: 'BrO-', + pka: 8.6, + specie: { label: 'BrO-', number: 1, pka: 8.6 }, + }, + { + ha: 'HCN', + a: 'CN-', + pka: 9.21, + specie: { label: 'CN-', number: 1, pka: 9.21 }, + }, + { + ha: 'NH4+', + a: 'NH3', + pka: 9.25, + specie: { label: 'NH3', number: 1, pka: 9.25 }, + }, + { + ha: 'CH2ClCOOH', + a: 'CH2ClCOO-', + pka: 2.89, + specie: { label: 'CH2ClCOO-', number: 1, pka: 2.89 }, + }, + { + ha: 'HCOOH', + a: 'HCOO-', + pka: 3.75, + specie: { label: 'HCOO-', number: 1, pka: 3.75 }, + }, + { + ha: 'C6H5COOH', + a: 'C6H5COO-', + pka: 4.2, + specie: { label: 'C6H5COO-', number: 1, pka: 4.2 }, + }, + { + ha: 'C66H5NH3+', + a: 'C66H5NH2', + pka: 4.6, + specie: { label: 'C66H5NH2', number: 1, pka: 4.6 }, + }, + { + ha: 'CH3COOH', + a: 'CH3COO-', + pka: 4.75, + specie: { label: 'CH3COO-', number: 1, pka: 4.75 }, + }, + { + ha: 'C2H5COOH', + a: 'C2H5COO-', + pka: 4.87, + specie: { label: 'C2H5COO-', number: 1, pka: 4.87 }, + }, + { + ha: 'C5H5NH+', + a: 'C5H5N', + pka: 5.25, + specie: { label: 'C5H5N', number: 1, pka: 5.25 }, + }, + { + ha: 'CH3NH3+', + a: 'CH3NH2', + pka: 10.66, + specie: { label: 'CH3NH2', number: 1, pka: 10.66 }, + }, + { + ha: '(C2H5)3NH+', + a: '(C2H5)3N', + pka: 10.75, + specie: { label: '(C2H5)3N', number: 1, pka: 10.75 }, + }, + { + ha: 'C2H5NH3+', + a: 'C2H5NH2', + pka: 10.8, + specie: { label: 'C2H5NH2', number: 1, pka: 10.8 }, + }, + { ha: 'HCl', a: 'Cl-', pka: 1, specie: { label: 'Cl-', number: 1, pka: 1 } }, +]; define(['lodash'], function (_) { class AcidBase { @@ -9,8 +155,8 @@ define(['lodash'], function (_) { } static getAllAcidBaseLabels() { - var species = new Set(); - for (var i = 0; i < pkas.length; i++) { + let species = new Set(); + for (let i = 0; i < pkas.length; i++) { species.add(pkas[i].ha); species.add(pkas[i].a); } @@ -18,8 +164,8 @@ define(['lodash'], function (_) { } addAcidBase(label, total) { - var titrProtonCount; - var titrSpecie = pkas.find(function (pka) { + let titrProtonCount; + let titrSpecie = pkas.find(function (pka) { return pka.ha === label; }); if (titrSpecie) { @@ -31,13 +177,11 @@ define(['lodash'], function (_) { }); if (titrSpecie) { titrProtonCount = 0; + } else if (label === 'OH-') { + this.addComponent('OH-', total); + return; } else { - if (label === 'OH-') { - this.addComponent('OH-', total); - return; - } else { - throw new Error('Could not find acid/base'); - } + throw new Error('Could not find acid/base'); } titrSpecie = titrSpecie.specie.label; } @@ -52,81 +196,82 @@ define(['lodash'], function (_) { total = -total; } if (!total) total = 0; - var comp = this.components.find((c) => c.label === label); + let comp = this.components.find((c) => c.label === label); if (comp) { comp.total += total; } else { this.components.push({ - label, total + label, + total, }); } } setTotal(componentLabel, total) { - var c = this.components.find((c) => c.label === componentLabel); + let c = this.components.find((c) => c.label === componentLabel); c.total = total; c.atEquilibrium = undefined; } setAtEquilibrium(componentLabel, atEquilibrium) { - var c = this.components.find((c) => c.label === componentLabel); + let c = this.components.find((c) => c.label === componentLabel); c.atEquilibrium = atEquilibrium; c.total = undefined; } getModel() { // Get all involved pkas - var pkas = this.pkas.filter((pka) => { + let pkas = this.pkas.filter((pka) => { return this.components.find(function (c) { return String(c.label) === String(pka.specie.label); }); }); // group pkas by component - var grouped = _.groupBy(pkas, function (pka) { + let grouped = _.groupBy(pkas, function (pka) { return String(pka.specie.label); }); + let nbComponents = this.components.length; - var nbComponents = this.components.length; - - var protonIndex = this.components.findIndex((c) => c.label === 'H+'); + let protonIndex = this.components.findIndex((c) => c.label === 'H+'); if (protonIndex === -1) throw new Error('Acid-base model has no proton'); - var model = {}; + let model = {}; // Model components model.components = new Array(nbComponents); for (i = 0; i < this.components.length; i++) { - model.components[i] = Object.assign({}, this.components[i]); + model.components[i] = { ...this.components[i] }; } // Model formed species model.formedSpecies = [ { label: 'OH-', - beta: Math.pow(10, -14), - components: new Array(nbComponents).fill(0) - } + beta: 10 ** -14, + components: new Array(nbComponents).fill(0), + }, ]; model.formedSpecies[0].components[protonIndex] = -1; - for (var i = 0; i < this.components.length; i++) { if (i === protonIndex) continue; - var group = grouped[this.components[i].label]; + let group = grouped[this.components[i].label]; if (!group) throw new Error('Should be unreachable'); - for (var j = 0; j < group.length; j++) { - var el = group[j]; + for (let j = 0; j < group.length; j++) { + let el = group[j]; model.formedSpecies.push({ label: String(el.ha), - beta: Math.pow(10, Number(el.specie.pka)), - components: new Array(nbComponents).fill(0) + beta: 10 ** Number(el.specie.pka), + components: new Array(nbComponents).fill(0), }); model.formedSpecies[model.formedSpecies.length - 1].components[i] = 1; - model.formedSpecies[model.formedSpecies.length - 1].components[protonIndex] = Number(el.specie.number); + model.formedSpecies[model.formedSpecies.length - 1].components[ + protonIndex + ] = Number(el.specie.number); } } diff --git a/ChemEquilibrium/chart.js b/ChemEquilibrium/chart.js index 8dfbe69b..816251c3 100644 --- a/ChemEquilibrium/chart.js +++ b/ChemEquilibrium/chart.js @@ -5,23 +5,23 @@ define(['src/util/color'], function (Color) { if (x.length !== y.length || y.length === 0) { throw new Error('Invalid data length'); } - var chart = { + let chart = { data: [], axis: [ { - label: options.xLabel || '' + label: options.xLabel || '', }, { - label: options.yLabel || '' - } - ] + label: options.yLabel || '', + }, + ], }; - var species = Object.keys(y[0]); - var colors = Color.getDistinctColors(species.length); + let species = Object.keys(y[0]); + let colors = Color.getDistinctColors(species.length); for (var i = 0; i < species.length; i++) { - var data = {}; + let data = {}; chart.data.push(data); // eslint-disable-next-line no-loop-func data.y = y.map((y) => { @@ -37,10 +37,10 @@ define(['src/util/color'], function (Color) { data.yAxis = 1; data.defaultStyle = { lineColor: colors[i], - lineWidth: 1 + lineWidth: 1, }; } return chart; - } + }, }; }); diff --git a/ChemEquilibrium/table.js b/ChemEquilibrium/table.js index c1593374..039785b0 100644 --- a/ChemEquilibrium/table.js +++ b/ChemEquilibrium/table.js @@ -1,11 +1,10 @@ - module.exports = function getTable(sol) { - var result = []; + let result = []; result.push(`x\t${sol.species.join('\t')}`); - for (var i = 0; i < sol.x.length; i++) { - var line = []; + for (let i = 0; i < sol.x.length; i++) { + let line = []; line.push(sol.x[i]); - for (var specie of sol.species) { + for (let specie of sol.species) { line.push(sol.solutions[i][specie]); } result.push(line.join('\t')); diff --git a/README.md b/README.md index 1ae572c9..cffe91c9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # visualizer-helper -Small pieces of code useful in the visualizer +Small pieces of code useful in the visualizer ## Build diff --git a/biology/needleman/data.js b/biology/needleman/data.js index 8b33ddeb..11880c9e 100644 --- a/biology/needleman/data.js +++ b/biology/needleman/data.js @@ -1096,9 +1096,9 @@ function createTable(v, w) { let n = v.length; let m = w.length; let rows = []; - for (var i = 0; i < n + 1; i++) { + for (let i = 0; i < n + 1; i++) { rows[i] = []; - for (var j = 0; j < m + 1; j++) { + for (let j = 0; j < m + 1; j++) { rows[i].push(0); } } @@ -1117,9 +1117,9 @@ function identityMatrix(n, match, penalization) { penalization = penalization || 0; let matrix = []; - for (var i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { matrix[i] = []; - for (var j = 0; j < n; j++) { + for (let j = 0; j < n; j++) { matrix[i][j] = i === j ? match : penalization; } } @@ -1140,9 +1140,9 @@ function similarityMatrix(v, w, scores) { let vocab = vocabulary(v + w); let matrix = {}; - for (var i in vocab) { + for (let i in vocab) { matrix[vocab[i]] = {}; - for (var j in vocab) { + for (let j in vocab) { matrix[vocab[i]][vocab[j]] = i === j ? match : mismatch; } } diff --git a/chemistry/PubChem.js b/chemistry/PubChem.js index d251d064..203bfc00 100644 --- a/chemistry/PubChem.js +++ b/chemistry/PubChem.js @@ -8,14 +8,14 @@ async function getMolecules(mf) { searchParams.set('fields', 'data.iupac,data.ocl'); searchParams.set('limit', '50000'); - let response = await fetch(`${pubchemURL}` + searchParams.toString()); + let response = await fetch(`${pubchemURL}${searchParams.toString()}`); let results = await response.json(); console.log(results.data); return results.data; } module.exports = { - choose: function (mf) { + choose(mf) { let promise = getMolecules(mf); return ui .choose([{ promise }], { diff --git a/chemistry/__tests__/sequenceSplitter.js b/chemistry/__tests__/sequenceSplitter.js deleted file mode 100644 index 5db3dfee..00000000 --- a/chemistry/__tests__/sequenceSplitter.js +++ /dev/null @@ -1,22 +0,0 @@ - -const sequenceSplitter = require('../sequenceSplitter'); - -test('AAA', () => { - expect(sequenceSplitter('AAA')).toHaveLength(3); -}); - -test('HAlaAlaAlaOH', () => { - expect(sequenceSplitter('HAlaAlaAlaOH')).toHaveLength(3); -}); - -test('HAlaAla(H-1OH)AlaOH', () => { - expect(sequenceSplitter('HAlaAla(H-1OH)AlaOH')).toHaveLength(3); -}); - -test('H(+)AlaAla(H-1OH)AlaOH', () => { - expect(sequenceSplitter('H(+)AlaAla(H-1OH)AlaOH')).toHaveLength(3); -}); - -test('ForAlaAla(H-1OH)AlaOH', () => { - expect(sequenceSplitter('ForAlaAla(H-1OH)AlaOH')).toHaveLength(3); -}); diff --git a/chemistry/__tests__/sequenceSplitter.test.js b/chemistry/__tests__/sequenceSplitter.test.js new file mode 100644 index 00000000..9c251962 --- /dev/null +++ b/chemistry/__tests__/sequenceSplitter.test.js @@ -0,0 +1,21 @@ +const sequenceSplitterTest = require('../sequenceSplitter'); + +test('AAA', () => { + expect(sequenceSplitterTest('AAA')).toHaveLength(3); +}); + +test('HAlaAlaAlaOH', () => { + expect(sequenceSplitterTest('HAlaAlaAlaOH')).toHaveLength(3); +}); + +test('HAlaAla(H-1OH)AlaOH', () => { + expect(sequenceSplitterTest('HAlaAla(H-1OH)AlaOH')).toHaveLength(3); +}); + +test('H(+)AlaAla(H-1OH)AlaOH', () => { + expect(sequenceSplitterTest('H(+)AlaAla(H-1OH)AlaOH')).toHaveLength(3); +}); + +test('ForAlaAla(H-1OH)AlaOH', () => { + expect(sequenceSplitterTest('ForAlaAla(H-1OH)AlaOH')).toHaveLength(3); +}); diff --git a/chemistry/chemcalcSequenceSVG.js b/chemistry/chemcalcSequenceSVG.js index 39b23691..16d33692 100644 --- a/chemistry/chemcalcSequenceSVG.js +++ b/chemistry/chemcalcSequenceSVG.js @@ -1,6 +1,6 @@ define([ 'https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8145c522b71fc9c872cb0bcae49a/dist/snap.svg-min.js', - './sequenceSplitter' + './sequenceSplitter', ], function (Snap, sequenceSplitter) { function getSVG(sequence, analysisResult, options) { const { @@ -12,28 +12,28 @@ define([ labelFontFamily = 'Verdana', labelSize = 8, verticalShiftForTerminalAnnotations = 20, - showLabels = true + showLabels = true, } = options; - var residues = []; - var mfParts = sequenceSplitter(sequence); - var results = JSON.parse(JSON.stringify(analysisResult)); + let residues = []; + let mfParts = sequenceSplitter(sequence); + let results = JSON.parse(JSON.stringify(analysisResult)); - var xPos = leftRightBorders; - var xOld = xPos; + let xPos = leftRightBorders; + let xOld = xPos; - var line = 0; + let line = 0; // we create a temporary paper in order to get the width of the text blocs - var tempPaper = Snap(1000, 40); - for (var i = 0; i < mfParts.length; i++) { - var part = mfParts[i]; - var text = tempPaper.text(xPos, 20, part); + let tempPaper = Snap(1000, 40); + for (let i = 0; i < mfParts.length; i++) { + let part = mfParts[i]; + let text = tempPaper.text(xPos, 20, part); text.attr({ 'font-family': labelFontFamily, 'font-weight': 'bold', - 'font-size': 12 + 'font-size': 12, }); - var textWidth = text.node.getBoundingClientRect().width; + let textWidth = text.node.getBoundingClientRect().width; xPos += textWidth; if (xPos > width - leftRightBorders) { xOld = leftRightBorders; @@ -49,7 +49,7 @@ define([ line, usedSlots: [], topPosition: 0, - bottomPosition: 0 + bottomPosition: 0, }); xPos += spaceBetweenResidues; xOld = xPos; @@ -59,9 +59,9 @@ define([ // we calculate all the lines based on the results for (let result of results) { // internal fragment ? - var parts = result.type.split(/(?=[a-z])/); - var firstPart = parts[0]; - var secondPart = parts[1]; + let parts = result.type.split(/(?=[a-z])/); + let firstPart = parts[0]; + let secondPart = parts[1]; if ('abc'.indexOf(firstPart.charAt(0)) > -1) { // n-terminal fragment @@ -115,40 +115,40 @@ define([ // for each line (internal fragment) we calculate the vertical position // where it should be drawn as well and the maximal number of lines - var maxNumberLines = 0; - for (var result of results) { + let maxNumberLines = 0; + for (let result of results) { if (result.internal) { result.slot = assignSlot(result.from, result.to); if (result.slot > maxNumberLines) maxNumberLines = result.slot; } } - var rowHeight = + let rowHeight = verticalShiftForTerminalAnnotations + spaceBetweenInteralLines * (maxNumberLines + 6); - var height = + let height = rowHeight * (line + 1) + 50 + verticalShiftForTerminalAnnotations; // We start to create the SVG and create the paper - var paper = Snap(width, height); + let paper = Snap(width, height); addScript(paper); residues.forEach(function (residue) { residue.y = (residue.line + 1) * rowHeight; - var text = paper.text(residue.xFrom, residue.y, residue.label); + let text = paper.text(residue.xFrom, residue.y, residue.label); text.attr({ id: `residue-${residue.nTer}` }); text.attr({ 'font-family': labelFontFamily, 'font-weight': 'bold', - 'font-size': 12 + 'font-size': 12, }); }); drawInternals(); drawTerminals(); - var svg = paper + let svg = paper .toString() .replace(/>/g, '>\r') .replace(/&/g, '&') @@ -160,14 +160,14 @@ define([ // we need to define the height of the line. // we need to find a height that is not yet used. function assignSlot(from, to) { - var used = {}; - for (var i = from; i < to; i++) { - var residue = residues[i]; + let used = {}; + for (let i = from; i < to; i++) { + let residue = residues[i]; residue.usedSlots.forEach(function (usedSlot, index) { used[index] = true; }); } - var counter = 0; + let counter = 0; while (true) { if (!used[counter]) { break; @@ -181,9 +181,9 @@ define([ } function drawTerminals() { - for (var result of results) { + for (let result of results) { var residue; - var nTerminal = false; + let nTerminal = false; if (result.fromNTerm) { residue = residues[result.to]; nTerminal = true; @@ -196,7 +196,7 @@ define([ residue.xTo + spaceBetweenResidues / 2, residue.y, residue.xTo + spaceBetweenResidues / 2, - residue.y - 8 + residue.y - 8, ); line.attr({ stroke: result.color, 'stroke-width': strokeWidth }); if (nTerminal) { @@ -204,13 +204,13 @@ define([ residue.xTo + spaceBetweenResidues / 2, residue.y, residue.xTo + spaceBetweenResidues / 2 - 5, - residue.y + 5 + residue.y + 5, ); line.attr({ stroke: result.color, 'stroke-width': strokeWidth }); drawLabel( result, residue.xTo + spaceBetweenResidues / 2 - 15, - residue.y + 12 + residue.bottomPosition * labelSize + residue.y + 12 + residue.bottomPosition * labelSize, ); residue.bottomPosition++; } else { @@ -218,13 +218,13 @@ define([ residue.xTo + spaceBetweenResidues / 2, residue.y - 8, residue.xTo + spaceBetweenResidues / 2 + 5, - residue.y - 13 + residue.y - 13, ); line.attr({ stroke: result.color, 'stroke-width': strokeWidth }); drawLabel( result, residue.xTo + spaceBetweenResidues / 2, - residue.y - 15 - residue.topPosition * labelSize + residue.y - 15 - residue.topPosition * labelSize, ); residue.topPosition++; } @@ -234,41 +234,41 @@ define([ function drawLabel(result, x, y) { if (!showLabels) return; - var label = result.type; - var similarity = Math.round(result.similarity); - var charge = result.charge > 0 ? `+${result.charge}` : result.charge; - var text = paper.text(x, y, label); + let label = result.type; + let similarity = Math.round(result.similarity); + let charge = result.charge > 0 ? `+${result.charge}` : result.charge; + let text = paper.text(x, y, label); text.attr({ fill: result.textColor, 'font-family': labelFontFamily, 'font-weight': 'bold', - 'font-size': labelSize + 'font-size': labelSize, }); - var textWidth = text.node.getBoundingClientRect().width + 3; + let textWidth = text.node.getBoundingClientRect().width + 3; text = paper.text(x + textWidth, y - labelSize / 2, charge); text.attr({ fill: result.textColor, 'font-family': labelFontFamily, - 'font-size': labelSize / 2 + 'font-size': labelSize / 2, }); text = paper.text(x + textWidth, y, similarity); text.attr({ fill: result.textColor, 'font-family': labelFontFamily, - 'font-size': labelSize / 2 + 'font-size': labelSize / 2, }); } function drawInternals() { - for (var result of results) { + for (let result of results) { if (result.internal) { - var fromResidue = residues[result.from + 1]; - var toResidue = residues[result.to]; + let fromResidue = residues[result.from + 1]; + let toResidue = residues[result.to]; // var charge = result.charge > 0 ? '+' + result.charge : result.charge; // var label = result.type + ' (' + charge + ', ' + Math.round(result.similarity) + '%)'; // we need to check on how many lines we are var fromX, toX, y; - for (var line = fromResidue.line; line <= toResidue.line; line++) { + for (let line = fromResidue.line; line <= toResidue.line; line++) { y = -10 - result.slot * spaceBetweenInteralLines + @@ -284,15 +284,15 @@ define([ } else { toX = width - 1; } - var drawLine = paper.line(fromX, y, toX, y); + let drawLine = paper.line(fromX, y, toX, y); drawLine.attr({ onmouseover: 'mouseOver(evt)', onmouseout: 'mouseOut(evt)', - id: `line${fromResidue.nTer}-${toResidue.nTer}` + id: `line${fromResidue.nTer}-${toResidue.nTer}`, }); drawLine.attr({ stroke: result.color, - 'stroke-width': strokeWidth + 'stroke-width': strokeWidth, }); drawLabel(result, (fromX + toX) / 2 - 10, y - 2); @@ -304,7 +304,7 @@ define([ } function addScript(paper) { - var script = ` // `; - var scriptElement = paper.el('script', { - type: 'application/ecmascript' + let scriptElement = paper.el('script', { + type: 'application/ecmascript', }); scriptElement.node.textContent = script; } diff --git a/chemistry/orbitals.js b/chemistry/orbitals.js index 73385575..375def68 100644 --- a/chemistry/orbitals.js +++ b/chemistry/orbitals.js @@ -1,8 +1,9 @@ +define([ + 'https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8145c522b71fc9c872cb0bcae49a/dist/snap.svg-min.js', +], function (Snap) { + let exports = {}; -define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8145c522b71fc9c872cb0bcae49a/dist/snap.svg-min.js'], function (Snap) { - var exports = {}; - - var defaultOptions = { + let defaultOptions = { width: 1000, height: 600, leftRightMargin: 4, @@ -13,93 +14,113 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 rectMargin: 10, spinOuterMarginRatio: 1 / 4, arrowStrokeWidth: 3, - arrowHeadSize: 3 + arrowHeadSize: 3, }; - - var paper, svg, svgModifier; - + let paper, svg, svgModifier; // Create svg function createSvg(electronicConfiguration, opts) { - opts = Object.assign({}, defaultOptions, opts); + opts = { ...defaultOptions, ...opts }; // User defined - var width = opts.width; - var height = opts.height; - var leftRightMargin = opts.leftRightMargin; - var topBottomMargin = opts.topBottomMargin; - var fontSize = opts.fontSize; - var rectWidth = opts.rectWidth; - var rectHeight = opts.rectHeight; - var rectMargin = opts.rectMargin; - var spinOuterMarginRatio = opts.spinOuterMarginRatio; - var arrowStrokeWidth = opts.arrowStrokeWidth; - var arrowHeadSize = opts.arrowHeadSize; + let width = opts.width; + let height = opts.height; + let leftRightMargin = opts.leftRightMargin; + let topBottomMargin = opts.topBottomMargin; + let fontSize = opts.fontSize; + let rectWidth = opts.rectWidth; + let rectHeight = opts.rectHeight; + let rectMargin = opts.rectMargin; + let spinOuterMarginRatio = opts.spinOuterMarginRatio; + let arrowStrokeWidth = opts.arrowStrokeWidth; + let arrowHeadSize = opts.arrowHeadSize; // Calculated - var drawWidth = width - 2 * leftRightMargin; - var drawHeight = height - 2 * topBottomMargin; - var levelHeight = fontSize + rectHeight; - var sSpace = (drawHeight - levelHeight) / 6; - var labelOffset = rectHeight + fontSize + 5; - var columnOffset = (drawWidth - 16 * rectWidth - 12 * rectMargin) / 3; - var pOffset = [sSpace / 4, null, sSpace * 5 - sSpace / 3, rectWidth + columnOffset]; - var dOffset = [2 * sSpace / 4, null, sSpace * 3 - sSpace / 3, 4 * rectWidth + 2 * rectMargin + 2 * columnOffset]; - var fOffset = [-1 / 4 * sSpace, null, 3 / 4 * sSpace, 9 * rectWidth + 6 * rectMargin + 3 * columnOffset]; - var spinOuterMargin = rectWidth * spinOuterMarginRatio; - var spinInnerMargin = rectWidth * (1 - 2 * spinOuterMarginRatio); + let drawWidth = width - 2 * leftRightMargin; + let drawHeight = height - 2 * topBottomMargin; + let levelHeight = fontSize + rectHeight; + let sSpace = (drawHeight - levelHeight) / 6; + let labelOffset = rectHeight + fontSize + 5; + let columnOffset = (drawWidth - 16 * rectWidth - 12 * rectMargin) / 3; + let pOffset = [ + sSpace / 4, + null, + sSpace * 5 - sSpace / 3, + rectWidth + columnOffset, + ]; + let dOffset = [ + (2 * sSpace) / 4, + null, + sSpace * 3 - sSpace / 3, + 4 * rectWidth + 2 * rectMargin + 2 * columnOffset, + ]; + let fOffset = [ + (-1 / 4) * sSpace, + null, + (3 / 4) * sSpace, + 9 * rectWidth + 6 * rectMargin + 3 * columnOffset, + ]; + let spinOuterMargin = rectWidth * spinOuterMarginRatio; + let spinInnerMargin = rectWidth * (1 - 2 * spinOuterMarginRatio); function drawElectrons(elConfig) { elConfig = parseelConfig(elConfig); - for (var i = 0; i < elConfig.length; i++) { - var layer = elConfig[i].layer; - var electrons = elConfig[i].electrons; - for (var j = 0; j < electrons; j++) { + for (let i = 0; i < elConfig.length; i++) { + let layer = elConfig[i].layer; + let electrons = elConfig[i].electrons; + for (let j = 0; j < electrons; j++) { drawElectron(layer, j); } } } function drawElectron(layer, electron) { - var group = getElectronGroup(layer, electron); - var spin = getElectronSpin(layer, electron); - var p; + let group = getElectronGroup(layer, electron); + let spin = getElectronSpin(layer, electron); + let p; if (spin > 0) { p = `M${spinOuterMargin},${rectHeight - 1} ${spinOuterMargin},${2 * arrowHeadSize + 1}`; } else { - var margin = spinOuterMargin + spinInnerMargin; + let margin = spinOuterMargin + spinInnerMargin; p = `M${margin},2 ${margin},${rectHeight - (2 * arrowHeadSize + 1)}`; } if (group) { - paper.path(p).attr({ - style: 'marker-end: url(#svgarrow);', - strokeWidth: arrowStrokeWidth, - stroke: '#000000', - dataClass: 'spin' - }).appendTo(group); + paper + .path(p) + .attr({ + style: 'marker-end: url(#svgarrow);', + strokeWidth: arrowStrokeWidth, + stroke: '#000000', + dataClass: 'spin', + }) + .appendTo(group); } } function drawRect(posx, posy, id) { - var rectId = getRectId(id); - paper.g().attr({ - transform: `translate(${posx},${posy})`, - id: `g${rectId}` - }).rect(0, 0, rectWidth, rectHeight).attr({ - fill: 'white', - stroke: 'grey', - strokeWidth: 1, - id: rectId, - class: 'elecRect' - }); + let rectId = getRectId(id); + paper + .g() + .attr({ + transform: `translate(${posx},${posy})`, + id: `g${rectId}`, + }) + .rect(0, 0, rectWidth, rectHeight) + .attr({ + fill: 'white', + stroke: 'grey', + strokeWidth: 1, + id: rectId, + class: 'elecRect', + }); svgModifier.push({ selector: `#${rectId}`, info: { - quanticNumbers: getQuanticNumbers(id) - } + quanticNumbers: getQuanticNumbers(id), + }, }); } @@ -107,34 +128,42 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 paper.text(posx, posy, text).attr({ fontSize, textAnchor: 'middle', - dataTest: 'abc' + dataTest: 'abc', }); } svgModifier = []; paper = Snap(width, height); - paper.path('M 0 0 L 10 4 L 0 8 z').marker(0, 0, arrowHeadSize, arrowHeadSize, 1, 4).attr({ - id: 'svgarrow', - viewBox: '0 0 10 8' - }); - - var i, j, x, y, label; + paper + .path('M 0 0 L 10 4 L 0 8 z') + .marker(0, 0, arrowHeadSize, arrowHeadSize, 1, 4) + .attr({ + id: 'svgarrow', + viewBox: '0 0 10 8', + }); + let i, j, x, y, label; // s for (i = 0; i < 7; i++) { label = `${7 - i}s`; - var w = drawHeight - levelHeight; - drawRect(leftRightMargin, i * w / 6 + topBottomMargin, `${label}1`); - drawText(leftRightMargin + rectWidth / 2, i * w / 6 + labelOffset, label); + let w = drawHeight - levelHeight; + drawRect(leftRightMargin, (i * w) / 6 + topBottomMargin, `${label}1`); + drawText( + leftRightMargin + rectWidth / 2, + (i * w) / 6 + labelOffset, + label, + ); } - // p for (i = 0; i < 6; i++) { label = `${7 - i}p`; - y = topBottomMargin + pOffset[0] + (i - 1) * (drawHeight - pOffset[0] - (drawHeight - pOffset[2])) / 4; + y = + topBottomMargin + + pOffset[0] + + ((i - 1) * (drawHeight - pOffset[0] - (drawHeight - pOffset[2]))) / 4; for (j = 0; j < 3; j++) { x = leftRightMargin + pOffset[3] + j * (rectWidth + rectMargin); drawRect(x, y, label + (j + 1)); @@ -146,7 +175,10 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 // d for (i = 0; i < 4; i++) { label = `${6 - i}d`; - y = topBottomMargin + dOffset[0] + (i - 1) * (drawHeight - dOffset[0] - (drawHeight - dOffset[2])) / 2; + y = + topBottomMargin + + dOffset[0] + + ((i - 1) * (drawHeight - dOffset[0] - (drawHeight - dOffset[2]))) / 2; for (j = 0; j < 5; j++) { x = leftRightMargin + dOffset[3] + j * (rectWidth + rectMargin); drawRect(x, y, label + (j + 1)); @@ -158,7 +190,10 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 // f for (i = 0; i < 2; i++) { label = `${5 - i}f`; - y = topBottomMargin + fOffset[0] + i * (drawHeight - fOffset[0] - (drawHeight - fOffset[2])); + y = + topBottomMargin + + fOffset[0] + + i * (drawHeight - fOffset[0] - (drawHeight - fOffset[2])); for (j = 0; j < 7; j++) { x = leftRightMargin + fOffset[3] + j * (rectWidth + rectMargin); drawRect(x, y, label + (j + 1)); @@ -173,33 +208,31 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 paper.remove(); } - // utils function getRectId(elConfig) { - var q = getQuanticNumbers(elConfig); + let q = getQuanticNumbers(elConfig); return `l${q.l}_m${q.m}_n${q.n}`; } function parseelConfig(elConfig) { elConfig = elConfig.split(' '); elConfig = elConfig.map(function (o) { - var m = o.match(/^(\d\w)(\d+)/); + let m = o.match(/^(\d\w)(\d+)/); return { layer: m[1], - electrons: +m[2] + electrons: +m[2], }; }); return elConfig; } - function getQuanticNumbers(elConfig) { elConfig = elConfig.split(' '); elConfig = elConfig[elConfig.length - 1]; - var ma = elConfig.match(/^(\d)(\w)(\d+)/); - var n = +ma[1]; - var l = ma[2]; - var m = +ma[3]; + let ma = elConfig.match(/^(\d)(\w)(\d+)/); + let n = +ma[1]; + let l = ma[2]; + let m = +ma[3]; switch (l) { case 's': @@ -218,13 +251,13 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 throw new Error(`Unexpected l: ${l}`); } - var num = l * 2 + 1; - m = (m - 1) % num - l; + let num = l * 2 + 1; + m = ((m - 1) % num) - l; return { l, m, n }; } function getLayerNum(layer) { - var l = layer[layer.length - 1].toLowerCase(); + let l = layer[layer.length - 1].toLowerCase(); switch (l) { case 's': return 1; @@ -240,16 +273,15 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 } function getElectronGroup(layer, electron) { - var id = getRectId(layer + (electron + 1)); + let id = getRectId(layer + (electron + 1)); return paper.select(`#g${id}`); } function getElectronSpin(layer, electron) { - var num = getLayerNum(layer); + let num = getLayerNum(layer); return Math.floor(electron / num) === 0 ? 1 : -1; } - exports.getSvg = function (...args) { createSvg(args); return svg; @@ -263,4 +295,3 @@ define(['https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8 return exports; }); - diff --git a/chemistry/sequenceSplitter.js b/chemistry/sequenceSplitter.js index f24047f0..1ccd81f8 100644 --- a/chemistry/sequenceSplitter.js +++ b/chemistry/sequenceSplitter.js @@ -2,27 +2,30 @@ Code that allows to split a sequence of aminoacids natural or non natural */ - module.exports = function sequenceSplitter(sequence) { - var parts = ['']; + let parts = ['']; if (sequence.match(/^[A-Z ]+$/)) { parts = sequence.replace(/ /g, '').split(/(?=[A-Z])/); } else { // we need to deal with upper and lowercases sequence = sequence.replace(/ /g, ''); - var parenthesisLevel = 0; - var begin = true; + let parenthesisLevel = 0; + let begin = true; for (let i = 0; i < sequence.length; i++) { let currentChar = sequence.charAt(i); parts[parts.length - 1] += currentChar; - let nextChar = (i < (sequence.length - 1)) ? sequence.charAt(i + 1) : ''; - let nextNextChar = (i < (sequence.length - 2)) ? sequence.charAt(i + 2) : ''; + let nextChar = i < sequence.length - 1 ? sequence.charAt(i + 1) : ''; + let nextNextChar = i < sequence.length - 2 ? sequence.charAt(i + 2) : ''; if (currentChar === '(') { parenthesisLevel++; } else if (currentChar === ')') { parenthesisLevel--; } - if (nextChar.match(/[A-Z]/) && nextNextChar.match(/[a-z]/) && parenthesisLevel === 0) { + if ( + nextChar.match(/[A-Z]/) && + nextNextChar.match(/[a-z]/) && + parenthesisLevel === 0 + ) { if (begin) { begin = false; } else { diff --git a/chemistry/showMfGroupsList.js b/chemistry/showMfGroupsList.js index 85681afc..4dcd3e06 100644 --- a/chemistry/showMfGroupsList.js +++ b/chemistry/showMfGroupsList.js @@ -2,8 +2,8 @@ We retrieve some exercises for structural analysis */ -import UI from 'src/util/ui'; import OCL from 'openchemlib'; +import UI from 'src/util/ui'; import MolecularFormula from '../eln/libs/MolecularFormula'; @@ -100,16 +100,15 @@ function getHtml(CustomMolecularFormula = MolecularFormula) { ${group.symbol} ${group.name} ${group.mfHtml}${ - group.mf - } + group.mf + } ${group.monoisotopicMass.toFixed(4)} ${group.kind} ${group.oneLetter ? group.oneLetter : ''} ${ group.ocl && group.ocl.value.length > 2 - ? "" + )}'>` : '' } diff --git a/chemistry/showMfHelp.js b/chemistry/showMfHelp.js index 4a4a95bf..15e8fd11 100644 --- a/chemistry/showMfHelp.js +++ b/chemistry/showMfHelp.js @@ -25,6 +25,6 @@ module.exports = function showMfHelp() { UI.dialog(html, { width: 500, height: 400, - title: 'HELP: entering a molecular formula' + title: 'HELP: entering a molecular formula', }); }; diff --git a/chemistry/structuralAnalysisExercises.js b/chemistry/structuralAnalysisExercises.js index fb5341ce..c9b04bbf 100644 --- a/chemistry/structuralAnalysisExercises.js +++ b/chemistry/structuralAnalysisExercises.js @@ -1,18 +1,18 @@ -import CA from 'src/util/couchdbAttachments'; import { Molecule } from 'openchemlib'; +import CA from 'src/util/couchdbAttachments'; async function fetchData( query = undefined, url = 'https://couch.cheminfo.org/cheminfo-public/668677b6432fb3fde76305cfe706856d', ) { - var ca = new CA(url); + let ca = new CA(url); - var files = await ca.fetchList(); + let files = await ca.fetchList(); files = files.filter((a) => a.filename.match('upload')); files = files.map((a) => { - var filename = a.filename.replace('upload/', ''); - var parts; + let filename = a.filename.replace('upload/', ''); + let parts; if (filename.match(/.*\.mol/)) { parts = [filename.replace(/\..*/, ''), 'mol']; } else { @@ -20,7 +20,7 @@ async function fetchData( parts = filename.split('_'); } return { - filename: filename, + filename, rn: parts[0], kind: parts[1], experiment: parts[2], @@ -32,16 +32,16 @@ async function fetchData( // we combine the files based on some filters - var data = {}; + let data = {}; - for (var file of files) { + for (let file of files) { if (!data[file.rn]) { data[file.rn] = { rn: file.rn, myResult: '', }; } - var datum = data[file.rn]; + let datum = data[file.rn]; switch (file.kind) { case 'mol': datum.mol = { type: 'mol2d', url: file.url }; @@ -104,12 +104,12 @@ async function fetchData( } } - var results = []; + let results = []; - for (var key of Object.keys(data)) { + for (let key of Object.keys(data)) { results.push(data[key]); } - var counter = 1; + let counter = 1; results.forEach((a) => { a.number = counter++; }); diff --git a/defaultOptions/mass.js b/defaultOptions/mass.js index 09314824..6e440873 100644 --- a/defaultOptions/mass.js +++ b/defaultOptions/mass.js @@ -1,4 +1,3 @@ - define(function () { return { monoisotopicMass: 300.123, @@ -22,14 +21,14 @@ define(function () { ya: false, yb: false, minInternal: 1, - maxInternal: 999 + maxInternal: 999, }, digestion: { enzyme: undefined, minMissed: undefined, maxMissed: undefined, minResidue: undefined, - maxResidue: undefined + maxResidue: undefined, }, options: { protonate: false, @@ -37,10 +36,11 @@ define(function () { minimalHeight: 0, widthTop: 0.1, widthBottom: 0.2, - widthFunction: '// var widthBottom = 0.01 + mass / 8000;\r\n// var widthTop = widthBottom / 2;', + widthFunction: + '// var widthBottom = 0.01 + mass / 8000;\r\n// var widthTop = widthBottom / 2;', zone: { low: -0.5, - high: 4.5 + high: 4.5, }, mfRange: 'C0-100 H0-200 N0-10 O0-10 S0-5 F0-5 Cl0-5 Br0-5', maxResults: 200, @@ -53,7 +53,7 @@ define(function () { massRange: 0.1, decimalsPPM: 4, decimalsMass: 4, - addExperimentalExtract: true - } + addExperimentalExtract: true, + }, }; }); diff --git a/edx/channel.js b/edx/channel.js index d8be935f..d7fc7f6f 100644 --- a/edx/channel.js +++ b/edx/channel.js @@ -1,14 +1,16 @@ -define(['https://cdnjs.cloudflare.com/ajax/libs/jschannel/1.0.0-git-commit1-8c4f7eb/jschannel.js'], function () { - var initialized = false; +define([ + 'https://cdnjs.cloudflare.com/ajax/libs/jschannel/1.0.0-git-commit1-8c4f7eb/jschannel.js', +], function () { + let initialized = false; function init(options) { if (initialized) return; initialized = true; options = options || {}; - var state = { - a: 1 + let state = { + a: 1, }; - var channel; + let channel; // Establish a channel only if this application is embedded in an iframe. // This will let the parent window communicate with this application using @@ -17,7 +19,7 @@ define(['https://cdnjs.cloudflare.com/ajax/libs/jschannel/1.0.0-git-commit1-8c4f channel = self.Channel.build({ window: window.parent, origin: '*', - scope: 'JSInput' + scope: 'JSInput', }); channel.bind('getGrade', options.getGrade || getGrade); @@ -43,7 +45,7 @@ define(['https://cdnjs.cloudflare.com/ajax/libs/jschannel/1.0.0-git-commit1-8c4f // object that will not be used here // (see http://mozilla.github.io/jschannel/docs/) function setState(...args) { - var stateStr = args.length === 1 ? args[0] : args[1]; + let stateStr = args.length === 1 ? args[0] : args[1]; state = JSON.parse(stateStr); } } diff --git a/eln/BioReaction.js b/eln/BioReaction.js index 73031014..ee4eea36 100644 --- a/eln/BioReaction.js +++ b/eln/BioReaction.js @@ -9,7 +9,7 @@ import elnPlugin from './libs/elnPlugin'; const DataObject = Datas.DataObject; -var defaultOptions = { +let defaultOptions = { varName: 'sample', track: false, bindChange: true, @@ -17,9 +17,9 @@ var defaultOptions = { class BioReaction { constructor(couchDB, uuid, options) { - this.options = Object.assign({}, defaultOptions, options); + this.options = { ...defaultOptions, ...options }; - var roc = API.cache('roc'); + let roc = API.cache('roc'); if (!roc) { roc = new Roc({ url: couchDB.url, @@ -32,7 +32,7 @@ class BioReaction { this.roc = roc; if (options.onSync) { - var emitter = this.roc.getDocumentEventEmitter(uuid); + let emitter = this.roc.getDocumentEventEmitter(uuid); emitter.on('sync', () => options.onSync(true)); emitter.on('unsync', () => options.onSync(false)); } @@ -55,7 +55,7 @@ class BioReaction { this.sample.$content.general = {}; } - var sampleVar = API.getVar(this.options.varName); + let sampleVar = API.getVar(this.options.varName); createVar(sampleVar, 'reactionCode'); createVar(sampleVar, 'creationDate'); @@ -117,14 +117,14 @@ class BioReaction { } async handleDrop(name, askType) { - var type; + let type; if (!name) { throw new Error('handleDrop expects a variable name'); } name = String(name); if (!askType) { // maps name of variable to type of data - var types = { + let types = { droppedNmr: 'nmr', droppedIR: 'ir', droppedMS: 'mass', @@ -160,7 +160,7 @@ class BioReaction { // Dropped data can be an array // Expecting format as from drag and drop module - var droppedDatas = API.getData(name); + let droppedDatas = API.getData(name); droppedDatas = droppedDatas.file || droppedDatas.str; if (type === 'other') { @@ -187,9 +187,9 @@ class BioReaction { case 'attachNMR': case 'attachIR': case 'attachMass': { - var tempType = action.name.replace('attach', ''); - var type = tempType.charAt(0).toLowerCase() + tempType.slice(1); - var droppedDatas = action.value; + let tempType = action.name.replace('attach', ''); + let type = tempType.charAt(0).toLowerCase() + tempType.slice(1); + let droppedDatas = action.value; droppedDatas = droppedDatas.file || droppedDatas.str; await this.attachFiles(droppedDatas, type); break; diff --git a/eln/ExpandableMolecule.js b/eln/ExpandableMolecule.js index 3f14e705..6994a125 100644 --- a/eln/ExpandableMolecule.js +++ b/eln/ExpandableMolecule.js @@ -1,5 +1,6 @@ import API from 'src/util/api'; import UI from 'src/util/ui'; + import { OCL, OCLUtils } from './libs/OCLUtils'; const { Molecule } = OCL; @@ -17,7 +18,7 @@ const defaultOptions = { class ExpandableMolecule { constructor(sample, options) { - this.options = Object.assign({}, defaultOptions, options); + this.options = { ...defaultOptions, ...options }; this.sample = sample; this.molfile = String( this.sample.getChildSync(['$content', 'general', 'molfile']) || '', @@ -33,9 +34,9 @@ class ExpandableMolecule { // is this really a modification ? or a loop event ... // need to compare former oclID with new oclID - var newMolecule = Molecule.fromMolfile(`${event.target}`); + let newMolecule = Molecule.fromMolfile(`${event.target}`); - var oclID = newMolecule.getIDCodeAndCoordinates(); + let oclID = newMolecule.getIDCodeAndCoordinates(); if (oclID.idCode !== this.idCode) { this.idCode = oclID.idCode; this.molfile = `${event.target}`; @@ -128,12 +129,12 @@ class ExpandableMolecule { We create the view variable with or without expanded hydrogens */ createViewVariable() { - var molecule = Molecule.fromMolfile(this.molfile); + let molecule = Molecule.fromMolfile(this.molfile); let calculateDiastereotopicID = this.calculateDiastereotopicID; if (calculateDiastereotopicID) { // is it reasonnable to calculate the DiastereotopicID. We check the time it will take - var start = Date.now(); + let start = Date.now(); molecule.getCompactCopy().getIDCode(); let expected = (Date.now() - start) * 4 * molecule.getAllAtoms(); if (expected > this.maxDiastereotopicCalculationTime) { diff --git a/eln/ExtSample.js b/eln/ExtSample.js index a31059a5..7430f2a8 100644 --- a/eln/ExtSample.js +++ b/eln/ExtSample.js @@ -8,7 +8,7 @@ import elnPlugin from './libs/elnPlugin'; const idb = new IDB('external-samples'); const defaultOptions = { - varName: 'sample' + varName: 'sample', }; class Sample { @@ -16,35 +16,35 @@ class Sample { // make sure we don't copy attachment metadata const s = sample.$content ? { - $content: { - general: sample.$content.general, - spectra: { - nmr: [], - mass: [], - ir: [], - chromatogram: [] + $content: { + general: sample.$content.general, + spectra: { + nmr: [], + mass: [], + ir: [], + chromatogram: [], + }, + identifier: sample.$content.identifier, + stock: sample.$content.stock, }, - identifier: sample.$content.identifier, - stock: sample.$content.stock } - } : { - $content: { - general: { - title: '', - description: '', - mf: '', - molfile: '' - }, - spectra: { - nmr: [], - mass: [], - ir: [], - chromatogram: [] + $content: { + general: { + title: '', + description: '', + mf: '', + molfile: '', + }, + spectra: { + nmr: [], + mass: [], + ir: [], + chromatogram: [], + }, + image: [], }, - image: [] - } - }; + }; this.sample = JSON.parse(JSON.stringify(s)); @@ -71,12 +71,12 @@ class Sample { API.setVariable('chromatogram', sampleVar, [ '$content', 'spectra', - 'chromatogram' + 'chromatogram', ]); API.setVariable('description', sampleVar, [ '$content', 'general', - 'description' + 'description', ]); API.setVariable('title', sampleVar, ['$content', 'general', 'title']); API.setVariable('iupac', sampleVar, ['$content', 'general', 'iupac']); @@ -133,7 +133,7 @@ class Sample { } sample = await API.createData( this.options.varName, - sample || this.sample + sample || this.sample, ); if (sample.$content.general.molfile) { @@ -179,7 +179,7 @@ class Sample { droppedDCS: 'differentialCentrifugalSedimentation', droppedXRF: 'xrf', droppedImage: 'image', - droppedGenbank: 'genbank' + droppedGenbank: 'genbank', }; if (!types[name]) { @@ -214,13 +214,13 @@ class Sample { mimetype: 'chemical/x-jcamp-dx', contentType: 'chemical/x-jcamp-dx', encoding: 'utf8', - content: converted[i] + content: converted[i], }); } droppedData.filename = droppedData.filename.replace( `.${extension}`, - '.jdx' + '.jdx', ); droppedData.mimetype = 'chemical/x-jcamp-dx'; droppedData.contentType = 'chemical/x-jcamp-dx'; @@ -233,7 +233,7 @@ class Sample { this.sample.$content, droppedData, {}, - { keepContent: true } + { keepContent: true }, ); } this.sample.triggerChange(); diff --git a/eln/MF.js b/eln/MF.js index fd62a888..a69d96ca 100644 --- a/eln/MF.js +++ b/eln/MF.js @@ -1,8 +1,8 @@ import API from 'src/util/api'; import UI from 'src/util/ui'; -import { OCL, OCLUtils } from './libs/OCLUtils'; import MolecularFormula from './libs/MolecularFormula'; +import { OCL, OCLUtils } from './libs/OCLUtils'; class MF { constructor(sample) { @@ -21,7 +21,6 @@ class MF { this.setCanonizedMF(mfInfo.mf); this.previousEMMF = mfInfo.monoisotopicMass; } catch (e) { - // eslint-disable-next-line no-console this.setCanonizedMF(''); console.log('Could not parse MF: ', mf); } @@ -30,16 +29,13 @@ class MF { } getIsotopicDistributionInstance(options) { - options = Object.assign( - {}, - { - ionizations: '+', - fwhm: 0.01, - maxLines: 5000, - minY: 1e-8 - }, - options - ); + options = { + ionizations: '+', + fwhm: 0.01, + maxLines: 5000, + minY: 1e-8, + ...options, + }; return new MolecularFormula.IsotopicDistribution(this.getMF(), options); } @@ -58,7 +54,7 @@ class MF { } fromMolfile() { - var mfInfo = this._mfInfoFromMolfile(); + let mfInfo = this._mfInfoFromMolfile(); if (mfInfo && this.previousEMMolfile !== mfInfo.monoisotopicMass) { this.previousEMMolfile = mfInfo.monoisotopicMass; this.setMF(mfInfo.mf); @@ -70,10 +66,10 @@ class MF { } _mfInfoFromMolfile() { - var molfile = this.getMolfile(); + let molfile = this.getMolfile(); if (molfile) { - var molecule = OCL.Molecule.fromMolfile(molfile); - var mf = OCLUtils.getMF(molecule).parts.join(' . '); + let molecule = OCL.Molecule.fromMolfile(molfile); + let mf = OCLUtils.getMF(molecule).parts.join(' . '); try { let mfInfo = new MolecularFormula.MF(mf).getInfo(); mfInfo.mf = mf; @@ -89,7 +85,7 @@ class MF { getMF() { return String( - this.sample.getChildSync(['$content', 'general', 'mf']) || '' + this.sample.getChildSync(['$content', 'general', 'mf']) || '', ); } @@ -122,7 +118,7 @@ class MF { this.setCanonizedMF(''); return; } - var mfInfo = new MolecularFormula.MF(this.getMF()).getInfo(); + let mfInfo = new MolecularFormula.MF(this.getMF()).getInfo(); if (this.previousEMMF !== mfInfo.monoisotopicMass) { this.previousEMMF = mfInfo.monoisotopicMass; this.setCanonizedMF(mfInfo.mf); @@ -139,16 +135,16 @@ class MF { } _mfColor() { - var existingMF = this.getMF(); - var molfile = this.getMolfile(); + let existingMF = this.getMF(); + let molfile = this.getMolfile(); if (molfile) { - var molecule = OCL.Molecule.fromMolfile(molfile); - var mf = molecule.getMolecularFormula().formula; - var existingMW = existingMF + let molecule = OCL.Molecule.fromMolfile(molfile); + let mf = molecule.getMolecularFormula().formula; + let existingMW = existingMF ? new MolecularFormula.MF(existingMF).getInfo().mw : 0; - var newMW = mf ? new MolecularFormula.MF(mf).getInfo().mw : 0; + let newMW = mf ? new MolecularFormula.MF(mf).getInfo().mw : 0; if (newMW !== existingMW) { API.createData('mfBGColor', 'pink'); } else { diff --git a/eln/Nmr1dManager.js b/eln/Nmr1dManager.js index 3a8deec2..5e7f54aa 100644 --- a/eln/Nmr1dManager.js +++ b/eln/Nmr1dManager.js @@ -3,9 +3,9 @@ import API from 'src/util/api'; import UI from 'src/util/ui'; import { getData } from './jpaths'; +import MolecularFormula from './libs/MolecularFormula'; import SD from './libs/SD'; import * as GUI from './nmrGUI'; -import MolecularFormula from './libs/MolecularFormula'; const Ranges = SD.Ranges; const NMR = SD.NMR; @@ -111,14 +111,14 @@ class Nmr1dManager { break; } case 'downloadSVG': { - var blob = new Blob([`${action.value}`], { + let blob = new Blob([`${action.value}`], { type: 'image/svg+xml;charset=utf-8', }); fileSaver(blob, 'spectra.svg'); break; } case 'toggleNMR1hAdvancedOptions': { - var advancedOptions1H = !API.cache('nmr1hAdvancedOptions'); + let advancedOptions1H = !API.cache('nmr1hAdvancedOptions'); API.cache('nmr1hAdvancedOptions', advancedOptions1H); if (advancedOptions1H) { API.createData( @@ -134,7 +134,7 @@ class Nmr1dManager { break; } case 'resetNMR1d': { - var type = action.name.replace(/[^0-9]/g, ''); + let type = action.name.replace(/[^0-9]/g, ''); type = `${type}d`; API.createData(`blackNMR${type}`, null); API.createData(`annotationNMR${type}`, null); @@ -142,7 +142,7 @@ class Nmr1dManager { break; } case 'switchNMRLayer': { - var goToLayer = + let goToLayer = action.value && action.value.dimension > 1 ? 'nmr2D' : 'Default layer'; @@ -153,20 +153,18 @@ class Nmr1dManager { } else { API.createData('blackNMR2d', null); } + } else if (action.value.jcamp) { + API.createData('blackNMR1d', action.value.jcamp.data); } else { - if (action.value.jcamp) { - API.createData('blackNMR1d', action.value.jcamp.data); - } else { - API.createData('blackNMR1d', null); - } + API.createData('blackNMR1d', null); } break; } case 'executePeakPicking': { - var options = API.getData('nmr1hOptions'); + let options = API.getData('nmr1hOptions'); delete options.from; delete options.to; - var currentNmr = API.getData('currentNmr'); + let currentNmr = API.getData('currentNmr'); if (currentNmr.dimension > 1) { if (typeof UI !== 'undefined') { UI.showNotification( @@ -201,7 +199,7 @@ class Nmr1dManager { break; } case 'clearAllAssignments': { - var nmr = this.sample.$content.spectra.nmr; + let nmr = this.sample.$content.spectra.nmr; nmr.forEach((n) => { if (n.range) { n.range.forEach((a) => { @@ -278,7 +276,7 @@ class Nmr1dManager { const spectrum = await this._getNMR(nmr); if (spectrum && spectrum.sd && nmr.range && nmr.range.length > 0) { const ranges = new Ranges(nmr.range); - var ppOptions = API.getData('nmr1hOptions'); + let ppOptions = API.getData('nmr1hOptions'); spectrum.updateIntegrals(ranges, { nH: Number(ppOptions.integral), }); @@ -286,32 +284,30 @@ class Nmr1dManager { } updateIntegrals(integral) { - var ppOptions = API.getData('nmr1hOptions'); - var currentRanges = this.getCurrentRanges(); + let ppOptions = API.getData('nmr1hOptions'); + let currentRanges = this.getCurrentRanges(); if (!currentRanges || currentRanges.length === 0) return; // We initialize ranges with the DataObject so that // the integral update is inplace - var ranges = new Ranges(currentRanges); + let ranges = new Ranges(currentRanges); ranges.updateIntegrals({ sum: Number(ppOptions.integral || integral) }); currentRanges.triggerChange(); } _getNMR(currentNMRLine) { - var filename = String(currentNMRLine.getChildSync(['jcamp', 'filename'])); + let filename = String(currentNMRLine.getChildSync(['jcamp', 'filename'])); return currentNMRLine.getChild(['jcamp', 'data']).then((jcamp) => { if (filename && this.spectra[filename]) { var spectrum = this.spectra[filename]; - } else { - if (jcamp) { - jcamp = String(jcamp.get()); - spectrum = NMR.fromJcamp(jcamp); - if (filename) { - this.spectra[filename] = spectrum; - } - } else { - spectrum = new NMR(); + } else if (jcamp) { + jcamp = String(jcamp.get()); + spectrum = NMR.fromJcamp(jcamp); + if (filename) { + this.spectra[filename] = spectrum; } + } else { + spectrum = new NMR(); } return spectrum; }); @@ -319,8 +315,8 @@ class Nmr1dManager { _autoRanges(nmrLine) { this._getNMR(nmrLine).then((nmrSpectrum) => { - var ppOptions = API.getData('nmr1hOptions').resurrect(); - var removeImpurityOptions = {}; + let ppOptions = API.getData('nmr1hOptions').resurrect(); + let removeImpurityOptions = {}; if (ppOptions.removeImpurities.useIt) { removeImpurityOptions = { solvent: nmrLine.solvent, @@ -328,7 +324,7 @@ class Nmr1dManager { error: ppOptions.removeImpurities.error, }; } - var ranges = nmrSpectrum.getRanges({ + let ranges = nmrSpectrum.getRanges({ nH: Number(ppOptions.integral), realTop: true, thresholdFactor: Number(ppOptions.noiseFactor), @@ -346,11 +342,11 @@ class Nmr1dManager { } async _createNMRannotationsAndACS() { - var nmrLine = API.getData('currentNmr'); - var ranges = nmrLine.range; - var nmrSpectrum = await this._getNMR(nmrLine); - var nucleus = nmrLine.nucleus[0]; - var observe = nmrLine.frequency; + let nmrLine = API.getData('currentNmr'); + let ranges = nmrLine.range; + let nmrSpectrum = await this._getNMR(nmrLine); + let nucleus = nmrLine.nucleus[0]; + let observe = nmrLine.frequency; if (nmrSpectrum && nmrSpectrum.sd) { nucleus = nmrSpectrum.getNucleus(0); observe = nmrSpectrum.observeFrequencyX(); @@ -393,7 +389,7 @@ class Nmr1dManager { } updateIntegralOptionsFromMF() { - var options = API.getData('nmr1hOptions'); + let options = API.getData('nmr1hOptions'); const currentIntegral = Number(options.integral); const newIntegral = this.getNumberHydrogens(); if (currentIntegral !== newIntegral) { @@ -403,7 +399,7 @@ class Nmr1dManager { // todo : migrate this code to spectra-data-ranges getRangesTotalIntegral() { - var ranges = API.getData('currentNmrRanges') || []; + let ranges = API.getData('currentNmrRanges') || []; let sum = 0; for (const range of ranges) { if (SD.Ranges.shouldIntegrate(range)) { @@ -414,7 +410,7 @@ class Nmr1dManager { } updateIntegralOptionsFromRanges() { - var options = API.getData('nmr1hOptions'); + let options = API.getData('nmr1hOptions'); const currentIntegral = Number(options.integral); const newIntegral = Math.round(this.getRangesTotalIntegral()); if (currentIntegral !== newIntegral && newIntegral > 0) { diff --git a/eln/Sample.js b/eln/Sample.js index 4de19718..25f3d871 100644 --- a/eln/Sample.js +++ b/eln/Sample.js @@ -852,12 +852,12 @@ async function pasteAnalysis(sample) { let i = 0; do { if (filename.includes('.')) { - const newName = filename.replace(/(.*)(\..*)/, '$1_' + i + '$2'); + const newName = filename.replace(/(.*)(\..*)/, `$1_${i}$2`); if (!existingAttachments[newName]) { return newName; } } else { - return filename + '_' + i; + return `${filename}_${i}`; } i++; } while (i < 500); diff --git a/eln/SampleFactory.js b/eln/SampleFactory.js index 99a3cd0a..0fe418eb 100644 --- a/eln/SampleFactory.js +++ b/eln/SampleFactory.js @@ -1,7 +1,7 @@ import Sample from './ExtSample'; export async function extSample(options = {}) { - var sample = new Sample({}, options); + let sample = new Sample({}, options); await sample._initialized; return sample; } diff --git a/eln/Sequence.js b/eln/Sequence.js index 9b95fcd0..1e2fd50a 100644 --- a/eln/Sequence.js +++ b/eln/Sequence.js @@ -3,7 +3,7 @@ import translateDNA from '../biology/translateDNA'; import MolecularFormula from './libs/MolecularFormula'; function explodeSequences(sample) { - var sequencePeptidic = getFirstPeptide(sample); + let sequencePeptidic = getFirstPeptide(sample); if (sequencePeptidic && sequencePeptidic.sequence) { sequencePeptidic.sequence = MolecularFormula.Peptide.sequenceToMF( @@ -11,7 +11,7 @@ function explodeSequences(sample) { ); } - var sequenceNucleic = getFirstNucleotide(sample); + let sequenceNucleic = getFirstNucleotide(sample); if (sequenceNucleic && sequenceNucleic.sequence) { sequenceNucleic.sequence = MolecularFormula.Nucleotide.sequenceToMF( String(sequenceNucleic.sequence), @@ -256,9 +256,9 @@ const sequencesInformationTwigTemplate = `