Skip to content

Commit

Permalink
fix: update MS data properties
Browse files Browse the repository at this point in the history
filterSpectrumData (argv/configParam) -> filterSpectrum; scanID (spectrum) -> id; spectrumType
(spectrum) -> type; chromatogramType (chromatogram) -> type; polarity (argv/configParam) ->
spectrumPolarity
  • Loading branch information
vmalnathnambiar committed Apr 3, 2024
1 parent f25cd6e commit 833a76b
Show file tree
Hide file tree
Showing 29 changed files with 222 additions and 238 deletions.
10 changes: 1 addition & 9 deletions data/targetFile/invalidLayout.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@ Sodium Formate-PosRef10 Mass Calibration 702.863456 1
Sodium Formate-PosRef11 Mass Calibration 770.85088 1
Sodium Formate-PosRef12 Mass Calibration 838.838303 1
Sodium Formate-PosRef13 Mass Calibration 906.825727 1
Sodium Formate-PosRef14 Mass Calibration 974.81315 1
Sodium Formate-PosRef15 Mass Calibration 1042.800574 1
Sodium Formate-PosRef16 Mass Calibration 1110.787998 1
Sodium Formate-PosRef17 Mass Calibration 1178.775421 1
Sodium Formate-PosRef18 Mass Calibration 1246.762845 1
Sodium Formate-PosRef19 Mass Calibration 1314.750268 1
Sodium Formate-PosRef20 Mass Calibration 1382.737692 1
Sodium Formate-PosRef21 Mass Calibration 1450.725115 1
Sodium Formate-PosRef22 Mass Calibration 1518.712539 1
Sodium Formate-PosRef14 Mass Calibration 974.81315 1
1-methylhistidine Analyte 340.1404 2.56 1 Arginine-13C6,15N4
3-methylhistidine Analyte 340.1404 2.47 1 Histidine-13C6,15N3
4-hydroxyproline Analyte 302.1135 1.57 1 Asparagine-13C4,15N2 Product 1
Expand Down
10 changes: 1 addition & 9 deletions data/targetFile/validLayout.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@ Sodium Formate-PosRef10 Mass Calibration 702.863456 1
Sodium Formate-PosRef11 Mass Calibration 770.85088 1
Sodium Formate-PosRef12 Mass Calibration 838.838303 1
Sodium Formate-PosRef13 Mass Calibration 906.825727 1
Sodium Formate-PosRef14 Mass Calibration 974.81315 1
Sodium Formate-PosRef15 Mass Calibration 1042.800574 1
Sodium Formate-PosRef16 Mass Calibration 1110.787998 1
Sodium Formate-PosRef17 Mass Calibration 1178.775421 1
Sodium Formate-PosRef18 Mass Calibration 1246.762845 1
Sodium Formate-PosRef19 Mass Calibration 1314.750268 1
Sodium Formate-PosRef20 Mass Calibration 1382.737692 1
Sodium Formate-PosRef21 Mass Calibration 1450.725115 1
Sodium Formate-PosRef22 Mass Calibration 1518.712539 1
Sodium Formate-PosRef14 Mass Calibration 974.81315 1
1-methylhistidine Analyte 340.1404 2.56 1 Arginine-13C6,15N4
3-methylhistidine Analyte 340.1404 2.47 1 Histidine-13C6,15N3
4-hydroxyproline Analyte 302.1135 1.57 1 Asparagine-13C4,15N2 Product 1
Expand Down
18 changes: 9 additions & 9 deletions docs/how-to-exfilms-the-complete-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ $ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -r (or --mzRange)

### Spectrum Data Filtering

`-s`, `--filterSpectrumData` \*_Required_
`-s`, `--filterSpectrum` \*_Required_

ExfilMS also provides you with the functionality of filtering the spectrum data based on its properties such as spectrum type, MS level and polarity. With this flag, you can also decide to exclude the spectra (m/z and intensity array) acquired of each scan timepoint (retention time) from being stored in the output file.
ExfilMS also provides you with the functionality of filtering the spectrum based on its properties such as type, MS level and polarity. With this flag, you can also decide to exclude the spectra (m/z and intensity array) acquired of each scan timepoint (retention time) from being stored in the output file.

