コード例 #1
0
def to_listing(value):
    @salad
    def map_obj(obj):
        if isinstance(obj, str):
            return obj
        elif isinstance(obj, dict):
            if 'class' in obj:
                if obj['class'] == 'File':
                    return File(**obj)
                elif obj['class'] == 'Directory':
                    return Directory(**obj)
                else:
                    raise TypeError('Unsupported {}'.format(obj))
            elif 'entry' in obj:
                return Dirent(**obj)
            else:
                return obj
        else:
            raise TypeError('Unsupported {}'.format(obj))

    if value is not None:
        if isinstance(value, str) or is_instance_all(File, Directory, Dirent,
                                                     str):
            return value
        elif isinstance(value, list):
            return list(map(map_obj, value))
        else:
            raise TypeError('TypeError, got {}'.format(type(value)))
コード例 #2
0
ファイル: workflow.py プロジェクト: sbg/sevenbridges-cwl
def to_out(value):
    @salad
    def map_obj(obj):
        if isinstance(obj, str):
            return obj
        return StepOutput(**obj)

    if value is not None:
        if is_instance_all(value, str, StepOutput):
            return value
        elif is_instance_all(value, dict, str):
            return list(map(map_obj, value))
        else:
            raise TypeError('TypeError, got: {}'.format(type(value)))
    else:
        return []
コード例 #3
0
ファイル: types.py プロジェクト: sbg/sevenbridges-cwl
def to_file_dir_list(value):
    @salad
    def map_dict(d):
        if d['class'] == 'Directory':
            return Directory(**d)
        elif d['class'] == 'File':
            return File(**d)
        else:
            raise ValueError('Unsupported class')

    if value is not None:
        if is_instance_all(value, File, Directory):
            return value
        elif is_instance_all(value, dict):
            return list(map(map_dict, value))
        else:
            raise TypeError('Expected list[File|Directory], got: {}'.format(
                type(value)))
コード例 #4
0
ファイル: workflow.py プロジェクト: sbg/sevenbridges-cwl
def to_steps(value):
    """Converts `value` into workflow steps."""

    @salad
    def map_to_cls(obj):
        return Step(**obj)

    if value is not None:
        if is_instance_all(value, Step):
            return value
        elif isinstance(value, list):
            return list(map(map_to_cls, value))
        else:
            raise TypeError('Expected steps, got: {}'.format(type(value)))
コード例 #5
0
def to_str_ibinding(value):
    """Converts list of values to list of str|input_binding|$directive"""
    @salad
    def map_obj(obj):
        if isinstance(obj, str):
            return obj
        return InputBinding(**obj)

    if value is not None:
        if is_instance_all(value, str, InputBinding):
            return value
        elif isinstance(value, list):
            return list(map(map_obj, value))
        else:
            raise TypeError('Expected list, got {}'.format(type(value)))
コード例 #6
0
def get_requirements(value):
    """Converts value to CommandLineTool requirements."""

    if value is not None:
        if is_instance_all(value, InlineJavascript, SchemaDef, Docker,
                           Software, InitialWorkDir, EnvVar, ShellCommand,
                           Resource):
            return value
        elif is_instance_all_dict(value, InlineJavascript, SchemaDef, Docker,
                                  Software, InitialWorkDir, EnvVar,
                                  ShellCommand, Resource):
            return value
        elif isinstance(value, list):
            return list(map(to_cmd_req, value))
        elif isinstance(value, dict):
            return {k: to_salad_obj(v) for k, v in value.items()}
        else:
            raise ValueError("Expected list, got {}.".format(type(value)))
コード例 #7
0
ファイル: __init__.py プロジェクト: sbg/sevenbridges-cwl
def to_step_req(value):
    @salad
    def map_obj(obj):
        return obj

    @salad
    def map_to_cls(d):
        m = dict(InlineJavascriptRequirement=InlineJavascript,
                 SchemaDefRequirement=SchemaDef,
                 DockerRequirement=Docker,
                 SoftwareRequirement=Software,
                 InitialWorkDirRequirement=InitialWorkDir,
                 EnvVarRequirement=EnvVar,
                 ShellCommandRequirement=ShellCommand,
                 ResourceRequirement=Resource,
                 SubworkflowFeatureRequirement=SubworkflowFeature,
                 ScatterFeatureRequirement=ScatterFeature,
                 MultipleInputFeatureRequirement=MultipleInputFeature,
                 StepInputExpressionRequirement=StepInputExpression)
        if 'class' in d:
            return m[d['class']](**d)
        else:
            raise Exception("Unsupported class: {}".format(d['class']))

    if value is not None:
        if is_instance_all(value, InlineJavascript, SchemaDef, Docker,
                           Software, InitialWorkDir, EnvVar, ShellCommand,
                           Resource, SubworkflowFeature, ScatterFeature,
                           MultipleInputFeature, StepInputExpression):
            return value
        elif is_instance_all_dict(value, InlineJavascript, SchemaDef, Docker,
                                  Software, InitialWorkDir, EnvVar,
                                  ShellCommand, Resource, SubworkflowFeature,
                                  ScatterFeature, MultipleInputFeature,
                                  StepInputExpression):
            return value
        elif isinstance(value, list):
            return list(map(map_to_cls, value))
        elif isinstance(value, dict):
            return {k: map_obj(v) for k, v in value.items()}
        else:
            raise TypeError('TypeError got: {}'.format(type(value)))
コード例 #8
0
ファイル: schema_def.py プロジェクト: sbg/sevenbridges-cwl
def to_schemadef_type(value):
    @salad
    def map_obj(obj):
        if isinstance(obj, dict):
            if obj['type'] == 'enum':
                return InputEnum(**obj)
            elif obj['type'] == 'record':
                return InputRecord(**obj)
            elif obj['type'] == 'array':
                return InputArray(**obj)
            else:
                raise ValueError("Unsupported type for shemadef: {}".format(
                    obj['type']))
        return obj

    if value is not None:
        if is_instance_all(value, InputRecord, InputEnum, InputArray):
            return value
        elif isinstance(value, list):
            return list(map(map_obj, value))
        else:
            raise TypeError(
                'Expected list[SchemaDef requirements], got {}'.format(
                    type(value)))