Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https://cwl-utils.readthedocs.io/ #57

Open
nyue opened this issue Feb 9, 2021 · 7 comments
Open

Fix https://cwl-utils.readthedocs.io/ #57

nyue opened this issue Feb 9, 2021 · 7 comments

Comments

@nyue
Copy link

nyue commented Feb 9, 2021

I am looking at the possibility of using cwl-utils to generate CWL files programmatically in Python

I discover cwl-utils when browsing python-cwlgen

I am hoping to find example that illustrate how CommandLineTool and CommandInputParameter should be put together via cwl-utils

I have not found any examples thus far.

Cheers

@illusional
Copy link
Collaborator

Hi @nyue, this issue on cwlgen has a rough guide on how cwl-utils can be used to generate CWL: common-workflow-lab/python-cwlgen#27

In essence, you can do something like the following:

import cwl_utils.parser_v1_2 as cwl

clt = cwl.CommandLineTool(
    # eg: keys from https://github.com/common-workflow-language/cwl-utils/blob/c7308efbbbd4d64f5d479f27bf46ca6041cfb7b2/cwl_utils/parser_v1_2.py#L7000-L7021
    id="mytoolid",
    inputs=[
        cwl. CommandInputParameter(**fields)
    ]
)

dict_representation = clt.save()

@nyue
Copy link
Author

nyue commented Feb 9, 2021

Thanks Michael. I am making some progress.

After the call to save() [I get a dictionary], what calls/method is there to write that out to a CWL file I can test with cwltool/cromwell ?

Cheers

@illusional
Copy link
Collaborator

This is a rough excerpt of the code I've used in the past:

def convert_tool_to_yaml(tool):
    # Convert dict to YAML
    import ruamel.yaml
    yaml = ruamel.yaml.YAML()

    tool_dict = tool.save()

    io = StringIO()
    yaml.dump(tool_dict, io)
    return io.getvalue()

Source: https://github.com/PMCC-BioinformaticsCore/janis-core/blob/e8d56ff04e093ffb91b6f4b7cc74b7124ad490cf/janis_core/translations/cwl.py#L93-L107

@nyue
Copy link
Author

nyue commented Feb 10, 2021

Thank you, got it writing out CWL/YAML file.

@nyue nyue closed this as completed Feb 10, 2021
@mr-c mr-c reopened this Feb 10, 2021
@mr-c
Copy link
Member

mr-c commented Feb 10, 2021

Glad you found a solution! I'm reopening this to remind us to improve the docs

@mr-c mr-c changed the title CWL generation programmatically docs needed for CWL generation programmatically Feb 10, 2021
@cwl-bot
Copy link

cwl-bot commented Feb 10, 2021

This issue has been mentioned on Common Workflow Language Discourse. There might be relevant details there:

https://cwl.discourse.group/t/how-to-implement-a-reduce-method-in-cwl/294/3

@mr-c mr-c changed the title docs needed for CWL generation programmatically Fix https://cwl-utils.readthedocs.io/ Apr 15, 2021
@golharam
Copy link

This was super helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants