Skip to content

Commit

Permalink
support multi-source-inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Sep 30, 2022
1 parent 75f41a1 commit 9b1dc0a
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## v1.4.5 [unreleased]

Switch to snakeyaml-engine (YAML 1.2) from snakeyaml (YAML 1.1)
Support workflows using `MultipleInputFeatureRequirement`

## v1.4.4 [2022-06-08]

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/commonwl/view/cwl/CWLService.java
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,14 @@ private Map<String, CWLElement> getStepInputsOutputs(Object inOut) {
if (Map.class.isAssignableFrom(inOutNode.getClass())) {
Map<String, Object> properties = (Map<String, Object>) inOutNode;
if (properties.containsKey(SOURCE)) {
inputOutput.addSourceID(stepIDFromSource((String) properties.get(SOURCE)));
Object source = properties.get(SOURCE);
if (List.class.isAssignableFrom(source.getClass())) {
for (String sourceEntry : (List<String>) source) {
inputOutput.addSourceID(stepIDFromSource(sourceEntry));
}
} else {
inputOutput.addSourceID(stepIDFromSource((String) source));
}
} else {
inputOutput.setDefaultVal(extractDefault(properties));
}
Expand Down
48 changes: 29 additions & 19 deletions src/test/java/org/commonwl/view/cwl/CWLServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@

package org.commonwl.view.cwl;

import static org.apache.commons.io.FileUtils.readFileToString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;

import org.apache.jena.query.Dataset;
import org.apache.jena.query.DatasetFactory;
import org.apache.jena.query.Query;
Expand All @@ -39,25 +56,6 @@
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;

import static org.apache.commons.io.FileUtils.readFileToString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

public class CWLServiceTest {

/**
Expand Down Expand Up @@ -156,6 +154,18 @@ public void parseWorkflowInlineOptionalTypesNative() throws Exception {
assertEquals(wkflow.getInputs().get("rfam_models").getType(), "{type=array, items=[string, File]}");

}

/**
* Test native loading parsing of MultipleInputFeatureRequirement using workflows
*/
@Test
public void parseWorkflowMultiInboundLins() throws Exception {
CWLService cwlService = new CWLService(rdfService, new CWLTool(), 5242880);
Workflow wkflow = cwlService.parseWorkflowNative(Paths.get("src/test/resources/cwl/complex-workflow/complex-workflow-1.cwl"),
null);
assertEquals(wkflow.getSteps().get("re_tar_step").getSources().get("file_list").getSourceIDs().get(0), "touch_step");
assertEquals(wkflow.getSteps().get("re_tar_step").getSources().get("file_list").getSourceIDs().get(1), "files");
}

/**
* Test native loading parsing of nested array types
Expand Down
123 changes: 123 additions & 0 deletions src/test/resources/cwl/complex-workflow/complex-workflow-1.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Source: https://github.com/heliumdatacommons/TOPMed_RNAseq_CWL/tree/578066ec5d6847892528f973b22531d4c8487280/workflows/complex-workflow

# BSD 3-Clause License
#
# Copyright (c) 2018, RTI International
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cwlVersion: v1.0
class: Workflow
id: complex-workflow
inputs:
archive:
type: string
files:
type:
type: array
items: File
new_archive:
type: string
touch_files:
type:
type: array
items: string
echo_message:
type: string
echo_output_location:
type: string

outputs:
archive_out:
type: File
outputSource: tar_step/archive_out
touch_out:
type:
type: array
items: File
outputSource: touch_step/file_out
echo_out:
type: File
outputSource: echo_step/echo_output
re_tar_out:
type: File
outputSource: re_tar_step/archive_out

steps:
tar_step:
run: tar.cwl
in:
archive_file:
source: "#archive"
file_list:
source: "#files"
out: [archive_out]

touch_step:
run: touch.cwl
scatter: filename
scatterMethod: dotproduct
in:
waitfor:
source: "#tar_step/archive_out"
filename:
source: "#touch_files"
out: [file_out]

echo_step:
run: echo.cwl
in:
message: "#echo_message"
output_location: "#echo_output_location"
out: [echo_output]

re_tar_step:
run: tar.cwl
in:
archive_file:
source: "#archive"
file_list:
source: ["#touch_step/file_out", "#files"]
linkMerge: merge_flattened
out: [archive_out]

# rm_step:
# run: rm.cwl
# scatter: filename
# scatterMethod: dotproduct
# in:
# waitfor:
# source: "#re_tar_step/archive_out"
# filename:
# source: ["#files", "#touch_step/file_out", "#echo_step/echo_output"]
# linkMerge: merge_flattened
# out: [standard_out]

requirements:
- class: StepInputExpressionRequirement
- class: ScatterFeatureRequirement
- class: MultipleInputFeatureRequirement

0 comments on commit 9b1dc0a

Please sign in to comment.