> [!NOTE]\
> The spectra exclusion filter is particularly useful if you are interested only in analysing the metadata of each spectrum (i.e., total ion current, base peak intensity).
Expand All @@ -296,7 +296,7 @@ _Choices: "profile", "centroid" || Default: Both spectrum types_
```md
# Filter for specific spectrum type

$ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSpectrumData) --spectrumType "profile" "centroid"
$ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSpectrum) --spectrumType "profile" "centroid"
```

<br>
Expand All @@ -307,22 +307,22 @@ _Input type: Space-separated numbers_\
_Default: MS level 1 and 2_

```md
# Filter for specific MS levels
# Filter for specific MS level

$ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSpectrumData) --msLevel 1 2
$ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSpectrum) --msLevel 1 2
```

<br>

`--polarity`
`--spectrumPolarity`

_Input type: Space-separated strings_\
_Choices: "positive", "negative" || Default: Both polarities_

```md
# Filter for specific polarities
# Filter for specific spectrum polarity

$ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSpectrumData) --polarity "positive" "negative"
$ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSpectrum) --spectrumPolarity "positive" "negative"
```

<br>
Expand All @@ -332,7 +332,7 @@ $ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSp
```md
# Exclude spectra (m/z and intensity values) from output file

$ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSpectrumData) --excludeSpectra
$ exfilms -i (or --inputDirectory) "/path/to/input/directory/" -s (or --filterSpectrum) --excludeSpectra
```

