Skip to content

Commit

Permalink
implement read_lines() with a functional test (#181)
Browse files Browse the repository at this point in the history
fix read_tsv() and add functional test
  • Loading branch information
mr-c authored Feb 16, 2022
1 parent 48a1569 commit 63d60b5
Show file tree
Hide file tree
Showing 10 changed files with 845 additions and 24 deletions.
21 changes: 13 additions & 8 deletions wdl2cwl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,20 @@ def get_literal_value(expr: WDL.Expr.Base) -> Optional[Any]:
if (contents == 'true') { return true;}
if (contents == 'false') { return false;}
throw "'read_boolean' received neither 'true' nor 'false': " + self[0].contents;
}""",
"read_lines": r"""${
var contents = self[0].contents.replace(/\r\n$/, "").replace(/\n$/, "").replace(/\r$/, "");
// ^ remove any trailing newline to prevent a null being returned
return contents.split(/\r\n|\r|\n/);
}""",
"read_tsv": r"""${
var result;
self.contents.split(/\n|(\n\r)/).forEach(function(line) {
var line_array;
line.split('\t').forEach(function(field) {
line_array.push(field)
})
result.push(line_array);
})
var result = Array();
var contents = self[0].contents.replace(/\r\n$/, "").replace(/\n$/, "").replace(/\r$/, "");
// ^ remove any trailing newline to prevent a null being returned
contents.split(/\r\n|\r|\n/).forEach(function(line) {
result.push(line.split('\t'));
});
return result;
}""",
}

Expand Down Expand Up @@ -763,6 +767,7 @@ def get_expr_apply(self, wdl_apply_expr: WDL.Expr.Apply) -> str:
"read_int",
"read_boolean",
"read_tsv",
"read_lines",
}
function_name = wdl_apply_expr.function_name
arguments = wdl_apply_expr.arguments
Expand Down
30 changes: 14 additions & 16 deletions wdl2cwl/tests/cwl_files/FunctionalEquivalence.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,13 @@ $graph:
glob: sequence_grouping.txt
outputEval: |-
${
var result;
self.contents.split(/\n|(\n\r)/).forEach(function(line) {
var line_array;
line.split('\t').forEach(function(field) {
line_array.push(field)
})
result.push(line_array);
})
var result = Array();
var contents = self[0].contents.replace(/\r\n$/, "").replace(/\n$/, "").replace(/\r$/, "");
// ^ remove any trailing newline to prevent a null being returned
contents.split(/\r\n|\r|\n/).forEach(function(line) {
result.push(line.split('\t'));
});
return result;
}
- id: sequence_grouping_with_unmapped
type:
Expand All @@ -284,14 +283,13 @@ $graph:
glob: sequence_grouping_with_unmapped.txt
outputEval: |-
${
var result;
self.contents.split(/\n|(\n\r)/).forEach(function(line) {
var line_array;
line.split('\t').forEach(function(field) {
line_array.push(field)
})
result.push(line_array);
})
var result = Array();
var contents = self[0].contents.replace(/\r\n$/, "").replace(/\n$/, "").replace(/\r$/, "");
// ^ remove any trailing newline to prevent a null being returned
contents.split(/\r\n|\r|\n/).forEach(function(line) {
result.push(line.split('\t'));
});
return result;
}
- cwlVersion: v1.2
id: BaseRecalibrator
Expand Down
Loading

0 comments on commit 63d60b5

Please sign in to comment.