# Path: seqcluster/libs/do.py
# def run(cmd, data=None, checks=None, region=None, log_error=True,
#         log_stdout=False):
# def find_bash():
# def find_cmd(cmd):
# def _normalize_cmd_args(cmd):
# def _do_run(cmd, checks, log_stdout=False):
# 
# Path: seqcluster/libs/utils.py
# def chdir(p):
# def safe_dirs(dirs):
# def safe_remove(fn):
# def safe_run(fn):
# def file_exists(fname):


import os.path as op
import os
import sys
import subprocess
import contextlib
import yaml
    import bcbio
        import bcbio.install as install
from argparse import ArgumentParser
from seqcluster.libs import do, utils
       from bcbio import install as bcb
       from bcbio import install as bcb
def chdir(new_dir):
    """
    stolen from bcbio.
    Context manager to temporarily change to a new directory.

    http://lucentbeing.com/blog/context-managers-and-the-with-statement-in-python/
    """
    cur_dir = os.getcwd()
    _mkdir(new_dir)
    os.chdir(new_dir)
    try:
        yield
    finally:
        os.chdir(cur_dir)

def _get_miraligner():
    opts = "-Xms750m -Xmx4g"
    try:
        tool = "miraligner"
        ret = os.system(tool)
        if ret != 0:
            raise SystemExit("%s not installed." % tool)
    except SystemExit:
        tool = None
        print("miraligner not found. I'll try to download it.")
        pass
    if not tool:
        if not utils.file_exists(op.abspath("miraligner.jar")):
            url = "https://raw.githubusercontent.com/lpantano/seqbuster/miraligner/modules/miraligner/miraligner.jar"
            cmd = ["wget", "-O miraligner.jar", "--no-check-certificate", url]

# Path: seqcluster/libs/do.py
# def run(cmd, data=None, checks=None, region=None, log_error=True,
#         log_stdout=False):
# def find_bash():
# def find_cmd(cmd):
# def _normalize_cmd_args(cmd):
# def _do_run(cmd, checks, log_stdout=False):
# 
# Path: seqcluster/libs/utils.py
# def chdir(p):
# def safe_dirs(dirs):
# def safe_remove(fn):
# def safe_run(fn):
# def file_exists(fname):


# Path: seqcluster/install.py
import os.path as op
import os
import sys
import subprocess
import contextlib
import yaml
    import bcbio
        import bcbio.install as install
from argparse import ArgumentParser
from seqcluster.libs import do, utils
       from bcbio import install as bcb
       from bcbio import install as bcb

def chdir(new_dir):
    """
    stolen from bcbio.
    Context manager to temporarily change to a new directory.

    http://lucentbeing.com/blog/context-managers-and-the-with-statement-in-python/
    """
    cur_dir = os.getcwd()
    _mkdir(new_dir)
    os.chdir(new_dir)
    try:
        yield
    finally:
        os.chdir(cur_dir)

def _get_miraligner():
    opts = "-Xms750m -Xmx4g"
    try:
        tool = "miraligner"
        ret = os.system(tool)
        if ret != 0:
            raise SystemExit("%s not installed." % tool)
    except SystemExit:
        tool = None
        print("miraligner not found. I'll try to download it.")
        pass
    if not tool:
        if not utils.file_exists(op.abspath("miraligner.jar")):
            url = "https://raw.githubusercontent.com/lpantano/seqbuster/miraligner/modules/miraligner/miraligner.jar"
            cmd = ["wget", "-O miraligner.jar", "--no-check-certificate", url]

            do.run(" ".join(cmd), "Download miraligner.")