npm.io
2.0.1 • Published 1 year ago

varian-converter

Licence
CC-BY-NC-SA-4.0
Version
2.0.1
Deps
3
Size
43 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

Zakodium logo

Maintained by Zakodium

Varian converter

NPM version npm download

Load and parse Varian NMR native format.

The code currently parses 1-dimensional NMR only.

Installation

npm i varian-converter filelist-utils

Usage

The convert1D function expects a FileCollection. There are normally 4 files in a 1D fid directory:

  1. fid
  2. procpar
  3. text
  4. log

1 and 2 must exist or convert1D will error out.

FileCollections are returned from the filelist-utils package which runs both in NodeJS and the browser.

For passing multiple directories the convert1D should run in a loop, each time passing a FileCollection corresponding to the 1D (fid and procpar must exist), pushing the result object elsewhere.

Use in a browser

The user may upload:

  • a zip file with the fid directory compressed
  • a fid directory

See the example folder.

Use in Node.js
  • Compressed fid directory
import { join } from 'path';
import { readFileSync } from 'fs';
// allows us to load a directory in NodeJS
import { fileCollectionFromZip } from 'filelist-utils';
import { convert1D as cv } from 'varian-converter';

const zipBuffer = readFileSync(join(__dirname, 'path/to/compressed.fid.zip'));
fileCollectionFromZip(zipBuffer)
  .then((fileCollection) => cv(fileCollection))
  .then((result) => console.log(result))
  .catch((e) => console.log(e));
  • Standard fid directory
import { join } from 'path';
import { fileCollectionFromPath } from 'filelist-utils';
import { convert1D as cv } from 'varian-converter';

const fileCollection = fileCollectionFromPath(
  join(__dirname, 'path/to/dir.fid'),
);
cv(fileCollection)
  .then((result) => console.log(result))
  .catch((e) => console.log(e));

Output

convert1D returns an object with the signature

{
  meta: Record<string,any>
  procpar: Record<string,any>
  fid: [data1, data2, data3..]
  x: Float64Array (time values)
}

License

2025 Zakodium Sàrl. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. CC BY-NC-SA 4.0