-
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.
feat(meanFilter): filter a serie2D by it's median (#36)
* feat(meanFilter): filter a serie2D by it's median * feat(meanFilter): allows to rename the filtered serie
- Loading branch information
1 parent
1025fdf
commit e68ba9b
Showing
5 changed files
with
112 additions
and
4 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
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,62 @@ | ||
import {Chromatogram} from '../..'; | ||
import {meanFilter} from '../../ms/meanFilter'; | ||
|
||
test('simple case', () => { | ||
let chromatogram = new Chromatogram( | ||
[1, 2], { | ||
ms: [ | ||
[[100, 200, 300], [10, 20, 300]], | ||
[[600], [274]] | ||
] | ||
} | ||
); | ||
|
||
let ms = meanFilter(chromatogram, 'ms'); | ||
expect(ms.data).toEqual([ | ||
[[300], [300]], | ||
[[], []] | ||
]); | ||
}); | ||
|
||
describe('inplace', () => { | ||
it('default behavior', () => { | ||
let chromatogram = new Chromatogram( | ||
[1, 2], { | ||
ms: [ | ||
[[100, 200, 300], [10, 20, 300]], | ||
[[600], [274]] | ||
] | ||
} | ||
); | ||
chromatogram.meanFilter('ms'); | ||
expect(chromatogram.series.msMedian.data).toEqual([ | ||
[[300], [300]], | ||
[[], []] | ||
]); | ||
expect(chromatogram.series.ms.data).toEqual([ | ||
[[100, 200, 300], [10, 20, 300]], | ||
[[600], [274]] | ||
]); | ||
}); | ||
|
||
it('input name', () => { | ||
let chromatogram = new Chromatogram( | ||
[1, 2], { | ||
ms: [ | ||
[[100, 200, 300], [10, 20, 300]], | ||
[[600], [274]] | ||
] | ||
} | ||
); | ||
chromatogram.meanFilter('ms', {serieName: 'filtered'}); | ||
expect(chromatogram.series.filtered.data).toEqual([ | ||
[[300], [300]], | ||
[[], []] | ||
]); | ||
expect(chromatogram.series.ms.data).toEqual([ | ||
[[100, 200, 300], [10, 20, 300]], | ||
[[600], [274]] | ||
]); | ||
}); | ||
}); | ||
|
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,28 @@ | ||
import arrayMean from 'ml-array-mean'; | ||
import {serieFromArray} from '../serieFromArray'; | ||
|
||
export function meanFilter(chromatogram, serieName, options = {}) { | ||
const { | ||
factor = 2 | ||
} = options; | ||
|
||
var serie = chromatogram.getSerie(serieName); | ||
var filtered = []; | ||
for (var i = 0; i < serie.data.length; i++) { | ||
filtered.push(applyFilter(serie.data[i], factor)); | ||
} | ||
|
||
return serieFromArray(filtered); | ||
} | ||
|
||
function applyFilter(serie, factor) { | ||
const meanIntensity = factor * arrayMean(serie[1]); | ||
var filtered = [[], []]; | ||
for (var i = 0; i < serie[0].length; i++) { | ||
if (serie[1][i] > meanIntensity) { | ||
filtered[0].push(serie[0][i]); | ||
filtered[1].push(serie[1][i]); | ||
} | ||
} | ||
return filtered; | ||
} |
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