# Path: bipy/utils.py
# def replace_suffix(filename, suffix, delim="."):
#     """ returns a filename with the suffix replaced
#     with a new suffix
#     exampoe: /path/to/test.run.sam -> /path/to/test.run.fa"""
#     dirname = os.path.dirname(filename)
#     filename = os.path.basename(filename)
#     fsplit = filename.split(delim)[:-1]
#     fsplit.append(suffix)
#     return os.path.join(dirname, delim.join(fsplit))
# 
# def flatten(l):
#     for el in l:
#         if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
#             for sub in flatten(el):
#                 yield sub
#         else:
#             yield el


import os
import subprocess
from bipy.utils import replace_suffix, flatten
from bcbio.utils import safe_makedir
""" handle running novoindex, making a new genome """


def _build_output_file(input_file, config):
    safe_makedir(config["dir"]["ref"])
    return os.path.join(config["dir"]["ref"],
                        os.path.basename(replace_suffix(input_file, "nix")))


def _build_command(input_file, novoindex_config, output_file):
    options = novoindex_config["options"].items()

# Path: bipy/utils.py
# def replace_suffix(filename, suffix, delim="."):
#     """ returns a filename with the suffix replaced
#     with a new suffix
#     exampoe: /path/to/test.run.sam -> /path/to/test.run.fa"""
#     dirname = os.path.dirname(filename)
#     filename = os.path.basename(filename)
#     fsplit = filename.split(delim)[:-1]
#     fsplit.append(suffix)
#     return os.path.join(dirname, delim.join(fsplit))
# 
# def flatten(l):
#     for el in l:
#         if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
#             for sub in flatten(el):
#                 yield sub
#         else:
#             yield el


# Path: bipy/toolbox/novoindex.py
import os
import subprocess
from bipy.utils import replace_suffix, flatten
from bcbio.utils import safe_makedir

""" handle running novoindex, making a new genome """


def _build_output_file(input_file, config):
    safe_makedir(config["dir"]["ref"])
    return os.path.join(config["dir"]["ref"],
                        os.path.basename(replace_suffix(input_file, "nix")))


def _build_command(input_file, novoindex_config, output_file):
    options = novoindex_config["options"].items()

    cmd = map(str, (flatten(["novoindex", options, output_file,