Ejemplo n.º 1
0
def get_method(method_namespace: str,
               method_name: str,
               method_version: int = None) -> "JSON":
    """
        If method_version is None, get the latest snapshot
    """
    if method_version is None:
        list_methods = fapi.list_repository_methods(namespace=method_namespace,
                                                    name=method_name)
        if list_methods.status_code != 200:
            raise ValueError('Unable to list methods ' + ' - ' +
                             str(list_methods.json()))
        methods = list_methods.json()
        version = -1
        for method in methods:
            version = max(version, method['snapshotId'])
        if version == -1:
            raise ValueError(method_name + ' not found')
        method_version = version

    method_def = fapi.get_repository_method(method_namespace, method_name,
                                            method_version)
    if method_def.status_code != 200:
        raise ValueError('Unable to fetch method {0}/{1}/{2} - {3}'.format(
            method_namespace, method_name, method_version,
            str(method_def.json())))

    return method_def.json()
Ejemplo n.º 2
0
def main(argsv):
    parser = argparse.ArgumentParser(
        description='Download one or more methods from Broad Methods Repository'
    )
    parser.add_argument('-m',
                        '--method',
                        dest='method',
                        action='store',
                        required=True,
                        help=alto.METHOD_HELP)

    args = parser.parse_args(argsv)
    method_namespace, method_name, method_version = alto.fs_split(args.method)
    list_methods = fapi.list_repository_methods(namespace=method_namespace,
                                                name=method_name,
                                                snapshotId=method_version)
    if list_methods.status_code != 200:
        raise ValueError('Unable to list methods ' + ' - ' +
                         str(list_methods.json))
    methods = list_methods.json()
    for method in methods:
        wdl = fapi.get_repository_method(
            method_namespace, method_name,
            method['snapshotId']).json()['payload']
        with open('{}_{}.wdl'.format(method_name, method['snapshotId']),
                  'w') as w:
            w.write(wdl)
Ejemplo n.º 3
0
def download_remote_wdls(namespace, workspace):
    """Update WDL scripts in wdls/production directory, to the ones currently being used in Firecloud
    """
    download_method_configs(namespace, workspace)
    method_configs = pd.read_table('method_configs/latest_method_configs.txt')
    for idx, method in method_configs.iterrows():
        res = firecloud_api.get_repository_method('tsca',
                                                  method['method_name'],
                                                  method['snapshot'])
        print("Updating WDL for %s:%s" %
              (method['method_name'], method['snapshot']))
        if res.status_code == 200:
            text_file = open(
                "../wdls/production/%s.wdl" % method['method_name'], "w")
            text_file.write(res.json()['payload'])
            text_file.close()
    return
def get_firecloud_workflow(method_namespace: str,
                           method_name: str,
                           method_version: int = None) -> dict:
    """Locate a workflow using the method_namespace, method_name and method_version hierachy and return results in a dictionary.

    Parameters
    ----------
    method_namespace: `str`
        The namespace that workflow belongs to (case-sensitive).
    method_name: `str`
        The workflow name (case-sensitive).
    version: `int`, optional (default: None)
        Snapshot ID. By default, the lastest snapshot recorded in Broad Methods Repository would be used.

    Returns
    -------
    `dict` object.
        A dictionary object containing the following entries:
            'namespace': workflow namespace as recorded in Broad Methods Repository.
            'name': workflow name as recorded in Broad Methods Repository.
            'snapshotId': workflow version as recorded in Broad Methods Repository.
            'url': URL to the WDL file.
            'methodUri': Uniform Resource Identifier that is recognized by Terra platform.

    Examples
    --------
    >>> results = get_firecloud_workflow('cumulus', 'cumulus')
    """
    method_record = None

    if method_version is not None:
        method_def = fapi.get_repository_method(method_namespace, method_name,
                                                method_version)
        if method_def.status_code != 200:
            raise ValueError(
                f"Unable to fetch workflow {method_namespace}/{method_name}/{method_version} - {method_def.json()}!"
            )
        method_record = method_def.json()
    else:
        list_methods = fapi.list_repository_methods(namespace=method_namespace,
                                                    name=method_name)
        if list_methods.status_code != 200:
            raise ValueError(
                f"Unable to list methods - {list_methods.json()}!")
        methods = list_methods.json()
        if len(methods) == 0:
            raise ValueError(
                f"Unable to locate workflow {method_namespace}/{method_name}!")

        method_record = methods[0]
        for method in methods[1:]:
            if method_record["snapshotId"] < method["snapshotId"]:
                method_record = method

    results = {
        "namespace":
        method_record["namespace"],
        "name":
        method_record["name"],
        "snapshotId":
        method_record["snapshotId"],
        "url":
        f"https://api.firecloud.org/ga4gh/v1/tools/{method_record['namespace']}:{method_record['name']}/versions/{method_record['snapshotId']}/plain-WDL/descriptor",
        "methodUri":
        f"agora://{method_record['namespace']}/{method_record['name']}/{method_record['snapshotId']}"
    }

    return results
Ejemplo n.º 5
0
def do_fc_inputs(method, out, config):
    method_namespace, method_name, method_version = kco.fs_split(method)
    if method_namespace is None:
        raise ValueError(
            'Method should be specified as namespace/name (e.g. regev/drop-seq)'
        )

    if method_version is None:
        version = -1
        list_methods = fapi.list_repository_methods(method_name)
        if list_methods.status_code != 200:
            raise ValueError('Unable to list methods ' + ' - ' +
                             str(list_methods.json))
        methods = list_methods.json()
        for method in methods:
            if method['namespace'] == method_namespace:
                version = max(version, method['snapshotId'])
        if version == -1:
            raise ValueError(method_name + ' not found')

        method_version = version
        payload = fapi.get_repository_method(method_namespace, method_name,
                                             method_version).json()['payload']
        tmp_wdl_file = tempfile.mkstemp(suffix='.wdl')[1]
        with open(tmp_wdl_file, 'w') as w:
            w.write(payload)

        repo_config = None
        if config is not None:
            config_namespace, config_name, config_version = kco.fs_split(
                config)
            if config_version is not None:
                repo_config = fapi.get_repository_config(
                    config_namespace, config_name, config_version).json()
            else:
                repo_configs = fapi.list_repository_configs().json()
                for config in repo_configs:
                    if config['namespace'] == config_namespace and config[
                            'name'] == config_name and config['method'][
                                'name'] == method_name and config['method'][
                                    'namespace'] == method_namespace:
                        repo_config = config
                        break
                if repo_config is not None:
                    repo_config = fapi.get_repository_config(
                        repo_config['namespace'], repo_config['name'],
                        repo_config['snapshotId']).json()

        jar = pkg_resources.resource_filename('kco', 'womtool-33.1.jar')
        tmp_json_file = tempfile.mkstemp(suffix='.json')[1]
        with open(tmp_json_file, 'w') as tmp_json_out:
            subprocess.check_call(
                ['java', '-jar', jar, 'inputs', tmp_wdl_file],
                stdout=tmp_json_out)
        with open(tmp_json_file, 'r') as tmp_json_in:
            inputs = json.loads(tmp_json_in.read())
        if repo_config is not None:
            repo_config = json.loads(repo_config['payload'])['inputs']
            for key in repo_config:
                value = repo_config[key]
                if inputs.get(key) is not None and value != '':
                    inputs[key] = value
        if out is None:
            out = method_name + '_inputs.json'
        if not out.lower().endswith('.json'):
            out = out + '.json'
        with open(out, 'w') as json_out:
            json.dump(inputs, json_out, indent=0)
        os.remove(tmp_json_file)
        os.remove(tmp_wdl_file)