varian-converter
v1.0.0
Published
Load and parse varian NMR native format
Downloads
1,628
Readme
varian-converter
Load and parse varian NMR native format.
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:
- fid
- procpar
- text
- log
1 and 2 must exist or convert1D
will error out.
FileCollection
s 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 Browser
The user may upload:
- a zip file with the fid directory compressed
- a fid directory
See the example folder.
Use in NodeJS
- 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)
}