-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from cheminfo-js/massIntegration
Mass integration closes #23
- Loading branch information
Showing
11 changed files
with
124 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {serieFromArray} from '../serieFromArray'; | ||
|
||
test('Errors', () => { | ||
expect(() => serieFromArray(1)).toThrow('Serie.fromArray requires as parameter an array of numbers or array'); | ||
expect(() => serieFromArray(['a'])).toThrow('Serie.fromArray requires as parameter an array of numbers or array'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {integrate, Chromatogram} from '../..'; | ||
import {integrate2D} from '../../util/integrate2D'; | ||
import {simple} from '../data/examples'; | ||
|
||
const highResolution = new Chromatogram( | ||
[1, 2], { | ||
ms: [ | ||
[[100.002, 200.02, 300.0002], [10, 20, 30]], | ||
[[100.001, 200.01, 300.0001], [11, 21, 31]], | ||
] | ||
} | ||
); | ||
|
||
test('Low resolution', () => { | ||
var result = integrate(simple, [1, 2]); | ||
expect(result).toEqual({ms: [ | ||
[100, 101, 200, 201, 300, 301], | ||
[10, 11, 20, 21, 30, 31] | ||
]}); | ||
}); | ||
|
||
test('High resolution', () => { | ||
expect(integrate(highResolution, [1, 2])).toEqual({ms: [ | ||
[100, 200, 300], | ||
[21, 41, 61] | ||
]}); | ||
|
||
expect(integrate(highResolution, [1, 2], { | ||
slot: 0.01 | ||
})).toEqual({ms: [ | ||
[100.00, 200.01, 200.02, 300.00], | ||
[21, 21, 20, 61] | ||
]}); | ||
}); | ||
|
||
test('Errors', () => { | ||
expect(() => integrate2D([])).toThrow('The serie is not of dimension 2'); | ||
expect(integrate2D({dimension: 2})).toEqual([]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
export function integrate2D(time, serie, from, to, fromIndex, toIndex) { | ||
if (serie.dimension !== 1) throw new Error('The serie is not of dimension 2'); | ||
import {asc} from 'num-sort'; | ||
|
||
export function integrate2D(serie, fromIndex, toIndex, slot) { | ||
if (serie.dimension !== 2) throw new Error('The serie is not of dimension 2'); | ||
if (!serie.data) return []; | ||
|
||
let data = []; | ||
for (let i = fromIndex; i <= toIndex; i++) { | ||
let massDictionary = {}; | ||
|
||
// TODO | ||
/* | ||
for (var j = 0; j < ms[i][0].length; j++) { | ||
// search possible position | ||
var position = { | ||
index: -1, | ||
distance: Number.MAX_VALUE | ||
}; | ||
for (var k = 0; k < masses.length; k++) { | ||
// TODO work in progress | ||
} | ||
for (var i = fromIndex; i <= toIndex; i++) { | ||
for (var j = 0; j < serie.data[i][0].length; j++) { | ||
// round the mass value | ||
var x = serie.data[i][0][j]; | ||
let mass = x + slot / 2 - (x + slot / 2) % slot; | ||
|
||
// check if merge needed | ||
// add the mass value to the dictionary | ||
if (massDictionary[mass]) { | ||
massDictionary[mass] += serie.data[i][1][j]; | ||
} else { | ||
massDictionary[mass] = serie.data[i][1][j]; | ||
} | ||
} | ||
*/ | ||
} | ||
|
||
const massList = Object.keys(massDictionary).map((val) => Number(val)).sort(asc); | ||
let integral = [ | ||
new Array(massList.length), | ||
new Array(massList.length) | ||
]; | ||
|
||
for (var k = 0; k < massList.length; k++) { | ||
integral[0][k] = Number(massList[k]); | ||
integral[1][k] = massDictionary[massList[k]]; | ||
} | ||
return data; | ||
return integral; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters