# HG changeset patch # User jjohnson # Date 1574650497 18000 # Node ID f59e7e242bdeb8cb24b4bf77c5b95440d10ba217 planemo upload commit f80f020c77d04c2e13b89aaea3d784314b940931-dirty diff -r 000000000000 -r f59e7e242bde data_manager/data_manager_cat.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager/data_manager_cat.py Sun Nov 24 21:54:57 2019 -0500 @@ -0,0 +1,103 @@ +#!/usr/bin/env python +from __future__ import print_function + +import argparse +import json +import os.path +import subprocess +import tarfile +import tempfile +import zipfile +try: + # For Python 3.0 and later + from urllib.request import urlopen +except ImportError: + # Fall back to Python 2 imports + from urllib2 import urlopen + + +def url_download(url, workdir): + file_path = os.path.join(workdir, 'download.dat') + src = None + dst = None + try: + src = urlopen(url) + with open(file_path, 'wb') as dst: + while True: + chunk = src.read(2**10) + if chunk: + dst.write(chunk) + else: + break + finally: + if src: + src.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(workdir) + os.remove(file_path) + + +def cat_prepare(install_dir): + cmd = ['CAT', 'prepare' '--fresh', '-q'] + cmd_stdout = tempfile.NamedTemporaryFile() + cmd_stderr = tempfile.NamedTemporaryFile() + return_code = subprocess.call(cmd, shell=True, cwd=install_dir, + stdout=cmd_stdout, stderr=cmd_stderr) + if return_code: + msg = "stdout:\n%s\nstderr:\n%s" % (cmd_stdout.read(), + cmd_stderr.read()) + cmd_stdout.close() + cmd_stderr.close() + raise Exception('Error: (%s), returncode=%s %s' + % (' '.join(cmd), return_code, msg)) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--config_file') + parser.add_argument('--install_path') + parser.add_argument('--db_url', default=None) + args = parser.parse_args() + + if not os.path.exists(args.install_path): + os.makedirs(args.install_path) + if args.db_url: + url_download(args.db_url, args.install_path) + else: + cat_prepare(args.install_path) + + cat_path = None + cat_db = None + tax_db = None + for root, dirs, files in os.walk(args.install_path): + for dname in dirs: + if dname.endswith('CAT_database'): + cat_db = dname + elif dname.endswith('taxonomy'): + tax_db = dname + if cat_db and tax_db: + cat_path = root + break + + cat_dir = os.path.basename(cat_path) + # params = json.loads(open(args.config_file).read()) + dm_dict = {} + dm_dict['data_tables'] = dm_dict.get('data_tables', {}) + data_table = 'cat_database' + dm_dict['data_tables'][data_table]\ + = dm_dict['data_tables'].get(data_table, []) + data_table_entry = dict(value=cat_dir, name=cat_dir, + database_folder=os.path.join(cat_dir, cat_db), + taxonomy_folder=os.path.join(cat_dir, tax_db)) + dm_dict['data_tables'][data_table].append(data_table_entry) + # save info to json file + open(args.config_file, 'wb').write(json.dumps(dm_dict)) + + +if __name__ == "__main__": + main() diff -r 000000000000 -r f59e7e242bde data_manager/data_manager_cat.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager/data_manager_cat.xml Sun Nov 24 21:54:57 2019 -0500 @@ -0,0 +1,44 @@ + + Install a new CAT database + + macros.xml + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r f59e7e242bde data_manager/macros.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager/macros.xml Sun Nov 24 21:54:57 2019 -0500 @@ -0,0 +1,267 @@ + + 5.0.3 + + + cat + + + + + CAT --version + + CAT_database + taxonomy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 'log' in select_outputs or not select_outputs + + + 'predicted_proteins_faa' in select_outputs + + + 'predicted_proteins_gff' in select_outputs + + + 'alignment_diamond' in select_outputs + + + + + + + 'orf2lca' in select_outputs + + + + + + + 'contig2classification' in select_outputs + + + + + + + 'bin2classification' in select_outputs + + + + + + + 'orf2lca' in names.add_names + + + + + + + 'classification' in names.add_names + + + + + + + 'classification' in summarise + + + + + + + + + + https://doi.org/10.1101/072868 + https://doi.org/10.1186/s13059-019-1817-x + + + + diff -r 000000000000 -r f59e7e242bde data_manager_conf.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data_manager_conf.xml Sun Nov 24 21:54:57 2019 -0500 @@ -0,0 +1,27 @@ + + + + + + + + + + ${database_folder} + CAT/${database_folder} + + ${GALAXY_DATA_MANAGER_DATA_PATH}/CAT/${database_folder} + abspath + + + + ${taxonomy_folder} + CAT/${taxonomy_folder} + + ${GALAXY_DATA_MANAGER_DATA_PATH}/CAT/${taxonomy_folder} + abspath + + + + + diff -r 000000000000 -r f59e7e242bde tool-data/cat_database.loc.sample --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool-data/cat_database.loc.sample Sun Nov 24 21:54:57 2019 -0500 @@ -0,0 +1,7 @@ +## A typical download from https://tbb.bio.uu.nl/bastiaan/CAT_prepare/CAT_prepare_20190719.tar.gz +# ls CAT_prepare_20190719/ +# 2019-07-19.CAT_prepare.fresh.log +# 2019-07-19_CAT_database +# 2019-07-19_taxonomy +#value name database_folder taxonomy_folder +#2019-07-19_CAT_database 2019-07-19_CAT_database /opt/galaxy/tool-data/cat_database/CAT_prepare_20190719/2019-07-19_CAT_database /opt/galaxy/tool-data/cat_database/CAT_prepare_20190719/2019-07-19_taxonomy diff -r 000000000000 -r f59e7e242bde tool_data_table_conf.xml.sample --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool_data_table_conf.xml.sample Sun Nov 24 21:54:57 2019 -0500 @@ -0,0 +1,7 @@ + + + + value, name, database_folder, taxonomy_folder + +
+