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
28 changes: 26 additions & 2 deletions app/routers/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io
from app.schemas import HealthCheck
from pydantic import BaseModel, HttpUrl, Field
from typing import Optional
from typing import Optional, List
import subprocess
import tempfile
import os
Expand Down Expand Up @@ -50,6 +50,10 @@ class UrlParseRequest(BaseModel):
)
raw_data: bool = Field(
False, description="Include raw data in the output (default: data source)")
include: Optional[List[str]] = Field(
None, description="Only include files matching pattern(s) (glob/regex string)")
exclude: Optional[List[str]] = Field(
None, description="Exclude files matching pattern(s) (glob/regex string)")

model_config = {
"json_schema_extra": {
Expand Down Expand Up @@ -95,6 +99,8 @@ def run_command(
auto_processing: bool = False,
auto_detection: bool = False,
raw_data: bool = False,
include: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
) -> StreamingResponse:
"""Execute nmr-cli parse-spectra command in Docker container."""

Expand All @@ -113,6 +119,12 @@ def run_command(
cmd.append("-d")
if raw_data:
cmd.append("-r")
if include:
cmd.append("--include")
cmd.extend(include)
if exclude:
cmd.append("--exclude")
cmd.extend(exclude)

try:
result = subprocess.run(
Expand Down Expand Up @@ -362,7 +374,11 @@ async def parse_spectra_from_file(
description="Enable ranges and zones automatic detection",
),
raw_data: bool = Form(
False, description="Include raw data in the output (default: data source references)")
False, description="Include raw data in the output (default: data source references)"),
include: Optional[List[str]] = Form(
None, description="Only include files matching pattern(s) (glob/regex string)"),
exclude: Optional[List[str]] = Form(
None, description="Exclude files matching pattern(s) (glob/regex string)"),
):
"""
## Parse spectra from an uploaded file
Expand All @@ -376,6 +392,8 @@ async def parse_spectra_from_file(
| `auto_processing` | Automatically process FID → FT spectra |
| `auto_detection` | Automatically detect ranges and zones |
| `raw_data` | Include raw data in the output (default: data source) |
| `include` | Only include files matching pattern(s) |
| `exclude` | Exclude files matching pattern(s) |
### Returns
Parsed spectra data in NMRium-compatible JSON format.
"""
Expand Down Expand Up @@ -405,6 +423,8 @@ async def parse_spectra_from_file(
auto_processing=auto_processing,
auto_detection=auto_detection,
raw_data=raw_data,
include=include,
exclude=exclude,
)

except HTTPException:
Expand Down Expand Up @@ -452,6 +472,8 @@ async def parse_spectra_from_url(request: UrlParseRequest):
| `auto_processing` | Automatically process FID → FT spectra |
| `auto_detection` | Automatically detect ranges and zones |
| `raw_data` | Include raw data in the output (default: data source) |
| `include` | Only include files matching pattern(s) |
| `exclude` | Exclude files matching pattern(s) |

### Returns
Parsed spectra data in NMRium-compatible JSON format.
Expand All @@ -463,6 +485,8 @@ async def parse_spectra_from_url(request: UrlParseRequest):
auto_processing=request.auto_processing,
auto_detection=request.auto_detection,
raw_data=request.raw_data,
include=request.include,
exclude=request.exclude,
)

except HTTPException:
Expand Down
16 changes: 12 additions & 4 deletions app/scripts/nmr-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# build the image ` docker build --tag nmr-cli . `
# run the container ` docker run -it nmr-cli bash `

FROM mcr.microsoft.com/playwright:v1.58.2-noble
# NOTE: if `docker run` prints
# "Error while loading conda entry point: conda-libmamba-solver (module 'libmambapy' has no attribute 'QueryFormat')"
# this is unrelated to this image/container — it comes from a version mismatch between
# conda-libmamba-solver and libmambapy in your HOST shell's conda (base) environment.
# It does not affect the container. To fix it on the host, run:
# conda update -n base -c conda-forge conda conda-libmamba-solver libmambapy
# or, if that doesn't resolve it:
# conda install -n base -c conda-forge --force-reinstall conda-libmamba-solver libmambapy
# or, to bypass libmamba entirely:
# conda config --set solver classic

FROM mcr.microsoft.com/playwright:v1.62.1-noble

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Downgrade to Node 22
RUN npm install -g n && n 22 && hash -r

WORKDIR /app

#ENV BASE_NMRIUM_URL=https://nmrium.nmrxiv.org/
Expand Down
Loading
Loading