Skip to content
Merged
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
1 change: 0 additions & 1 deletion app/scripts/nmr-cli/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package-lock.json
node_modules/
build/

Expand Down
4 changes: 2 additions & 2 deletions app/scripts/nmr-cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY package.json ./
COPY package.json package-lock.json ./

RUN npm install
RUN npm ci

COPY . ./

Expand Down
22 changes: 9 additions & 13 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.

3 changes: 2 additions & 1 deletion app/scripts/nmr-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "nmr-cli",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "./build/index.js",
"scripts": {
"build": "tsc",
Expand Down Expand Up @@ -33,7 +34,7 @@
},
"devDependencies": {
"@types/lodash.merge": "^4.6.9",
"@types/node": "^26.2.0",
"@types/node": "^26.6.3",
"@types/yargs": "^17.0.35",
"ts-node": "^10.9.2",
"typescript": "^5.9.3"
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/nmr-cli/src/correlation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
loadFileCollection,
parsingOptions,
processSpectra,
} from './parse/prase-spectra'
import { isSpectrum2D } from './parse/data/data2d/isSpectrum2D'
} from './parse/prase-spectra.js'
import { isSpectrum2D } from './parse/data/data2d/isSpectrum2D.js'

// Default tolerances confirmed by vcnainala on issue #66
const DEFAULT_TOLERANCE_H = 0.02
Expand Down
61 changes: 31 additions & 30 deletions app/scripts/nmr-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env node
import yargs, { type Argv, type CommandModule, type Options } from 'yargs'
import { parseSpectra } from './parse/prase-spectra'
import { generateSpectrumFromPublicationString } from './publication-string'
import { generateNMRiumFromPeaks } from './peaks-to-nmrium'
import type { PeaksToNMRiumInput } from './peaks-to-nmrium'
import { generateCorrelationData } from './correlation'
import { parseSpectra } from './parse/prase-spectra.js'
import { generateSpectrumFromPublicationString } from './publication-string.js'
import { generateNMRiumFromPeaks } from './peaks-to-nmrium.js'
import type { PeaksToNMRiumInput } from './peaks-to-nmrium.js'
import { generateCorrelationData } from './correlation.js'
import { hideBin } from 'yargs/helpers'
import { parsePredictionCommand } from './prediction'
import { readFileSync } from 'fs'
import { IncludeData } from '@zakodium/nmrium-core'
import { parsePredictionCommand } from './prediction/index.js'
import { readFileSync } from 'node:fs'

const usageMessage = `
Usage: nmr-cli <command> [options]
Expand Down Expand Up @@ -103,59 +102,58 @@ Examples:
`

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

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

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

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

/**
/**
* -d, --auto-detection
* Perform automatic ranges and zones detection.
*/
d?: boolean;
d?: boolean
/**
* -o, --output
* -o, --output
* Output file path
*/
o?: string;
o?: string
/**
* -r, --raw-data
* -r, --raw-data
* Include raw data in the output, defaults to dataSource
*/
r?: boolean;
r?: boolean

/**
* --include
* Only include files matching these pattern(s) when reading a directory (file-collection's filter.include).
*/
include?: string[];
include?: string[]

/**
* --exclude
* Exclude files matching these pattern(s) when reading a directory (file-collection's filter.exclude).
*/
exclude?: string[];

exclude?: string[]
}

// Define options for parsing a spectra file
Expand Down Expand Up @@ -201,12 +199,14 @@ const fileOptions: { [key in keyof FileOptionsArgs]: Options } = {
include: {
type: 'array',
string: true,
description: 'Only include files matching pattern(s) when reading a directory (glob/regex string)',
description:
'Only include files matching pattern(s) when reading a directory (glob/regex string)',
},
exclude: {
type: 'array',
string: true,
description: 'Exclude files matching pattern(s) when reading a directory (glob/regex string)',
description:
'Exclude files matching pattern(s) when reading a directory (glob/regex string)',
},
} as const

Expand Down Expand Up @@ -252,7 +252,7 @@ const peaksToNMRiumCommand: CommandModule = {
} catch (error) {
console.error(
'Error:',
error instanceof Error ? error.message : String(error),
error instanceof Error ? error.message : String(error)
)
process.exit(1)
}
Expand All @@ -262,7 +262,8 @@ const peaksToNMRiumCommand: CommandModule = {
// Define the correlation command
const correlationCommand: CommandModule = {
command: ['correlation', 'corr'],
describe: 'Build correlation data from NMR spectra fetched from a URL or a local directory',
describe:
'Build correlation data from NMR spectra fetched from a URL or a local directory',
builder: yargs => {
return yargs
.options({
Expand Down Expand Up @@ -312,7 +313,7 @@ const correlationCommand: CommandModule = {
} catch (error) {
console.error(
'Error:',
error instanceof Error ? error.message : String(error),
error instanceof Error ? error.message : String(error)
)
process.exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { NmrData1D } from 'cheminfo-types';
import type { NmrData1D } from 'cheminfo-types'

function convert(value: Float64Array | number[] = []): Float64Array {
return !ArrayBuffer.isView(value) && value ? Float64Array.from(value) : value;
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