We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Then you could add a ReadJsonOperator with the following diff:
ReadJsonOperator
Index: janis_core/operators/selectors.py IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- janis_core/operators/selectors.py (revision 96718bc123b9dc556ad1a56d476bf3da2804dc77) +++ janis_core/operators/selectors.py (date 1611704151813) @@ -221,6 +221,13 @@ return ReadContents(self) + def read_json(self): + # could always check self.returntype() and decide to use read_json or ParseJson + + from janis_core.operators.standard import ReadJsonOperator + + return ReadJsonOperator(self) + def __getitem__(self, item): from janis_core.operators.operator import IndexOperator Index: janis_core/operators/standard.py IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- janis_core/operators/standard.py (revision 96718bc123b9dc556ad1a56d476bf3da2804dc77) +++ janis_core/operators/standard.py (date 1611704003239) @@ -42,6 +42,37 @@ return f.read() +class ReadJsonOperator(Operator): + @staticmethod + def friendly_signature(): + return f"File -> Dict[str, any]" + + def evaluate(self, inputs): + file = self.evaluate_arg(self.args[0], inputs) + from json import load + + with open(file) as f: + return load(f) + + def to_wdl(self, unwrap_operator, *args): + f = unwrap_operator(self.args[0]) + return f"read_json({f})" + + def to_cwl(self, unwrap_operator, *args): + fp = unwrap_operator(self.args[0]) + return f"JSON.parse({fp}.contents)" + + def requires_contents(self): + return True + + def argtypes(self) -> List[DataType]: + return [File()] + + def returntype(self): + # dictionary? + return String + + class JoinOperator(Operator): def __init__(self, iterable, separator): super().__init__(iterable, separator)
And bobs your uncle, you can do something like this:
t = CommandToolBuilder( tool="test_readcontents", base_command=["echo", "1"], inputs=[ToolInput("inp", File)], outputs=[ ToolOutput( "out_json", String, selector=InputSelector("inp").read_json()["out"] ), ], container=None, version="-1", )
task test_readcontents { # ... output { String out_json = read_json(inp)["out"] } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Then you could add a
ReadJsonOperator
with the following diff:And bobs your uncle, you can do something like this:
The text was updated successfully, but these errors were encountered: