How to use the medaka.options function in medaka

To help you get started, we’ve selected a few medaka examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nanoporetech / medaka / medaka / models.py View on Github external
elif model not in medaka.options.allowed_models:
        raise ValueError(
            "Model {} is not a known model or existant file.".format(model))
    else:
        # check for model in model stores
        fname = '{}_model.hdf5'.format(model)
        fps = [
            os.path.join(ms, fname)
            for ms in medaka.options.model_stores]
        for fp in fps:
            if os.path.exists(fp):
                return fp

        # try to download model
        url = medaka.options.model_url_template.format(
            pkg=__package__, subdir=medaka.options.model_subdir, fname=fname)
        try:
            data = requests.get(url).content
            # check data is a model
            with tempfile.TemporaryDirectory() as tmpdir:
                tmp_file = os.path.join(tmpdir, "tmp_model.hdf5")
                with open(tmp_file, 'wb') as tmp_model:
                    tmp_model.write(data)
                with medaka.datastore.DataStore(tmp_file) as ds:
                    ds.get_meta('model_function')
        except Exception:
            raise DownloadError(
                "The model file for {} is not already installed and "
                "could not be downloaded. Check you are connected to"
                " the internet and try again.".format(model))
        else:
            # save the model
github nanoporetech / medaka / medaka / medaka.py View on Github external
def print_all_models(args):
    print('Available:', ', '.join(medaka.options.allowed_models))
    for key in ('consensus', 'snp', 'variant'):
        # medaka_variant relies on this order
        print('Default {}: '.format(key), medaka.options.default_models[key])
github nanoporetech / medaka / medaka / models.py View on Github external
def resolve_model(model):
    """Resolve a model filepath, downloading known models if necessary.

    :param model_name: str, model filepath or model ID

    :returns: str, filepath to model file.
    """
    if os.path.exists(model):  # model is path to model file
        return model
    elif model not in medaka.options.allowed_models:
        raise ValueError(
            "Model {} is not a known model or existant file.".format(model))
    else:
        # check for model in model stores
        fname = '{}_model.hdf5'.format(model)
        fps = [
            os.path.join(ms, fname)
            for ms in medaka.options.model_stores]
        for fp in fps:
            if os.path.exists(fp):
                return fp

        # try to download model
        url = medaka.options.model_url_template.format(
            pkg=__package__, subdir=medaka.options.model_subdir, fname=fname)
        try:
github nanoporetech / medaka / medaka / medaka.py View on Github external
def __init__(
            self, option_strings, dest, default=None, required=False,
            help='Model file.'):
        super().__init__(
            option_strings, dest, nargs=1, default=default, required=required,
            help='{} {{{}}}'.format(help, ', '.join(medaka.options.allowed_models)))
github nanoporetech / medaka / medaka / models.py View on Github external
:param model_name: str, model filepath or model ID

    :returns: str, filepath to model file.
    """
    if os.path.exists(model):  # model is path to model file
        return model
    elif model not in medaka.options.allowed_models:
        raise ValueError(
            "Model {} is not a known model or existant file.".format(model))
    else:
        # check for model in model stores
        fname = '{}_model.hdf5'.format(model)
        fps = [
            os.path.join(ms, fname)
            for ms in medaka.options.model_stores]
        for fp in fps:
            if os.path.exists(fp):
                return fp

        # try to download model
        url = medaka.options.model_url_template.format(
            pkg=__package__, subdir=medaka.options.model_subdir, fname=fname)
        try:
            data = requests.get(url).content
            # check data is a model
            with tempfile.TemporaryDirectory() as tmpdir:
                tmp_file = os.path.join(tmpdir, "tmp_model.hdf5")
                with open(tmp_file, 'wb') as tmp_model:
                    tmp_model.write(data)
                with medaka.datastore.DataStore(tmp_file) as ds:
                    ds.get_meta('model_function')
github nanoporetech / medaka / medaka / medaka.py View on Github external
def _model_arg():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter, add_help=False)
    parser.add_argument('--model', action=ResolveModel,
            default=medaka.options.default_models['consensus'],
            help='Model to use.')
    parser.add_argument('--allow_cudnn', dest='allow_cudnn', default=True, action='store_true', help=argparse.SUPPRESS)
    parser.add_argument('--disable_cudnn', dest='allow_cudnn', default=False, action='store_false',
            help='Disable use of cuDNN model layers.')
    return parser
github nanoporetech / medaka / medaka / models.py View on Github external
return model
    elif model not in medaka.options.allowed_models:
        raise ValueError(
            "Model {} is not a known model or existant file.".format(model))
    else:
        # check for model in model stores
        fname = '{}_model.hdf5'.format(model)
        fps = [
            os.path.join(ms, fname)
            for ms in medaka.options.model_stores]
        for fp in fps:
            if os.path.exists(fp):
                return fp

        # try to download model
        url = medaka.options.model_url_template.format(
            pkg=__package__, subdir=medaka.options.model_subdir, fname=fname)
        try:
            data = requests.get(url).content
            # check data is a model
            with tempfile.TemporaryDirectory() as tmpdir:
                tmp_file = os.path.join(tmpdir, "tmp_model.hdf5")
                with open(tmp_file, 'wb') as tmp_model:
                    tmp_model.write(data)
                with medaka.datastore.DataStore(tmp_file) as ds:
                    ds.get_meta('model_function')
        except Exception:
            raise DownloadError(
                "The model file for {} is not already installed and "
                "could not be downloaded. Check you are connected to"
                " the internet and try again.".format(model))
        else: