Пример #1
0
 def outputs(self) -> List[j.ToolOutput]:
     return [
         j.ToolOutput(
             "extended",
             Csv(),
             glob=j.InputSelector("reportPrefix") + ".extended.csv",
         ),
         j.ToolOutput("summary",
                      Csv(),
                      glob=j.InputSelector("reportPrefix") +
                      ".summary.csv"),
         j.ToolOutput(
             "metrics",
             j.File(),
             glob=j.InputSelector("reportPrefix") + ".metrics.json.gz",
         ),
         j.ToolOutput("vcf",
                      VcfTabix(),
                      glob=j.InputSelector("reportPrefix") + ".vcf.gz"),
         j.ToolOutput(
             "runinfo",
             JsonFile(),
             glob=j.InputSelector("reportPrefix") + ".runinfo.json",
         ),
         j.ToolOutput(
             "rocOut",
             j.File(),
             glob=j.InputSelector("reportPrefix") + ".roc.all.csv.gz",
         ),
         j.ToolOutput(
             "indelLocations",
             j.File(),
             glob=j.InputSelector("reportPrefix") +
             ".roc.Locations.INDEL.csv.gz",
         ),
         j.ToolOutput(
             "indelPassLocations",
             j.File(),
             glob=j.InputSelector("reportPrefix") +
             ".roc.Locations.INDEL.PASS.csv.gz",
         ),
         j.ToolOutput(
             "snpLocations",
             j.File(),
             glob=j.InputSelector("reportPrefix") +
             ".roc.Locations.SNP.csv.gz",
         ),
         j.ToolOutput(
             "snpPassLocations",
             j.File(),
             glob=j.InputSelector("reportPrefix") +
             ".roc.Locations.SNP.PASS.csv.gz",
         ),
     ]
Пример #2
0
    def convert_javascript_token(self, token: str):
        input_selector_match = self.input_selector_matcher.match(token)
        if input_selector_match:
            return j.InputSelector(input_selector_match.groups()[0])

        if token.endswith(".size"):
            return j.FileSizeOperator(self.convert_javascript_token(
                token[:-5]))
        if token.endswith(".basename"):
            return j.BasenameOperator(self.convert_javascript_token(
                token[:-9]))
        if token.endswith(".path"):
            # Ignore it because Janis will automatically put this back in where relevant
            return self.convert_javascript_token(token[:-5])
        if token.endswith(".contents"):
            return j.ReadContents(self.convert_javascript_token(token[:-9]))

        is_string = self.string_matcher.match(token)
        if is_string:
            return token[1:-1]

        try:
            return self.parse_number_from_string(token)
        except ValueError:
            pass

        j.Logger.warn(
            f"Couldn't translate javascript token, will use the placeholder '<expr>{token}</expr>'"
        )
        return f"<expr>{token}</expr>"
Пример #3
0
    def translate_expr(
        self,
        expr: WDL.Expr.Base,
        input_selector_getter: Callable[[str], any] = None
    ) -> Optional[Union[j.Selector, List[j.Selector], int, str, float, bool]]:
        if expr is None:
            return None

        tp = lambda exp: self.translate_expr(
            exp, input_selector_getter=input_selector_getter)

        if isinstance(expr, WDL.Expr.Array):
            # a literal array
            return [self.translate_expr(e) for e in expr.items]
        if isinstance(expr, WDL.Expr.String):
            return self.translate_wdl_string(expr)
        elif isinstance(expr,
                        (WDL.Expr.Int, WDL.Expr.Boolean, WDL.Expr.Float)):
            return expr.literal.value
        if isinstance(expr, WDL.Expr.Placeholder):
            return self.translate_expr(expr.expr)
        if isinstance(expr, WDL.Expr.IfThenElse):
            return j.If(tp(expr.condition), tp(expr.consequent),
                        tp(expr.alternative))
        elif isinstance(expr, WDL.Expr.Get):
            n = str(expr.expr)
            if input_selector_getter:
                return input_selector_getter(n)
            return j.InputSelector(n)
        elif isinstance(expr, WDL.Expr.Apply):
            return self.translate_apply(
                expr, input_selector_getter=input_selector_getter)

        raise Exception(
            f"Unsupported WDL expression type: {expr} ({type(expr)})")