<!-- URLs used in the markdown document-->
15 changes: 10 additions & 5 deletions src/__tests__/cvParamMap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('cvParamMap', () => {
expect(keyMap['negative scan']).toStrictEqual('polarity');
expect(keyMap['base peak intensity']).toStrictEqual('basePeakIntensity');
expect(keyMap['total ion current']).toStrictEqual('totalIonCurrent');
expect(keyMap['profile spectrum']).toStrictEqual('spectrumType');
expect(keyMap['centroid spectrum']).toStrictEqual('spectrumType');
expect(keyMap['profile spectrum']).toStrictEqual('type');
expect(keyMap['centroid spectrum']).toStrictEqual('type');
expect(keyMap['base peak m/z']).toStrictEqual('basePeakMZ');
expect(keyMap['scan start time']).toStrictEqual('retentionTime');
expect(keyMap['preset scan configuration']).toStrictEqual(
Expand Down Expand Up @@ -55,12 +55,15 @@ describe('cvParamMap', () => {
expect(keyMap['time array']).toStrictEqual('timeArray');
expect(keyMap['64-bit float']).toStrictEqual('precision');
expect(keyMap['32-bit float']).toStrictEqual('precision');
expect(keyMap['64-bit integer']).toStrictEqual('precision');
expect(keyMap['32-bit integer']).toStrictEqual('precision');
expect(keyMap['no compression']).toStrictEqual('compression');
expect(keyMap['zlib compression']).toStrictEqual('compression');
expect(keyMap['total ion current chromatogram']).toStrictEqual(
'chromatogramType',
expect(keyMap['total ion current chromatogram']).toStrictEqual('type');
expect(keyMap['basepeak chromatogram']).toStrictEqual('type');
expect(keyMap['selected reaction monitoring chromatogram']).toStrictEqual(
'type',
);
expect(keyMap['basepeak chromatogram']).toStrictEqual('chromatogramType');
expect(keyMap.MS_dwell_time).toStrictEqual('dwellTime');
expect(keyMap['non-standard data array']).toStrictEqual('msLevelArray');
});
Expand All @@ -83,6 +86,8 @@ describe('cvParamMap', () => {
);
expect(valueMap['64-bit float']).toStrictEqual(64);
expect(valueMap['32-bit float']).toStrictEqual(32);
expect(valueMap['64-bit integer']).toStrictEqual(64);
expect(valueMap['32-bit integer']).toStrictEqual(32);
expect(valueMap['no compression']).toStrictEqual('none');
expect(valueMap['zlib compression']).toStrictEqual('zlib');
expect(valueMap['total ion current chromatogram']).toStrictEqual(
Expand Down
14 changes: 6 additions & 8 deletions src/__tests__/initChromatogramArray.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('initChromatogramArray', () => {
index: 0,
id: 'TIC',
arrayLength: null,
chromatogramType: 'total ion current chromatogram',
type: 'total ion current chromatogram',
polarity: null,
dwellTime: null,
precursorIsolationWindowTarget: null,
Expand All @@ -30,7 +30,7 @@ describe('initChromatogramArray', () => {
index: 1,
id: 'BPC',
arrayLength: null,
chromatogramType: 'base peak chromatogram',
type: 'base peak chromatogram',
polarity: null,
dwellTime: null,
precursorIsolationWindowTarget: null,
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('initChromatogramArray', () => {
index: testBasicChromatogram.length + index,
id: `EIC ${value}`,
arrayLength: null,
chromatogramType: 'extracted ion chromatogram',
type: 'extracted ion chromatogram',
polarity: null,
dwellTime: null,
precursorIsolationWindowTarget: null,
Expand All @@ -90,9 +90,7 @@ describe('initChromatogramArray', () => {
expect(chromatogram[0].arrayLength).toStrictEqual(
testBasicChromatogram[0].arrayLength,
);
expect(chromatogram[0].chromatogramType).toStrictEqual(
testBasicChromatogram[0].chromatogramType,
);
expect(chromatogram[0].type).toStrictEqual(testBasicChromatogram[0].type);
expect(chromatogram[0].polarity).toStrictEqual(
testBasicChromatogram[0].polarity,
);
Expand Down Expand Up @@ -136,8 +134,8 @@ describe('initChromatogramArray', () => {
expect(chromatogram[3].arrayLength).toStrictEqual(
testTargetedChromatogram[3].arrayLength,
);
expect(chromatogram[3].chromatogramType).toStrictEqual(
testTargetedChromatogram[3].chromatogramType,
expect(chromatogram[3].type).toStrictEqual(
testTargetedChromatogram[3].type,
);
expect(chromatogram[3].polarity).toStrictEqual(
testTargetedChromatogram[3].polarity,
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/parseMZML.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { describe, test, expect, beforeAll, afterAll } from 'vitest';
import { parseMZML } from '../utils/parseMZML.js';

/**
* To test parseMZML() - and extractMZML(), extractSpectrum(), filterSpectrum(), extractChromatogram()
* To test parseMZML() - and extractMZML(), extractSpectrum(), filterSpectra(), extractChromatogram()
* Input: configParam (Object)
* Output: NA || Error message (Error)
*/
Expand All @@ -23,10 +23,10 @@ describe('parseMZML', () => {
decimalPlace: NaN,
targeted: false,
mzRange: false,
filterSpectrumData: false,
filterSpectrum: false,
spectrumType: ['centroid'],
msLevel: [1, 2],
polarity: ['positive'],
spectrumPolarity: ['positive'],
excludeSpectra: false,
mzTargetList: [
70.065, 90.76644, 110.071, 116.0499, 116.0709, 158.964068, 165.089,
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('parseMZML', () => {
test('spectrum data filtering: Bruker', async () => {
testConfigParam.targeted = true;
testConfigParam.maxMZ = 1518.7175;
testConfigParam.filterSpectrumData = true;
testConfigParam.filterSpectrum = true;
testConfigParam.excludeSpectra = true;
testConfigParam.fileList = testFileBruker;

Expand Down Expand Up @@ -248,13 +248,13 @@ describe('parseMZML', () => {
expect(await parseMZML(testConfigParam));
});

test('catch error: logDirectory is not type string', async () => {
test('catch error: logDirectory is not of type string', async () => {
testConfigParam.fileList = ['S15_Bruker_ImpactII_QToFMS.mzML'];
testConfigParam.logDirectory = 0;
expect(await parseMZML(testConfigParam));
});

// ! Uncovered Lines - extractChromatogram.js line 91-92, 125-126
// ! Uncovered Lines - extractChromatogram.js line 94-95, 128-129
// Test data only consist of isolationWindowTarget for the mappedKey (Both precursor and product data)

// ! Uncovered Lines - extractSpectrum.js line 69, 107, 150, 165
Expand Down
21 changes: 9 additions & 12 deletions src/__tests__/parseTargetFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('parseTargetFile', () => {
decimalPlace: NaN,
targetFile: '',
mzTolerance: 0.005,
filterSpectrumData: false,
filterSpectrum: false,
msLevel: [1, 2],
};
const testMzTargetListDefault = [
Expand All @@ -29,12 +29,10 @@ describe('parseTargetFile', () => {
332.1241, 335.136, 336.1343, 340.1404, 345.167, 346.151, 346.1615, 351.1678,
352.1292, 355.1752, 362.1564, 362.926338, 375.1452, 388.1761, 430.913762,
473.1932, 478.21, 487.2088, 498.901186, 501.2432, 566.888609, 634.876033,
702.863456, 770.85088, 838.838303, 906.825727, 974.81315, 1042.800574,
1110.787998, 1178.775421, 1246.762845, 1314.750268, 1382.737692,
1450.725115, 1518.712539,
702.863456, 770.85088, 838.838303, 906.825727, 974.81315,
];
const testMinMzDefault = 70.06;
const testMaxMzDefault = 1518.7175390000002;
const testMaxMzDefault = 974.81815;
const testMzTargetList = [
70.065, 90.7664, 110.071, 116.0499, 116.0709, 158.9641, 165.089, 171.055,
175.119, 188.0705, 226.9515, 232.1081, 237.1008, 239.6092, 244.1081,
Expand All @@ -46,11 +44,10 @@ describe('parseTargetFile', () => {
335.136, 336.1343, 340.1404, 345.167, 346.151, 346.1615, 351.1678, 352.1292,
355.1752, 362.1564, 362.9263, 375.1452, 388.1761, 430.9138, 473.1932,
478.21, 487.2088, 498.9012, 501.2432, 566.8886, 634.876, 702.8635, 770.8509,
838.8383, 906.8257, 974.8132, 1042.8006, 1110.788, 1178.7754, 1246.7628,
1314.7503, 1382.7377, 1450.7251, 1518.7125,
838.8383, 906.8257, 974.8132,
];
const testMinMZ = 70.06;
const testMaxMZ = 1518.7175;
const testMaxMZ = 974.8182;

// Tests
test('throw error: input file pattern check', async () => {
Expand Down Expand Up @@ -103,7 +100,7 @@ describe('parseTargetFile', () => {

test('throw error: no target m/z data found', async () => {
// Valid file with invalid spectrum msLevel filtering
testConfigParam.filterSpectrumData = true;
testConfigParam.filterSpectrum = true;
testConfigParam.msLevel = [3];
await expect(parseTargetFile(testConfigParam)).rejects.toThrowError(
'parseTargetFile(): Target m/z data not found',
Expand All @@ -116,21 +113,21 @@ describe('parseTargetFile', () => {
);

// Without spectrum msLevel filtering
testConfigParam.filterSpectrumData = false;
testConfigParam.filterSpectrum = false;
await expect(parseTargetFile(testConfigParam)).rejects.toThrowError(
'parseTargetFile(): Target m/z data not found',
);

// Empty file with just the header
testConfigParam.filterSpectrumData = true;
testConfigParam.filterSpectrum = true;
testConfigParam.msLevel = [1, 2];
testConfigParam.targetFile = './data/targetFile/empty.tsv';
await expect(parseTargetFile(testConfigParam)).rejects.toThrowError(
'parseTargetFile(): Target m/z data not found',
);

// Without spectrum msLevel filtering
testConfigParam.filterSpectrumData = false;
testConfigParam.filterSpectrum = false;
await expect(parseTargetFile(testConfigParam)).rejects.toThrowError(
'parseTargetFile(): Target m/z data not found',
);
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/setForSpectraFiltering.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('setForSpectraFiltering', () => {
minMZ: undefined,
maxMZ: undefined,
mzTargetList: undefined,
filterSpectrumData: false,
filterSpectrum: false,
msLevel: undefined,
};

Expand Down Expand Up @@ -75,15 +75,15 @@ describe('setForSpectraFiltering', () => {
expect(configParam.maxMZ).toBeDefined();

// Filter spectrum data with invalid target file layout
testConfigParam.filterSpectrumData = true;
testConfigParam.filterSpectrum = true;
testConfigParam.msLevel = [1];
testConfigParam.targetFile = './data/targetFile/invalidLayout.tsv';
await expect(setForSpectraFiltering(testConfigParam)).rejects.toThrowError(
'parseTargetFile(): Target m/z data not found',
);

// Same as above but without filter spectrum data
testConfigParam.filterSpectrumData = false;
// Same as above but without filtering spectrum
testConfigParam.filterSpectrum = false;
await expect(setForSpectraFiltering(testConfigParam)).rejects.toThrowError(
'parseTargetFile(): Target m/z data not found',
);
Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/setYargsDefaults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ describe('setYargsDefaults', () => {
mzRange: false,
minMZ: 0,
maxMZ: NaN,
filterSpectrumData: false,
filterSpectrum: false,
spectrumType: ['profile', 'centroid'],
msLevel: [1, 2],
polarity: ['positive', 'negative'],
spectrumPolarity: ['positive', 'negative'],
excludeSpectra: false,
};
const testFile1 = join(testArgv.inputDirectory, 'testFile1.mzML');
Expand Down Expand Up @@ -84,12 +84,10 @@ describe('setYargsDefaults', () => {
expect(configParam.mzRange).toStrictEqual(testArgv.mzRange);
expect(configParam).not.toHaveProperty('minMZ');
expect(configParam).not.toHaveProperty('maxMZ');
expect(configParam.filterSpectrumData).toStrictEqual(
testArgv.filterSpectrumData,
);
expect(configParam.filterSpectrum).toStrictEqual(testArgv.filterSpectrum);
expect(configParam).not.toHaveProperty('spectrumType');
expect(configParam).not.toHaveProperty('msLevel');
expect(configParam).not.toHaveProperty('polarity');
expect(configParam).not.toHaveProperty('spectrumPolarity');
expect(configParam).not.toHaveProperty('excludeSpectra');
});

Expand All @@ -98,7 +96,7 @@ describe('setYargsDefaults', () => {
testArgv.outputDirectory = './.tmp/setYargsDefaults/outputDirectory/';
testArgv.targeted = true;
testArgv.mzRange = true;
testArgv.filterSpectrumData = true;
testArgv.filterSpectrum = true;
const configParam = await setYargsDefaults(testArgv);
expect(configParam.fileList).toStrictEqual(testArgv.fileList);
expect(configParam.outputDirectory).toStrictEqual(testArgv.outputDirectory);
Expand All @@ -109,7 +107,9 @@ describe('setYargsDefaults', () => {
expect(configParam.maxMZ).toStrictEqual(testArgv.maxMZ);
expect(configParam.spectrumType).toStrictEqual(testArgv.spectrumType);
expect(configParam.msLevel).toStrictEqual(testArgv.msLevel);
expect(configParam.polarity).toStrictEqual(testArgv.polarity);
expect(configParam.spectrumPolarity).toStrictEqual(
testArgv.spectrumPolarity,
);
expect(configParam.excludeSpectra).toStrictEqual(testArgv.excludeSpectra);
});

Expand Down

0 comments on commit 833a76b

Please sign in to comment.