def _max(self, key): # type: (str) -> object """Return the smallest value in the parameter's "max" list. Applies round() method to the output of LFParameter._max() to get a more comparable result regarding floating point arithmetic issues. Keyword Arguments: key -- name of the parameter """ return round(LFParameters._max(self, key), self._floatPointPrecision)
def main(): # Create the argument parser and parse the arguments parser = argparse.ArgumentParser( description="Run LipidFinder's Amalgamator.") parser.add_argument('-neg', '--negative', metavar='FILE', type=str, required=True, help="negative data file") parser.add_argument('-pos', '--positive', metavar='FILE', type=str, required=True, help="positive data file") parser.add_argument('-o', '--output', metavar='DIR', type=str, help="folder where the output files will be stored") parser.add_argument('-p', '--params', metavar='FILE', type=str, required=True, help="parameters JSON file") parser.add_argument('--timestamp', action='store_true', help="add a timestamp to the output folder's name") parser.add_argument('--version', action='version', version="LipidFinder 2.0") args = parser.parse_args() # Load parameters and input data parameters = LFParameters(module='amalgamator', src=args.params) negData = LFDataFrame(args.negative, parameters) posData = LFDataFrame(args.positive, parameters) # Check if the output directory exists. If not, create it. dst = args.output if (args.output) else '' if (args.timestamp): timestamp = datetime.utcnow().strftime('%Y%m%d_%H%M%S') dst += '_{0}'.format(timestamp) if (dst) else timestamp dst = normalise_path(dst) if (not os.path.isdir(dst)): os.makedirs(dst) # Run Amalgamator Amalgamator.amalgamate_data(negData, posData, parameters, dst)
def main(): # Create the argument parser and parse the arguments parser = argparse.ArgumentParser( description="Run LipidFinder's PeakFilter.") parser.add_argument('-i', '--input', metavar='INPUT', type=str, required=True, help="file or folder with input data") parser.add_argument('-o', '--output', metavar='DIR', type=str, help="folder where the output files will be stored") parser.add_argument('-p', '--params', metavar='FILE', type=str, required=True, help='parameters JSON file') parser.add_argument('--timestamp', action='store_true', help="add a timestamp to the output folder's name") parser.add_argument('--verbose', action='store_true', help="generate intermediate CSV result files") parser.add_argument('--version', action='version', version="LipidFinder v2.0") args = parser.parse_args() # Load parameters and input data parameters = LFParameters(module='peakfilter', src=args.params) data = LFDataFrame(args.input, parameters) # Check if the output directory exists. If not, create it. dst = args.output if (args.output) else '' if (args.timestamp): timestamp = datetime.utcnow().strftime('%Y%m%d_%H%M%S') dst += '_{0}'.format(timestamp) if (dst) else timestamp dst = normalise_path(dst) if (not os.path.isdir(dst)): os.makedirs(dst) # Run PeakFilter PeakFilter.peak_filter(data, parameters, dst, args.verbose)
def __init__(self, support=True, **kwargs): # type: (bool, ...) -> LFParametersCLI """Constructor of the class LFParametersCLI. First, the module's parameters template file is loaded. Next, if a source JSON parameters file path is provided, the default values are overwritten by the corresponding new (valid) values. Finally, the question-answering system is executed. Keyword Arguments: support -- display help information together with the description [default: True] """ LFParameters.__init__(self, **kwargs) self._showHelp = support # Launch a question-answering system to review the parameters print( ("The next questions will help you review the parameters for " "LipidFinder's{0}{1} module. A short description of the " "parameter and its current value{0}are displayed. Next, you can " "either introduce the new value(s) or press ENTER,{0}leaving the" " default one(s).{0}").format(os.linesep, self._module)) for key in (x for x in self._parameters.keys() if self._is_active(x)): data = self._parameters[key] typeStr = data['type'] # Compose the main request message to display text = '{0}{1}{2}{0}'.format(os.linesep, data['description'], ' [y/n]' if typeStr == 'bool' else '') if (self._showHelp): # Show help if available for the parameter if (('help_cli' in data) and data['help_cli']): # Some parameters might have an option available # only for GUI, e.g. "Leave empty to include all." text += 'Help: {0}{1}'.format(data['help_cli'], os.linesep) elif ('help' in data): text += 'Help: {0}{1}'.format(data['help'], os.linesep) # Request the parameter value with a question-answering # system if (typeStr == 'bool'): # Add the current value to the request message text += '[current: {0}] '.format('YES' if self[key] else 'NO') self._request_bool(key, text) elif (typeStr in ['int', 'float']): # Add the current value to the request message if (self[key] is not None): # Add the current value to the request message text += '[current: {0}] '.format(self[key]) self._request_number(key, text) elif (typeStr == 'selection'): # Add the available options to the request message text += 'Options: {0}{1}'.format( self._from_list_to_str(data['options'], typeStr), os.linesep) if (self[key]): # Add the current value to the request message text += '[current: {0}] '.format(self[key]) self._request_str_input(key, text) elif (typeStr in ['int range', 'float range']): if (self[key]): # Add the current value to the request message text += '[current: {0}] '.format( self._from_list_to_str(self[key], typeStr)) self._request_range(key, text) elif (typeStr == 'multiselection'): # Add the available options to the request message text += 'Options: {0}{1}'.format( self._from_list_to_str(data['options'], typeStr), os.linesep) if (self[key]): # Add the current value to the request message text += '[current: {0}] '.format( self._from_list_to_str(self[key], typeStr)) self._request_list_input(key, text) elif (typeStr == 'pairs'): # Load the list of valid values for each 2-tuple from # the first column of the file whose path is saved as # value of another parameter ("file" key in the current # parameter's information) srcFilePath = self._parameters[data['file']]['value'] options = pandas.read_csv(srcFilePath).iloc[:, 0].tolist() # Add the available options to the request message text += 'Options: ' + self._from_list_to_str(options, typeStr) \ + os.linesep if (self[key]): # Add the current value to the request message text += '[current: {0}] '.format( self._from_list_to_str(self[key], typeStr)) self._request_list_input(key, text) else: if (self[key]): # Add the current value to the request message text += '[current: {0}] '.format(self[key]) self._request_str_input(key, text) # Question-answering system to save current parameters' values text = ("{0}{0}Where do you want to save the new set of parameters " "(path)?{0} ".format(os.linesep)) while True: answer = input(text) if (answer): self.write(normalise_path(answer)) break
def __init__(self, precision=4, **kwargs): # type: (int, ...) -> LFParametersGUI """Constructor of the class LFParametersGUI. First, the module's parameters template file is loaded. Next, if a source JSON parameters file path is provided, the default values are overwritten by the corresponding new (valid) values. Finally, the graphical user interface is displayed. Keyword Arguments: precision -- number of decimal digits to use with floats (e.g. a precision of 2 forces a difference of 0.01 between any two consecutive float numbers) [default: 4] """ # Minimum difference between two consecutive float numbers self._floatPointPrecision = precision self._floatStep = 10**-(precision) # Load the parameters dictionary using parent class' constructor LFParameters.__init__(self, **kwargs) # Default style self._style = {'description_width': '0px'} # Default width of input widgets self._inputWidth = '26%' # Generate an ordered dict to store each parameter's set of # widgets in the same order as in the parameters' dict self._widgets = OrderedDict() # Create every widget of the GUI for key, data in self._parameters.items(): disabled = not self._is_active(key) # Load the information of each parameter self._widgets[key] = [ self._create_label(key, disabled), self._create_help_icon(key, disabled) ] # Create the input widget or container of input widgets for # each parameter type if (data['type'] == 'bool'): self._widgets[key].append( self._create_bool_widget(key, disabled)) elif (data['type'] == 'int'): self._widgets[key].append( self._create_int_widget(key, disabled)) elif (data['type'] == 'float'): self._widgets[key].append( self._create_float_widget(key, disabled)) elif (data['type'] == 'selection'): self._widgets[key].append( self._create_selection_widget(key, disabled)) elif (data['type'] == 'path'): self._widgets[key].append( self._create_path_widget(key, disabled)) elif (data['type'] == 'int range'): self._widgets[key].append( self._create_int_range_widget(key, disabled)) elif (data['type'] == 'float range'): self._widgets[key].append( self._create_float_range_widget(key, disabled)) elif (data['type'] == 'multiselection'): self._widgets[key].append( self._create_multiselection_widget(key, disabled)) elif (data['type'] == 'pairs'): self._widgets[key].append( self._create_pairs_widget(key, disabled)) else: # data['type'] == 'str' self._widgets[key].append( self._create_str_widget(key, disabled)) # Display the GUI hboxLayout = Layout(align_items='center') for key, widgetList in self._widgets.items(): display(widgets.HBox(widgetList, layout=hboxLayout)) # Finally, create the save interface to allow the user to save # the current parameters values in a JSON file display(widgets.HBox([], layout=Layout(height='15px'))) display( widgets.HBox([], layout=Layout(height='0px', border='2px solid lightgray'))) display(widgets.HBox([], layout=Layout(height='2px'))) self._widgets['save'] = self._create_save_widget() hboxLayout = Layout(justify_content='space-between', align_items='center') display(widgets.HBox(self._widgets['save'], layout=hboxLayout))