Пример #1
0
def setup(args):
    template, template_txt = name_to_config(args.template)
    base_item = template["details"][0]
    project_name, metadata, global_vars = _pname_and_metadata(args.metadata)
    remotes = _retrieve_remote([args.template, args.metadata])
    inputs = args.input_files + remotes.get("inputs", [])
    items = [
        _add_metadata(item, metadata, remotes)
        for item in _prep_items_from_base(base_item, inputs)
    ]

    out_dir = os.path.join(os.getcwd(), project_name)
    work_dir = utils.safe_makedir(os.path.join(out_dir, "work"))
    if len(items) == 0:
        out_config_file = _write_template_config(template_txt, project_name,
                                                 out_dir)
        print "Template configuration file created at: %s" % out_config_file
        print "Edit to finalize custom options, then prepare full sample config with:"
        print "  bcbio_nextgen.py -w template %s %s sample1.bam sample2.fq" % \
            (out_config_file, project_name)
    else:
        out_config_file = _write_config_file(items, global_vars, template,
                                             project_name, out_dir)
        print "Configuration file created at: %s" % out_config_file
        print "Edit to finalize and run with:"
        print "  cd %s" % work_dir
        print "  bcbio_nextgen.py ../config/%s" % os.path.basename(
            out_config_file)
        if remotes.get("base"):
            remote_path = os.path.join(remotes["base"],
                                       os.path.basename(out_config_file))
            bucket, key = utils.s3_bucket_key(remote_path)
            s3.upload_file_boto(out_config_file, bucket, key)
            print "Also uploaded to AWS S3 in %s" % remotes["base"]
            print "Run directly with bcbio_vm.py run %s" % remote_path
Пример #2
0
def setup(args):
    template, template_txt = name_to_config(args.template)
    base_item = template["details"][0]
    project_name, metadata, global_vars = _pname_and_metadata(args.metadata)
    remotes = _retrieve_remote([args.template, args.metadata])
    inputs = args.input_files + remotes.get("inputs", [])
    items = [_add_metadata(item, metadata, remotes)
             for item in _prep_items_from_base(base_item, inputs)]

    out_dir = os.path.join(os.getcwd(), project_name)
    work_dir = utils.safe_makedir(os.path.join(out_dir, "work"))
    if len(items) == 0:
        out_config_file = _write_template_config(template_txt, project_name, out_dir)
        print "Template configuration file created at: %s" % out_config_file
        print "Edit to finalize custom options, then prepare full sample config with:"
        print "  bcbio_nextgen.py -w template %s %s sample1.bam sample2.fq" % \
            (out_config_file, project_name)
    else:
        out_config_file = _write_config_file(items, global_vars, template, project_name, out_dir)
        print "Configuration file created at: %s" % out_config_file
        print "Edit to finalize and run with:"
        print "  cd %s" % work_dir
        print "  bcbio_nextgen.py ../config/%s" % os.path.basename(out_config_file)
        if remotes.get("base"):
            remote_path = os.path.join(remotes["base"], os.path.basename(out_config_file))
            bucket, key = utils.s3_bucket_key(remote_path)
            s3.upload_file_boto(out_config_file, bucket, key)
            print "Also uploaded to AWS S3 in %s" % remotes["base"]
            print "Run directly with bcbio_vm.py run %s" % remote_path
Пример #3
0
def _retrieve_remote(fnames):
    """Retrieve remote inputs found in the same bucket as the template or metadata files.
    """
    for fname in fnames:
        if fname.startswith(utils.SUPPORTED_REMOTES):
            bucket_name, key_name = utils.s3_bucket_key(fname)
            folder = os.path.dirname(key_name)
            conn = boto.connect_s3()
            bucket = conn.get_bucket(bucket_name)
            inputs = []
            regions = []
            for key in bucket.get_all_keys(prefix=folder):
                if key.name.endswith(tuple(KNOWN_EXTS.keys())):
                    inputs.append("s3://%s/%s" % (bucket_name, key.name))
                elif key.name.endswith((".bed", ".bed.gz")):
                    regions.append("s3://%s/%s" % (bucket_name, key.name))
            remote_base = "s3://{bucket_name}/{folder}".format(**locals())
            return {"base": remote_base,
                    "inputs": inputs,
                    "region": regions[0] if len(regions) == 1 else None}
    return {}
Пример #4
0
def load_s3(sample_config):
    """Move a sample configuration locally, providing remote upload.
    """
    with utils.s3_handle(sample_config) as in_handle:
        config = yaml.load(in_handle)
    bucket, key = utils.s3_bucket_key(sample_config)
    config["upload"] = {"method": "s3",
                        "dir": os.path.join(os.pardir, "final"),
                        "bucket": bucket,
                        "folder": os.path.join(os.path.dirname(key), "final")}
    if not os.access(os.pardir, os.W_OK | os.X_OK):
        raise IOError("Cannot write to the parent directory of work directory %s\n"
                      "bcbio wants to store prepared uploaded files to %s\n"
                      "We recommend structuring your project in a project specific directory structure\n"
                      "with a specific work directory (mkdir -p your-project/work && cd your-project/work)."
                      % (os.getcwd(), os.path.join(os.pardir, "final")))
    config = _add_jar_resources(config, bucket, key)
    out_file = os.path.join(utils.safe_makedir(os.path.join(os.getcwd(), "config")),
                            os.path.basename(key))
    with open(out_file, "w") as out_handle:
        yaml.dump(config, out_handle, default_flow_style=False, allow_unicode=False)
    return out_file
Пример #5
0
def _retrieve_remote(fnames):
    """Retrieve remote inputs found in the same bucket as the template or metadata files.
    """
    for fname in fnames:
        if fname.startswith(utils.SUPPORTED_REMOTES):
            bucket_name, key_name = utils.s3_bucket_key(fname)
            folder = os.path.dirname(key_name)
            conn = boto.connect_s3()
            bucket = conn.get_bucket(bucket_name)
            inputs = []
            regions = []
            for key in bucket.get_all_keys(prefix=folder):
                if key.name.endswith(tuple(KNOWN_EXTS.keys())):
                    inputs.append("s3://%s/%s" % (bucket_name, key.name))
                elif key.name.endswith((".bed", ".bed.gz")):
                    regions.append("s3://%s/%s" % (bucket_name, key.name))
            remote_base = "s3://{bucket_name}/{folder}".format(**locals())
            return {
                "base": remote_base,
                "inputs": inputs,
                "region": regions[0] if len(regions) == 1 else None
            }
    return {}