def get_plugin_and_folder(inputzip=None, inputdir=None, inputfile=None): """ Main function. """ if (inputzip and inputdir) \ or (inputzip and inputfile) \ or (inputdir and inputfile): raise MQ2Exception('You must provide either a zip file or a ' 'directory or an input file as input.') if not inputzip and not inputdir and not inputfile: raise MQ2Exception('You must provide either a zip file or a ' 'directory or an input file as input.') # retrieve input: file, directory, zip if inputzip: tmp_folder = set_tmp_folder() extract_zip(inputzip, tmp_folder) elif inputfile: tmp_folder = inputfile else: tmp_folder = inputdir # retrieve the plugins plugins = load('MQ2.plugins', subclasses=PluginInterface) LOG.debug('Plugin loaded: %s' % [plugin.name for plugin in plugins]) # keep only the plugins that will work plugins = [plugin for plugin in plugins if plugin.is_applicable()] LOG.debug('Plugin applicable: %s' % [plugin.name for plugin in plugins]) # keep only the plugins that have the file(s) they need if inputfile: plugins = [ plugin for plugin in plugins if plugin.valid_file(tmp_folder) ] else: plugins = [ plugin for plugin in plugins if plugin.get_files(tmp_folder) ] LOG.debug('Plugin w/ valid input: %s' % [plugin.name for plugin in plugins]) if len(plugins) > 1: raise MQ2Exception('Your dataset contains valid input for ' 'several plugins.') if len(plugins) == 0: raise MQ2Exception('Invalid dataset: your input cannot not be ' 'processed by any of the current plugins.') plugin = plugins[0] return (plugin, tmp_folder)
def get_plugin_and_folder(inputzip=None, inputdir=None, inputfile=None): """ Main function. """ if (inputzip and inputdir) \ or (inputzip and inputfile) \ or (inputdir and inputfile): raise MQ2Exception('You must provide either a zip file or a ' 'directory or an input file as input.') if not inputzip and not inputdir and not inputfile: raise MQ2Exception('You must provide either a zip file or a ' 'directory or an input file as input.') # retrieve input: file, directory, zip if inputzip: tmp_folder = set_tmp_folder() extract_zip(inputzip, tmp_folder) elif inputfile: tmp_folder = inputfile else: tmp_folder = inputdir # retrieve the plugins plugins = load('MQ2.plugins', subclasses=PluginInterface) LOG.debug('Plugin loaded: %s' % [plugin.name for plugin in plugins]) # keep only the plugins that will work plugins = [plugin for plugin in plugins if plugin.is_applicable()] LOG.debug('Plugin applicable: %s' % [plugin.name for plugin in plugins]) # keep only the plugins that have the file(s) they need if inputfile: plugins = [plugin for plugin in plugins if plugin.valid_file(tmp_folder)] else: plugins = [plugin for plugin in plugins if plugin.get_files(tmp_folder)] LOG.debug('Plugin w/ valid input: %s' % [plugin.name for plugin in plugins]) if len(plugins) > 1: raise MQ2Exception('Your dataset contains valid input for ' 'several plugins.') if len(plugins) == 0: raise MQ2Exception('Invalid dataset: your input cannot not be ' 'processed by any of the current plugins.') plugin = plugins[0] return (plugin, tmp_folder)
def get_mapqtl_session(session_id): """ Retrieve the list of MapQTL session available. @param session_id the session identifier uniquely identifying the MapQTL zip file and the JoinMap map file. The session identifier also uniquely identifies the folder in which are the files uploaded. """ folder = os.path.join(UPLOAD_FOLDER, session_id) tmp_folder = None sessions = [] try: tmp_folder = set_tmp_folder() extract_zip(os.path.join(folder, 'input.zip'), tmp_folder) filelist = [] for root, dirs, files in os.walk(tmp_folder): for filename in files: if filename.startswith('Session') \ and filename.endswith('.mqo'): session = filename.split()[1].strip() if session not in sessions: sessions.append(session) except IOError, err: raise MQ2NoSuchSessionException(err)