Search in sources :

Example 1 with WorkflowInputs

use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.

the class GalaxyWorkflowsIT method runSingleCollectionWorkflow.

/**
 * Starts the execution of a workflow with a list of fastq files and the given workflow id.
 * @param inputFilesForward  A list of forward read fastq files start the workflow.
 * @param inputFilesReverse  A list of reverse read fastq files start the workflow.
 * @param inputFileType The file type of the input files.
 * @param workflowId  The id of the workflow to start.
 * @param workflowInputLabel The label of a workflow input in Galaxy.
 * @throws ExecutionManagerException If there was an error executing the workflow.
 */
private WorkflowOutputs runSingleCollectionWorkflow(List<Path> inputFilesForward, List<Path> inputFilesReverse, InputFileType inputFileType, String workflowId, String workflowInputLabel) throws ExecutionManagerException {
    checkNotNull(inputFilesForward, "inputFilesForward is null");
    checkNotNull(inputFilesReverse, "inputFilesReverse is null");
    checkArgument(inputFilesForward.size() == inputFilesReverse.size(), "inputFiles have different number of elements");
    checkNotNull(inputFileType, "inputFileType is null");
    checkNotNull(workflowInputLabel, "workflowInputLabel is null");
    for (Path file : inputFilesForward) {
        checkArgument(Files.exists(file), "inputFileForward " + file + " does not exist");
    }
    for (Path file : inputFilesReverse) {
        checkArgument(Files.exists(file), "inputFilesReverse " + file + " does not exist");
    }
    History workflowHistory = galaxyHistory.newHistoryForWorkflow();
    WorkflowDetails workflowDetails = workflowsClient.showWorkflow(workflowId);
    // upload dataset to history
    List<Dataset> inputDatasetsForward = uploadFilesListToHistory(inputFilesForward, inputFileType, workflowHistory);
    List<Dataset> inputDatasetsReverse = uploadFilesListToHistory(inputFilesReverse, inputFileType, workflowHistory);
    assertEquals(inputFilesForward.size(), inputDatasetsForward.size());
    assertEquals(inputDatasetsForward.size(), inputDatasetsReverse.size());
    // construct list of datasets
    CollectionResponse collection = constructPairedFileCollection(inputDatasetsForward, inputDatasetsReverse, workflowHistory);
    logger.debug("Constructed dataset collection: id=" + collection.getId() + ", " + collection.getName());
    String workflowInputId = galaxyWorkflowService.getWorkflowInputId(workflowDetails, workflowInputLabel);
    WorkflowInputs inputs = new WorkflowInputs();
    inputs.setDestination(new WorkflowInputs.ExistingHistory(workflowHistory.getId()));
    inputs.setWorkflowId(workflowDetails.getId());
    inputs.setInput(workflowInputId, new WorkflowInputs.WorkflowInput(collection.getId(), WorkflowInputs.InputSourceType.HDCA));
    // execute workflow
    WorkflowOutputs output = workflowsClient.runWorkflow(inputs);
    logger.debug("Running workflow in history " + output.getHistoryId());
    return output;
}
Also used : Path(java.nio.file.Path) WorkflowOutputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) WorkflowDetails(com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails) History(com.github.jmchilton.blend4j.galaxy.beans.History)

Example 2 with WorkflowInputs

use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesParametersSuccess.

/**
 * Tests out successfully preparing paired workflow input files for
 * execution with parameters.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IOException
 * @throws IridaWorkflowException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesParametersSuccess() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
    History history = new History();
    history.setName("testPrepareAnalysisFilesParametersSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    History createdHistory = historiesClient.create(history);
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdPairedWithParameters);
    Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
    String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
    Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
    Map<String, String> parameters = ImmutableMap.of("coverage", "20");
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupPairSubmissionInDatabase(1L, pairSequenceFiles1A, pairSequenceFiles2A, referenceFilePath, parameters, validWorkflowIdPairedWithParameters);
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
    assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
    WorkflowInputsGalaxy workflowInputsGalaxy = preparedWorkflow.getWorkflowInputs();
    assertNotNull("the returned workflow inputs should not be null", workflowInputsGalaxy);
    assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("the created history has an invalid number of elements", 4, historyContents.size());
    WorkflowInputs workflowInputs = preparedWorkflow.getWorkflowInputs().getInputsObject();
    assertNotNull("created workflowInputs is null", workflowInputs);
    Map<String, Object> toolParameters = workflowInputs.getParameters().get("core_pipeline_outputs_paired_with_parameters");
    assertNotNull("toolParameters is null", toolParameters);
    String coverageMinValue = (String) toolParameters.get("coverageMin");
    assertEquals("coverageMinValue should have been changed", "20", coverageMinValue);
    assertEquals("coverageMidValue should have been changed", ImmutableMap.of("coverageMid", "20"), toolParameters.get("conditional"));
    String coverageMaxValue = (String) toolParameters.get("coverageMin");
    assertEquals("coverageMaxValue should have been changed", "20", coverageMaxValue);
}
Also used : Path(java.nio.file.Path) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 3 with WorkflowInputs

use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.

the class AnalysisParameterServiceGalaxyTest method testPrepareParametersOverrideMultipleLevelSuccess.

/**
 * Tests preparing workflow parameters with multiple levels and overriding
 * with custom value successfully.
 *
 * @throws IridaWorkflowParameterException
 */
