Commit 558ed10b authored by Yan's avatar Yan
Browse files

OpenTims - using decorator for logging

parent 8f4c29ad
...@@ -17,6 +17,12 @@ import prasopes.datatools as dt ...@@ -17,6 +17,12 @@ import prasopes.datatools as dt
logger = logging.getLogger('dsLogger') logger = logging.getLogger('dsLogger')
def logdecor(fnc):
logger.info(fnc.__doc__ + "...")
fnc()
logger.info("DONE: " + fnc.__doc__)
class Dataset(): class Dataset():
def __init__(self, rawfile): def __init__(self, rawfile):
self.filename = rawfile self.filename = rawfile
...@@ -127,8 +133,9 @@ class BrukerTimsDataset(Dataset): ...@@ -127,8 +133,9 @@ class BrukerTimsDataset(Dataset):
super().__init__(rawfile) super().__init__(rawfile)
self.refresh() self.refresh()
@logdecor
def refresh(self): def refresh(self):
logger.info("refreshing timsTOF dataset") """refreshing timsTOF dataset"""
if(os.path.isdir(self.filename)): if(os.path.isdir(self.filename)):
self.dataset = OpenTIMS(pathlib.Path(self.filename)) self.dataset = OpenTIMS(pathlib.Path(self.filename))
else: else:
...@@ -156,8 +163,9 @@ class BrukerTimsDataset(Dataset): ...@@ -156,8 +163,9 @@ class BrukerTimsDataset(Dataset):
bindy = np.bincount(binpos, y) / length bindy = np.bincount(binpos, y) / length
return bindx, bindy return bindx, bindy
@logdecor
def get_chromatograms(self): def get_chromatograms(self):
logger.info("getting timsTOF chromatogram") """getting timsTOF chromatogram"""
times = self.dataset.retention_times / 60 times = self.dataset.retention_times / 60
if cf.settings().value("timstof/fastchrom", type=bool): if cf.settings().value("timstof/fastchrom", type=bool):
# Thx to Michał Startek, slight deviation, but much faster # Thx to Michał Startek, slight deviation, but much faster
...@@ -171,8 +179,9 @@ class BrukerTimsDataset(Dataset): ...@@ -171,8 +179,9 @@ class BrukerTimsDataset(Dataset):
logger.info("DONE: getting timsTOF chromatogram") logger.info("DONE: getting timsTOF chromatogram")
return [[times, intensities]] return [[times, intensities]]
@logdecor
def get_spectra(self, mint=None, maxt=None): def get_spectra(self, mint=None, maxt=None):
logger.info("getting timsTOF spectra") """getting timsTOF spectra"""
mint = mint or self.mintime mint = mint or self.mintime
maxt = maxt or self.maxtime maxt = maxt or self.maxtime
framessel = self.sampletimes(mint, maxt, cf.settings().value( framessel = self.sampletimes(mint, maxt, cf.settings().value(
...@@ -181,11 +190,11 @@ class BrukerTimsDataset(Dataset): ...@@ -181,11 +190,11 @@ class BrukerTimsDataset(Dataset):
masses, ints = self.binit( masses, ints = self.binit(
massints['mz'], massints['intensity'], massints['mz'], massints['intensity'],
cf.settings().value("timstof/ms_bins", type=float), len(framessel)) cf.settings().value("timstof/ms_bins", type=float), len(framessel))
logger.info("DONE: getting timsTOF spectra")
return [[masses, ints]] return [[masses, ints]]
@logdecor
def get_mobspectra(self, mint=None, maxt=None): def get_mobspectra(self, mint=None, maxt=None):
logger.info("getting timsTOF spectra") """getting timsTOF spectra"""
mint = mint or self.mintime mint = mint or self.mintime
maxt = maxt or self.maxtime maxt = maxt or self.maxtime
framessel = self.sampletimes(mint, maxt, cf.settings().value( framessel = self.sampletimes(mint, maxt, cf.settings().value(
...@@ -196,8 +205,9 @@ class BrukerTimsDataset(Dataset): ...@@ -196,8 +205,9 @@ class BrukerTimsDataset(Dataset):
cf.settings().value("timstof/mob_bins", type=float), len(framessel)) cf.settings().value("timstof/mob_bins", type=float), len(framessel))
return [[masses, ints]] return [[masses, ints]]
@logdecor
def get_peakchrom(self, startm, endm): def get_peakchrom(self, startm, endm):
logger.info("getting peak ion chromatogram") """getting peak ion chromatogram"""
intensity = np.divide([ intensity = np.divide([
np.sum(i['intensity'][dt.argsubselect(i['mz'], startm, endm)]) np.sum(i['intensity'][dt.argsubselect(i['mz'], startm, endm)])
for i in self.dataset.query_iter( for i in self.dataset.query_iter(
...@@ -205,10 +215,11 @@ class BrukerTimsDataset(Dataset): ...@@ -205,10 +215,11 @@ class BrukerTimsDataset(Dataset):
np.clip(self.chromatograms[0][1], np.finfo(np.float32).eps, None)) np.clip(self.chromatograms[0][1], np.finfo(np.float32).eps, None))
return intensity return intensity
@logdecor
def get_mzmobpeakchrom(self, startmz, endmz, startmob, endmob): def get_mzmobpeakchrom(self, startmz, endmz, startmob, endmob):
"""getting mz/mob peak ion chromatogram..."""
boundsmz = sorted([startmz, endmz]) boundsmz = sorted([startmz, endmz])
boundsmob = sorted([startmob, endmob]) boundsmob = sorted([startmob, endmob])
logger.info("getting mz/mob peak ion chromatogram")
intensity = np.divide([ intensity = np.divide([
np.sum(i['intensity'][dt.argsubselect_2d( np.sum(i['intensity'][dt.argsubselect_2d(
i['mz'], startmz, endmz, i['mz'], startmz, endmz,
...@@ -217,7 +228,6 @@ class BrukerTimsDataset(Dataset): ...@@ -217,7 +228,6 @@ class BrukerTimsDataset(Dataset):
np.arange(self.dataset.max_frame)+1, columns=( np.arange(self.dataset.max_frame)+1, columns=(
'intensity', 'mz', 'inv_ion_mobility'))], 'intensity', 'mz', 'inv_ion_mobility'))],
np.clip(self.chromatograms[0][1], np.finfo(np.float32).eps, None)) np.clip(self.chromatograms[0][1], np.finfo(np.float32).eps, None))
logger.info("DONE: getting mz/mob peak ion chromatogram")
return intensity return intensity
def get_subspace(self, xax, subselect, start, end, bins, def get_subspace(self, xax, subselect, start, end, bins,
...@@ -226,7 +236,7 @@ class BrukerTimsDataset(Dataset): ...@@ -226,7 +236,7 @@ class BrukerTimsDataset(Dataset):
maxt = maxt or self.maxtime maxt = maxt or self.maxtime
msg = ("getting timsTOF for {:.3f}-{:.3f} minutes, subselecting" msg = ("getting timsTOF for {:.3f}-{:.3f} minutes, subselecting"
" {}: {}-{}").format(mint, maxt, subselect, start, end) " {}: {}-{}").format(mint, maxt, subselect, start, end)
logger.info(msg) logger.info(msg+"...")
framessel = self.sampletimes(mint, maxt, cf.settings().value( framessel = self.sampletimes(mint, maxt, cf.settings().value(
"timstof/mob_sampling", type=int)) "timstof/mob_sampling", type=int))
massintstof = self.dataset.query( massintstof = self.dataset.query(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment