Skip to content

Commit

Permalink
feat!: setup typescript (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
wadjih-bencheikh18 authored Oct 26, 2021
1 parent edd8a79 commit 4e61017
Show file tree
Hide file tree
Showing 42 changed files with 65,181 additions and 338 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
extends: cheminfo
extends: cheminfo-typescript
parserOptions:
sourceType: module
37 changes: 5 additions & 32 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,9 @@ on:
branches: master
pull_request:

env:
NODE_VERSION: 14.x

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: npm install
- name: Run ESLint
run: npm run eslint
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test-coverage
- name: Send coverage report to Codecov
uses: codecov/codecov-action@v1
nodejs:
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
with:
node-version-matrix: '[14, 16]'
lint-check-types: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist
lib
coverage
.eslintcache
lib-esm
130 changes: 44 additions & 86 deletions CHANGELOG.md

Large diffs are not rendered by default.

3,948 changes: 3,947 additions & 1 deletion examples/data.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions examples/example.js → examples/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { join } from 'path';

import { generateSpectrum } from 'spectrum-generator';

import { gsd, optimizePeaks } from '../src';
import { DataType, gsd, optimizePeaks } from '../src';

const peaks = [
{ x: -0.1, y: 0.2, width: 0.3 },
Expand All @@ -20,14 +20,18 @@ const peaks = [
const from = -1;
const to = 1;

const original = generateSpectrum(peaks, { from, to, nbPoints: 101 });
const original = generateSpectrum(peaks, {
from,
to,
nbPoints: 101,
});

let peakList = gsd(original, {
minMaxRatio: 0,
realTopDetection: false,
smoothY: false,
heightFactor: 1,
shape: { kind: 'gaussian' },
shape: { kind: 'gaussian', width: 0 },
});

let optimizedPeaks = optimizePeaks(original, peakList);
Expand Down Expand Up @@ -63,8 +67,8 @@ let reconstructed = generateSpectrum(optimizedPeaks, {
to,
nbPoints: 5001,
});
reconstructed.x = Array.from(reconstructed.x)
reconstructed.y = Array.from(reconstructed.y)
reconstructed.x = Array.from(reconstructed.x);
reconstructed.y = Array.from(reconstructed.y);

original.x = Array.from(original.x);
original.y = Array.from(original.y);
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
46 changes: 26 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@
"name": "ml-gsd",
"version": "7.0.1",
"description": "Global Spectra Deconvolution",
"main": "lib/index.js",
"module": "src/index.js",
"main": "./lib/index.js",
"module": "./lib-esm/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib",
"src"
"src",
"lib-esm"
],
"env": {
"jest": true
},
"scripts": {
"build": "rollup -c && cheminfo-build --entry src/index.js --root GSD",
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"example": "nodemon -w src -w examples/example.js -r esm examples/example.js",
"eslint": "eslint src --cache",
"eslint-fix": "npm run eslint -- --fix",
"compile": "rollup -c",
"prepack": "npm run compile",
"prepack": "npm run compile && npm run tsc",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test": "npm run test-coverage && npm run eslint",
"test": "npm run test-coverage && npm run eslint && npm run check-types",
"test-only": "jest",
"test-coverage": "jest --coverage"
"test-coverage": "jest --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc --project tsconfig.cjs.json",
"tsc-esm": "tsc --project tsconfig.esm.json"
},
"repository": {
"type": "git",
Expand All @@ -45,9 +51,6 @@
"url": "https://github.com/mljs/global-spectral-deconvolution/issues"
},
"homepage": "https://github.com/mljs/global-spectral-deconvolution",
"jest": {
"testEnvironment": "node"
},
"prettier": {
"arrowParens": "always",
"semi": true,
Expand All @@ -56,25 +59,28 @@
"trailingComma": "all"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.15.4",
"@types/jest": "^27.0.2",
"chemcalc": "^3.4.1",
"cheminfo-build": "^1.1.11",
"eslint": "^7.32.0",
"eslint-config-cheminfo": "^5.5.0",
"eslint": "^8.1.0",
"eslint-config-cheminfo-typescript": "^10.1.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jest": "^25.2.2",
"esm": "^3.2.25",
"jest": "^27.2.4",
"jest-matcher-deep-close-to": "^3.0.0",
"mf-global": "^1.4.6",
"jest": "^27.3.1",
"jest-matcher-deep-close-to": "^3.0.2",
"mf-global": "^1.4.7",
"ml-stat": "^1.3.3",
"nodemon": "^2.0.13",
"nodemon": "^2.0.14",
"prettier": "^2.4.1",
"rollup": "^2.58.0",
"spectrum-generator": "^5.4.0",
"rimraf": "^3.0.2",
"spectrum-generator": "^5.4.1",
"ts-jest": "^27.0.7",
"typescript": "^4.4.4",
"xy-parser": "^3.2.0"
},
"dependencies": {
"cheminfo-types": "^0.5.0",
"cheminfo-types": "^0.6.0",
"ml-peak-shape-generator": "^2.0.2",
"ml-savitzky-golay-generalized": "2.0.3",
"ml-spectra-fitting": "^2.0.0",
Expand Down
8 changes: 0 additions & 8 deletions rollup.config.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import { readFileSync } from 'fs';
import { join } from 'path';

let { gsd, joinBroadPeaks } = require('..');
import { gsd, joinBroadPeaks } from '..';

describe('Global spectra deconvolution NMR spectra', () => {
it('Should give 120 peaks', () => {
let spectrum = JSON.parse(
let spectrum: number[][] = JSON.parse(
readFileSync(join(__dirname, '/data/bigLowS2NSpectrum.json'), 'utf8'),
);

Expand All @@ -22,7 +22,6 @@ describe('Global spectra deconvolution NMR spectra', () => {
sgOptions: { windowSize: 13, polynomial: 3 },
},
);

pp = joinBroadPeaks(pp, { width: 0.25 });

expect(pp).toHaveLength(91);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { readFileSync } from 'fs';
import { join } from 'path';

let { gsd, joinBroadPeaks } = require('..');
import { gsd, joinBroadPeaks } from '..';

describe('Global spectra deconvolution NMR spectra', () => {
// Test case obtained from Pag 443, Chap 8.
it('Should give 1 broad peak and around 14 other peaks', () => {
let spectrum = JSON.parse(
let spectrum: number[][] = JSON.parse(
readFileSync(join(__dirname, '/data/broadNMR.json'), 'utf-8'),
);
let result = gsd(
Expand All @@ -21,7 +21,10 @@ describe('Global spectra deconvolution NMR spectra', () => {
},
},
);
const newResult = joinBroadPeaks(result, { width: 0.25, shape: { kind: 'lorentzian' } });
const newResult = joinBroadPeaks(result, {
width: 0.25,
shape: { kind: 'lorentzian', width: 0 },
});
expect(newResult).toHaveLength(14);
newResult.forEach((peak) => {
if (Math.abs(peak.x - 4.31) < 0.01) {
Expand Down
377 changes: 376 additions & 1 deletion src/__tests__/data/C2.json

Large diffs are not rendered by default.

52,084 changes: 52,083 additions & 1 deletion src/__tests__/data/bigLowS2NSpectrum.json

Large diffs are not rendered by default.

1,273 changes: 1,272 additions & 1 deletion src/__tests__/data/broadNMR.json

Large diffs are not rendered by default.

6,499 changes: 6,498 additions & 1 deletion src/__tests__/data/ethylvinylether.json

Large diffs are not rendered by default.

559 changes: 557 additions & 2 deletions src/__tests__/data/infraRed.json

Large diffs are not rendered by default.

37 changes: 36 additions & 1 deletion src/__tests__/data/test.json
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
[[7,9,9.1,9.2,9.3,9.4,9.5,9.6,9.7,9.8,9.9,10,10.1,10.2,10.3,10.4,10.5,10.6,10.7,10.8,10.9,11,11.1,11.2,11.3,11.4,11.5,11.6,11.7,11.8,11.9,12,12.1,12.2,12.3,12.4,12.5,12.6,12.7,12.8,12.9,13,13.1,13.2,13.3,13.4,13.5,13.6,13.7,13.8,13.9,14,14.1,14.2,14.3,14.4,14.5,14.6,14.7,14.8,14.9,15,15.1,15.2,15.3,15.4,15.5,15.6,15.7,15.8,15.9,16,18],[0,1.3670611642005019e-12,7.018086806749659e-12,3.408530039598323e-11,1.566149139777829e-10,6.807955480447043e-10,2.799741264282628e-9,1.0892728768715286e-8,4.0093417978312345e-8,1.3961339042194703e-7,4.5993733696714487e-7,0.0000014334675420984624,0.000004226634174912734,0.000011790142647798723,0.00003111437370683429,0.00007768204955055934,0.00018348387377726662,0.0004100083945771263,0.0008667727242782787,0.001733546091298024,0.0032800711886719187,0.005871498495868112,0.009943347114095245,0.01593068598959557,0.0241465479122752,0.03462542672692695,0.046973848446379925,0.06028934116907687,0.07320700001112898,0.0841007412472281,0.09141030799602905,0.09400723223468063,0.09148237573734981,0.08425429229202339,0.0734587840992098,0.06065939675121234,0.04747989885270652,0.0352766117093386,0.024937897013924,0.016839966447159693,0.010931586752334044,0.0068875528273207405,0.004268351566479456,0.0026429525578170743,0.001658457916881255,0.001062033447037501,0.0006915187612199856,0.00045217216244198535,0.00029227323368097015,0.00018409073424885283,0.00011177068037381833,0.00006493783224280769,0.00003593624229100207,0.00001888916056485795,0.000009414867005196313,0.000004445430848023085,0.0000019873111386235026,8.408686570700081e-7,3.366812086048201e-7,1.2755306072424386e-7,4.5721144094463724e-8,1.5505362353033094e-8,4.974557268319468e-9,1.5100204968309241e-9,4.3363951518037203e-10,1.1781279472885229e-10,3.028124080443153e-11,7.363299670553255e-12,1.6939043561733317e-12,3.6865734785911304e-13,7.590572003661311e-14,1.4785762111538834e-14,0]]
[
[
7, 9, 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9, 10, 10.1, 10.2, 10.3,
10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 11, 11.1, 11.2, 11.3, 11.4, 11.5, 11.6,
11.7, 11.8, 11.9, 12, 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 12.8, 12.9,
13, 13.1, 13.2, 13.3, 13.4, 13.5, 13.6, 13.7, 13.8, 13.9, 14, 14.1, 14.2,
14.3, 14.4, 14.5, 14.6, 14.7, 14.8, 14.9, 15, 15.1, 15.2, 15.3, 15.4, 15.5,
15.6, 15.7, 15.8, 15.9, 16, 18
],
[
0, 1.3670611642005019e-12, 7.018086806749659e-12, 3.408530039598323e-11,
1.566149139777829e-10, 6.807955480447043e-10, 2.799741264282628e-9,
1.0892728768715286e-8, 4.0093417978312345e-8, 1.3961339042194703e-7,
4.5993733696714487e-7, 0.0000014334675420984624, 0.000004226634174912734,
0.000011790142647798723, 0.00003111437370683429, 0.00007768204955055934,
0.00018348387377726662, 0.0004100083945771263, 0.0008667727242782787,
0.001733546091298024, 0.0032800711886719187, 0.005871498495868112,
0.009943347114095245, 0.01593068598959557, 0.0241465479122752,
0.03462542672692695, 0.046973848446379925, 0.06028934116907687,
0.07320700001112898, 0.0841007412472281, 0.09141030799602905,
0.09400723223468063, 0.09148237573734981, 0.08425429229202339,
0.0734587840992098, 0.06065939675121234, 0.04747989885270652,
0.0352766117093386, 0.024937897013924, 0.016839966447159693,
0.010931586752334044, 0.0068875528273207405, 0.004268351566479456,
0.0026429525578170743, 0.001658457916881255, 0.001062033447037501,
0.0006915187612199856, 0.00045217216244198535, 0.00029227323368097015,
0.00018409073424885283, 0.00011177068037381833, 0.00006493783224280769,
0.00003593624229100207, 0.00001888916056485795, 0.000009414867005196313,
0.000004445430848023085, 0.0000019873111386235026, 8.408686570700081e-7,
3.366812086048201e-7, 1.2755306072424386e-7, 4.5721144094463724e-8,
1.5505362353033094e-8, 4.974557268319468e-9, 1.5100204968309241e-9,
4.3363951518037203e-10, 1.1781279472885229e-10, 3.028124080443153e-11,
7.363299670553255e-12, 1.6939043561733317e-12, 3.6865734785911304e-13,
7.590572003661311e-14, 1.4785762111538834e-14, 0
]
]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { readFileSync } from 'fs';

import { gsd } from '..';
import { gsd } from '../gsd';

describe('Global spectra deconvolution NMR spectra', () => {
// Test case obtained from Pag 443, Chap 8.
it('Ethylvinylether should have 21 peaks', () => {
let spectrum = JSON.parse(
let spectrum: number[][] = JSON.parse(
readFileSync(`${__dirname}/data/ethylvinylether.json`, 'utf-8'),
);
let result = gsd(
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/general.test.js → src/__tests__/general.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readFileSync } from 'fs';
import { join } from 'path';

import { gsd } from '..';
import { gsd } from '../gsd';

function lorentzian(x, x0 = 0, gamma = 1) {
function lorentzian(x: number, x0 = 0, gamma = 1) {
return (
(gamma * gamma) / (Math.PI * gamma * (gamma * gamma + (x - x0) * (x - x0)))
);
Expand All @@ -12,7 +12,7 @@ function lorentzian(x, x0 = 0, gamma = 1) {
describe('Global spectra deconvolution simple simulated spectrum', () => {
// Test case obtained from Pag 443, Chap 8.
it('Should provide the right result ...', () => {
let spectrum = JSON.parse(
let spectrum: number[][] = JSON.parse(
readFileSync(join(__dirname, '/data//C2.json'), 'utf8'),
);
let result = gsd(
Expand All @@ -35,8 +35,8 @@ describe('Global spectra deconvolution simple simulated spectrum', () => {
it('Should give 10 peaks', () => {
const size = 300;
const fourth = size / 11;
let times = new Array(size);
let tic = new Array(size);
let times: number[] = new Array(size);
let tic: number[] = new Array(size);

for (let i = 0; i < size; ++i) {
times[i] = i;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { readFileSync } from 'fs';

import { gsd } from '..';
import { DataType, gsd } from '../gsd';

describe('Global spectra deconvolution Infrared spectra', () => {
// Test case obtained from Pag 443, Chap 8.
it('Should get the correct result', () => {
let spectrum = JSON.parse(
let spectrum: DataType = JSON.parse(
readFileSync(`${__dirname}/data/infraRed.json`, 'utf-8'),
);
gsd(spectrum, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { gsd, optimizePeaks } from '..';
import CC from 'chemcalc';
import Stat from 'ml-stat';

let CC = require('chemcalc');
let Stat = require('ml-stat');
import { DataType, gsd, optimizePeaks } from '..';

let spectrum = CC.analyseMF('Cl2.Br2', {
isotopomers: 'arrayXXYY',
fwhm: 0.01,
gaussianWidth: 11,
});
let xy = spectrum.arrayXXYY;
let x = xy[0];
let y = xy[1];
let xy: DataType = spectrum.arrayXXYY;
let x: number[] = xy[0];
let y: number[] = xy[1];
let max = Stat.array.max(y);
let noiseLevel = Stat.array.median(y.filter((a) => a > 0)) * 3;
let noiseLevel = Stat.array.median(y.filter((a: number) => a > 0)) * 3;
/*
69.938 100
71.935 63.99155
Expand All @@ -39,6 +39,7 @@ describe('Check the peak picking of a simulated mass spectrum', () => {
factorWidth: 4,
shape: {
kind: 'gaussian',
width: 0,
},
});
expect(result[0].x).toBeCloseTo(69.938, 1);
Expand Down
Loading

0 comments on commit 4e61017

Please sign in to comment.