Пример #1
0
	def test_make_xml(self):
		output_fp = path.join(self.output_dir, 'example_script.xml')
		self._paths_to_clean_up = [output_fp, './example_script.py']
		copyfile(self.script_fp, './example_script.py')

		make_xml(self.script_fp, self.output_dir, None)

		self.assertTrue(path.exists(output_fp), 'The xml file was not created in the appropiate location')
Пример #2
0
def integrate(scripts_dir, galaxy_dist_dir, config_file, update_tool_conf,
                                                                        log_fp):
    """Integrates the tools in the scripts folder into the given Galaxy instance

    Inputs:
        scripts_dir: path to the directory containing all the scripts to be 
            integrated on Galaxy
        galaxy_dist_dir: path to the Galaxy's installation folder
        config_file: path to the Galaxy-QIIME configuration file
        update_tool_conf: boolean showing if the current tool_conf file should
            be updated or a new tool_conf file should be created 
        log_fp: path to where the log file should be written

    Walks through all the scripts present in the 'scripts_dir' folder and 
    integrates them in the Galaxy instance 'galaxy_dist_dir'. The integration is
    done according to the 'config_file', which specifies: the different sections
    in which the scripts will be grouped, which scripts of the script folder 
    will be integrated and which option of these script will NOT be included
    in the Galaxy interface.

    If update_tool_conf is True, it will update the current tool_conf.xml file
    present in the Galaxy instance. Otherwise, it will override it with a new
    tool_conf.xml configuration file.

    If a log_fp is given, the script will write the log file into this path.
    Otherwise, it will create a log file in the scripts_dir folder
    """
    script_dict, sections = parse_config_file(open(config_file, 'U'))

    galaxy_dist_dir = path.abspath(galaxy_dist_dir)

    create_dirs(galaxy_dist_dir, sections)

    tool_conf = get_galaxy_tool_conf_file(galaxy_dist_dir, update_tool_conf)

    section_dict = {}
    for section in sections:
        section_dict[section] = []

    if not log_fp:
        log_fp = path.join(scripts_dir, 'integration.log')

    log_file = open(log_fp, 'w')

    addsitedir(scripts_dir)

    for root, dirs, files in walk(scripts_dir):
        for name in files:
            if name.endswith('.py'):
                log_file.write("Generating XML file for %s script... " % name)
                if name in script_dict.keys():
                    section, remove_opts = script_dict[name]
                    output_dir = path.join(galaxy_dist_dir, 'tools',
                        section.replace(" ", "").lower())
                    try:
                        make_xml(name, output_dir, remove_opts)
                        section_dict[section].append(name)
                        log_file.write("Ok\n")
                    except Exception as exc:
                        log_file.write(str(type(exc)) + " : " + str(exc) + "\n")
                else:
                    log_file.write("skipped - not in configuration file\n")


    log_file.write("Generating tool_conf... ")
    update_tool_conf_xml(tool_conf, section_dict)
    log_file.write("Ok\n")

    log_file.write("Writing tool_conf... ")
    # Write tool_conf.xml file
    tool_conf_fp = path.join(galaxy_dist_dir, 'tool_conf.xml')
    f = open(tool_conf_fp, 'w')
    f.write(tool_conf.toprettyxml(indent='\t'))
    f.close()
    log_file.write("Ok\n")

    log_file.write("Generating activate.sh file... ")
    create_activate_file(galaxy_dist_dir)
    log_file.write("Ok\n")

    # Close log file
    log_file.close()
Пример #3
0
__email__ = "*****@*****.**"
__status__ = "Development"

from cogent.util.option_parsing import parse_command_line_parameters, make_option
from xml_generator import make_xml

script_info = {}
script_info['brief_description'] = "Generates a Galaxy XML file from a given QIIME script"
script_info['script_description'] = "Reads the input script, looks for his 'script_info' and extract all the information necessary to generate the XML file. The script generated takes the same name as the original script, but changing his extension to XML. Once the XML is generated, the script must be put into the Galaxy's tools folder and edit tool_conf.xml "
script_info['script_usage'] = [("Example:", "Generate the Galaxy XML file from the script 'my_script.py' without including the '--opt_a' and the '--opt_b' options.", "%prog -i my_script.py -r opt_a,opt_b")]
script_info['output_description'] = "An XML file that Galaxy can reads and make the tool available via web browser"
script_info['required_options'] = [
	make_option('-i', '--script_fp', type="existing_filepath",
				help='the QIIME python script filepath to generate'),
	make_option('-o', '--output_dir', type="existing_dirpath",
				help='output directory where to save the XML file')
]
script_info['optional_options'] = [
	make_option('-r', '--remove_opts', type="string",
				help='List of option names (e.g. "option1,option2") that will not appear in the xml'),
]
script_info['version'] = __version__

if __name__ == '__main__':
	option_parser, opts, args = parse_command_line_parameters(**script_info)
	script_fp = opts.script_fp
	output_dir = opts.output_dir
	remove_opts = opts.remove_opts

	make_xml(script_fp, output_dir, remove_opts)
Пример #4
0
def integrate(scripts_dir, galaxy_dist_dir, config_file, update_tool_conf, log_fp):
	"""
		scripts_dir: full path to the directory which contains the scripts to integrate
		galaxy_dist_dir: full path to the Galaxy home directory
		config_file: path to the configuration file which contains the section structure of the scripts
	"""
	script_dict, sections = parse_config_file(open(config_file, 'U'))

	create_dirs(galaxy_dist_dir, sections)

	tool_conf = get_galaxy_tool_conf_file(galaxy_dist_dir, update_tool_conf)

	section_dict = {}
	for section in sections:
		section_dict[section] = []

	if not log_fp:
		log_fp = path.join(scripts_dir, 'integration.log')

	log_file = open(log_fp, 'w')

	addsitedir(scripts_dir)

	for root, dirs, files in walk(scripts_dir):
		for name in files:
			if name.endswith('.py'):
				log_file.write("Generating XML file for %s script... " % name)
				if name in script_dict.keys():
					section, remove_opts = script_dict[name]
					output_dir = path.join(galaxy_dist_dir, 'tools', section.replace(" ", "").lower())
					try:
						make_xml(name, output_dir, remove_opts)
						section_dict[section].append(name)
						log_file.write("Ok\n")
					except Exception as exc:
						log_file.write(str(type(exc)) + " : " + str(exc) + "\n")
				else:
					log_file.write("skipped - not in configuration file\n")


	log_file.write("Generating tool_conf... ")
	update_tool_conf_xml(tool_conf, section_dict)
	log_file.write("Ok\n")

	log_file.write("Writing tool_conf... ")
	# Write tool_conf.xml file
	tool_conf_fp = path.join(galaxy_dist_dir, 'tool_conf.xml')
	f = open(tool_conf_fp, 'w')
	f.write(tool_conf.toprettyxml(indent='\t'))
	f.close()
	log_file.write("Ok\n")

	log_file.write("Updating environment... ")
	command_string = 'echo "\nexport GALAXY_HOME=%s" >> ~/.bashrc' % path.abspath(galaxy_dist_dir)
	(append_status, append_out) = commands.getstatusoutput(command_string)
	if append_status != 0:
		raise ValueError, "Error updating environment"
	else:
		log_file.write("Ok\n")

	# Close log file
	log_file.close()