Skip to content

Commit

Permalink
fixed manual reference issues in data pre-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwigc committed Mar 11, 2024
1 parent 22ee861 commit 4295df6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion metabolabpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__author__ = 'Christian Ludwig ([email protected])'
__credits__ = 'Christian Ludwig ([email protected])'
__version__ = '0.9.28'
__version__ = '0.9.29'
__license__ = 'GPLv3'
83 changes: 47 additions & 36 deletions metabolabpy/nmr/nmrData.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(self):
self.ref_point = np.array([0, 0, 0], dtype='int')
self.refsw = np.array([0, 0, 0], dtype='float64')
self.ref_tmsp_range = 0.3 # [ppm]
self.ref = 'auto'
self.apc = apcbc.Apcbc()
self.projected_j_res = False
self.orig_j_res_set = -1
Expand Down Expand Up @@ -716,42 +717,43 @@ def autopick_hsqc(self, metabolite_list=[]):
# end autopick_hsqc

def auto_ref(self, tmsp=True):
if self.acq.o1 == 0:
self.ref_shift[0] = 4.76
else:
self.ref_shift[0] = self.acq.o1 / self.acq.bf1

self.ref_point[0] = int(len(self.spc[0]) / 2)
if (self.dim == 2):
self.ref_shift[1] = (self.acq.spc_frequency[1] + self.acq.spc_offset[1]) / self.acq.spc_frequency[1] - 1.0
self.ref_point[1] = int(len(self.spc) / 2)
if (tmsp == True):
self.ref_point[0] = self.ppm2points(0.0, 0)
self.ref_shift[0] = 0.0
pts = self.ppm2points(np.array([-self.ref_tmsp_range, self.ref_tmsp_range]), 0)
npts = len(self.spc[0])
r = np.arange(npts - max(pts), npts - min(pts))
spc = np.sum(self.spc, 0)
spc = spc[r].real
ref_p = np.where(spc == np.amax(spc))
self.ref_point[0] -= ref_p[0][0] - int((max(pts) - min(pts)) / 2) + 1

self.proc.ref_point[0] = self.ref_point[0]
self.proc.ref_point[1] = self.ref_point[1]

if (self.dim == 1):
if (tmsp == True):
self.ref_point[0] = self.ppm2points(0.0, 0)
if self.ref_point[0] < 0 or self.ref_point[0] > len(self.spc[0]):
return
self.ref_shift[0] = 0.0
pts = self.ppm2points(np.array([-self.ref_tmsp_range, self.ref_tmsp_range]), 0)
npts = len(self.spc[0])
r = np.arange(npts - max(pts), npts - min(pts))
r = np.copy(r[np.where(r < len(self.spc[0]))])
spc = self.spc[0][r].real
ref_p = np.where(spc == np.amax(spc))
self.ref_point[0] -= ref_p[0][0] - int((max(pts) - min(pts)) / 2) + 1
if self.ref == 'auto':
if self.acq.o1 == 0:
self.ref_shift[0] = 4.76
else:
self.ref_shift[0] = self.acq.o1 / self.acq.bf1

self.ref_point[0] = int(len(self.spc[0]) / 2)
if (self.dim == 2):
self.ref_shift[1] = (self.acq.spc_frequency[1] + self.acq.spc_offset[1]) / self.acq.spc_frequency[1] - 1.0
self.ref_point[1] = int(len(self.spc) / 2)
if (tmsp == True):
self.ref_point[0] = self.ppm2points(0.0, 0)
self.ref_shift[0] = 0.0
pts = self.ppm2points(np.array([-self.ref_tmsp_range, self.ref_tmsp_range]), 0)
npts = len(self.spc[0])
r = np.arange(npts - max(pts), npts - min(pts))
spc = np.sum(self.spc, 0)
spc = spc[r].real
ref_p = np.where(spc == np.amax(spc))
self.ref_point[0] -= ref_p[0][0] - int((max(pts) - min(pts)) / 2) + 1

self.proc.ref_point[0] = self.ref_point[0]
self.proc.ref_point[1] = self.ref_point[1]

if (self.dim == 1):
if (tmsp == True):
self.ref_point[0] = self.ppm2points(0.0, 0)
if self.ref_point[0] < 0 or self.ref_point[0] > len(self.spc[0]):
return
self.ref_shift[0] = 0.0
pts = self.ppm2points(np.array([-self.ref_tmsp_range, self.ref_tmsp_range]), 0)
npts = len(self.spc[0])
r = np.arange(npts - max(pts), npts - min(pts))
r = np.copy(r[np.where(r < len(self.spc[0]))])
spc = self.spc[0][r].real
ref_p = np.where(spc == np.amax(spc))
self.ref_point[0] -= ref_p[0][0] - int((max(pts) - min(pts)) / 2) + 1

self.calc_ppm()

Expand Down Expand Up @@ -1697,6 +1699,15 @@ def read_spc(self):

# end read_spc

def set_auto_ref(self, ref='auto'):
self.ref = ref

def set_autobaseline(self, autobaseline=False):
for k in range(len(self.nmrdat[self.s])):
self.nmrdat[self.s][k].proc.autobaseline = autobaseline

# end set_autobaseline

def set_title_information(self, xls=pd.DataFrame(), excel_name='', pos_label='', rack_label='', replace_orig_title=False, c_dict=[]):
if len(xls) == 0 or len(pos_label) == 0 or len(rack_label) == 0 or len(excel_name) == 0:
return
Expand Down
3 changes: 2 additions & 1 deletion metabolabpy/nmr/nmrDataSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def ft_all(self):
for k in range(n_exp):
self.e = k
self.ft()

#
self.e = orig_exp
return "Finished ft_all"
# end ft_all
Expand Down Expand Up @@ -1484,6 +1484,7 @@ def reference1d_all(self, old_ppm=0.0, new_ppm=0.0, find_maximum=True):

self.nmrdat[s][k].ref_point[0] = len(self.nmrdat[s][k].spc[0]) - ref_point - 1
self.nmrdat[s][k].ref_shift[0] = new_ppm
self.nmrdat[s][k].ref = 'manual'
self.nmrdat[s][k].calc_ppm()
# end reference1d_all

Expand Down

0 comments on commit 4295df6

Please sign in to comment.