@Test
public void testPrepareParametersOverrideMultipleLevelSuccess() throws IridaWorkflowParameterException {
    IridaToolParameter iridaToolParameter = new IridaToolParameter("galaxy-tool1", "level1.parameter1");
    IridaWorkflowParameter parameter1 = new IridaWorkflowParameter("parameter1", "0", Lists.newArrayList(iridaToolParameter));
    List<IridaWorkflowParameter> iridaWorkflowParameters = Lists.newArrayList(parameter1);
    when(iridaWorkflowDescription.getParameters()).thenReturn(iridaWorkflowParameters);
    Map<String, String> parameters = Maps.newHashMap();
    parameters.put("parameter1", "1");
    WorkflowInputsGalaxy workflowInputsGalaxy = analysisParameterService.prepareAnalysisParameters(parameters, iridaWorkflow);
    assertNotNull("workflowInputsGalaxy is null", workflowInputsGalaxy);
    WorkflowInputs workflowInputs = workflowInputsGalaxy.getInputsObject();
    Map<Object, Map<String, Object>> workflowParameters = workflowInputs.getParameters();
    Map<String, Object> tool1Parameters = workflowParameters.get("galaxy-tool1");
    assertNotNull("parameters for galaxy-tool1 should not be null", tool1Parameters);
    assertEquals("parameter not properly defined", ImmutableMap.of("level1", ImmutableMap.of("parameter1", "1")), tool1Parameters);
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with WorkflowInputs

use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.

the class AnalysisParameterServiceGalaxyTest method testPrepareParametersOverrideSuccessTwoTools.

/**
 * Tests preparing workflow parameters and overriding with custom value
 * successfully in two tools.
 *
 * @throws IridaWorkflowParameterException
 */
@Test
public void testPrepareParametersOverrideSuccessTwoTools() throws IridaWorkflowParameterException {
    Map<String, String> parameters = Maps.newHashMap();
    parameters.put("parameter1", "1");
    IridaToolParameter iridaToolParameter = new IridaToolParameter("galaxy-tool1", "parameter1");
    IridaToolParameter iridaToolParameter2 = new IridaToolParameter("galaxy-tool1", "parameter2");
    IridaWorkflowParameter parameter1 = new IridaWorkflowParameter("parameter1", "0", Lists.newArrayList(iridaToolParameter, iridaToolParameter2));
    List<IridaWorkflowParameter> iridaWorkflowParameters = Lists.newArrayList(parameter1);
    when(iridaWorkflowDescription.getParameters()).thenReturn(iridaWorkflowParameters);
    WorkflowInputsGalaxy workflowInputsGalaxy = analysisParameterService.prepareAnalysisParameters(parameters, iridaWorkflow);
    assertNotNull("workflowInputsGalaxy is null", workflowInputsGalaxy);
    WorkflowInputs workflowInputs = workflowInputsGalaxy.getInputsObject();
    Map<Object, Map<String, Object>> workflowParameters = workflowInputs.getParameters();
    Map<String, Object> tool1Parameters = workflowParameters.get("galaxy-tool1");
    assertNotNull("parameters for galaxy-tool1 should not be null", tool1Parameters);
    assertEquals("galaxy-tool1,parameter1 is not valid", "1", tool1Parameters.get("parameter1"));
    assertEquals("galaxy-tool1,parameter2 is not valid", "1", tool1Parameters.get("parameter2"));
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with WorkflowInputs

use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.

the class AnalysisParameterServiceGalaxyTest method testPrepareParametersSuccessNoParameters.

/**
 * Tests preparing workflow parameters when there are no parameters to prepare.
 *
 * @throws IridaWorkflowParameterException
 */
@Test
public void testPrepareParametersSuccessNoParameters() throws IridaWorkflowParameterException {
    when(iridaWorkflowDescription.acceptsParameters()).thenReturn(false);
    WorkflowInputsGalaxy workflowInputsGalaxy = analysisParameterService.prepareAnalysisParameters(ImmutableMap.of(), iridaWorkflow);
    assertNotNull("workflowInputsGalaxy is null", workflowInputsGalaxy);
    WorkflowInputs workflowInputs = workflowInputsGalaxy.getInputsObject();
    assertNotNull("workflowInputs is null", workflowInputs);
    verify(iridaWorkflowDescription).acceptsParameters();
}
Also used : WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) Test(org.junit.Test)

Aggregations

WorkflowInputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs)17 WorkflowInputsGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy)13 Test (org.junit.Test)11 ImmutableMap (com.google.common.collect.ImmutableMap)7 Map (java.util.Map)7 History (com.github.jmchilton.blend4j.galaxy.beans.History)6 IridaToolParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter)5 IridaWorkflowParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter)5 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)4 PreparedWorkflowGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy)4 Dataset (com.github.jmchilton.blend4j.galaxy.beans.Dataset)4 WorkflowDetails (com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails)4 Path (java.nio.file.Path)4 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)3 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)3 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)3 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)3 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)3 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)3 WorkflowOutputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs)3