Skip to content

Commit

Permalink
Enable to deduce Spectral_dim_transfer metadata from peak frequencies
Browse files Browse the repository at this point in the history
  • Loading branch information
yokochi47 committed Dec 6, 2024
1 parent 48c1132 commit 6d2c570
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 608 deletions.
5 changes: 0 additions & 5 deletions wwpdb/utils/nmr/mr/ParserListenerUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2086,11 +2086,6 @@
'encoded_reduced_dimension_id': None
}

SPECTRAL_DIM_TRANSFER_TEMPLATE = {'spectral_dim_id_1': None,
'spectral_dim_id_2': None,
'indirect': None,
'type': None}


def toRegEx(string: str) -> str:
""" Return regular expression for a given string including XPLOR-NIH wildcard format.
Expand Down
118 changes: 16 additions & 102 deletions wwpdb/utils/nmr/pk/AriaPKParserListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@see: https://aria-test.pasteur.fr/documentation/input-format/version-2.1/spectrum
"""
import sys
import numpy as np

from antlr4 import ParseTreeListener

Expand All @@ -32,6 +31,9 @@ class AriaPKParserListener(ParseTreeListener, BasePKParserListener):

__cur_path = None

__spectrum_names = None
__spectrum_name = None

__index = None
__proton1_ppm = None
__proton1_ppm_error = None
Expand Down Expand Up @@ -74,111 +76,13 @@ def __init__(self, verbose=True, log=sys.stdout,
# Enter a parse tree produced by XMLParser#document.
def enterDocument(self, ctx: XMLParser.DocumentContext): # pylint: disable=unused-argument
self.__cur_path = ''
self.__spectrum_names = {}

self.enter()

# Exit a parse tree produced by XMLParser#document.
def exitDocument(self, ctx: XMLParser.DocumentContext): # pylint: disable=unused-argument

if len(self.spectral_dim) > 0:
for d, v in self.spectral_dim.items():
for _id, _v in v.items():
self.acq_dim_id = 1
for __d, __v in _v.items():
if 'freq_hint' in __v:
if len(__v['freq_hint']) > 0:
center = np.mean(np.array(__v['freq_hint']))

if __v['atom_isotope_number'] is None:
if 125 < center < 130:
__v['atom_type'] = 'C'
__v['atom_isotope_number'] = 13
__v['axis_code'] = 'C_aro'
elif 115 < center < 125:
__v['atom_type'] = 'N'
__v['atom_isotope_number'] = 15
__v['axis_code'] = 'N_ami'
elif 170 < center < 180:
__v['atom_type'] = 'C'
__v['atom_isotope_number'] = 13
__v['axis_code'] = 'CO'
elif 6 < center < 9:
__v['atom_type'] = 'H'
__v['atom_isotope_number'] = 1
__v['axis_code'] = 'H_ami_or_aro'
elif 4 < center < 6:
__v['atom_type'] = 'H'
__v['atom_isotope_number'] = 1
__v['axis_code'] = 'H'
elif 2 < center < 4:
__v['atom_type'] = 'H'
__v['atom_isotope_number'] = 1
__v['axis_code'] = 'H_ali'
elif 60 < center < 90:
__v['atom_type'] = 'C'
__v['atom_isotope_number'] = 13
__v['axis_code'] = 'C'
elif 30 < center < 50:
__v['atom_type'] = 'C'
__v['atom_isotope_number'] = 13
__v['axis_code'] = 'C_ali'

isotope_number = __v['atom_isotope_number']

if isotope_number is not None:
__v['acquisition'] = 'yes' if __d == self.acq_dim_id\
and (isotope_number == 1 or (isotope_number == 13 and self.exptlMethod == 'SOLID-STATE NMR')) else 'no'

if __d == 1 and __v['acquisition'] == 'no':
self.acq_dim_id = self.num_of_dim

__v['under_sampling_type'] = 'not observed' if __v['acquisition'] == 'yes' else 'aliased'

if __v['spectral_region'] is None and len(__v['freq_hint']) > 0:
atom_type = __v['atom_type']
if 125 < center < 130 and atom_type == 'C':
__v['spectral_region'] = 'C_aro'
elif 115 < center < 125 and atom_type == 'N':
__v['spectral_region'] = 'N_ami'
elif 170 < center < 180 and atom_type == 'C':
__v['spectral_region'] = 'CO'
elif 6 < center < 9 and atom_type == 'H':
__v['spectral_region'] = 'H_ami_or_aro'
elif 4 < center < 6 and atom_type == 'H':
__v['spectral_region'] = 'H_all'
elif 2 < center < 4 and atom_type == 'H':
__v['spectral_region'] = 'H_ali'
elif 60 < center < 90 and atom_type == 'C':
__v['spectral_region'] = 'C_all'
elif 30 < center < 50 and atom_type == 'C':
__v['spectral_region'] = 'C_ali'

if len(__v['freq_hint']) > 0 and d > 2 and __d >= 2\
and self.exptlMethod != 'SOLID-STATE NMR' and __v['atom_isotope_number'] == 13:
max_ppm = max(__v['freq_hint'])
min_ppm = min(__v['freq_hint'])
width = max_ppm - min_ppm
if center < 100.0 and width < 50.0:
__v['under_sampling_type'] = 'fold'

del __v['freq_hint']

for __v in _v.values():
if __v['axis_code'] == 'H_ami_or_aro':
has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values())
__v['axis_code'] = 'H_aro' if has_a else 'H_ami'
if __v['spectral_region'] == 'H_ami_or_aro':
has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values())
__v['spectral_region'] = 'H_aro' if has_a else 'H_ami'

if self.debug:
print(f'num_of_dim: {d}, list_id: {_id}')
for __d, __v in _v.items():
print(f'{__d} {__v}')

self.exit()

self.__cur_path = None
self.exit(self.__spectrum_names)

# Enter a parse tree produced by XMLParser#prolog.
def enterProlog(self, ctx: XMLParser.PrologContext): # pylint: disable=unused-argument
Expand All @@ -202,6 +106,7 @@ def enterElement(self, ctx: XMLParser.ElementContext):

if self.__cur_path == '/spectrum':
self.num_of_dim = -1
self.__spectrum_name = None

elif self.__cur_path == '/spectrum/peak':
self.__volume = None
Expand Down Expand Up @@ -277,6 +182,10 @@ def exitElement(self, ctx: XMLParser.ElementContext): # pylint: disable=unused-
self.num_of_dim += 1
self.__hetero2_active = True
self.initSpectralDim()
if self.num_of_dim not in self.__spectrum_names:
self.__spectrum_names[self.num_of_dim] = {}
if self.cur_list_id not in self.__spectrum_names[self.num_of_dim]:
self.__spectrum_names[self.num_of_dim][self.cur_list_id] = self.__spectrum_name

index = self.__index

Expand Down Expand Up @@ -722,7 +631,12 @@ def enterAttribute(self, ctx: XMLParser.AttributeContext):
name = str(ctx.Name())
string = str(ctx.STRING())[1:-1].strip()

if self.__cur_path == '/spectrum/peak':
if self.__cur_path == '/spectrum':

if name == 'name':
self.__spectrum_name = string

elif self.__cur_path == '/spectrum/peak':

if name == 'number':
self.__index = int(string)
Expand Down
Loading

0 comments on commit 6d2c570

Please sign in to comment.