-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
154 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from typing import Annotated | ||
from fastapi import APIRouter, HTTPException, status, FastAPI, File, UploadFile | ||
from fastapi.responses import Response | ||
from app.schemas import HealthCheck | ||
import subprocess | ||
import json | ||
|
||
router = APIRouter( | ||
prefix="/spectra", | ||
tags=["spectra"], | ||
dependencies=[], | ||
responses={404: {"description": "Not found"}}, | ||
) | ||
|
||
@router.get("/", include_in_schema=False) | ||
@router.get( | ||
"/health", | ||
tags=["healthcheck"], | ||
summary="Perform a Health Check on Chem Module", | ||
response_description="Return HTTP Status Code 200 (OK)", | ||
status_code=status.HTTP_200_OK, | ||
include_in_schema=False, | ||
response_model=HealthCheck, | ||
) | ||
def get_health() -> HealthCheck: | ||
""" | ||
## Perform a Health Check | ||
Endpoint to perform a healthcheck on. This endpoint can primarily be used Docker | ||
to ensure a robust container orchestration and management is in place. Other | ||
services which rely on proper functioning of the API service will not deploy if this | ||
endpoint returns any other HTTP status code except 200 (OK). | ||
Returns: | ||
HealthCheck: Returns a JSON response with the health status | ||
""" | ||
return HealthCheck(status="OK") | ||
|
||
|
||
@router.post( | ||
"/parse", | ||
tags=["spectra"], | ||
summary="Parse the input spectra format and extract metadata", | ||
response_description="", | ||
status_code=status.HTTP_200_OK, | ||
) | ||
async def parse_spectra(file: UploadFile): | ||
""" | ||
## Parse the spectra file and extract meta-data | ||
Endpoint to uses nmr-load-save to read the input spectra file (.jdx,.nmredata,.dx) and extracts metadata | ||
Returns: | ||
data: spectra data in json format | ||
""" | ||
try: | ||
contents = file.file.read() | ||
file_path = "/tmp/" + file.filename | ||
with open(file_path, 'wb') as f: | ||
f.write(contents) | ||
p = subprocess.Popen("npx nmr-cli -p " + file_path, stdout=subprocess.PIPE, shell=True) | ||
(output, err) = p.communicate() | ||
p_status = p.wait() | ||
return output | ||
except Exception as e: | ||
raise HTTPException( | ||
status_code=422, | ||
detail="Error paring the structure " + e.message + ". Error: " + err + ". Status:" + p_status, | ||
headers={"X-Error": "RDKit molecule input parse error"}, | ||
) | ||
finally: | ||
file.file.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env node | ||
const {join,isAbsolute}= require("path"); | ||
const yargs = require("yargs"); | ||
const loader = require("nmr-load-save"); | ||
const fileUtils = require("filelist-utils"); | ||
|
||
const usageMessage ="Usage: nmr-cli -u <url> or -p <path>" | ||
|
||
const options = yargs | ||
.usage(usageMessage) | ||
.option("u", { alias: "url", describe: "File URL", type: "string",nargs:1}) | ||
.option("p", { alias: "path", describe: "Directory path", type: "string",nargs:1}).showHelpOnFail(); | ||
|
||
async function loadSpectrumFromURL(url) { | ||
const {pathname:relativePath,origin:baseURL} = new URL(url); | ||
const source = { | ||
entries: [ | ||
{ | ||
relativePath, | ||
} | ||
], | ||
baseURL | ||
}; | ||
const fileCollection = await fileUtils.fileCollectionFromWebSource(source,{}); | ||
|
||
const { | ||
nmriumState: { data }, | ||
} = await loader.read(fileCollection); | ||
return data; | ||
} | ||
|
||
|
||
async function loadSpectrumFromFilePath(path) { | ||
const dirPath = isAbsolute(path)?path:join(process.cwd(),path) | ||
|
||
const fileCollection = await fileUtils.fileCollectionFromPath(dirPath,{}); | ||
|
||
const { | ||
nmriumState: { data }, | ||
} = await loader.read(fileCollection); | ||
return data; | ||
} | ||
|
||
|
||
const parameters = options.argv; | ||
|
||
if(parameters.u && parameters.p){ | ||
options.showHelp(); | ||
}else{ | ||
|
||
if(parameters.u){ | ||
loadSpectrumFromURL(parameters.u).then((result)=>{ | ||
console.log(JSON.stringify(result)) | ||
}) | ||
|
||
} | ||
|
||
if(parameters.p){ | ||
loadSpectrumFromFilePath(parameters.p).then((result)=>{ | ||
console.log(JSON.stringify(result)) | ||
}) | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
6 changes: 3 additions & 3 deletions
6
app/scripts/nmr-load-save/package-lock.json → app/scripts/nmr-cli/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters