def test_string_formatter(self): wf = WorkflowBuilder("wf") wf.input("sampleName", str) wf.input("platform", str) wf.input( "readGroupHeaderLine", String(optional=True), default=StringFormatter( "@RG\\tID:{name}\\tSM:{name}\\tLB:{name}\\tPL:{pl}", name=InputSelector("sampleName"), pl=InputSelector("platform"), ), ) wf.step("print", EchoTestTool(inp=wf.readGroupHeaderLine)) wf.output("out", source=wf.print) d, _ = cwl.CwlTranslator.translate_workflow( wf, with_container=False, allow_empty_container=True ) stepinputs = d.save()["steps"][0]["in"] self.assertEqual(4, len(stepinputs)) expression = stepinputs[-1]["valueFrom"] expected = ( "$((inputs._print_inp_readGroupHeaderLine != null) " "? inputs._print_inp_readGroupHeaderLine " ': "@RG\\\\tID:{name}\\\\tSM:{name}\\\\tLB:{name}\\\\tPL:{pl}".replace(/\\{name\\}/g, inputs._print_inp_sampleName).replace(/\\{pl\\}/g, inputs._print_inp_platform))' ) self.assertEqual(expected, expression)
def process_subpipeline(**connections): w = WorkflowBuilder("somatic_subpipeline") w.input("bam", BamBai) w.input("intervals", Bed) w.input("reference", FastaWithDict) w.input("known_sites", Array(VcfTabix)) w.step( "base_recalibrator", gatk4.Gatk4BaseRecalibratorLatest( bam=w.bam, intervals=w.intervals, reference=w.reference, knownSites=w.known_sites, ), ) w.step( "apply_bqsr", gatk4.Gatk4ApplyBqsrLatest( bam=w.bam, recalFile=w.base_recalibrator.out, intervals=w.intervals, reference=w.reference, ), ) w.output("out", source=w.apply_bqsr.out) return w(**connections)
def test_add_non_scatter2(self): w = WorkflowBuilder("scatterededge") w.input("inp", Array(String())) w.step("stp", ArrayTestTool(inputs=w.inp)) e = first_value(w.stp.sources["inputs"].source_map) self.assertFalse(e.scatter)
def test_simple(self): w = WorkflowBuilder("test_add_single_to_array_edge") w.step("ech", SingleTestTool(input1="Hello"), doc="Print 'Hello'") c = CwlTranslator.translate_workflow_to_all_in_one( w, allow_empty_container=True ) print(CwlTranslator.stringify_translated_workflow(c))
def test_two_similar_tools(self): w = WorkflowBuilder("testTwoToolsWithSameId") w.input("inp", str) w.step("stp1", TestTool(testtool=w.inp)) w.step("stp2", TestToolV2(testtool=w.inp)) wf_wdl, _ = WdlTranslator.translate_workflow(w) expected = """\ version development import "tools/TestTranslationtool.wdl" as T import "tools/TestTranslationtool_v0_0_2.wdl" as T2 workflow testTwoToolsWithSameId { input { String inp } call T.TestTranslationtool as stp1 { input: testtool=inp } call T2.TestTranslationtool as stp2 { input: testtool=inp } }""" self.assertEqual(expected, wf_wdl.get_string())
def test_add_output(self): w = WorkflowBuilder("test_add_input") w.step("stp", SingleTestTool(), ignore_missing=True) w.output("outputStep", str, source=w.stp) self.assertEqual(len(w.output_nodes), 1) self.assertEqual(w.outputStep, next(iter(w.output_nodes.values()))) self.assertIsNotNone(w.nodes["stp"])
def test_add_single_to_array_edge(self): w = WorkflowBuilder("test_add_single_to_array_edge") w.input("inp1", String()) w.step("stp1", ArrayTestTool(inputs=w.inp1)) e = first_value(w.stp1.sources["inputs"].source_map) self.assertTrue(w.has_multiple_inputs) self.assertTrue(e.compatible_types)
def test_add_single_to_array_edge(self): w = WorkflowBuilder("test_add_single_to_array_edge") w.input("inp1", str) w.step("stp1", ArrayTestTool(inputs=w.inp1)) c, _, _ = CwlTranslator().translate(w, to_console=False, allow_empty_container=True) self.assertEqual(cwl_multiinput, c)
def test_alias_selector(self): w = WorkflowBuilder("wf") w.input("inp", str) w.step("echo", EchoTestTool(inp=w.inp.as_type(str))) w.output("out", source=w.echo.out) sn: List[cwlgen.WorkflowStep] = cwl.translate_step_node( w.step_nodes["echo"], inputs_dict={"inp": ToolInput("inp", str)} ) self.assertEqual("inp", sn[0].in_[0].source)
def process_subpipeline(**connections): w = WorkflowBuilder("split_bam_subpipeline") w.input("bam", BamBai) w.input("intervals", Bed(optional=True)) w.step("split_bam", gatk4.Gatk4SplitReads_4_1_3(bam=w.bam, intervals=w.intervals)) w.output("out", source=w.split_bam.out) return w(**connections)
def test_output_name_and_folder(self): w = WorkflowBuilder("wf") w.input("inp", str) w.step("print", Echo(inp=w.inp)) w.output("out", source=w.print, output_name=w.inp, output_folder=[w.inp]) inputs = {"inp": ["test1", "test2"]} modifier = BatchPipelineModifier(BatchRunRequirements(["inp"], "inp")) new_workflow = modifier.tool_modifier(w, inputs, {}) print(new_workflow)
def test_translate_single_to_array_edge(self): w = WorkflowBuilder("wf") w.input("inp", str) stp1 = w.step("stp1", TestTool(testtool=w.inp), ignore_missing=True) stp2 = w.step("stp2", TestTool(arrayInp=stp1.std, testtool=w.inp), ignore_missing=True) outp = wdl.translate_step_node(stp2, stp2.id(), {}, set()) self.assertEqual(outp.get_string().split("\n")[3].strip(), f"arrayInp=[{stp1.id()}.std]")
def test_two_similar_tools(self): w = WorkflowBuilder("testTwoToolsWithSameId") w.input("inp", str) w.step("stp1", TestTool(testtool=w.inp)) w.step("stp2", TestToolV2(testtool=w.inp)) wf_cwl, _ = CwlTranslator.translate_workflow(w) stps = {stp.id: stp for stp in wf_cwl.steps} self.assertEqual("tools/TestTranslationtool.cwl", stps["stp1"].run) self.assertEqual("tools/TestTranslationtool_v0_0_2.cwl", stps["stp2"].run)
def test_add_rescatter_scattered(self): w = WorkflowBuilder("scatterededge") w.input("inp1", Array(String())) stp1 = w.step("stp1", SingleTestTool(inputs=w.inp1), scatter="inputs") stp2 = w.step("stp2", SingleTestTool(inputs=stp1), scatter="inputs") e1 = first_value(stp1.sources["inputs"].source_map) e2 = first_value(stp2.sources["inputs"].source_map) self.assertTrue(e1.scatter) self.assertTrue(e2.scatter)
def test_read_contents(self): w = WorkflowBuilder("wf") w.input("inp", str) w.step("stp", EchoTestTool(inp=w.inp)) w.output("out", source=w.stp.out.contents()) w_cwl = cwl.CwlTranslator().translate_workflow(w, with_container=False)[0] self.assertEqual(2, len(w_cwl.steps)) self.assertEqual( "${return {out: inputs._stpout.contents }}", w_cwl.steps[1].run.expression ) self.assertTrue(w_cwl.steps[1].run.inputs[0].loadContents)
def test_expression_default(self): wf = WorkflowBuilder("test_expression_defaults") wf.input("inp", Optional[str]) wf.step( "echo", EchoTestTool(inp="Hello, " + If(IsDefined(wf.inp), wf.inp, ", Michael!")), ) wf.output("out", source=wf.echo) wf.translate("cwl")
def test_merge(self): w = WorkflowBuilder("scatterededge") w.input("inp1", Array(String())) w.step("scatteredStp1", SingleTestTool(inputs=w.inp1), scatter="inputs") stp = w.step("mergeStp2", ArrayTestTool(inputs=w.scatteredStp1)) e1 = first_value(w.scatteredStp1.sources["inputs"].source_map) e2 = first_value(w.mergeStp2.sources["inputs"].source_map) self.assertTrue(e1.scatter) self.assertFalse(e2.scatter) self.assertTrue(e2.compatible_types)
def test_subworkflow(self): w = WorkflowBuilder("test_subworkflow") sub_w = WorkflowBuilder("subworkflow") sub_w.input("sub_inp", str) sub_w.step("sub_stp", SingleTestTool(inputs=sub_w.sub_inp)) sub_w.output("sub_out", source=sub_w.sub_stp.out) w.input("inp", str) w.step("stp_workflow", sub_w(sub_inp=w.inp)) w.output("out", source=w.stp_workflow.sub_out) # would be good to come up with some tests # w.translate("wdl") self.assertTrue(True)
def test_dot_4(self): w = WorkflowBuilder("sbmf") w.input("inp", Array(str)) w.input("inp2", Array(str)) w.input("inp3", Array(str)) w.input("inp4", Array(str)) step = w.step( "dotTool", SingleTestTool(inputs=w.inp, input2=w.inp2, input3=w.inp3, input4=w.inp4), scatter=ScatterDescription( fields=["inputs", "input2", "input3", "input4"], method=ScatterMethods.dot, ), ) outp = wdl.translate_step_node( step, "A.SingleTestTool", {}, {"inp", "inp2", "inp3", "inp4"} ) expected = """\ scatter (Q in zip(inp, zip(inp2, zip(inp3, inp4)))) { call A.SingleTestTool as dotTool { input: inputs=Q.left, input2=Q.right.left, input3=Q.right.right.left, input4=Q.right.right.right } }""" self.assertEqual(expected, outp.get_string(indent=0))
def test_add_non_scatter(self): w = WorkflowBuilder("scatterededge") inp = w.input("inp", str) stp = w.step("stp", SingleTestTool(inputs=inp)) e = first_value(w.stp.sources["inputs"].source_map) self.assertIsNone(stp.scatter)
def setUpClass(cls): w = WorkflowBuilder("test_operators") w.input("inp", Array(File())) inval = w.inp[0].basename() w.step("echo", SingleTestTool(input1=inval)) w.output("out", source=w.echo) cls.wf = w w2 = WorkflowBuilder("test_scattered_operator_with_alias") w2.input("inp", Array(Array(String))) w2.step("echo", SingleTestTool(input1=w2.inp[0]), scatter="input1") w2.output("out", source=w.echo) cls.wf2 = w2
def test_add_non_scatter_fail(self): w = WorkflowBuilder("scatterededge") w.input("inp", Array(str)) stp = w.step("stp", SingleTestTool(inputs=w.inp)) e = first_value(w.stp.sources["inputs"].source_map) self.assertFalse(e.compatible_types)
def test_add_scatter_nested_arrays_incompatible(self): w = WorkflowBuilder("scatterededge") w.input("inp", Array(Array(int))) stp = w.step("stp", ArrayTestTool(inputs=w.inp), scatter="inputs") e = first_value(w.stp.sources["inputs"].source_map) self.assertFalse(e.compatible_types) self.assertListEqual(["inputs"], stp.scatter.fields)
def test_add_scatter_incompatible(self): w = WorkflowBuilder("scatterededge") w.input("inp", Array(int)) stp = w.step("stp", SingleTestTool(inputs=w.inp), scatter="inputs") e = first_value(w.stp.sources["inputs"].source_map) self.assertTrue(e.scatter) self.assertFalse(e.compatible_types)
def test_add_scatter_nested_arrays(self): w = WorkflowBuilder("scatterededge") w.input("inp", Array(Array(str))) stp = w.step("stp", ArrayTestTool(inps=w.inp), scatter="inps") e = w.stp.sources["inps"].source_map[0] self.assertTrue(e.compatible_types) self.assertListEqual(["inps"], stp.scatter.fields)
def test_add_scatter(self): w = WorkflowBuilder("scatterededge") w.input("inp", Array(str)) stp = w.step("stp", SingleTestTool(inputs=w.inp), scatter="inputs") e = first_value(w.stp.sources["inputs"].source_map) self.assertTrue(e.compatible_types) self.assertListEqual(["inputs"], stp.scatter.fields)
def process_subpipeline(**connections): w = WorkflowBuilder("samtools_mpileup_subpipeline") w.input("vcf", Vcf) w.input("bam", BamBai) w.input("reference", FastaWithDict) w.step( "samtools_mpileup", SamToolsMpileupLatest( bam=w.bam, positions=w.vcf, reference=w.reference, countOrphans=True, noBAQ=True, minBQ=0, maxDepth=10000, ), ) w.output("out", source=w.samtools_mpileup.out) return w(**connections)
def test_add_qualified_edge(self): w = WorkflowBuilder("test_add_edge") inp = w.input("inp", str).input_node stp = w.step("stp", SingleTestTool(input1=w.inp)) e = stp.sources["input1"].source_map[0] self.assertEqual(e.source.input_node.id(), inp.id()) self.assertEqual(e.finish.id(), stp.id()) self.assertEqual(e.ftag, first_value(stp.inputs()).id())
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 )
def WorkflowBuilder(self): w = WorkflowBuilder("test_add_node") inp = w.input("inp", str) stp = w.step("stp", SingleTestTool(), ignore_missing=True) self.assertEqual(len(w.input_nodes), 1) self.assertEqual(len(w.step_nodes), 1) self.assertEqual(len(w.output_nodes), 0) self.assertEqual(w.nodes["inp"].id(), inp.id()) self.assertEqual(w.nodes["stp"].id(), stp.id())