Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 62 additions & 5 deletions app/scripts/nmr-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion app/scripts/nmr-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@
"nmr-cli": "./build/index.js"
},
"dependencies": {
"@zakodium/nmr-types": "^0.4.0",
"@zakodium/nmrium-core": "^0.4.2",
"@zakodium/nmrium-core-plugins": "^0.5.3",
"axios": "^1.13.0",
"file-collection": "^5.4.0",
"lodash.merge": "^4.6.2",
"mf-parser": "^3.6.0",
"ml-spectra-processing": "^14.18.0",
"nmr-processing": "^20.1.0",
"playwright": "^1.56.1",
"yargs": "^18.0.0"
},
"devDependencies": {
"@types/lodash.merge": "^4.6.9",
"@types/node": "^24.9.1",
"@types/yargs": "^17.0.34",
"ts-node": "^10.9.2",
"typescript": "^5.9.3"
}
}
}
83 changes: 60 additions & 23 deletions app/scripts/nmr-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import yargs, { type Argv, type CommandModule, type Options } from 'yargs'
import { loadSpectrumFromURL, loadSpectrumFromFilePath } from './prase-spectra'
import { loadSpectrumFromURL, loadSpectrumFromFilePath } from './parse/prase-spectra'
import { generateSpectrumFromPublicationString } from './publication-string'
import { parsePredictionCommand } from './prediction/parsePredictionCommand'
import { hideBin } from 'yargs/helpers'
Expand All @@ -14,18 +14,14 @@ Commands:
predict Predict spectrum from Mol

Options for 'parse-spectra' command:
-u, --url File URL
-p, --path Directory path
-s, --capture-snapshot Capture snapshot
-u, --url File URL
-dir, --dir-path Directory path
-s, --capture-snapshot Capture snapshot
-p, --auto-processing Automatic processing of spectrum (FID → FT spectra).
-d, --auto-detection Enable ranges and zones automatic detection.

Arguments for 'parse-publication-string' command:
publicationString Publication string

Options for 'parse-spectra' command:
-u, --url File URL
-p, --path Directory path
-s, --capture-snapshot Capture snapshot


Options for 'predict' command:
-ps,--peakShape Peak shape algorithm (default: "lorentzian") choices: ["gaussian", "lorentzian"]
Expand All @@ -46,16 +42,43 @@ Options for 'predict' command:

Examples:
nmr-cli parse-spectra -u file-url -s // Process spectra files from a URL and capture an image for the spectra
nmr-cli parse-spectra -p directory-path -s // process a spectra files from a directory and capture an image for the spectra
nmr-cli parse-spectra -dir directory-path -s // process a spectra files from a directory and capture an image for the spectra
nmr-cli parse-spectra -u file-url // Process spectra files from a URL
nmr-cli parse-spectra -p directory-path // Process spectra files from a directory
nmr-cli parse-spectra -dir directory-path // Process spectra files from a directory
nmr-cli parse-publication-string "your publication string"
`

interface FileOptionsArgs {
u?: string
p?: string
s?: boolean
export interface FileOptionsArgs {
/**
* -u, --url
* File URL to load remote spectra or data.
*/
u?: string;

/**
* -dir, --dir-path
* Local directory path for file input or output.
*/
dir?: string;

/**
* -s, --capture-snapshot
* Capture a visual snapshot of the current state or spectrum.
*/
s?: boolean;

/**
* -p, --auto-processing
* Automatically process spectrum from FID to FT spectra.
* Mandatory when automatic detection (`--auto-detection`) is enabled.
*/
p?: boolean;

/**
* -d, --auto-detection
* Perform automatic ranges and zones detection.
*/
d?: boolean;
}

// Define options for parsing a spectra file
Expand All @@ -66,8 +89,8 @@ const fileOptions: { [key in keyof FileOptionsArgs]: Options } = {
type: 'string',
nargs: 1,
},
p: {
alias: 'path',
dir: {
alias: 'dir-path',
describe: 'Directory path',
type: 'string',
nargs: 1,
Expand All @@ -77,6 +100,16 @@ const fileOptions: { [key in keyof FileOptionsArgs]: Options } = {
describe: 'Capture snapshot',
type: 'boolean',
},
p: {
alias: 'auto-processing',
describe: 'Auto processing',
type: 'boolean',
},
d: {
alias: 'auto-detection',
describe: 'Ranges and zones auto detection',
type: 'boolean',
},
} as const

const parseFileCommand: CommandModule<{}, FileOptionsArgs> = {
Expand All @@ -85,21 +118,25 @@ const parseFileCommand: CommandModule<{}, FileOptionsArgs> = {
builder: yargs => {
return yargs
.options(fileOptions)
.conflicts('u', 'p') as Argv<FileOptionsArgs>
.conflicts('u', 'dir') as Argv<FileOptionsArgs>
},
handler: argv => {

const { u, dir } = argv;
// Handle parsing the spectra file logic based on argv options
if (argv?.u) {
loadSpectrumFromURL(argv.u, argv.s).then(result => {
if (u) {
loadSpectrumFromURL({ u, ...argv }).then(result => {
console.log(JSON.stringify(result))
})
}

if (argv?.p) {
loadSpectrumFromFilePath(argv.p, argv.s).then(result => {

if (dir) {
loadSpectrumFromFilePath({ dir, ...argv }).then(result => {
console.log(JSON.stringify(result))
})
}

},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { NmrData1D } from 'cheminfo-types';

function convert(value: Float64Array | number[] = []): Float64Array {
return !ArrayBuffer.isView(value) && value ? Float64Array.from(value) : value;
}

export function convertDataToFloat64Array(data: NmrData1D): NmrData1D {
return {
x: convert(data.x),
re: convert(data.re),
im: convert(data?.im),
};
}
Loading
Loading