brukerconverter
Advanced tools
Comparing version
@@ -31,22 +31,12 @@ import { DoubleArray } from 'cheminfo-types'; | ||
/** | ||
* should we ignore fid | ||
* @default false | ||
* should we keep 1D spectra | ||
* @default true | ||
*/ | ||
ignoreFID?: boolean; | ||
keep1D?: boolean; | ||
/** | ||
* should we ignore the ft transformed fid | ||
* @default false | ||
* should we keep 2D spectra | ||
* @default true | ||
*/ | ||
ignoreFT?: boolean; | ||
keep2D?: boolean; | ||
/** | ||
* should we ignore 1D spectra | ||
* @default false | ||
*/ | ||
ignore1D?: boolean; | ||
/** | ||
* should we ignore 2D spectra | ||
* @default false | ||
*/ | ||
ignore2D?: boolean; | ||
/** | ||
* should we take only the first processed data (procno). | ||
@@ -56,2 +46,8 @@ * @default true | ||
onlyFirstProcessedData?: boolean; | ||
/** | ||
* allow filter by only processed (FT) or raw data (FID), set a preference for | ||
* FT or FID if both exists, or always load both. | ||
* @default 'both' | ||
*/ | ||
dataSelection?: 'ft' | 'fid' | 'both' | 'preferFT' | 'preferFID'; | ||
} | ||
@@ -121,7 +117,7 @@ | ||
export interface Files { | ||
relativePath: string; | ||
export interface File { | ||
relativePath?: string; | ||
name: string; | ||
lastModified: number; | ||
size: number; | ||
size?: number; | ||
} | ||
@@ -137,3 +133,3 @@ | ||
shiftOffsetNum: 0; | ||
source: BrukerSource & { | ||
source: GeneralBrukerSource & { | ||
is1D: boolean; | ||
@@ -171,3 +167,3 @@ }; | ||
isFID: boolean; | ||
files?: Files; | ||
files?: File[]; | ||
} | ||
@@ -184,3 +180,3 @@ | ||
shiftOffsetNum: 0; | ||
source: BrukerSource & { is2D: boolean }; | ||
source: GeneralBrukerSource & { is2D: boolean }; | ||
} | ||
@@ -187,0 +183,0 @@ |
@@ -11,8 +11,6 @@ 'use strict'; | ||
* Retrieve the list of files for further process | ||
* @param {FileCollection[]} fileCollection | ||
* @param {FileCollection} fileCollection | ||
* @param {object} [options={}] | ||
* @param {number[]} [options.processingNumbers] - processing number to select, default the smallest number | ||
* @param {number[]} [options.experimentNumbers] - experiment number to select, default all | ||
* @param {boolean} [options.keepFID=true] - should we keep fid | ||
* @param {boolean} [options.keepFT=true] - should we keep the ft transformed fid | ||
* @param {boolean} [options.keep1D=true] - should we keep 1D spectra | ||
@@ -27,4 +25,3 @@ * @param {boolean} [options.keep2D=true] - should we keep 2D spectra | ||
experimentNumbers, | ||
keepFID = true, | ||
keepFT = true, | ||
dataSelection = 'both', | ||
keep1D = true, | ||
@@ -36,2 +33,3 @@ keep2D = true, | ||
const experiments = {}; | ||
const fileList = fileCollection.files.map((file) => file.relativePath); | ||
for (let file of fileCollection) { | ||
@@ -51,3 +49,3 @@ let procno; | ||
id = parts.slice(0, -3).join('/'); | ||
} else if (file.name.match(/^(ser|fid|acqus|acqu2s)$/)) { | ||
} else if (isRawOrAcquisitionFile(file, fileList)) { | ||
const firstLevel = parts.indexOf(file.name); | ||
@@ -143,11 +141,18 @@ expno = Number(parts[firstLevel - 1]); | ||
const { processedData: processed, ...experiment } = { ...experiments[key] }; | ||
if (experiment.ser || experiment.fid) { | ||
if (Object.keys(processed).length > 0) { | ||
const firstProcessed = processed[Object.keys(processed)[0]]; | ||
const processedKeys = Object.keys(processed); | ||
const hasRawData = experiment.ser || experiment.fid; | ||
if ( | ||
(hasRawData && dataSelection !== 'ft' && dataSelection !== 'preferFT') || | ||
(dataSelection === 'preferFT' && !processedKeys.length) | ||
) { | ||
if (processedKeys.length > 0) { | ||
const firstProcessed = processed[processedKeys[0]]; | ||
if (firstProcessed.procs) { | ||
experiment.fileCollectionItems.push(firstProcessed.procs); //seems useless | ||
experiment.fileCollectionItems.push(firstProcessed.procs); | ||
experiment.procs = firstProcessed.procs; | ||
} | ||
if (firstProcessed.proc2s) { | ||
// experiment.fileCollectionItems.push(firstProcessed.proc2s); //seems useless | ||
experiment.fileCollectionItems.push(firstProcessed.proc2s); | ||
experiment.proc2s = firstProcessed.proc2s; | ||
@@ -158,2 +163,9 @@ } | ||
} | ||
if ( | ||
dataSelection === 'fid' || | ||
(dataSelection === 'preferFID' && hasRawData) | ||
) { | ||
continue; | ||
} | ||
for (let processedKey in processed) { | ||
@@ -177,8 +189,2 @@ const oneProcessed = processed[processedKey]; | ||
// we can not easily filter | ||
if (!keepFID) { | ||
experimentsArray = experimentsArray.filter((item) => !item.isFID); | ||
} | ||
if (!keepFT) { | ||
experimentsArray = experimentsArray.filter((item) => !item.isFT); | ||
} | ||
if (!keep1D) { | ||
@@ -194,2 +200,10 @@ experimentsArray = experimentsArray.filter((item) => !item.is1D); | ||
function isRawOrAcquisitionFile(file, fileList) { | ||
return ( | ||
file.name.match(/^(ser|acqus|acqu2s)$/) || | ||
(file.name.match(/^(fid)$/) && | ||
fileList.includes(file.relativePath.replace(/fid$/, 'acqus'))) | ||
); | ||
} | ||
function joinInfoMeta(target, toAppend) { | ||
@@ -597,4 +611,2 @@ for (let key in toAppend.meta) { | ||
} | ||
// todo we could as well keep the FileList at this level if | ||
// we want to keep the original data | ||
} | ||
@@ -601,0 +613,0 @@ |
{ | ||
"name": "brukerconverter", | ||
"version": "6.0.8", | ||
"version": "6.0.9-pre.1677169339", | ||
"description": "Parse and convert Bruker raw data", | ||
@@ -47,3 +47,3 @@ "main": "lib/index.js", | ||
"cheminfo-types": "^1.4.0", | ||
"filelist-utils": "^1.7.0", | ||
"filelist-utils": "^1.7.0-pre.1676560930", | ||
"iobuffer": "^5.3.2", | ||
@@ -54,2 +54,2 @@ "is-any-array": "^2.0.0", | ||
} | ||
} | ||
} |
@@ -37,2 +37,39 @@ import { join } from 'path'; | ||
}); | ||
it('keep only fid', async () => { | ||
const fileCollection = await fileCollectionFromPath( | ||
join(__dirname, 'data/withoutExpno'), | ||
); | ||
const results = await convertFileCollection(fileCollection, { | ||
converter: { keepFiles: true }, | ||
filter: { dataSelection: 'fid' }, | ||
}); | ||
expect(results).toHaveLength(1); | ||
expect(results[0].source).toMatchCloseTo({ | ||
name: 'withoutExpno', | ||
expno: 0, | ||
is1D: true, | ||
isFID: true, | ||
}); | ||
expect(results[0].spectra[0].data.re).toHaveLength(65536 / 2); | ||
}); | ||
it('keep only ft', async () => { | ||
const fileCollection = await fileCollectionFromPath( | ||
join(__dirname, 'data/withoutExpno'), | ||
); | ||
const results = await convertFileCollection(fileCollection, { | ||
converter: { keepFiles: true }, | ||
filter: { dataSelection: 'ft' }, | ||
}); | ||
expect(results).toHaveLength(1); | ||
expect(results[0].source).toMatchCloseTo({ | ||
name: 'withoutExpno', | ||
expno: 0, | ||
procno: 1, | ||
is1D: true, | ||
isFT: true, | ||
}); | ||
expect(results[0].spectra[0].data.re).toHaveLength(65536 / 2); | ||
}); | ||
it('advanced example', async () => { | ||
@@ -39,0 +76,0 @@ const fileCollection = await getCoffee(); |
@@ -32,2 +32,61 @@ import { join } from 'path'; | ||
describe('dataSelection', () => { | ||
it('priorize FT', async () => { | ||
const fileCollection = await fileCollectionFromPath( | ||
join(__dirname, 'data/10'), | ||
); | ||
const results = groupByExperiments(fileCollection, { | ||
dataSelection: 'preferFT', | ||
}); | ||
expect(results).toHaveLength(1); | ||
expect(results[0].expno).toBe(10); | ||
expect(results[0].procno).toBe(1); | ||
}); | ||
it('priorize FID', async () => { | ||
const fileCollection = await fileCollectionFromPath( | ||
join(__dirname, 'data/10'), | ||
); | ||
const results = groupByExperiments(fileCollection, { | ||
dataSelection: 'preferFID', | ||
}); | ||
expect(results).toHaveLength(1); | ||
expect(results[0].expno).toBe(10); | ||
expect(results[0]).not.toHaveProperty('procno'); | ||
}); | ||
it('keep both', async () => { | ||
const fileCollection = await fileCollectionFromPath( | ||
join(__dirname, 'data/10'), | ||
); | ||
const results = groupByExperiments(fileCollection, { | ||
dataSelection: 'both', | ||
}); | ||
expect(results).toHaveLength(2); | ||
expect(results[0].expno).toBe(10); | ||
expect(results[0].name).toBe('10'); | ||
expect(results[1].expno).toBe(10); | ||
expect(results[1].name).toBe('10'); | ||
}); | ||
it('keep only ft', async () => { | ||
const fileCollection = await fileCollectionFromPath( | ||
join(__dirname, 'data/10'), | ||
); | ||
const results = groupByExperiments(fileCollection, { | ||
dataSelection: 'ft', | ||
}); | ||
expect(results).toHaveLength(1); | ||
expect(results[0].expno).toBe(10); | ||
expect(results[0].procno).toBe(1); | ||
}); | ||
it('keep only FID', async () => { | ||
const fileCollection = await fileCollectionFromPath( | ||
join(__dirname, 'data/10'), | ||
); | ||
const results = groupByExperiments(fileCollection, { | ||
dataSelection: 'fid', | ||
}); | ||
expect(results).toHaveLength(1); | ||
expect(results[0].expno).toBe(10); | ||
expect(results[0]).not.toHaveProperty('procno'); | ||
}); | ||
}); | ||
describe('groupByExperiments', () => { | ||
@@ -43,3 +102,3 @@ it('no options', async () => { | ||
keep2D: false, | ||
keepFID: false, | ||
dataSelection: 'ft', | ||
}); | ||
@@ -60,3 +119,3 @@ expect(results).toHaveLength(8); | ||
keep2D: false, | ||
keepFT: false, | ||
dataSelection: 'fid', | ||
}); | ||
@@ -77,3 +136,3 @@ expect(results).toHaveLength(7); | ||
keep1D: false, | ||
keepFID: false, | ||
dataSelection: 'ft', | ||
}); | ||
@@ -86,3 +145,3 @@ expect(results).toHaveLength(1); | ||
keep1D: false, | ||
keepFT: false, | ||
dataSelection: 'fid', | ||
}); | ||
@@ -102,3 +161,3 @@ expect(results).toHaveLength(2); | ||
onlyFirstProcessedData: false, | ||
keepFID: false, | ||
dataSelection: 'ft', | ||
}); | ||
@@ -111,3 +170,3 @@ expect(results).toHaveLength(9); | ||
processingNumbers: [2], | ||
keepFID: false, | ||
dataSelection: 'ft', | ||
}); | ||
@@ -120,3 +179,3 @@ expect(results).toHaveLength(0); | ||
processingNumbers: [1], | ||
keepFID: false, | ||
dataSelection: 'ft', | ||
}); | ||
@@ -123,0 +182,0 @@ expect(results).toHaveLength(9); |
/** | ||
* Retrieve the list of files for further process | ||
* @param {FileCollection[]} fileCollection | ||
* @param {FileCollection} fileCollection | ||
* @param {object} [options={}] | ||
* @param {number[]} [options.processingNumbers] - processing number to select, default the smallest number | ||
* @param {number[]} [options.experimentNumbers] - experiment number to select, default all | ||
* @param {boolean} [options.keepFID=true] - should we keep fid | ||
* @param {boolean} [options.keepFT=true] - should we keep the ft transformed fid | ||
* @param {boolean} [options.keep1D=true] - should we keep 1D spectra | ||
@@ -18,4 +16,3 @@ * @param {boolean} [options.keep2D=true] - should we keep 2D spectra | ||
experimentNumbers, | ||
keepFID = true, | ||
keepFT = true, | ||
dataSelection = 'both', | ||
keep1D = true, | ||
@@ -27,2 +24,3 @@ keep2D = true, | ||
const experiments = {}; | ||
const fileList = fileCollection.files.map((file) => file.relativePath); | ||
for (let file of fileCollection) { | ||
@@ -42,3 +40,3 @@ let procno; | ||
id = parts.slice(0, -3).join('/'); | ||
} else if (file.name.match(/^(ser|fid|acqus|acqu2s)$/)) { | ||
} else if (isRawOrAcquisitionFile(file, fileList)) { | ||
const firstLevel = parts.indexOf(file.name); | ||
@@ -134,11 +132,18 @@ expno = Number(parts[firstLevel - 1]); | ||
const { processedData: processed, ...experiment } = { ...experiments[key] }; | ||
if (experiment.ser || experiment.fid) { | ||
if (Object.keys(processed).length > 0) { | ||
const firstProcessed = processed[Object.keys(processed)[0]]; | ||
const processedKeys = Object.keys(processed); | ||
const hasRawData = experiment.ser || experiment.fid; | ||
if ( | ||
(hasRawData && dataSelection !== 'ft' && dataSelection !== 'preferFT') || | ||
(dataSelection === 'preferFT' && !processedKeys.length) | ||
) { | ||
if (processedKeys.length > 0) { | ||
const firstProcessed = processed[processedKeys[0]]; | ||
if (firstProcessed.procs) { | ||
experiment.fileCollectionItems.push(firstProcessed.procs); //seems useless | ||
experiment.fileCollectionItems.push(firstProcessed.procs); | ||
experiment.procs = firstProcessed.procs; | ||
} | ||
if (firstProcessed.proc2s) { | ||
// experiment.fileCollectionItems.push(firstProcessed.proc2s); //seems useless | ||
experiment.fileCollectionItems.push(firstProcessed.proc2s); | ||
experiment.proc2s = firstProcessed.proc2s; | ||
@@ -149,2 +154,9 @@ } | ||
} | ||
if ( | ||
dataSelection === 'fid' || | ||
(dataSelection === 'preferFID' && hasRawData) | ||
) { | ||
continue; | ||
} | ||
for (let processedKey in processed) { | ||
@@ -168,8 +180,2 @@ const oneProcessed = processed[processedKey]; | ||
// we can not easily filter | ||
if (!keepFID) { | ||
experimentsArray = experimentsArray.filter((item) => !item.isFID); | ||
} | ||
if (!keepFT) { | ||
experimentsArray = experimentsArray.filter((item) => !item.isFT); | ||
} | ||
if (!keep1D) { | ||
@@ -184,1 +190,9 @@ experimentsArray = experimentsArray.filter((item) => !item.is1D); | ||
} | ||
function isRawOrAcquisitionFile(file, fileList) { | ||
return ( | ||
file.name.match(/^(ser|acqus|acqu2s)$/) || | ||
(file.name.match(/^(fid)$/) && | ||
fileList.includes(file.relativePath.replace(/fid$/, 'acqus'))) | ||
); | ||
} |
@@ -31,4 +31,2 @@ import { convert1D } from './convert1D'; | ||
} | ||
// todo we could as well keep the FileList at this level if | ||
// we want to keep the original data | ||
} | ||
@@ -35,0 +33,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1153987
0.29%1714
6.59%2
100%