Skip to content

Commit 8f125be

Browse files
authored
Merge pull request #86 from NFDI4Chem/expose-nmrium-features
feat: expose nmrium features
2 parents b9b2cbb + 2d84e7e commit 8f125be

21 files changed

+835
-36
lines changed

app/scripts/nmr-cli/package-lock.json

Lines changed: 62 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/scripts/nmr-cli/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,23 @@
1515
"nmr-cli": "./build/index.js"
1616
},
1717
"dependencies": {
18+
"@zakodium/nmr-types": "^0.4.0",
1819
"@zakodium/nmrium-core": "^0.4.2",
1920
"@zakodium/nmrium-core-plugins": "^0.5.3",
2021
"axios": "^1.13.0",
2122
"file-collection": "^5.4.0",
23+
"lodash.merge": "^4.6.2",
24+
"mf-parser": "^3.6.0",
25+
"ml-spectra-processing": "^14.18.0",
2226
"nmr-processing": "^20.1.0",
2327
"playwright": "^1.56.1",
2428
"yargs": "^18.0.0"
2529
},
2630
"devDependencies": {
31+
"@types/lodash.merge": "^4.6.9",
2732
"@types/node": "^24.9.1",
2833
"@types/yargs": "^17.0.34",
2934
"ts-node": "^10.9.2",
3035
"typescript": "^5.9.3"
3136
}
32-
}
37+
}

app/scripts/nmr-cli/src/index.ts

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
import yargs, { type Argv, type CommandModule, type Options } from 'yargs'
3-
import { loadSpectrumFromURL, loadSpectrumFromFilePath } from './prase-spectra'
3+
import { loadSpectrumFromURL, loadSpectrumFromFilePath } from './parse/prase-spectra'
44
import { generateSpectrumFromPublicationString } from './publication-string'
55
import { parsePredictionCommand } from './prediction/parsePredictionCommand'
66
import { hideBin } from 'yargs/helpers'
@@ -14,18 +14,14 @@ Commands:
1414
predict Predict spectrum from Mol
1515
1616
Options for 'parse-spectra' command:
17-
-u, --url File URL
18-
-p, --path Directory path
19-
-s, --capture-snapshot Capture snapshot
17+
-u, --url File URL
18+
-dir, --dir-path Directory path
19+
-s, --capture-snapshot Capture snapshot
20+
-p, --auto-processing Automatic processing of spectrum (FID → FT spectra).
21+
-d, --auto-detection Enable ranges and zones automatic detection.
2022
2123
Arguments for 'parse-publication-string' command:
2224
publicationString Publication string
23-
24-
Options for 'parse-spectra' command:
25-
-u, --url File URL
26-
-p, --path Directory path
27-
-s, --capture-snapshot Capture snapshot
28-
2925
3026
Options for 'predict' command:
3127
-ps,--peakShape Peak shape algorithm (default: "lorentzian") choices: ["gaussian", "lorentzian"]
@@ -46,16 +42,43 @@ Options for 'predict' command:
4642
4743
Examples:
4844
nmr-cli parse-spectra -u file-url -s // Process spectra files from a URL and capture an image for the spectra
49-
nmr-cli parse-spectra -p directory-path -s // process a spectra files from a directory and capture an image for the spectra
45+
nmr-cli parse-spectra -dir directory-path -s // process a spectra files from a directory and capture an image for the spectra
5046
nmr-cli parse-spectra -u file-url // Process spectra files from a URL
51-
nmr-cli parse-spectra -p directory-path // Process spectra files from a directory
47+
nmr-cli parse-spectra -dir directory-path // Process spectra files from a directory
5248
nmr-cli parse-publication-string "your publication string"
5349
`
5450

55-
interface FileOptionsArgs {
56-
u?: string
57-
p?: string
58-
s?: boolean
51+
export interface FileOptionsArgs {
52+
/**
53+
* -u, --url
54+
* File URL to load remote spectra or data.
55+
*/
56+
u?: string;
57+
58+
/**
59+
* -dir, --dir-path
60+
* Local directory path for file input or output.
61+
*/
62+
dir?: string;
63+
64+
/**
65+
* -s, --capture-snapshot
66+
* Capture a visual snapshot of the current state or spectrum.
67+
*/
68+
s?: boolean;
69+
70+
/**
71+
* -p, --auto-processing
72+
* Automatically process spectrum from FID to FT spectra.
73+
* Mandatory when automatic detection (`--auto-detection`) is enabled.
74+
*/
75+
p?: boolean;
76+
77+
/**
78+
* -d, --auto-detection
79+
* Perform automatic ranges and zones detection.
80+
*/
81+
d?: boolean;
5982
}
6083

6184
// Define options for parsing a spectra file
@@ -66,8 +89,8 @@ const fileOptions: { [key in keyof FileOptionsArgs]: Options } = {
6689
type: 'string',
6790
nargs: 1,
6891
},
69-
p: {
70-
alias: 'path',
92+
dir: {
93+
alias: 'dir-path',
7194
describe: 'Directory path',
7295
type: 'string',
7396
nargs: 1,
@@ -77,6 +100,16 @@ const fileOptions: { [key in keyof FileOptionsArgs]: Options } = {
77100
describe: 'Capture snapshot',
78101
type: 'boolean',
79102
},
103+
p: {
104+
alias: 'auto-processing',
105+
describe: 'Auto processing',
106+
type: 'boolean',
107+
},
108+
d: {
109+
alias: 'auto-detection',
110+
describe: 'Ranges and zones auto detection',
111+
type: 'boolean',
112+
},
80113
} as const
81114

82115
const parseFileCommand: CommandModule<{}, FileOptionsArgs> = {
@@ -85,21 +118,25 @@ const parseFileCommand: CommandModule<{}, FileOptionsArgs> = {
85118
builder: yargs => {
86119
return yargs
87120
.options(fileOptions)
88-
.conflicts('u', 'p') as Argv<FileOptionsArgs>
121+
.conflicts('u', 'dir') as Argv<FileOptionsArgs>
89122
},
90123
handler: argv => {
124+
125+
const { u, dir } = argv;
91126
// Handle parsing the spectra file logic based on argv options
92-
if (argv?.u) {
93-
loadSpectrumFromURL(argv.u, argv.s).then(result => {
127+
if (u) {
128+
loadSpectrumFromURL({ u, ...argv }).then(result => {
94129
console.log(JSON.stringify(result))
95130
})
96131
}
97132

98-
if (argv?.p) {
99-
loadSpectrumFromFilePath(argv.p, argv.s).then(result => {
133+
134+
if (dir) {
135+
loadSpectrumFromFilePath({ dir, ...argv }).then(result => {
100136
console.log(JSON.stringify(result))
101137
})
102138
}
139+
103140
},
104141
}
105142

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { NmrData1D } from 'cheminfo-types';
2+
3+
function convert(value: Float64Array | number[] = []): Float64Array {
4+
return !ArrayBuffer.isView(value) && value ? Float64Array.from(value) : value;
5+
}
6+
7+
export function convertDataToFloat64Array(data: NmrData1D): NmrData1D {
8+
return {
9+
x: convert(data.x),
10+
re: convert(data.re),
11+
im: convert(data?.im),
12+
};
13+
}

0 commit comments

Comments
 (0)