def convert_transformations_to_workflow(transformations) -> Workflow: transformations: List[JanisTransformation] = transformations initial_tr: JanisTransformation = transformations[0] final_tr: JanisTransformation = transformations[-1] w = WorkflowBuilder( f"convert_{initial_tr.type1.name().lower()}_to_{final_tr.type2.name().lower()}" ) prev_input = w.input(f"inp_{initial_tr.type1.name().lower()}", initial_tr.type1) for transform in transformations: stpid = f"transform_{transform.type1.name().lower()}_to_{transform.type2.name().lower()}" stp_inputs = { **(transform.tool.connections or {}), transform.relevant_tool_input: prev_input, } prev_input = w.step( stpid, transform.tool(**stp_inputs))[transform.relevant_tool_output] w.output("out", final_tr.type2, source=prev_input, output_name=False) return w
def wrapped_in_wf(self): from copy import copy from janis_core.workflow.workflow import WorkflowBuilder wf = WorkflowBuilder(self.id() + "Wf") inpmap = {} for i in self.inputs(): if isinstance(i.input_type, Filename): intp = String(optional=True) else: intp = copy(i.input_type) if i.default: intp.optional = True inpmap[i.id()] = wf.input(i.id(), intp) stp = wf.step(self.tool().lower(), self(**inpmap)) for o in self.outputs(): wf.output(o.id(), source=stp[o.id()]) return wf
def test_workflow(self): w = WorkflowBuilder("test_container_workflow") w.input("inp", String) w.input("aInp", Array(String)) w.step("stp1", TestTool(testtool=w.inp)) w.step("stp1_v2", TestToolV2(testtool=w.inp)) w.step("stp2", ArrayTestTool(inps=w.aInp)) cons = w.containers() self.assertSetEqual( { "ArrayStepTool", "TestTranslationtool", "TestTranslationtool_v0_0_2" }, set(cons.keys()), ) self.assertIsNone(cons["ArrayStepTool"]) self.assertEqual("ubuntu:latest", cons["TestTranslationtool"]) self.assertEqual("ubuntu:latest", cons["TestTranslationtool_v0_0_2"])
def test_switch(self): from janis_unix import Echo, Cat w = WorkflowBuilder("switchTest") w.input("inp", int, value=2) w.input("inp1", str, value="Hello") w.input("inp2", str, value="Hi there") w.conditional( "echoswitch", [ (w.inp > 1, Echo(inp=w.inp1)), (w.inp.equals(1), Echo(inp="tasy case")), Echo(inp=w.inp2), ], ) w.output("out", source=w.echoswitch) _, wdl_tools = WdlTranslator.translate_workflow(w) expected = """\ version development import "echo_v1_0_0.wdl" as E workflow echoswitch { input { Int cond_inp String switch_case_1_inp String? switch_case_2_inp = "tasy case" String switch_case_3_inp } if ((cond_inp > 1)) { call E.echo as switch_case_1 { input: inp=switch_case_1_inp } } if (((cond_inp == 1) && !((cond_inp > 1)))) { call E.echo as switch_case_2 { input: inp=select_first([switch_case_2_inp, "tasy case"]) } } if (!(((cond_inp > 1) || (cond_inp == 1)))) { call E.echo as switch_case_3 { input: inp=switch_case_3_inp } } output { File out = select_first([switch_case_1.out, switch_case_2.out, switch_case_3.out]) } }""" echoswitch = wdl_tools["echoswitch"].get_string() self.assertEqual(expected, echoswitch)
def test_1(self): from janis_unix import Echo, Cat w = WorkflowBuilder("conditionalTest") w.input("inp", int, value=1) w.input("name", str, value="Michael") w.step("echo", Echo(inp=w.name), when=w.inp > 1) w.step("cat", Cat(file=w.echo.out), when=w.echo.out.equals("Hello, Michael")) w.output("out", source=w.echo.out) w.translate( "wdl" # to_disk=True, export_path="~/Desktop/tmp/{name}", validate=True )