diff --git a/src/constant.py b/src/constant.py index 8b7ab2bc545e12f8aab1805d67b6c9515d46f6bf..ba73cea71e1ff1280046cb4d8bc33b330c84b4ad 100644 --- a/src/constant.py +++ b/src/constant.py @@ -123,7 +123,7 @@ END_PIPE_OPERATOR = r"\s*(\s*\|\s*\w+)+" # PROCESS #-------------------------- -FILE = r'file +(\w+) *\n' +FILE = r'file +(\w+) *\n|file +\( *(\w+) *\) *\n' FROM = r' from ([^\n]+)\n' INPUT = r"\n\s*input *:" INTO = r'into +([\w, ]+)' diff --git a/src/process.py b/src/process.py index 33122ac347103d381fa80bfce91e0c038c8190f9..b018c639f42ba7b4b6cbd1209d4daf59d3a23d88 100644 --- a/src/process.py +++ b/src/process.py @@ -354,7 +354,12 @@ class Process(Nextflow_Building_Blocks): #Case there is a single channel as an input -> doesn't use from to import channel -> uses file (see https://github.com/nextflow-io/nextflow/blob/45ceadbdba90b0b7a42a542a9fc241fb04e3719d/docs/process.rst) pattern = constant.FILE for match in re.finditer(pattern, line+"\n"): - extracted = match.group(1).strip() + #In the first case it's "file ch" in the second "file (ch)" + try: + extracted = match.group(1).strip() + except: + extracted = match.group(2).strip() + add_channel(extracted) self.raw_input_names.append(extracted) @@ -581,6 +586,8 @@ class Process(Nextflow_Building_Blocks): for line in code.split("\n"): line = line.replace(" into ", ", emit: ") line = line.replace(" mode flatten", "") + #Remove optionnal true #TODO check if this breaks soemthing + line = line.replace("optional true", "") line = process_2_DSL2(line) lines.append(line) code = "\n".join(lines) @@ -590,8 +597,7 @@ class Process(Nextflow_Building_Blocks): def replacer(match): return match.group(1) for o in line[1:]: - code = re.sub(fr"\,\s*{re.escape(o.get_code())}(\s|\,|\))", replacer, code) - + code = re.sub(fr"\,\s*{re.escape(o.get_code())}(\s|\,|\))", replacer, code+"\n") return code #This method is to detect which are the channels which need to be flattened @@ -609,13 +615,16 @@ class Process(Nextflow_Building_Blocks): if(bool(re.fullmatch(r"\w+\.val", raw_input_names[i]))): raw_input_names[i] = raw_input_names[i].split('.')[0] return raw_input_names - + + def get_parameters_call(self): + return ', '.join(self.clean_raw_input_names(self.raw_input_names)) + def convert_to_DSL2(self): if(self.get_DSL()=="DSL2"): print("Workflow is already written in DSL2") else: code = self.get_code() - call = [f"{self.get_name()}({', '.join(self.clean_raw_input_names(self.raw_input_names))})"] + call = [f"{self.get_name()}({self.get_parameters_call()})"] code = code.replace(self.input_code, self.convert_input_code_to_DSL2()) code = code.replace(self.output_code, self.convert_output_code_to_DSL2()) channels_to_flatten = self.get_channels_to_flatten()