Mercurial > repos > greg > data_manager_plant_tribes_configs_downloader
changeset 0:6e9b8d65a1de draft
Uploaded
author | greg |
---|---|
date | Mon, 13 Feb 2017 13:43:24 -0500 |
parents | |
children | d0c1a579684a |
files | .shed.yml data_manager/data_manager_plant_tribes_configs_download.py data_manager/data_manager_plant_tribes_configs_download.xml data_manager_conf.xml tool-data/plant_tribes_configs.loc.sample tool_data_table_conf.xml.sample |
diffstat | 6 files changed, 195 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.shed.yml Mon Feb 13 13:43:24 2017 -0500 @@ -0,0 +1,12 @@ +categories: +- Data Managers +description: Data Manager for installing PlantTribes default configuration files +homepage_url: http://amborella.huck.psu.edu/ +long_description: | + PlantTribes is a collection of automated modular analysis pipelines that utilize objective + classifications of complete protein sequences from sequenced plant genomes to perform + comparative evolutionary studies. +name: data_manager_plant_tribes_configs_downloader +owner: iuc +remote_repository_url: https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_plant_tribes_configs_downloader +type: unrestricted
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager/data_manager_plant_tribes_configs_download.py Mon Feb 13 13:43:24 2017 -0500 @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# Data manager for downloading PlantTribes configs data. +import argparse +import json +import os +import shutil +import sys +import tarfile +import urllib2 +import zipfile + + +DEFAULT_DATA_TABLE_NAMES = ["plant_tribes_configs"] + + +def add_data_table_entry(data_manager_dict, data_table_name, data_table_entry): + data_manager_dict['data_tables'] = data_manager_dict.get('data_tables', {}) + data_manager_dict['data_tables'][data_table_name] = data_manager_dict['data_tables'].get(data_table_name, []) + data_manager_dict['data_tables'][data_table_name].append(data_table_entry) + return data_manager_dict + + +def make_directory(dir): + if not os.path.exists(dir): + os.makedirs(dir) + + +def remove_directory(dir): + if os.path.exists(dir): + shutil.rmtree(dir) + + +def url_download(target_directory, url, description, data_table_names=DEFAULT_DATA_TABLE_NAMES): + work_directory = os.path.abspath(os.path.join(os.getcwd(), 'configs')) + make_directory(work_directory) + file_path = os.path.join(work_directory, os.path.basename(url)) + src = None + dst = None + try: + req = urllib2.Request(url) + src = urllib2.urlopen(req) + dst = open(file_path, 'wb') + while True: + chunk = src.read(2**10) + if chunk: + dst.write(chunk) + else: + break + except Exception, e: + print >>sys.stderr, str(e) + finally: + if src: + src.close() + if dst: + dst.close() + if tarfile.is_tarfile(file_path): + fh = tarfile.open(file_path, 'r:*') + elif zipfile.is_zipfile(file_path): + fh = zipfile.ZipFile(file_path, 'r') + else: + return + fh.extractall(work_directory) + os.remove(file_path) + # Move the config files into defined output directory. + for filename in os.listdir(work_directory): + shutil.move(os.path.join(work_directory, filename), target_directory) + remove_directory(work_directory) + data_manager_dict = {} + # Populate the data table, there should be a single entry in target_directory. + for file_path in os.listdir(target_directory): + full_path = os.path.abspath(os.path.join(target_directory, file_path)) + entry_name = "%s" % os.path.basename(file_path) + data_table_entry = dict(value=entry_name, name=entry_name, path=full_path, description=description) + for data_table_name in data_table_names: + data_manager_dict = add_data_table_entry(data_manager_dict, data_table_name, data_table_entry) + return data_manager_dict + + +parser = argparse.ArgumentParser() +parser.add_argument('--description', dest='description', default=None, help='Description') +parser.add_argument('--name', dest='name', help='Data table entry unique ID') +parser.add_argument('--out_file', dest='out_file', help='JSON output file') +parser.add_argument('--web_url', dest='web_url', help='Web URL') + +args = parser.parse_args() + +# Some magic happens with tools of type "manage_data" in that the output +# file contains some JSON data that allows us to define the target directory. +params = json.loads(open(args.out_file).read()) +target_directory = params['output_data'][0]['extra_files_path'] +make_directory(target_directory) + +if args.description is None: + description = '' +else: + description = args.description.strip() + +# Get the configs data. +data_manager_dict = url_download(target_directory, args.web_url, description) +# Write the JSON output dataset. +fh = open(args.out_file, 'wb') +fh.write(json.dumps(data_manager_dict)) +fh.close()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager/data_manager_plant_tribes_configs_download.xml Mon Feb 13 13:43:24 2017 -0500 @@ -0,0 +1,50 @@ +<tool id="data_manager_plant_tribes_configs_download" name="PlantTribes Scaffolds Download" version="1.0.0" tool_type="manage_data"> + <description></description> + <stdio> + <exit_code range=":-1" level="fatal" description="Error: Cannot open file" /> + <exit_code range="1:" level="fatal" description="Error" /> + </stdio> + <command> + <![CDATA[ + python $__tool_directory__/data_manager_plant_tribes_configs_download.py + --name "$name" + --description "$description" + --web_url "$web_url" + --out_file "$out_file" + ]]> + </command> + <inputs> + <param name="name" type="text" value="" label="Data table entry unique ID"/> + <param name="description" type="text" value="" label="Description of the data" help="Value is optional"/> + <param name="web_url" type="text" value="" label="Web URL" optional="False" /> + </inputs> + <outputs> + <data name="out_file" format="data_manager_json" /> + </outputs> + <tests> + </tests> + <help> +.. class:: infomark + +**What it does** + +This tool fetches default configuration files used by the PlantTribes Galaxy tools and populates the +plant_tribes_configs data table. The configs can be imported using a URL, and an optional description +can be provided that will appear next to the file name in the data table entry. Default configuration +files provided by the Floral Genome Project can be downloaded here: + + * PlantTribes default configuration files, version 1.0): http://fgp.huck.psu.edu/planttribes_config/22Gv1.0.tar.gz + * PlantTribes default configuration files, version 1.1): http://fgp.huck.psu.edu/planttribes_config/22Gv1.1.tar.gz + + </help> + <citations> + <citation type="bibtex"> + @unpublished{None, + author = {Greg Von Kuster}, + title = {None}, + year = {None}, + eprint = {None}, + url = {https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_plant_tribes_configs_downloader} + }</citation> + </citations> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager_conf.xml Mon Feb 13 13:43:24 2017 -0500 @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<data_managers> + <data_manager tool_file="data_manager/data_manager_plant_tribes_configs_download.xml" id="data_manager_plant_tribes_configs_download" > + <data_table name="plant_tribes_configs"> + <output> + <column name="value" /> + <column name="name"/> + <column name="path" output_ref="out_file"> + <move type="file"> + <source>${path}</source> + <target base="${GALAXY_DATA_MANAGER_DATA_PATH}">plant_tribes/configs/${value}</target> + </move> + <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/plant_tribes/configs/${value}</value_translation> + <value_translation type="function">abspath</value_translation> + </column> + <column name="description" /> + </output> + </data_table> + </data_manager> +</data_managers>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool-data/plant_tribes_configs.loc.sample Mon Feb 13 13:43:24 2017 -0500 @@ -0,0 +1,4 @@ +## Plant Tribes configs +#Value Name Path Description +#22Gv1.0 22Gv1.0 /plant_tribes/configs/22Gv1.0 PlantTribes default configs, version 1.0; 22Gv1.0) +#22Gv1.1 22Gv1.1 /plant_tribes/configs/22Gv1.1 PlantTribes default configs, version 1.1; 22Gv1.1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool_data_table_conf.xml.sample Mon Feb 13 13:43:24 2017 -0500 @@ -0,0 +1,6 @@ +<tables> + <table name="plant_tribes_configs" comment_char="#"> + <columns>value, name, path, description</columns> + <file path="tool-data/plant_tribes_configs.loc" /> + </table> +</tables>