Пример #4
0
    def test_1(self):
        import janis_core as j

        class FileWithSec(j.File):
            def __init__(self, optional=False):
                super().__init__(optional=optional, extension=".txt")

            def secondary_files(self):
                return [".sec"]

        Tool = j.CommandToolBuilder(
            tool="ls",
            base_command=["ls"],
            inputs=[
                j.ToolInput("inp",
                            FileWithSec,
                            secondaries_present_as={".sec": "^.sec"})
            ],
            outputs=[
                j.ToolOutput("std", j.Stdout),
                j.ToolOutput(
                    "out",
                    FileWithSec,
                    secondaries_present_as={".sec": "^.sec"},
                    glob=j.InputSelector("inp"),
                ),
            ],
            container="ubuntu:latest",
            version="v0.1.0",
        )

        Tool.translate("wdl")
Пример #5
0
 def get_outputs(self,
                 names: List[NamedArgument]) -> List[janis.ToolOutput]:
     ret = []
     for arg in names:
         typ = arg.arg.get_type()
         if isinstance(typ, cli_types.CliFileSystemType) and typ.output:
             ret.append(
                 janis.ToolOutput(
                     tag="out_" + arg.name,
                     output_type=self.arg_to_janis_type(arg.arg),
                     doc=arg.arg.description,
                     selector=janis.InputSelector("in_" + arg.name),
                 ))
     return ret
Пример #6
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
How to create an empty directory, using the value of an input
"""

import janis_core as j

CLT = j.CommandToolBuilder(
    tool="create_initial_stuff",
    base_command=["ls", "*"],
    version="dev",
    container="ubuntu:latest",
    inputs=[
        j.ToolInput("name_of_output_folder",
                    j.String(optional=True),
                    default="some-string")
    ],
    outputs=[j.ToolOutput("out_dir", j.Directory, selector="some-string")],
    directories_to_create=[j.InputSelector("name_of_output_folder")],
    files_to_create=[(
        j.StringFormatter("{dir}/file.txt",
                          dir=j.InputSelector("name_of_output_folder")),
        "contents of file",
    )],
)

if __name__ == "__main__":
    CLT().translate("cwl")
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
NB: Although WDL supports optional files, some backends of Cromwell do not.
"""

import janis_core as j

ToolWithOptionalOutput = j.CommandToolBuilder(
    tool="optional_output_tool",
    version="v0.1.0",
    container="ubuntu:latest",
    base_command=[],
    arguments=[j.ToolArgument("echo 1 > ", shell_quote=False)],
    inputs=[
        j.ToolInput("outputFilename",
                    j.String(optional=True),
                    default="out.csv",
                    position=1)
    ],
    outputs=[
        j.ToolOutput("out",
                     j.File(optional=True),
                     selector=j.InputSelector("outputFilename"))
    ],
)

if __name__ == "__main__":
    ToolWithOptionalOutput().translate("wdl")
Пример #8
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
We'll use Janis to _try_ and collect a SINGLE file with the extension '.txt',
but one won't exist. CWL will automatically coerce the empty File[0] to File? (null).

However, in WDL, we have do this slightly differently:
    File? out = if length(glob("*.txt")) > 0 then glob("*.txt")[0] else None

NB: Although WDL supports optional files, some backends of Cromwell do not.
"""

import janis_core as j

ToolWithDynamicGlob = j.CommandToolBuilder(
    tool="tool_with_dynamic_glob",
    version="v0.1.0",
    container="ubuntu:latest",
    base_command=None,
    # write '1' to a file called 'out.csv'
    arguments=[j.ToolArgument("echo 1 > out.csv", shell_quote=False)],
    inputs=[j.ToolInput("extension", str)],
    outputs=[
        j.ToolOutput("out_csv_files", j.Array(j.File), selector=j.WildcardSelector("*" + j.InputSelector("extension"))),
    ],
)

if __name__ == "__main__":
    ToolWithDynamicGlob().translate("cwl")