brukerconverter
Advanced tools
| import { groupByExperiments } from './groupByExperiments'; | ||
| import { convertOneExperiment } from './util/convertOneExperiment.js'; | ||
| /** | ||
| * | ||
| * @param {*} fileCollection | ||
| * @param {object} [options={}] | ||
| * @param {object} [options.filter] | ||
| * @param {object} [options.converter] | ||
| * @returns | ||
| */ | ||
| export async function convertFileCollection(fileCollection, options = {}) { | ||
| const { filter, converter } = options; | ||
| const results = []; | ||
| const experiments = groupByExperiments(fileCollection, filter); | ||
| for (let experiment of experiments) { | ||
| const result = await convertOneExperiment(experiment, converter); | ||
| if (result) { | ||
| results.push(result); | ||
| } | ||
| } | ||
| return results; | ||
| } |
| import { fileCollectionFromZip } from 'filelist-utils'; | ||
| import { convertFileCollection } from '../convertFileCollection'; | ||
| export function convertZip(zip, options) { | ||
| const fileCollection = fileCollectionFromZip(zip); | ||
| return convertFileCollection(fileCollection, options); | ||
| } |
| import { DoubleArray } from 'cheminfo-types'; | ||
| import type { PartialFile, PartialFileList } from 'filelist-utils'; | ||
| import type { FileCollectionItem, FileCollection } from 'filelist-utils'; | ||
| import { DoubleMatrix } from 'ml-spectra-processing'; | ||
@@ -16,3 +16,5 @@ | ||
| type FirstLevelPartialFile = Partial<Record<FirstLevelKeys, PartialFile>>; | ||
| type FirstLevelPartialFile = Partial< | ||
| Record<FirstLevelKeys, FileCollectionItem> | ||
| >; | ||
@@ -59,3 +61,3 @@ export interface GroupByExperimentsOptions { | ||
| name: string; | ||
| fileList: PartialFileList; | ||
| fileCollection: FileCollection; | ||
| expno: number; | ||
@@ -72,3 +74,3 @@ is2D?: boolean; | ||
| expno: number; | ||
| fileList: PartialFileList; | ||
| fileCollection: FileCollection; | ||
| processedData?: ProcessedData; | ||
@@ -81,3 +83,3 @@ is2D?: boolean; | ||
| export function groupByExperiments( | ||
| fileList: PartialFileList, | ||
| fileCollection: FileCollection, | ||
| options?: GroupByExperimentsOptions, | ||
@@ -166,4 +168,4 @@ ): Experiment[]; | ||
| export function convertFileList( | ||
| fileList: PartialFileList, | ||
| fileCollection: FileCollection, | ||
| options?: ConvertFileListOptions, | ||
| ): Promise<SpectraData[]>; |
+16
-10
@@ -5,2 +5,3 @@ 'use strict'; | ||
| var filelistUtils = require('filelist-utils'); | ||
| var jcampconverter = require('jcampconverter'); | ||
@@ -13,3 +14,3 @@ var iobuffer = require('iobuffer'); | ||
| * Retrieve the list of files for further process | ||
| * @param {File[]} fileList | ||
| * @param {FileCollection[]} fileList | ||
| * @param {object} [options={}] | ||
@@ -48,4 +49,4 @@ * @param {number|number[]} [options.processingNumber] - processing number to select, default the smallest number | ||
| let id; | ||
| const parts = file.webkitRelativePath.split('/'); | ||
| if (file.webkitRelativePath.match(/\/pdata\/[0-9]+\/.*$/)) { | ||
| const parts = file.relativePath.split('/'); | ||
| if (file.relativePath.match(/\/pdata\/[0-9]+\/.*$/)) { | ||
| currentProcessingNo = Number(parts[parts.length - 2]); | ||
@@ -55,3 +56,3 @@ currentExperimentNo = Number(parts[parts.length - 4]); | ||
| id = parts.slice(0, -3).join('/'); | ||
| } else if (file.webkitRelativePath.match(/[0-9]+\/.*$/)) { | ||
| } else if (file.relativePath.match(/[0-9]+\/.*$/)) { | ||
| currentExperimentNo = Number(parts[parts.length - 2]); | ||
@@ -138,3 +139,2 @@ name = parts[parts.length - 3] || parts[parts.length - 2]; | ||
| } | ||
| // console.log('experiments', experiments) | ||
| // We convert the object to an array | ||
@@ -192,3 +192,3 @@ // and before filtering we will move all the processedData | ||
| } | ||
| // console.log(experimentsArray) | ||
| return experimentsArray; | ||
@@ -591,3 +591,3 @@ } | ||
| * | ||
| * @param {*} fileList | ||
| * @param {*} fileCollection | ||
| * @param {object} [options={}] | ||
@@ -598,6 +598,6 @@ * @param {object} [options.filter] | ||
| */ | ||
| async function convertFileList(fileList, options = {}) { | ||
| async function convertFileCollection(fileCollection, options = {}) { | ||
| const { filter, converter } = options; | ||
| const results = []; | ||
| const experiments = groupByExperiments(fileList, filter); | ||
| const experiments = groupByExperiments(fileCollection, filter); | ||
| for (let experiment of experiments) { | ||
@@ -612,3 +612,9 @@ const result = await convertOneExperiment(experiment, converter); | ||
| exports.convertFileList = convertFileList; | ||
| function convertZip(zip, options) { | ||
| const fileCollection = filelistUtils.fileCollectionFromZip(zip); | ||
| return convertFileCollection(fileCollection, options); | ||
| } | ||
| exports.convertFileCollection = convertFileCollection; | ||
| exports.convertZip = convertZip; | ||
| exports.groupByExperiments = groupByExperiments; |
+9
-9
| { | ||
| "name": "brukerconverter", | ||
| "version": "4.1.7", | ||
| "version": "5.0.0", | ||
| "description": "Parse and convert Bruker raw data", | ||
@@ -35,20 +35,20 @@ "main": "lib/index.js", | ||
| "@babel/plugin-transform-modules-commonjs": "^7.18.6", | ||
| "@types/jest": "^28.1.6", | ||
| "bruker-data-test": "0.2.1", | ||
| "@types/jest": "^29.1.1", | ||
| "bruker-data-test": "0.4.0", | ||
| "cheminfo-build": "^1.1.11", | ||
| "eslint": "^8.20.0", | ||
| "eslint": "^8.24.0", | ||
| "eslint-config-cheminfo": "^8.0.2", | ||
| "jest": "^28.1.3", | ||
| "jest": "^29.1.2", | ||
| "jest-matcher-deep-close-to": "^3.0.2", | ||
| "prettier": "^2.7.1", | ||
| "rollup": "^2.77.2" | ||
| "rollup": "^2.79.1" | ||
| }, | ||
| "dependencies": { | ||
| "cheminfo-types": "^1.4.0", | ||
| "filelist-utils": "^0.5.0", | ||
| "filelist-utils": "^0.11.0", | ||
| "iobuffer": "^5.1.0", | ||
| "is-any-array": "^2.0.0", | ||
| "jcampconverter": "^9.0.2", | ||
| "ml-spectra-processing": "^11.9.0" | ||
| "ml-spectra-processing": "^11.12.0" | ||
| } | ||
| } | ||
| } |
+5
-5
@@ -21,8 +21,8 @@ #brukerconverter | ||
| const { convertFileList } = require('brukerconverter'); | ||
| const { fileListFromZip } = require('fileList-utils'); | ||
| const { fileListFromZip } = require('fileCollection-utils'); | ||
| const { getZipped } = require('bruker-data-test'); | ||
| async function asyncCall(zip) { | ||
| const fileList = await fileListFromZip(zip); | ||
| const result = await convertFileList(fileList); | ||
| const fileCollection = await fileListFromZip(zip); | ||
| const result = await convertFileList(fileCollection); | ||
| console.log(result); | ||
@@ -44,4 +44,4 @@ //...{ spectra, meta, source } | ||
| async function asyncCall(path) { | ||
| const fileList = await fileListFromPath(path); | ||
| const result = await convertFileList(fileList); | ||
| const fileCollection = await fileListFromPath(path); | ||
| const result = await convertFileList(fileCollection); | ||
| console.log(result); | ||
@@ -48,0 +48,0 @@ //...{ spectra, meta, source } |
| import { getCoffee } from 'bruker-data-test'; | ||
| import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to'; | ||
| import { convertFileList } from '../convertFileList.js'; | ||
| import { convertFileCollection } from '../convertFileCollection.js'; | ||
@@ -9,6 +9,6 @@ expect.extend({ toBeDeepCloseTo, toMatchCloseTo }); | ||
| jest.setTimeout(60000); | ||
| describe('convertFileList', () => { | ||
| describe('convertFileCollection', () => { | ||
| it('advanced example', async () => { | ||
| const fileList = getCoffee(); | ||
| const results = await convertFileList(fileList); | ||
| const fileCollection = await getCoffee(); | ||
| const results = await convertFileCollection(fileCollection); | ||
| expect(results).toHaveLength(18); | ||
@@ -15,0 +15,0 @@ |
@@ -1,13 +0,11 @@ | ||
| import { getZipped } from 'bruker-data-test'; | ||
| import { fileListFromZip } from 'filelist-utils'; | ||
| import { getData } from 'bruker-data-test'; | ||
| import { fileCollectionFromZip } from 'filelist-utils'; | ||
| import { convertFileList } from '../convertFileList.js'; | ||
| import { convertFileCollection } from '../convertFileCollection.js'; | ||
| describe('Test with zip file', () => { | ||
| it('cyclospirin proton spectrum', async () => { | ||
| const zip = await getZipped() | ||
| .filter((file) => file.name === 'cyclosporin_1h.zip')[0] | ||
| .arrayBuffer(); | ||
| const fileList = await fileListFromZip(zip); | ||
| let result = await convertFileList(fileList, { | ||
| const zip = await getData('cyclosporin_1h.zip'); | ||
| const fileCollection = await fileCollectionFromZip(zip); | ||
| let result = await convertFileCollection(fileCollection, { | ||
| xy: true, | ||
@@ -23,7 +21,5 @@ keepSpectra: true, | ||
| it('cyclosporin hmbc', async () => { | ||
| const zip = await getZipped() | ||
| .filter((file) => file.name === 'cyclosporin_hmbc.zip')[0] | ||
| .arrayBuffer(); | ||
| const fileList = await fileListFromZip(zip); | ||
| let result = await convertFileList(fileList, { | ||
| const zip = await getData('cyclosporin_hmbc.zip'); | ||
| const fileCollection = await fileCollectionFromZip(zip); | ||
| let result = await convertFileCollection(fileCollection, { | ||
| converter: { | ||
@@ -30,0 +26,0 @@ xy: true, |
@@ -6,9 +6,10 @@ import { getCoffee } from 'bruker-data-test'; | ||
| describe('groupByExperiments', () => { | ||
| const fileList = getCoffee(); | ||
| it('no options', async () => { | ||
| const results = groupByExperiments(fileList); | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection); | ||
| expect(results).toHaveLength(18); | ||
| }); | ||
| it('ignore fid and 2d', async () => { | ||
| const results = groupByExperiments(fileList, { | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection, { | ||
| ignore2D: true, | ||
@@ -28,3 +29,4 @@ ignoreFID: true, | ||
| it('ignore ft and 2d', async () => { | ||
| const results = groupByExperiments(fileList, { | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection, { | ||
| ignore2D: true, | ||
@@ -44,3 +46,4 @@ ignoreFT: true, | ||
| it('ignore fid and 1d', async () => { | ||
| const results = groupByExperiments(fileList, { | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection, { | ||
| ignore1D: true, | ||
@@ -52,3 +55,4 @@ ignoreFID: true, | ||
| it('ignore ft and 1d', async () => { | ||
| const results = groupByExperiments(fileList, { | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection, { | ||
| ignore1D: true, | ||
@@ -60,3 +64,4 @@ ignoreFT: true, | ||
| it('get only procNo equal 1', async () => { | ||
| const results = groupByExperiments(fileList, { | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection, { | ||
| processingNumber: 1, | ||
@@ -67,3 +72,4 @@ }); | ||
| it('get only the first procno ignoring raw data', async () => { | ||
| const results = groupByExperiments(fileList, { | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection, { | ||
| onlyFirstProcessedData: false, | ||
@@ -75,3 +81,4 @@ ignoreFID: true, | ||
| it('get only the second procno ignoring raw data', async () => { | ||
| const results = groupByExperiments(fileList, { | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection, { | ||
| processingNumber: 2, | ||
@@ -83,3 +90,4 @@ ignoreFID: true, | ||
| it('get only procNo equal 1 ignoring raw data', async () => { | ||
| const results = groupByExperiments(fileList, { | ||
| const fileCollection = await getCoffee(); | ||
| const results = groupByExperiments(fileCollection, { | ||
| processingNumber: 1, | ||
@@ -86,0 +94,0 @@ ignoreFID: true, |
| /** | ||
| * Retrieve the list of files for further process | ||
| * @param {File[]} fileList | ||
| * @param {FileCollection[]} fileList | ||
| * @param {object} [options={}] | ||
@@ -37,4 +37,4 @@ * @param {number|number[]} [options.processingNumber] - processing number to select, default the smallest number | ||
| let id; | ||
| const parts = file.webkitRelativePath.split('/'); | ||
| if (file.webkitRelativePath.match(/\/pdata\/[0-9]+\/.*$/)) { | ||
| const parts = file.relativePath.split('/'); | ||
| if (file.relativePath.match(/\/pdata\/[0-9]+\/.*$/)) { | ||
| currentProcessingNo = Number(parts[parts.length - 2]); | ||
@@ -44,3 +44,3 @@ currentExperimentNo = Number(parts[parts.length - 4]); | ||
| id = parts.slice(0, -3).join('/'); | ||
| } else if (file.webkitRelativePath.match(/[0-9]+\/.*$/)) { | ||
| } else if (file.relativePath.match(/[0-9]+\/.*$/)) { | ||
| currentExperimentNo = Number(parts[parts.length - 2]); | ||
@@ -127,3 +127,2 @@ name = parts[parts.length - 3] || parts[parts.length - 2]; | ||
| } | ||
| // console.log('experiments', experiments) | ||
| // We convert the object to an array | ||
@@ -181,4 +180,4 @@ // and before filtering we will move all the processedData | ||
| } | ||
| // console.log(experimentsArray) | ||
| return experimentsArray; | ||
| } |
+2
-1
@@ -1,2 +0,3 @@ | ||
| export { convertFileList } from './convertFileList'; | ||
| export { convertZip } from './helpers/convertZip'; | ||
| export { convertFileCollection } from './convertFileCollection'; | ||
| export { groupByExperiments } from './groupByExperiments'; |
| import { groupByExperiments } from './groupByExperiments'; | ||
| import { convertOneExperiment } from './util/convertOneExperiment.js'; | ||
| /** | ||
| * | ||
| * @param {*} fileList | ||
| * @param {object} [options={}] | ||
| * @param {object} [options.filter] | ||
| * @param {object} [options.converter] | ||
| * @returns | ||
| */ | ||
| export async function convertFileList(fileList, options = {}) { | ||
| const { filter, converter } = options; | ||
| const results = []; | ||
| const experiments = groupByExperiments(fileList, filter); | ||
| for (let experiment of experiments) { | ||
| const result = await convertOneExperiment(experiment, converter); | ||
| if (result) { | ||
| results.push(result); | ||
| } | ||
| } | ||
| return results; | ||
| } |
50344
1.93%21
5%1431
1.06%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
Updated