-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·166 lines (144 loc) · 5.01 KB
/
index.ts
File metadata and controls
executable file
·166 lines (144 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env node
import yargs, { type Argv, type CommandModule, type Options } from 'yargs'
import { loadSpectrumFromURL, loadSpectrumFromFilePath } from './parse/prase-spectra'
import { generateSpectrumFromPublicationString } from './publication-string'
import { parsePredictionCommand } from './prediction/parsePredictionCommand'
import { hideBin } from 'yargs/helpers'
const usageMessage = `
Usage: nmr-cli <command> [options]
Commands:
parse-spectra Parse a spectra file to NMRium file
parse-publication-string resurrect spectrum from the publication string
predict Predict spectrum from Mol
Options for 'parse-spectra' command:
-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 'predict' command:
-ps,--peakShape Peak shape algorithm (default: "lorentzian") choices: ["gaussian", "lorentzian"]
-n, --nucleus Predicted nucleus, choices: ["1H","13C"] (required)
-i, --id Input ID (default: 1)
-t, --type NMR type (default: "nmr;1H;1d")
-s, --shifts Chemical shifts (default: "1")
--solvent NMR solvent (default: "Dimethylsulphoxide-D6 (DMSO-D6, C2D6SO)")
-m, --molText MOL text (required)
--from From in (ppm)
--to To in (ppm)
--nbPoints Number of points (default: 1024)
--lineWidth Line width (default: 1)
--frequency NMR frequency (MHz) (default: 400)
--tolerance Tolerance to group peaks with close shift (default: 0.001)
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 -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 -dir directory-path // Process spectra files from a directory
nmr-cli parse-publication-string "your publication string"
`
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
const fileOptions: { [key in keyof FileOptionsArgs]: Options } = {
u: {
alias: 'url',
describe: 'File URL',
type: 'string',
nargs: 1,
},
dir: {
alias: 'dir-path',
describe: 'Directory path',
type: 'string',
nargs: 1,
},
s: {
alias: 'capture-snapshot',
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> = {
command: ['parse-spectra', 'ps'],
describe: 'Parse a spectra file to NMRium file',
builder: yargs => {
return yargs
.options(fileOptions)
.conflicts('u', 'dir') as Argv<FileOptionsArgs>
},
handler: argv => {
const { u, dir } = argv;
// Handle parsing the spectra file logic based on argv options
if (u) {
loadSpectrumFromURL({ u, ...argv }).then(result => {
console.log(JSON.stringify(result))
})
}
if (dir) {
loadSpectrumFromFilePath({ dir, ...argv }).then(result => {
console.log(JSON.stringify(result))
})
}
},
}
// Define the parse publication string command
const parsePublicationCommand: CommandModule = {
command: ['parse-publication-string', 'pps'],
describe: 'Parse a publication string',
handler: argv => {
const publicationString = argv._[1]
// Handle parsing publication string
if (typeof publicationString == 'string') {
const nmriumObject =
generateSpectrumFromPublicationString(publicationString)
console.log(JSON.stringify(nmriumObject))
}
},
}
yargs(hideBin(process.argv))
.usage(usageMessage)
.command(parseFileCommand)
.command(parsePublicationCommand)
.command(parsePredictionCommand)
.showHelpOnFail(true)
.help()
.parse()