Пример #1
0
    def test_commandtool_string(self):

        t = CommandToolBuilder(
            tool="id",
            base_command=None,
            inputs=[ToolInput("inp", Optional[str])],
            outputs=[
                ToolOutput("out", str, glob=InputSelector("inp").assert_not_null())
            ],
            version=None,
            container=None,
        )

        cwltool = t.translate("cwl", allow_empty_container=True, to_console=False)
        print(cwltool)
Пример #2
0
def from_container(
    container: str,
    basecommand: List[str],
    helpcommand="-h",
    containersoftware="docker",
    optionsmarker: Optional[str] = None,
    name: Optional[str] = None,
    version: Optional[str] = None,
    type: ToolTemplateType = ToolTemplateType.base,
):
    helpstr = get_help_from_container(
        container=container,
        basecommand=basecommand,
        help_param=helpcommand,
        containersoftware=containersoftware,
    )
    tooldoc, args = parse_str(helpstr, option_marker=optionsmarker)

    if not version:
        comps = container.split(":")
        version = comps[-1] if len(comps) > 1 else "Latest"

    if not version:
        version = get_version_from_container(
            container,
            basecommand,
            versionparam="-v",
            containersoftware=containersoftware,
        )

    tool_id = name or basecommand
    if isinstance(tool_id, list):
        tool_id = "".join(s.title() for s in tool_id)
    else:
        tool_id = tool_id[0].upper() + tool_id[1:]

    t = CommandToolBuilder(
        tool=tool_id,
        base_command=basecommand,
        inputs=args,
        outputs=[],
        metadata=ToolMetadata(documentation=tooldoc) if tooldoc else None,
        version=version,
        container=container,
    )

    return t.translate("janis", to_console=False), helpstr
Пример #3
0
 def test_create_single_file_from_operator(self):
     command = CommandToolBuilder(
         **self.initial_params,
         files_to_create=[("my-path.txt", InputSelector("inp").contents())],
     )
     req = CwlTranslator.build_initial_workdir_from_tool(command).listing
     self.assertEqual(1, len(req))
     self.assertEqual("my-path.txt", req[0].entryname)
     self.assertEqual("$(inputs.inp.contents)", req[0].entry)
Пример #4
0
 def test_create_single_directory_from_selector(self):
     command = CommandToolBuilder(
         **self.initial_params, directories_to_create=InputSelector("name")
     )
     req = CwlTranslator.build_initial_workdir_from_tool(command).listing
     self.assertEqual(1, len(req))
     self.assertEqual(
         '$({ class: "Directory", basename: inputs.name, listing: [] })', req[0]
     )
Пример #5
0
    def test_input_value_removing_extension(self):
        clt = CommandToolBuilder(
            tool="dev",
            base_command="echo",
            inputs=[ToolInput("inp", File(extension=".txt"))],
            outputs=[ToolOutput("out", str, selector=ReadContents(Stdout()))],
            version="v1.0",
            container="ubuntu",
        )

        arg = cwl.translate_tool_argument(
            ToolArgument(InputSelector("inp", remove_file_extension=True) + ".bam"),
            clt,
            inputs_dict={t.id(): t for t in clt.inputs()},
        )

        self.assertEqual(
            '$((inputs.inp.basename.replace(/.txt$/, "") + ".bam"))', arg.valueFrom
        )
Пример #6
0
    def test_read_contents_as_int(self):

        t = CommandToolBuilder(
            tool="test_readcontents",
            base_command=["echo", "1"],
            inputs=[],
            outputs=[ToolOutput("out", Float, glob=ReadContents(Stdout()).as_float())],
            container=None,
            version="-1",
        )
        translated = CwlTranslator.translate_tool_internal(
            t, allow_empty_container=True
        )
        self.assertTrue(translated.outputs[0].outputBinding.loadContents)
        self.assertEqual("float", translated.outputs[0].type)
Пример #7
0
 def test_create_single_file_path_from_operator(self):
     command = CommandToolBuilder(
         **self.initial_params,
         files_to_create=[
             (
                 StringFormatter("{name}.txt", name=InputSelector("name")),
                 "this is contents",
             )
         ],
     )
     req = CwlTranslator.build_initial_workdir_from_tool(command).listing
     self.assertEqual(1, len(req))
     self.assertIsInstance(req[0], cwlgen.Dirent)
     self.assertEqual(
         '$("{name}.txt".replace(/\{name\}/g, inputs.name))', req[0].entryname
     )
     self.assertEqual("this is contents", req[0].entry)
Пример #8
0
    def test_filter_null(self):
        T = CommandToolBuilder(
            tool="testsingleinput",
            base_command="echo",
            inputs=[ToolInput("inp", str, position=0)],
            outputs=[ToolOutput("out", Stdout)],
            version="v1",
            container=None,
        )
        w = WorkflowBuilder("wf")
        w.input("inp", Array(Optional[str], optional=True))
        w.step("stp", T(inp=FilterNullOperator(w.inp)), scatter="inp")
        w.output("out", source=w.stp.out)

        w_cwl = cwl.CwlTranslator().translate_workflow(w, with_container=False)[0]
        self.assertEqual(2, len(w_cwl.steps))
        self.assertEqual(
            "_evaluate_prescatter-stp-inp/out", w_cwl.steps[1].in_[0].source
        )
from janis_bioinformatics.data_types import Bam, BamBai, FastaWithIndexes, VcfTabix, Vcf

# Add tool definitions here

Gatk4BaseRecalibrator_4_1_4 = CommandToolBuilder(
    tool="Gatk4BaseRecalibrator",
    container="broadinstitute/gatk:4.1.4.0",
    version="v4.1.4.0",
    base_command=["gatk", "BaseRecalibrator"],
    inputs=[
        ToolInput("bam", BamBai, prefix="--input"),
        ToolInput("reference", FastaWithIndexes, prefix="--reference"),
        ToolInput("outputFilename",
                  Filename(extension=".table"),
                  prefix="--output"),
        ToolInput("knownSites",
                  Array(VcfTabix),
                  prefix="--known-sites",
                  prefix_applies_to_all_elements=True),
    ],
    outputs=[
        ToolOutput("out_recalibration_report",
                   File,
                   selector=InputSelector("outputFilename"))
    ],
)

Gatk4ApplyBQSR_4_1_4 = CommandToolBuilder(
    tool="Gatk4ApplyBqsr",
    container="broadinstitute/gatk:4.1.4.0",
    version="v4.1.4.0",
Пример #10
0
        self.output("output_vcf", source=self.merge.output_vcf)


Gatk4MergeVcfs_4_1_4 = CommandToolBuilder(
    tool="Gatk4MergeVcfs",
    base_command=["gatk", "MergeVcfs"],
    inputs=[
        ToolInput(
            "vcfs",
            Array(VcfTabix),
            prefix="--INPUT",
            prefix_applies_to_all_elements=True,
        ),
        ToolInput(
            "output_filename",
            Filename(suffix=".merged", extension=".vcf.gz"),
            prefix="--OUTPUT",
        ),
    ],
    outputs=[
        ToolOutput("output_vcf",
                   VcfTabix,
                   glob=InputSelector("output_filename"))
    ],
    version="4.1.4.0",
    container="broadinstitute/gatk:4.1.4.0",
)

if __name__ == "__main__":
    Gatk4GermlineSnpsIndels().translate("wdl")
    # Gatk4MergeVcfs_4_1_4().translate("wdl")
from janis_core import (
    CommandToolBuilder,
    ToolInput,
    ToolOutput,
    File,
    WildcardSelector,
    String,
    ToolArgument,
)

ToolWithOptionalWildcardOutput = CommandToolBuilder(
    tool="optional_wildcard_output_tool",
    version="v0.1.0",
    container="ubuntu:latest",
    base_command=[],
    arguments=[ToolArgument("echo 1 > ", shell_quote=False)],
    inputs=[
        ToolInput(
            "outputFilename", String(optional=True), default="out.csv", position=1
        )
    ],
    outputs=[
        ToolOutput("out", File(optional=True), selector=WildcardSelector("*.txt"))
    ],
)