# Path: cloudbio/custom/shared.py
# CBL_REPO_ROOT_URL = "https://raw.github.com/chapmanb/cloudbiolinux/master/"
# def chdir(new_dir):
# def safe_makedir(dname):
# def which(program, env=None):
#     def is_exe(fpath):
# def _if_not_installed(pname):
#     def argcatcher(func):
#         def decorator(*args, **kwargs):
# def _all_cbl_paths(env, ext):
# def _executable_not_on_path(pname):
# def _galaxy_tool_install(args):
# def _galaxy_tool_present(args):
# def _if_not_python_lib(library):
#     def argcatcher(func):
#         def decorator(*args, **kwargs):
# def make_tmp_dir_local(ext, work_dir):
# def _make_tmp_dir(ext=None, work_dir=None):
# def __work_dir():
# def _get_expected_file(url, dir_name=None, safe_tar=False, tar_file_name=None):
# def _safe_dir_name(dir_name, need_dir=True):
# def _remote_fetch(env, url, out_file=None, allow_fail=False, fix_fn=None, samedir=False):
# def _fetch_and_unpack(url, need_dir=True, dir_name=None, revision=None,
#                       safe_tar=False, tar_file_name=None):
# def _configure_make(env):
# def _ac_configure_make(env):
# def _make_copy(find_cmd=None, premake_cmd=None, do_make=True):
#     def _do_work(env):
# def _get_install(url, env, make_command, post_unpack_fn=None, revision=None, dir_name=None,
#                  safe_tar=False, tar_file_name=None):
# def _apply_patch(env, url):
# def _get_install_local(url, env, make_command, dir_name=None,
#                        post_unpack_fn=None, safe_tar=False, tar_file_name=None):
# def _symlinked_install_dir(pname, version, env, extra_dir=None):
# def _symlinked_dir_exists(pname, version, env, extra_dir=None):
# def _symlinked_shared_dir(pname, version, env, extra_dir=None):
# def _symlinked_java_version_dir(pname, version, env):
# def _java_install(pname, version, url, env, install_fn=None,
#                   pre_fetch_fn=None):
# def _python_cmd(env):
# def _pip_cmd(env):
# def _conda_cmd(env):
# def _is_anaconda(env):
# def _python_make(env):
# def _get_installed_file(env, local_file):
# def _get_installed_file_contents(env, local_file):
# def _write_to_file(contents, path, mode):
# def _get_bin_dir(env):
# def _get_include_dir(env):
# def _get_lib_dir(env):
# def _get_install_subdir(env, subdir):
# def _set_default_config(env, install_dir, sym_dir_name="default"):
# def _setup_simple_service(service_name):
# def _render_config_file_template(env, name, defaults={}, overrides={}, default_source=None):
# def _extend_env(env, defaults={}, overrides={}):
# def _setup_conf_file(env, dest, name, defaults={}, overrides={}, default_source=None, mode="0755"):
# def _add_to_profiles(line, profiles=[], use_sudo=True):
# def install_venvburrito():
# def _create_python_virtualenv(env, venv_name, reqs_file=None, reqs_url=None):
#     def create():
# def _create_local_python_virtualenv(env, venv_name, reqs_file, reqs_url):
# def _create_global_python_virtualenv(env, venv_name, reqs_file, reqs_url):
# def _get_bitbucket_download_url(revision, default_repo):
# def _read_boolean(env, name, default):
# 
# Path: cloudbio/custom/versioncheck.py
# def _parse_from_stdoutflag(out, flag, stdout_index=-1):
# def _clean_version(x):
# def up_to_date(env, cmd, version, args=None, stdout_flag=None,
#                stdout_index=-1):
# def is_version(env, cmd, version, args=None, stdout_flag=None,
#                stdout_index=-1):
# def get_installed_version(env, cmd, version, args=None, stdout_flag=None,
#                           stdout_index=-1):
# 
# Path: cloudbio/libraries.py
# def r_library_installer(config):
# def _make_install_script(out_file, config):


import os
import re
import yaml
from fabric.api import *
from fabric.contrib.files import *
from shared import (_if_not_installed, _make_tmp_dir,
                    _get_install, _get_install_local, _make_copy, _configure_make,
                    _java_install, _python_cmd,
                    _symlinked_java_version_dir, _fetch_and_unpack, _python_make,
                    _get_lib_dir, _get_include_dir, _apply_patch)
from cloudbio.custom import shared, versioncheck
from cloudbio import libraries
from cloudbio.flavor.config import get_config_file
    install_dir = shared._symlinked_shared_dir("fastqc_screen", version, env)
    executable = "fastq_screen"
    if install_dir:
        with _make_tmp_dir() as work_dir:
            with cd(work_dir):
                out_file = shared._remote_fetch(env, url)
                env.safe_run("tar -xzvpf %s" % out_file)
                with cd("fastq_screen_v%s" % version):
                    env.safe_sudo("mv * %s" % install_dir)
                env.safe_sudo("ln -s %s/%s %s/bin/%s" % (install_dir, executable,
                                                         env.system_install, executable))

def install_bedtools(env):
    """A flexible suite of utilities for comparing genomic features.
    https://code.google.com/p/bedtools/
    """
    version = "2.17.0"
    if versioncheck.up_to_date(env, "bedtools --version", version, stdout_flag="bedtools"):
        return
    url = "https://bedtools.googlecode.com/files/" \
          "BEDTools.v%s.tar.gz" % version
    _get_install(url, env, _make_copy("ls -1 bin/*"))

_shrec_run = """
#!/usr/bin/perl
use warnings;
use strict;
use FindBin qw($RealBin);
use Getopt::Long;


# Path: cloudbio/custom/shared.py
# CBL_REPO_ROOT_URL = "https://raw.github.com/chapmanb/cloudbiolinux/master/"
# def chdir(new_dir):
# def safe_makedir(dname):
# def which(program, env=None):
#     def is_exe(fpath):
# def _if_not_installed(pname):
#     def argcatcher(func):
#         def decorator(*args, **kwargs):
# def _all_cbl_paths(env, ext):
# def _executable_not_on_path(pname):
# def _galaxy_tool_install(args):
# def _galaxy_tool_present(args):
# def _if_not_python_lib(library):
#     def argcatcher(func):
#         def decorator(*args, **kwargs):
# def make_tmp_dir_local(ext, work_dir):
# def _make_tmp_dir(ext=None, work_dir=None):
# def __work_dir():
# def _get_expected_file(url, dir_name=None, safe_tar=False, tar_file_name=None):
# def _safe_dir_name(dir_name, need_dir=True):
# def _remote_fetch(env, url, out_file=None, allow_fail=False, fix_fn=None, samedir=False):
# def _fetch_and_unpack(url, need_dir=True, dir_name=None, revision=None,
#                       safe_tar=False, tar_file_name=None):
# def _configure_make(env):
# def _ac_configure_make(env):
# def _make_copy(find_cmd=None, premake_cmd=None, do_make=True):
#     def _do_work(env):
# def _get_install(url, env, make_command, post_unpack_fn=None, revision=None, dir_name=None,
#                  safe_tar=False, tar_file_name=None):
# def _apply_patch(env, url):
# def _get_install_local(url, env, make_command, dir_name=None,
#                        post_unpack_fn=None, safe_tar=False, tar_file_name=None):
# def _symlinked_install_dir(pname, version, env, extra_dir=None):
# def _symlinked_dir_exists(pname, version, env, extra_dir=None):
# def _symlinked_shared_dir(pname, version, env, extra_dir=None):
# def _symlinked_java_version_dir(pname, version, env):
# def _java_install(pname, version, url, env, install_fn=None,
#                   pre_fetch_fn=None):
# def _python_cmd(env):
# def _pip_cmd(env):
# def _conda_cmd(env):
# def _is_anaconda(env):
# def _python_make(env):
# def _get_installed_file(env, local_file):
# def _get_installed_file_contents(env, local_file):
# def _write_to_file(contents, path, mode):
# def _get_bin_dir(env):
# def _get_include_dir(env):
# def _get_lib_dir(env):
# def _get_install_subdir(env, subdir):
# def _set_default_config(env, install_dir, sym_dir_name="default"):
# def _setup_simple_service(service_name):
# def _render_config_file_template(env, name, defaults={}, overrides={}, default_source=None):
# def _extend_env(env, defaults={}, overrides={}):
# def _setup_conf_file(env, dest, name, defaults={}, overrides={}, default_source=None, mode="0755"):
# def _add_to_profiles(line, profiles=[], use_sudo=True):
# def install_venvburrito():
# def _create_python_virtualenv(env, venv_name, reqs_file=None, reqs_url=None):
#     def create():
# def _create_local_python_virtualenv(env, venv_name, reqs_file, reqs_url):
# def _create_global_python_virtualenv(env, venv_name, reqs_file, reqs_url):
# def _get_bitbucket_download_url(revision, default_repo):
# def _read_boolean(env, name, default):
# 
# Path: cloudbio/custom/versioncheck.py
# def _parse_from_stdoutflag(out, flag, stdout_index=-1):
# def _clean_version(x):
# def up_to_date(env, cmd, version, args=None, stdout_flag=None,
#                stdout_index=-1):
# def is_version(env, cmd, version, args=None, stdout_flag=None,
#                stdout_index=-1):
# def get_installed_version(env, cmd, version, args=None, stdout_flag=None,
#                           stdout_index=-1):
# 
# Path: cloudbio/libraries.py
# def r_library_installer(config):
# def _make_install_script(out_file, config):


# Path: cloudbio/custom/bio_nextgen.py
import os
import re
import yaml
from fabric.api import *
from fabric.contrib.files import *
from shared import (_if_not_installed, _make_tmp_dir,
                    _get_install, _get_install_local, _make_copy, _configure_make,
                    _java_install, _python_cmd,
                    _symlinked_java_version_dir, _fetch_and_unpack, _python_make,
                    _get_lib_dir, _get_include_dir, _apply_patch)
from cloudbio.custom import shared, versioncheck
from cloudbio import libraries
from cloudbio.flavor.config import get_config_file

    install_dir = shared._symlinked_shared_dir("fastqc_screen", version, env)
    executable = "fastq_screen"
    if install_dir:
        with _make_tmp_dir() as work_dir:
            with cd(work_dir):
                out_file = shared._remote_fetch(env, url)
                env.safe_run("tar -xzvpf %s" % out_file)
                with cd("fastq_screen_v%s" % version):
                    env.safe_sudo("mv * %s" % install_dir)
                env.safe_sudo("ln -s %s/%s %s/bin/%s" % (install_dir, executable,
                                                         env.system_install, executable))

def install_bedtools(env):
    """A flexible suite of utilities for comparing genomic features.
    https://code.google.com/p/bedtools/
    """
    version = "2.17.0"
    if versioncheck.up_to_date(env, "bedtools --version", version, stdout_flag="bedtools"):
        return
    url = "https://bedtools.googlecode.com/files/" \
          "BEDTools.v%s.tar.gz" % version
    _get_install(url, env, _make_copy("ls -1 bin/*"))

_shrec_run = """
#!/usr/bin/perl
use warnings;
use strict;
use FindBin qw($RealBin);
use Getopt::Long;


my @java_args;