@zakodium/nmrium-core 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/nmrium-core.d.ts +21 -21
- package/dist/nmrium-core.js +2 -2
- package/package.json +7 -9
package/README.md
CHANGED
|
@@ -31,14 +31,14 @@ It contains the following features:
|
|
|
31
31
|
## Usage
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
|
-
import {
|
|
34
|
+
import { FileCollection } from 'file-collection';
|
|
35
35
|
import { NMRiumCore } from '@zakodium/nmrium-core';
|
|
36
36
|
import plugins from '@zakodium/nmrium-core-plugins';
|
|
37
37
|
|
|
38
38
|
const core = new NMRiumCore();
|
|
39
39
|
core.registerPlugins(plugins);
|
|
40
40
|
|
|
41
|
-
const fileCollection =
|
|
41
|
+
const fileCollection = FileCollection.fromPath('path_to_data');
|
|
42
42
|
// we can read a zip, jdx, jdf, nmredata, json, nmrium file extensions
|
|
43
43
|
const result = await core.read(fileCollection, options);
|
|
44
44
|
|
package/dist/nmrium-core.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type { CorrelationData } from 'nmr-correlation';
|
|
2
2
|
import type { FifoLoggerOptions } from 'fifo-logger';
|
|
3
|
-
import { FileCollection } from '
|
|
4
|
-
import type {
|
|
5
|
-
import type { Filter1DEntry } from 'nmr-
|
|
6
|
-
import type { Filter1DOptions } from 'nmr-
|
|
7
|
-
import type { Filter2DEntry } from 'nmr-
|
|
8
|
-
import type { Filter2DOptions } from 'nmr-
|
|
9
|
-
import type { Info1D } from 'nmr-
|
|
10
|
-
import type { Info2D } from 'nmr-
|
|
11
|
-
import type { Integrals } from 'nmr-
|
|
3
|
+
import { FileCollection } from 'file-collection';
|
|
4
|
+
import type { FileItem } from 'file-collection';
|
|
5
|
+
import type { Filter1DEntry } from '@zakodium/nmr-types';
|
|
6
|
+
import type { Filter1DOptions } from '@zakodium/nmr-types';
|
|
7
|
+
import type { Filter2DEntry } from '@zakodium/nmr-types';
|
|
8
|
+
import type { Filter2DOptions } from '@zakodium/nmr-types';
|
|
9
|
+
import type { Info1D } from '@zakodium/nmr-types';
|
|
10
|
+
import type { Info2D } from '@zakodium/nmr-types';
|
|
11
|
+
import type { Integrals } from '@zakodium/nmr-types';
|
|
12
12
|
import type { Logger } from 'cheminfo-types';
|
|
13
|
-
import type { MatrixOptions } from 'nmr-
|
|
13
|
+
import type { MatrixOptions } from '@zakodium/nmr-types';
|
|
14
14
|
import type { NmrData1D } from 'cheminfo-types';
|
|
15
15
|
import type { NmrData2D } from 'cheminfo-types';
|
|
16
|
-
import type { Peaks } from 'nmr-
|
|
17
|
-
import type { Ranges } from 'nmr-
|
|
16
|
+
import type { Peaks } from '@zakodium/nmr-types';
|
|
17
|
+
import type { Ranges } from '@zakodium/nmr-types';
|
|
18
18
|
import { SerializedNmriumState } from './core_serialize.js';
|
|
19
|
-
import type {
|
|
20
|
-
import type { Zones } from 'nmr-
|
|
19
|
+
import type { Source } from 'file-collection';
|
|
20
|
+
import type { Zones } from '@zakodium/nmr-types';
|
|
21
21
|
|
|
22
22
|
export declare interface ActiveSpectrum {
|
|
23
23
|
id: string;
|
|
@@ -370,7 +370,7 @@ declare interface LoadersPreferences {
|
|
|
370
370
|
declare type MatrixGeneration = Record<string, MatrixGenerationOptions>;
|
|
371
371
|
|
|
372
372
|
export declare interface MatrixGenerationOptions {
|
|
373
|
-
matrixOptions: MatrixOptions
|
|
373
|
+
matrixOptions: MatrixOptions<object>;
|
|
374
374
|
/**
|
|
375
375
|
* boolean indicator to hide/show box plot
|
|
376
376
|
* @default false
|
|
@@ -420,20 +420,20 @@ export declare class NMRiumCore {
|
|
|
420
420
|
registerPlugin(plugin: NMRiumPlugin): void;
|
|
421
421
|
registerPlugins(plugins: NMRiumPlugin[]): void;
|
|
422
422
|
private migrate;
|
|
423
|
-
read(input: FileCollection |
|
|
423
|
+
read(input: FileCollection | FileItem, options?: Partial<ParsingOptions>): ReturnType<typeof read>;
|
|
424
424
|
readNMRiumObject(nmriumObjectInput: object, options?: ParsingOptions): Promise<Partial<NmriumState>>;
|
|
425
|
-
readFromWebSource(source:
|
|
425
|
+
readFromWebSource(source: Source, options?: ParsingOptions): Promise<Partial<NmriumState>>;
|
|
426
426
|
serializeNmriumState(nmriumState: NmriumState, options?: SerializeNmriumStateOptions): SerializedNmriumState;
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
export declare interface NmriumData extends BaseNmriumData {
|
|
430
430
|
spectra: Spectrum[];
|
|
431
|
-
source?:
|
|
431
|
+
source?: Source;
|
|
432
432
|
}
|
|
433
433
|
|
|
434
434
|
export declare interface NmriumDataSource extends BaseNmriumData {
|
|
435
435
|
spectra: SpectraSource[];
|
|
436
|
-
source:
|
|
436
|
+
source: Source;
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
export declare interface NMRiumGeneralPreferences {
|
|
@@ -498,7 +498,7 @@ export declare interface NMRiumPluginOnReadProcess {
|
|
|
498
498
|
* @param file
|
|
499
499
|
* @param options
|
|
500
500
|
*/
|
|
501
|
-
onFile?: (file:
|
|
501
|
+
onFile?: (file: FileItem, options?: ParsingOptions) => Promise<NmriumData>;
|
|
502
502
|
/**
|
|
503
503
|
* Hooks on processFileCollection, in last steps, after fully load data.
|
|
504
504
|
* Filter data, apply processing, etc.
|
|
@@ -806,7 +806,7 @@ export declare interface RangesViewState {
|
|
|
806
806
|
declare function read(_options: ReadOptions): Promise<ReadReturn>;
|
|
807
807
|
|
|
808
808
|
declare interface ReadOptions {
|
|
809
|
-
input: FileCollection |
|
|
809
|
+
input: FileCollection | FileItem;
|
|
810
810
|
migrator: (state: object) => any;
|
|
811
811
|
plugins: Map<string, NMRiumPlugin>;
|
|
812
812
|
options?: ParsingOptions;
|
package/dist/nmrium-core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var le={NORMAL:"NORMAL",FORMULA:"FORMULA"};var ce={RELATIVE:"relative",ABSOLUTE:"absolute",MIN:"min",MAX:"max"};var ue=[{name:"pixels",unit:"px"},{name:"inches",unit:"in"},{name:"feet",unit:"ft"},{name:"yards",unit:"yd"},{name:"centimeters",unit:"cm"},{name:"millimeters",unit:"mm"},{name:"meters",unit:"m"},{name:"points",unit:"pt"},{name:"picas",unit:"pc"}];var P=9;var pe=[{key:"CT",description:"CT from NMR Solutions"}];import{isAnyArray as fe}from"is-any-array";import{xMultiply as
|
|
1
|
+
var le={NORMAL:"NORMAL",FORMULA:"FORMULA"};var ce={RELATIVE:"relative",ABSOLUTE:"absolute",MIN:"min",MAX:"max"};var ue=[{name:"pixels",unit:"px"},{name:"inches",unit:"in"},{name:"feet",unit:"ft"},{name:"yards",unit:"yd"},{name:"centimeters",unit:"cm"},{name:"millimeters",unit:"mm"},{name:"meters",unit:"m"},{name:"points",unit:"pt"},{name:"picas",unit:"pc"}];var P=9;var pe=[{key:"CT",description:"CT from NMR Solutions"}];import{isAnyArray as fe}from"is-any-array";import{xMultiply as I}from"ml-spectra-processing";var me=crypto.randomUUID.bind(crypto),b=me;function N(e){let{id:t=b(),meta:n,peaks:r={},filters:o=[],info:s={},ranges:u={},integrals:i={},selector:a,dependentVariables:c=[],...f}=e,l={id:t,meta:n,filters:o},{data:d=ge(c[0].components)}=e;if(Array.isArray(s.nucleus)&&(s.nucleus=s.nucleus[0]),l.data={x:[],re:[],im:[],...d},"scaleFactor"in s){let{scaleFactor:p}=s,{re:g,im:y}=l.data;I(g,p,{output:g}),y&&I(y,p,{output:y})}a&&(l.selector=a);let m=fe(d.im);if(l.info={phc0:0,phc1:0,nucleus:"1H",isFid:!1,isComplex:m,dimension:1,name:s?.name||t,...s},s.isFid&&s.reverse&&m){let{im:p}=l.data;I(p,-1,{output:p}),l.info.reverse=!1}return l.display={isVisible:!0,isPeaksMarkersVisible:!0,isRealSpectrumVisible:!0,isVisibleInDomain:!0,...e.display},l.peaks={values:[],options:{},...r},l.ranges={values:[],options:{sum:null,isSumConstant:!0,sumAuto:!0},...u},l.integrals={values:[],options:{},...i},{...f,...l}}function ge(e){let t=e[0]?.data?.x||[],n=e[0]?.data?.re||e[0]?.data?.y||[],r=e[0]?.data?.im||e[1]?.data?.y||null;return t.length>0&&t[0]>t[1]&&(t.reverse(),n.reverse(),r&&r.reverse()),{x:t,re:n,im:r}}import{matrixToArray as de,xMinMaxValues as ye,xNoiseSanPlot as Se}from"ml-spectra-processing";var j={z:[[]],minX:0,minY:0,maxX:0,maxY:0},Pe={re:j,im:j},xe={rr:j};function O(e){let{id:t=b(),meta:n={},dependentVariables:r=[],info:o={},filters:s=[],zones:u=[],...i}=e,a={id:t,meta:n,filters:s};a.info={nucleus:["1H","1H"],isFid:!1,isComplex:!1,name:o?.name||b(),...o},a.originalInfo=structuredClone(a.info),a.display={isPositiveVisible:!0,isNegativeVisible:!0,isVisible:!0,dimension:2,...e.display,...e.display};let{data:c=r[0].components}=e;if(a.data={...a.info.isFid?Pe:xe,...c},a.originalData=structuredClone(a.data),!("spectrumSize"in o)){let f=o.isFid?"re":"rr",l=a.data[f].z.length,d=l>0?a.data[f].z[0].length:0;a.info.spectrumSize=[d,l]}if(!o.isFid){let f=a.data.rr,l=de(f.z),{positive:d,negative:m}=Se(l),{min:p,max:g}=ye(l);a.data.rr={...f,minZ:p,maxZ:g},a.info.noise={positive:d,negative:m}}return a.zones={values:[],options:{},...u},{...i,...a}}import{xSequentialFillFromTo as Ne}from"ml-spectra-processing";import{isAnyArray as be}from"is-any-array";function L(e,t=0){if(be(e)){let n=e.at(t);if(n!==void 0)return n;throw new RangeError("An array with a index out of boundaries")}return e}var he=new Set(["t1ir","T1"]);function $(e){let t=[];for(let n of e){let{info:{pulseSequence:r,isFid:o}}=n,{data:s,info:u,meta:{vdlistValues:i=[]}}=n;if(!(r&&he.has(r))||i.length===0){t.push(n);continue}let c=o?"re":"rr",f={};for(let S in u)f[S]=L(u[S]);let{z:l,maxX:d,minX:m}=s[c],p=Ne({from:m,to:d,size:l[0].length}),[g,y]=Oe(n);for(let S=0;S<i.length;S++){let h={re:p,x:p};for(let D in s)h[De(D)]=s[D].z.at(g*(S+y));t.push(N({data:h,info:{...f,name:`${f.name}_${i[S]}`,dimension:1,vd:i[S]}}))}}return t}function De(e){return["rr","re"].includes(e)?"re":["im","ri","ir","ii"].includes(e)?"im":"x"}function Oe(e){let{meta:{PAGE:t}}=e,n=!0;if(t){let r=o=>Number.parseFloat(o.replace(/[F|T]1=/,""));n=r(t[0])>r(t[2])}return n?[-1,1]:[1,0]}var Re=2,ve=1;function we(e){let{spectra:t=[],molecules:n}=e,r=[];for(let o of t){let{info:s}=o;switch(s.dimension){case ve:r.push(N(o));break;case Re:r.push(O(o));break;default:throw new Error("dimension does not supported")}}return{molecules:n,spectra:$(r)}}function x(e,t){return JSON.parse(JSON.stringify(e),function(r,o){if(r in t){this[t[r]]=o;return}return o})}function V(e){if(e?.version===1)return e;let t={...e,version:1},n={j:"js",signal:"signals",integral:"integration",peak:"peaks",diaID:"diaIDs"};for(let r of t.spectra){if(r.ranges){let o=x(r.ranges,n);r.ranges=Array.isArray(o)?{values:o}:o}else if(r.zones){let o=x(r.zones,n);r.zones=Array.isArray(o)?{values:o}:o}r.peaks&&(r.peaks=Array.isArray(r.peaks)?{values:r.peaks}:r.peaks),r.integrals&&(r.integrals=Array.isArray(r.integrals)?{values:r.integrals}:r.integrals)}return t}function z(e){if(e?.version===2)return e;let t={...e,version:2},n={peaks:{delta:"x",originDelta:"originalX",intensity:"y"},ranges:{atomIDs:"atoms",intensity:"y"}};for(let r of t.spectra)r.peaks?r.peaks=x(r.peaks,n.peaks):r.ranges?r.ranges=x(r.ranges,n.ranges):r.zones&&(r.zones.values=Fe(r.zones.values));return t}function Fe(e){return e.map(t=>(t.signals&&(t.signals=t.signals.map(n=>{if(n.x&&n.y){let{x:{fromTo:r,...o},y:{fromTo:s,...u}}=n;n={...n,x:{...o,...r},y:{...u,...s}}}else{let{fromTo:r,deltaX:o,resolutionX:s,nucleusX:u,deltaY:i,resolutionY:a,nucleusY:c,shiftX:f,shiftY:l,...d}=n;n={...d,x:{from:r[0].from,to:r[0].to,delta:o,resolution:s,nucleus:u},y:{from:r[1].from,to:r[1].to,delta:i,resolution:a,nucleus:c}}}return n},[])),t),[])}var Ce={name:"apodization",label:"Apodization",value:{lineBroadening:1,gaussBroadening:0,lineBroadeningCenter:0}};function B(e){if(e?.version===3)return e;let t={...e,version:3};for(let n of t.spectra)if(Array.isArray(n?.filters)&&n?.filters.length>0){let r=n.filters.findIndex(o=>o.name==="lineBroadening");if(r!==-1){let o={...n.filters[r],...Ce};n.filters[r]=n.filters[r-1],n.filters[r-1]=o}}return t}function _(e){if(e?.version===4)return e;let{version:t,...n}=e,r=[],o={};for(let{source:i,...a}of n.spectra){let c={},{info:f={},display:l={}}=a;if(f?.dimension===2&&!i?.jcampURL)if(f.isFt)c.data={rr:a.data};else continue;if(i?.jcampURL){let{jcampURL:p,jcampSpectrumIndex:g}=i,y=p.match(/(?<baseURL>^\w+:\/{2}\w+\/)(?<relativePath>.*)/);o[p]||(o[p]={baseURL:y?.groups.baseURL||"",relativePath:y?.groups.relativePath||p.replace(/^\.\//,"")}),c.sourceSelector={files:[o[p].relativePath]},g!==void 0&&(c.sourceSelector.jcamp={index:g})}c.filters=Ae(a.filters);let{name:d,...m}=l;d&&(c.info={...f,name:d}),c.display=m,r.push({...a,...c})}let s={data:{...n,spectra:r},version:4},u={entries:Object.values(o)};return u.entries.length>0&&(s.data.source=u),s}function Ae(e=[]){let t=[];for(let n of e){let{name:r,value:o}=n;switch(r){case"zeroFilling":t.push({...n,value:{nbPoints:o}});break;case"shiftX":case"shift2DX":case"shift2DY":t.push({...n,value:{shift:o}});break;default:t.push({...n})}}return t}function U(e){if(e?.version===5)return e;let t={...e,version:5},n={originFrom:"originalFrom",originTo:"originalTo",originDelta:"originalDelta",originX:"originalX",originY:"originalY",originZ:"originalZ"};for(let r of t?.data?.spectra||[])for(let o of["peaks","ranges","zones"])r?.[o]&&(r[o]=x(r[o],n));return t}function K(e){if(e?.version===6)return e;let t={...e,version:6};for(let n of t?.data?.spectra||[]){let{digitalFilter:r,fft:o,phaseCorrection:s}=Me(n);o?.flag&&r?.flag&&s&&Math.floor(r.value.digitalFilterValue)%2>0&&(s.value.ph0-=180)}return t}function Me(e,t=["phaseCorrection","fft","digitalFilter"]){let{filters:n=[]}=e,r={};for(let o of t)r[o]=n.find(s=>s.name===o);return r}function R(e,t="localStorage"){if(e?.version===7)return e;if(t==="nmrium")return q(e);let n={...e,version:7};for(let r in e.workspaces)n.workspaces[r]=q(n.workspaces[r]);return n}function q(e){let{formatting:{nuclei:t,panels:n}={nuclei:null,panels:null},version:r,...o}=e,s={...o};return t&&(s.nuclei=Te(t)),n&&(s.panels=n),s}function Te(e){let t=[],n={name:"nucleus",ppm:"ppmFormat",hz:"hzFormat"};for(let r in e)t.push(x(e[r],n));return t}function X(e){if(e?.version===7)return e;let t={...e,version:7};return t?.settings&&(t.settings=R(t.settings,"nmrium")),t}function v(e,t="localStorage"){if(e?.version===8)return e;if(t==="nmrium")return J(e);let n={...e,version:8};for(let r in e.workspaces)n.workspaces[r]=J(n.workspaces[r]);return n}function J(e){let{version:t,...n}=e,r={...n};return r.display.panels=Ee(e),r}function Ee(e){let t={},n=e.display.panels;for(let r of Object.keys(n)){let{display:o,open:s}=n[r];t[r]={display:o,visible:o,open:s}}return t}function Y(e){if(e?.version===8)return e;let t={...e,version:8};t?.settings&&(t.settings=v(t.settings,"nmrium"));for(let n of t?.data?.spectra||[]){let{filters:r=[]}=n;for(let i=0;i<r.length;i++){let{flag:a,isDeleteAllow:c,label:f,...l}=r[i];r[i]={...l,enabled:a}}let o=r.findIndex(i=>i.name==="apodization");if(o!==-1){let i=r[o],{lineBroadening:a,gaussBroadening:c,lineBroadeningCenter:f}=i.value;i.value={exponential:{apply:!0,options:{lineBroadening:c>0?-a:a}}},c>0&&(i.value.gaussian={apply:!0,options:{lineBroadening:.6*c,lineBroadeningCenter:f}}),r[o]=i}let s=r.findIndex(i=>i.name==="apodizationDimension1"),u=r.findIndex(i=>i.name==="apodizationDimension2");if(s!==-1){let i=r[s],{shapes:a}=i.value.compose;i.value=H(a)}if(u!==-1){let i=r[u],{shapes:a}=i.value.compose;i.value=H(a)}}return t}function H(e){let t={};for(let{shape:n}of e){let{kind:r,options:o}=n;if(r==="sineBell"){let{exponent:s,offset:u}=o,i=s===2?"sineSquare":"sineBell";t[i]={apply:!0,options:{offset:u}}}}return t}function W(e){let{version:t,plugins:n,...r}=e;return t===9?e:{version:9,plugins:{},...r}}var ke=[V,z,B,_,U,K,X,Y,W];function Q(e,t,n){let r=structuredClone(e),o=Object.entries(e?.plugins??{});for(let[i,{version:a}]of o){let c=n.get(i);if(!(c&&c.version>=a)){if(c){console.warn(`Plugin "${c.id}" is loaded with a version older (${c.version}) than the one used to save the state (${a}).
|
|
2
2
|
NMRium may fail to load the state.
|
|
3
3
|
Please update the plugin to the latest version.`);continue}console.warn(`Plugin "${i}@${a}" is not registered. NMRium may fail to load the state.
|
|
4
|
-
Please consider open this file with the plugin installed.`)}}let s=new Set,u=()=>{let i=r.version;for(let a of n.values())for(let c of a.migrations){if(s.has(c)||i<c.minCore||c.maxCore&&i>c.maxCore)continue;if((r.plugins?.[a.id]?.version||0)===a.version)break;r=c.up(r),s.add(c)}};for(let i=e?.version||0;i<t;i++){let a=
|
|
4
|
+
Please consider open this file with the plugin installed.`)}}let s=new Set,u=()=>{let i=r.version;for(let a of n.values())for(let c of a.migrations){if(s.has(c)||i<c.minCore||c.maxCore&&i>c.maxCore)continue;if((r.plugins?.[a.id]?.version||0)===a.version)break;r=c.up(r),s.add(c)}};for(let i=e?.version||0;i<t;i++){let a=ke[i];r=a(r),u()}u(),r.plugins||(r.plugins={});for(let i of n.values())r.plugins?.[i.id]||(r.plugins[i.id]={id:i.id,version:i.version}),r.plugins[i.id].id=i.id,r.plugins[i.id].version=i.version;return r}import{FileCollection as Ke}from"file-collection";var ee={SDF:"sdf",MOL:"mol",NMRIUM:"nmrium",JSON:"json",JCAMP:"jcamp",DX:"dx",JDX:"jdx",JDF:"jdf",NMREDATA:"nmredata",SMILES:"smiles",SMI:"smi"};function w(e){return e.includes(".")?e.replace(/^.*\./,"").toLowerCase():""}function C(e,t={},n){let{data:r,...o}=e;if(!r)return e;let{spectra:s=[]}=r,{keep1D:u=!0,keep2D:i=!0,onlyReal:a}=t,c=a?"ft":t.dataSelection||"both",f=[];for(let l of s){if(!l.info){f.push(l);continue}let{isFid:d,dimension:m,name:p}=l.info;if(!F(m===1&&!u,p,n)&&!F(m===2&&!i,p,n)&&!F(d&&c==="ft",p,n)&&!F(!d&&c==="fid",p,n))if(a&&!d)if(l.info.isComplex=!1,Ie(l)){let{rr:g}=l.data;f.push({...l,data:{rr:g}})}else{let{re:g,x:y}=l.data;f.push({...l,data:{re:g,x:y}})}else f.push(l)}return{data:{...r,spectra:f},...o}}function F(e,t,n){return e?(n?.warn(`Skipping ${t} because it didn't match the import filters.`),!0):!1}function Ie(e){let{info:t}=e;return t?.dimension===2}function A(e){let{nmriumState:t,plugins:n,options:r}=e;for(let o of n.values()){let s=o.onReadProcess?.onProcessing;s&&s(t,r)}}async function M(e,t,n={}){let{sourceSelector:r,converter:o,keepSource:s,logger:u}=n,i=[],a=[];for(let m of t.values()){let{onReadProcess:p}=m;p&&(p?.onFiles&&i.push(m),p?.supportedExtensions?.length&&p?.onFile&&a.push(m))}let c=await Promise.allSettled(i.map(m=>m.onReadProcess.onFiles(e,n))),f=[],l=await Promise.allSettled(e.files.flatMap(m=>{let p=w(m.name).toLowerCase();return a.flatMap(g=>{let{supportedExtensions:y,onFile:S}=g.onReadProcess;return y.includes(p)?(f.push({file:m,plugin:g}),S(m,{logger:u,sourceSelector:r,converter:o,keepSource:s})):[]})})),d={spectra:[],molecules:[]};for(let m=0;m<c.length;m++){let p=c[m];switch(p.status){case"fulfilled":{let{spectra:g=[],molecules:y=[]}=p.value||{};d.spectra.push(...g),d.molecules.push(...y);break}case"rejected":{let g=p.reason,y=i[m];n.logger?.error(`Load file collection with plugin ${y.id}@${y.version} fails with: ${g}`);break}}}for(let m=0;m<l.length;m++){let p=l[m];switch(p.status){case"fulfilled":{let{spectra:g=[],molecules:y=[]}=p.value||{};d.spectra.push(...g),d.molecules.push(...y);break}case"rejected":{let g=p.reason,{file:y,plugin:S}=f[m];n.logger?.error(`Load file ${y.relativePath} with plugin ${S.id}@${S.version} fails with: ${g}`);break}}}return d}import{FileCollection as Be}from"file-collection";import{FileCollection as je}from"file-collection";import te from"lodash.merge";import{xIsEquallySpaced as Le}from"ml-spectra-processing";async function T(e){let{nmriumObjectInput:t,options:n={},migrator:r,plugins:o}=e,s=r(t),{data:u,...i}=s;if(!u)return{...i};let a={data:{...u,spectra:[]},...i},c=a.data,{source:f,spectra:l,molecules:d}=c,m;f&&(m=await je.fromSource(f,{unzip:{zipExtensions:["zip","nmredata"]}}));let p=[];for(let g of u.spectra)if(m){let{sourceSelector:y}=g,S=E({input:m,migrator:r,plugins:o,options:{...n,sourceSelector:y}}).then(h=>{let{nmriumState:{data:D}}=h,{spectra:se=[],molecules:Z=[]}=D||{};Z.length>0&&d.length===0&&d.push(...Z);for(let ae of se)l.push(Ve(g,ze(ae)))});p.push(S)}else{let{dimension:y}=g.info;if(y===1){if(!Le(g.data)){n.logger?.error('The ".nmrium" file is corrupted; the X-axis values are not equally distant.');continue}l.push(N(g))}else y===2&&l.push(O(g))}return await Promise.allSettled(p),a}function Ve(e,t){let{data:n,...r}=e;if("ranges"in t){let{data:o,...s}=t;return{...te(s,r),data:o}}else if("zones"in t){let{data:o,...s}=t;return{...te(s,r),data:o}}else return t}function ze(e){return{...e,id:b()}}async function re(e){let{file:t,options:n={},migrator:r,plugins:o}=e,s=await t.arrayBuffer(),u=await(Ue(s)?_e(s):t.text());return T({nmriumObjectInput:JSON.parse(u),plugins:o,migrator:r,options:n})}async function _e(e){let t=await Be.fromZip(e);if(t.files.length===0)throw new Error("compressed nmrium file is corrupted");return t.files[0].text()}function Ue(e){if(e.byteLength<4)return!1;let t=new Uint8Array(e);return t[0]===80&&t[1]===75&&(t[2]===3||t[2]===5||t[2]===7)&&(t[3]===4||t[3]===6||t[3]===8)}async function E(e){let{options:t={},input:n,migrator:r,plugins:o}=e,s=We(await Xe(n),t.sourceSelector?.files),u=Ge(s);if(u)return{nmriumState:await re({file:u,migrator:r,plugins:o,options:t}),containsNmrium:!0};let i=await M(s,o,t),a=C({version:9,data:i},t?.sourceSelector?.general,t.logger),{onLoadProcessing:c,experimentalFeatures:f}=t,l={...c,autoProcessing:c?.autoProcessing??!1,experimentalFeatures:f};return A({nmriumState:a,plugins:o,options:l}),{nmriumState:a,containsNmrium:!1}}function Xe(e){return Array.isArray(e)?Promise.reject(new Error("For a set of fileCollectionItems pass a FileCollection instance")):Ye(e)?Promise.resolve(e):new Ke().appendExtendedSource({...e,uuid:crypto.randomUUID()})}function Ye(e){return typeof e=="object"&&"files"in e}function We(e,t){if(!t)return e;let n=new Set(t);return e.filter(r=>n.has(r.relativePath))}function Ge(e){return e.files.find(t=>w(t.name).toLowerCase()===ee.NMRIUM)}function k(e,t){let n={};for(let r in e)t.includes(r)||(n[r]=e[r]);return n}var Ze=["data","originalData","info","originalInfo","meta","customInfo"],$e=["sourceSelector","originalData","originalInfo"];function ne(e,t={}){let{version:n,data:r}=e;if(r.actionType)return e;let o={version:n,plugins:e.plugins},{includeData:s}=t;s!=="noData"&&(o.data=qe({...r},s));let{includeSettings:u,includeView:i}=t;return u&&(o.settings=e.settings),i&&(o.view=e.view),o}function qe(e,t="rawData"){let{spectra:n}=e;switch(t){case"dataSource":return Je(e);case"rawData":return{...k(e,["source"]),spectra:n.map(Qe)};default:return e}}function Je(e){let{spectra:t}=e;if(!e.source)throw new Error("source property should exists for dataSource serialization");return{...e,spectra:t.map(He)}}function He(e){return k(e,Ze)}function Qe(e){let{data:t,info:n,originalData:r,originalInfo:o}=e,s=k(e,$e);return s.data=r||t,s.info=o||n,s}import{FileCollection as et}from"file-collection";async function oe(e){let{source:t,plugins:n,options:r={}}=e,{keepSource:o=!0,converter:s,...u}=r,i={source:t,spectra:[],molecules:[]},a=await et.fromSource(t,{unzip:{zipExtensions:["zip","nmredata"]}}),{spectra:c=[],molecules:f=[]}=await M(a,n,{keepSource:o,converter:{...s,bruker:{keepFiles:!0,...Reflect.get(s??{},"bruker")}},...u});i.spectra.push(...c),i.molecules.push(...f);let l=C({version:9,data:i},r?.sourceSelector?.general),{onLoadProcessing:d}=u,m={filters:d?.filters,autoProcessing:d?.autoProcessing??!1,experimentalFeatures:r.experimentalFeatures};return A({nmriumState:l,plugins:n,options:m}),l}var G=class{version=9;plugins=new Map;registerPlugin(t){if(this.plugins.has(t.id)){console.warn(`Plugin ${t.id} is already registered. skip.`),console.debug("Plugin already registered:",this.plugins.get(t.id)),console.debug("Plugin to register:",t);return}this.plugins.set(t.id,t)}registerPlugins(t){for(let n of t)this.registerPlugin(n)}migrate(t){return Q(t,this.version,this.plugins)}read(t,n={}){return E({input:t,migrator:this.migrate.bind(this),plugins:this.plugins,options:n})}readNMRiumObject(t,n){return T({nmriumObjectInput:t,options:n,plugins:this.plugins,migrator:this.migrate.bind(this)})}readFromWebSource(t,n){return oe({source:t,options:n,plugins:this.plugins})}serializeNmriumState(t,n){return ne(t,n)}};function tt(e,t){if(t>9)return 0;let n=-1;for(let r=0;r<e.length;r++)if(e[r].version>t){n=r;break}return n}var ie=[{version:6,fun:R},{version:7,fun:v}];function rt(e){let{version:t}=e||{},n=tt(ie,t);if(n===-1)return{...e,version:9};let r=ie.slice(n);for(let o of r)e=o.fun(e);return e}export{le as ANALYSIS_COLUMN_TYPES,ce as ANALYSIS_COLUMN_VALUES_KEYS,P as CURRENT_EXPORT_VERSION,pe as EXTERNAL_API_KEYS,G as NMRiumCore,we as formatSpectra,b as generateID,L as getOneIfArray,rt as migrateSettings,ue as units};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "The core of NMRium: types, state, state migration and plugin system.",
|
|
5
5
|
"author": "Zakodium Sàrl",
|
|
6
6
|
"license": "CC-BY-NC-SA-4.0",
|
|
@@ -18,29 +18,27 @@
|
|
|
18
18
|
"bundle": "node scripts/esbuild.js && npm run bundle-types",
|
|
19
19
|
"bundle-types": "npm run tsc && yarn g:api-extractor",
|
|
20
20
|
"clean": "rimraf types dist coverage",
|
|
21
|
-
"dev:eslint-fix": "eslint --cache --fix $(git diff --name-only --relative) --quiet",
|
|
22
21
|
"prepack": "npm run clean && npm run bundle",
|
|
23
|
-
"dev:prettier-write": "prettier --write $(git diff --name-only --relative)",
|
|
24
22
|
"test": "yarn g:test-only && yarn g:check-types && yarn g:eslint && yarn g:prettier",
|
|
25
23
|
"tsc": "tsc --project tsconfig.types.json"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
26
|
"@types/lodash.merge": "^4.6.9",
|
|
29
|
-
"@types/node": "^
|
|
27
|
+
"@types/node": "^24.0.14",
|
|
28
|
+
"@zakodium/nmr-types": "^0.1.0",
|
|
30
29
|
"esbuild": "^0.25.5",
|
|
31
30
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
32
31
|
"rimraf": "^6.0.1",
|
|
33
|
-
"vitest": "^3.
|
|
32
|
+
"vitest": "^3.2.4"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"cheminfo-types": "^1.8.1",
|
|
37
|
-
"fifo-logger": "^
|
|
38
|
-
"
|
|
36
|
+
"fifo-logger": "^2.0.0",
|
|
37
|
+
"file-collection": "^5.0.0",
|
|
39
38
|
"is-any-array": "^2.0.1",
|
|
40
39
|
"lodash.merge": "^4.6.2",
|
|
41
40
|
"ml-spectra-processing": "^14.12.0",
|
|
42
|
-
"nmr-correlation": "^2.3.5"
|
|
43
|
-
"nmr-processing": "^18.1.0"
|
|
41
|
+
"nmr-correlation": "^2.3.5"
|
|
44
42
|
},
|
|
45
43
|
"volta": {
|
|
46
44
|
"extends": "../../../package.json"
|