#=========================================================================================
# Licence, Reference and Credits
#=========================================================================================
__copyright__ = "Copyright (C) CCPN project (http://www.ccpn.ac.uk) 2014 - 2021"
__credits__ = ("Ed Brooksbank, Joanna Fox, Victoria A Higman, Luca Mureddu, Eliza Płoskoń",
"Timothy J Ragan, Brian O Smith, Gary S Thompson & Geerten W Vuister")
__licence__ = ("CCPN licence. See http://www.ccpn.ac.uk/v3-software/downloads/license")
__reference__ = ("Skinner, S.P., Fogh, R.H., Boucher, W., Ragan, T.J., Mureddu, L.G., & Vuister, G.W.",
"CcpNmr AnalysisAssign: a flexible platform for integrated NMR analysis",
"J.Biomol.Nmr (2016), 66, 111-124, http://doi.org/10.1007/s10858-016-0060-y")
#=========================================================================================
# Last code modification
#=========================================================================================
__modifiedBy__ = "$modifiedBy: Ed Brooksbank $"
__dateModified__ = "$dateModified: 2021-06-30 09:45:22 +0100 (Wed, June 30, 2021) $"
__version__ = "$Revision: 3.0.4 $"
#=========================================================================================
# Created
#=========================================================================================
__author__ = "$Author: Luca Mureddu $"
__date__ = "$Date: 2017-05-28 10:28:42 +0000 (Sun, May 28, 2017) $"
#=========================================================================================
# Start of code
#=========================================================================================
#### GUI IMPORTS
from ccpn.ui.gui.widgets.PipelineWidgets import GuiPipe
from PyQt5 import QtWidgets
from ccpn.ui.gui.widgets.Label import Label
from ccpn.ui.gui.widgets.FileDialog import LineEditButtonDialog
from ccpn.ui.gui.widgets.RadioButtons import RadioButtons
#### NON GUI IMPORTS
from ccpn.framework.lib.pipeline.PipeBase import SpectraPipe, PIPE_SCREEN
from ccpn.util.Path import aPath
import os
import datetime
import pandas as pd
########################################################################################################################
### Attributes:
### Used in setting the dictionary keys on _kwargs either in GuiPipe and Pipe
########################################################################################################################
PipeName = 'Output Hits'
SavePath = 'Save_Directory_Path'
SaveOutputMode = 'Save_Output_Mode'
CSV = 'CSV'
TAB = 'Tab'
XLSX = 'XLSX'
Json = 'Json'
Modes = [CSV, TAB, XLSX, Json]
DefaultPath = aPath('~')
########################################################################################################################
########################################## ALGORITHM ########################################################
########################################################################################################################
########################################################################################################################
########################################## GUI PIPE #############################################################
########################################################################################################################
[docs]class OutputHitsGuiPipe(GuiPipe):
pipeName = PipeName
def __init__(self, name=pipeName, parent=None, project=None, **kwds):
super(OutputHitsGuiPipe, self)
GuiPipe.__init__(self, parent=parent, name=name, project=project, **kwds)
self._parent = parent
row = 0
row += 1
self.modeLabel = Label(self.pipeFrame, SaveOutputMode, grid=(row, 0))
setattr(self, SaveOutputMode,
RadioButtons(self.pipeFrame, texts=Modes, direction='v', vAlign='c', selectedInd=1, grid=(row, 1)))
row += 1
self.savePathLabel = Label(self.pipeFrame, SavePath, grid=(row, 0))
setattr(self, SavePath,
LineEditButtonDialog(self.pipeFrame, textDialog='', fileMode='directory', grid=(row, 1)))
# self._setDefaultDataPath()
def _setDefaultDataPath(self):
'writes the default data path in the pipe lineEdit'
if self.application is not None:
getattr(self, SavePath).lineEdit.set(self.application.preferences.general.dataPath)
########################################################################################################################
########################################## PIPE #############################################################
########################################################################################################################
[docs]class OutputHitsPipe(SpectraPipe):
guiPipe = OutputHitsGuiPipe
pipeName = PipeName
pipeCategory = PIPE_SCREEN
_kwargs = {
SavePath : DefaultPath,
SaveOutputMode: ''
}
[docs] def runPipe(self, spectra):
"""
"""
#TODO complete this pipe
date = datetime.datetime.now().strftime("%y-%m-%d-%H-%M")
df = pd.DataFrame()
path = self._kwargs[SavePath] + '/'
newPath = path + self.pipeline.pipelineName+'_'+date
mode = self._kwargs[SaveOutputMode]
sucess = False
if df is not None:
if mode == CSV:
df.to_csv(newPath)
sucess = True
if mode == TAB:
df.to_csv(newPath, sep='\t')
sucess = True
if mode == Json:
df.to_json(newPath + '.json', orient='split')
sucess = True
if mode == XLSX:
df.to_excel(newPath + '.xlsx', sheet_name=self.pipeline.pipelineName, index=False, )
if sucess:
self.project._logger.info("Hits Output saved in %s" % path)
return spectra
# OutputHitsPipe.register()