Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to version 1.1.2 #193

Merged
merged 3 commits into from
May 21, 2024
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
19 changes: 11 additions & 8 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
name: Test with pytest
name: Tests

on: [push]

jobs:
build-linux:
run-unit-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install dependencies
run: |
$CONDA/bin/conda env update --file environment.yml --name base
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: python-v38
environment-file: environment.yml
miniforge-version: latest
- name: Test with pytest
shell: bash -el {0}
run: |
# pip install -r requirements.txt
$CONDA/bin/python -m pytest
conda activate python-v38
python -m pytest
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This backend web service provides NMR/IR/MS processing for jcamp/RAW/mzML files.

![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)
![Testing](https://github.com/ComPlat/chem-spectra-app/actions/workflows/unit_test.yml/badge.svg)

The frontend is provided by chem-spectra-client.

### Install
Expand Down
13 changes: 11 additions & 2 deletions chem_spectra/controller/transform_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from chem_spectra.model.transformer import TransformerModel as TraModel
from chem_spectra.lib.converter.bagit.base import BagItBaseConverter
from chem_spectra.model.molecule import MoleculeModel


trans_api = Blueprint('transform_api', __name__)
Expand All @@ -33,7 +34,8 @@ def zip_jcamp_n_img():
molfile = FileContainer(request.files.get('molfile'))
params = extract_params(request)
if file: # and allowed_file(file):
cmpsr, invalid_molfile = TraModel(file, molfile=molfile, params=params).to_composer()
transform_model = TraModel(file, molfile=molfile, params=params)
cmpsr, invalid_molfile = transform_model.to_composer()
if (not cmpsr):
abort(403)

Expand Down Expand Up @@ -79,7 +81,14 @@ def zip_jcamp_n_img():
)
rsp.headers['X-Extra-Info-JSON'] = json.dumps({'spc_type': spc_type, 'invalid_molfile': invalid_molfile})
else:
tf_jcamp, tf_img, tf_csv, tf_nmrium = cmpsr.tf_jcamp(), cmpsr.tf_img(), cmpsr.tf_csv(), cmpsr.generate_nmrium()
tf_jcamp, tf_img, tf_csv = cmpsr.tf_jcamp(), cmpsr.tf_img(), cmpsr.tf_csv()
tf_nmrium = None
try:
molecule_model = MoleculeModel(molfile, cmpsr.core.ncl, decorate=False)
tf_nmrium = cmpsr.generate_nmrium(molfile_data=molecule_model.moltxt)
except Exception:
pass

spc_type = cmpsr.core.ncl if cmpsr.core.typ == 'NMR' else cmpsr.core.typ
if (tf_csv is not None and tf_csv != False):
memory = to_zip_response([tf_jcamp, tf_img, tf_csv])
Expand Down
36 changes: 32 additions & 4 deletions chem_spectra/lib/composer/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,21 +587,36 @@ def tf_csv(self):
})
return tf_csv

def generate_nmrium(self):
def generate_nmrium(self, version=4, molfile_data=None):
typ = self.core.typ
if 'NMR' != typ:
return None

dic_data = {'actionType': 'INITIATE', 'version': 3}
spectra = self.__generate_nmrim_spectra()
dic_data['spectra'] = spectra
if version == 3:
dic_data = self.__generate_nmrium_version_3(molfile_data=molfile_data)
else:
dic_data = self.__generate_nmrium_data(version=version, molfile_data=molfile_data)

json_data = json.dumps(dic_data)

tf_nmrium = tempfile.NamedTemporaryFile(suffix='.nmrium')
tf_nmrium.write(bytes(json_data, 'UTF-8'))
tf_nmrium.seek(0)
return tf_nmrium

def __generate_nmrium_version_3(self, molfile_data=None):
dic_data = {'actionType': 'INITIATE', 'version': 3}
spectra = self.__generate_nmrim_spectra()
dic_data['spectra'] = spectra
dic_data['molecules'] = self.__generate_molecules(molfile_data)
return dic_data

def __generate_nmrium_data(self, version, molfile_data=None):
dic_data = {'version': version, 'data': {}, 'view': {}}
spectra = self.__generate_nmrim_spectra()
dic_data['data']['spectra'] = spectra
dic_data['data']['molecules'] = self.__generate_molecules(molfile_data)
return dic_data

def __generate_nmrim_spectra(self):
spectra = []
Expand Down Expand Up @@ -780,3 +795,16 @@ def __generate_nmrim_ranges(self):
dic_ranges['values'].append(rang_item)

return dic_ranges

def __generate_molecules(self, molfile_data):
if molfile_data is None:
return []

molecule_id = str(uuid.uuid4())
return [
{
'id': molecule_id,
'label': 'P1',
'molfile': molfile_data
}
]
67 changes: 38 additions & 29 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,70 @@ channels:
dependencies:
- _libgcc_mutex=0.1=main
- _openmp_mutex=5.1=1_gnu
- ca-certificates=2023.08.22=h06a4308_0
- ca-certificates=2024.3.11=h06a4308_0
- ld_impl_linux-64=2.38=h1181459_1
- libffi=3.4.4=h6a678d5_0
- libffi=3.4.4=h6a678d5_1
- libgcc-ng=11.2.0=h1234567_1
- libgomp=11.2.0=h1234567_1
- libstdcxx-ng=11.2.0=h1234567_1
- ncurses=6.4=h6a678d5_0
- openssl=3.0.11=h7f8727e_2
- pip=23.3=py38h06a4308_0
- python=3.8.18=h955ad1f_0
- openssl=3.0.13=h7f8727e_1
- pip=24.0=py38h06a4308_0
- python=3.8.19=h955ad1f_0
- readline=8.2=h5eee18b_0
- setuptools=68.0.0=py38h06a4308_0
- sqlite=3.41.2=h5eee18b_0
- tk=8.6.12=h1ccaba5_0
- wheel=0.41.2=py38h06a4308_0
- xz=5.4.2=h5eee18b_0
- zlib=1.2.13=h5eee18b_0
- setuptools=69.5.1=py38h06a4308_0
- sqlite=3.45.3=h5eee18b_0
- tk=8.6.14=h39e8969_0
- wheel=0.43.0=py38h06a4308_0
- xz=5.4.6=h5eee18b_1
- zlib=1.2.13=h5eee18b_1
- pip:
- atomicwrites==1.3.0
- attrs==23.1.0
- certifi==2023.7.22
- astroid==2.15.8
- atomicwrites==1.4.1
- attrs==23.2.0
- certifi==2024.2.2
- cftime==1.6.3
- chardet==3.0.4
- chardet==5.2.0
- charset-normalizer==3.3.2
- click==8.0.0
- click==8.1.7
- contourpy==1.1.1
- coverage==4.5.3
- cycler==0.10.0
- coverage==7.5.1
- coverage-badge==1.1.1
- cycler==0.12.1
- dill==0.3.8
- entrypoints==0.3
- exceptiongroup==1.1.3
- flake8==3.7.7
- exceptiongroup==1.2.1
- flake8==3.7.9
- flask==2.2.5
- flask-jwt-extended==4.5.2
- fonttools==4.43.1
- gunicorn==19.9.0
- idna==2.7
- fonttools==4.51.0
- gunicorn==22.0.0
- idna==3.7
- importlib-metadata==3.6.0
- importlib-resources==5.1.3
- iniconfig==2.0.0
- isort==5.13.2
- itsdangerous==2.0.0
- jinja2==3.1.2
- jinja2==3.1.4
- kiwisolver==1.4.5
- lazy-object-proxy==1.10.0
- markupsafe==2.1.2
- matplotlib==3.7.3
- mccabe==0.6.1
- more-itertools==7.2.0
- netcdf4==1.5.3
- numpy==1.22.4
- olefile==0.46
- packaging==23.2
- packaging==24.0
- pandas==2.0.3
- pathlib2==2.3.4
- pillow==10.0.1
- pillow==10.3.0
- platformdirs==4.2.1
- pluggy==0.12.0
- py==1.11.0
- pycodestyle==2.5.0
- pyflakes==2.1.1
- pyjwt==2.8.0
- pylint==2.17.7
- pymzml==2.5.2
- pyopenms==2.6.0
- pyparsing==2.4.2
Expand All @@ -74,9 +80,12 @@ dependencies:
- scipy==1.7.3
- six==1.11.0
- tomli==2.0.1
- tzdata==2023.3
- tomlkit==0.12.4
- typing-extensions==4.11.0
- tzdata==2024.1
- urllib3==1.26.18
- werkzeug==3.0.1
- werkzeug==3.0.3
- wrapt==1.16.0
- zipp==0.5.2
- -e git+https://github.com/ComPlat/nmrglue.git@e6e8a63b1848ae0525f07de0a6ec0cfdb900ba60#egg=nmrglue
prefix: /home/eln/anaconda3/envs/python-v38
26 changes: 13 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
rdkit==2023.9.1
atomicwrites==1.3.0
attrs==23.1.0
certifi==2023.7.22
chardet==3.0.4
Click==8.0
coverage==4.5.3
cycler==0.10.0
atomicwrites==1.4.1
attrs==23.2.0
certifi==2024.2.2
chardet==5.2.0
Click==8.1.7
coverage==7.5.1
cycler==0.12.1
entrypoints==0.3
flake8==3.7.7
flake8==3.7.9
Flask==2.2.5
gunicorn==19.9.0
idna==2.7
gunicorn==22.0.0
idna==3.7
importlib-metadata==3.6.0
itsdangerous==2.0
Jinja2==3.1.2
Jinja2==3.1.4
MarkupSafe==2.1.2
matplotlib==3.7.3
mccabe==0.6.1
Expand All @@ -25,7 +25,7 @@ numpy==1.22.4
olefile==0.46
pandas==2.0.3
pathlib2==2.3.4
Pillow==10.0.1
Pillow==10.3.0
pluggy==0.12.0
pycodestyle==2.5.0
pyflakes==2.1.1
Expand All @@ -39,7 +39,7 @@ requests==2.31.0
scipy==1.7.3
six==1.11.0
urllib3==1.26.18
Werkzeug==3.0.1
Werkzeug==3.0.3
zipp==0.5.2
pyopenms==2.6.0
PyJWT==2.8.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='chem-spectra-app',
version='1.1.1',
version='1.1.2',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/source/nmrium/nmrium_data_schema_v3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 3,
"actionType": "",
"spectra": [],
"molecules": []
}
8 changes: 8 additions & 0 deletions tests/fixtures/source/nmrium/nmrium_data_schema_v4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 4,
"data": {
"spectra": [],
"molecules": []
},
"view": {}
}
8 changes: 8 additions & 0 deletions tests/fixtures/source/nmrium/nmrium_data_schema_v5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 5,
"data": {
"spectra": [],
"molecules": []
},
"view": {}
}
1 change: 1 addition & 0 deletions tests/fixtures/source/nmrium/nmrium_test_v4.nmrium

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/fixtures/source/nmrium/nmrium_test_v5.nmrium

Large diffs are not rendered by default.

Loading
Loading