Search in sources :

Example 6 with WorkflowInputs

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

the class AnalysisParameterServiceGalaxyTest method testPrepareParametersDefaultSuccess.

/**
 * Tests preparing workflow parameters and using the default value defined.
 *
 * @throws IridaWorkflowParameterException
 */
@Test
public void testPrepareParametersDefaultSuccess() throws IridaWorkflowParameterException {
    Map<String, String> parameters = Maps.newHashMap();
    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", "0", tool1Parameters.get("parameter1"));
}
Also used : 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 7 with WorkflowInputs

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

the class AnalysisParameterServiceGalaxy method prepareAnalysisParameters.

/**
 * {@inheritDoc}
 */
@Override
public WorkflowInputsGalaxy prepareAnalysisParameters(Map<String, String> parameters, IridaWorkflow iridaWorkflow) throws IridaWorkflowParameterException {
    checkNotNull(parameters, "parameters is null");
    checkNotNull(iridaWorkflow, "iridaWorkflow is null");
    WorkflowInputs inputs = new WorkflowInputs();
    Set<String> parameterNamesUsed = Sets.newHashSet();
    if (!iridaWorkflow.getWorkflowDescription().acceptsParameters()) {
        if (parameters.isEmpty()) {
            logger.debug("workflow " + iridaWorkflow + " does not accept parameters and no parameters passed.");
        } else {
            throw new IridaWorkflowNoParameterException("The workflow " + iridaWorkflow + " does not accept parameters but parameters " + parameters + " were passed.");
        }
    } else {
        List<IridaWorkflowParameter> iridaParameters = iridaWorkflow.getWorkflowDescription().getParameters();
        ParameterBuilderGalaxy parameterBuilder = new ParameterBuilderGalaxy();
        for (IridaWorkflowParameter iridaParameter : iridaParameters) {
            String parameterName = iridaParameter.getName();
            String value = parameters.get(parameterName);
            parameterNamesUsed.add(parameterName);
            if (ignoreDefaultValue(parameters, parameterName)) {
                logger.debug("Parameter with name=" + parameterName + " will ignore the default value=" + iridaParameter.getDefaultValue());
            } else {
                if (useDefaultValue(parameters, parameterName)) {
                    value = iridaParameter.getDefaultValue();
                    logger.debug("Parameter with name=" + parameterName + ", for workflow=" + iridaWorkflow + ", has no value set, using defaultValue=" + value);
                }
                for (IridaToolParameter iridaToolParameter : iridaParameter.getToolParameters()) {
                    String toolId = iridaToolParameter.getToolId();
                    String galaxyParameterName = iridaToolParameter.getParameterName();
                    parameterBuilder.addParameter(toolId, galaxyParameterName, value);
                    logger.debug("Setting parameter iridaName=" + parameterName + ", galaxyToolId=" + toolId + ", galaxyParameterName=" + galaxyParameterName + ", value=" + value);
                }
            }
        }
        for (ParameterBuilderGalaxy.ParameterId parameterId : parameterBuilder.getParameterIds()) {
            inputs.setToolParameter(parameterId.getToolId(), parameterId.getStartName(), parameterBuilder.getMappingForParameterId(parameterId));
        }
    }
    Set<String> parameterNamesUnused = Sets.difference(parameters.keySet(), parameterNamesUsed);
    if (!parameterNamesUnused.isEmpty()) {
        throw new IridaWorkflowParameterException("The set of parameters " + parameterNamesUnused + " are not defined in " + iridaWorkflow);
    } else {
        return new WorkflowInputsGalaxy(inputs);
    }
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) IridaWorkflowNoParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNoParameterException) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) IridaWorkflowParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)

Example 8 with WorkflowInputs

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

the class GalaxyWorkflowsIT method runSingleFileTabularWorkflow.

/**
 * Runs a test workflow with the given parameters and input file.
 *
 * @param workflowId
 *            The id of the workflow to run.
 * @param workflowInputLabel
 *            The lable of the input for the workflow.
 * @param history
 *            The history to run the workflow in.
 * @param inputFile
 *            The file to run the workflow on.
 * @param toolName
 *            The toolName of a parameter to override.
 * @param toolParameter
 *            The overridden tool parameter.
 * @return A {@link WorkflowOutputs} for this workflow.
 * @throws ExecutionManagerException
 */
private WorkflowOutputs runSingleFileTabularWorkflow(String workflowId, String workflowInputLabel, History history, Path inputFile, String toolName, ToolParameter toolParameter) throws ExecutionManagerException {
    checkArgument(Files.exists(inputFile), "inputFile " + inputFile + " does not exist");
    WorkflowDetails workflowDetails = workflowsClient.showWorkflow(workflowId);
    // upload dataset to history
    Dataset inputDataset = fileToHistory(inputFile, "tabular", history.getId());
    assertNotNull(inputDataset);
    String workflowInputId = galaxyWorkflowService.getWorkflowInputId(workflowDetails, workflowInputLabel);
    WorkflowInputs inputs = new WorkflowInputs();
    inputs.setDestination(new WorkflowInputs.ExistingHistory(history.getId()));
    inputs.setWorkflowId(workflowDetails.getId());
    inputs.setInput(workflowInputId, new WorkflowInputs.WorkflowInput(inputDataset.getId(), WorkflowInputs.InputSourceType.HDA));
    inputs.setToolParameter(toolName, toolParameter);
    // execute workflow
    WorkflowOutputs output = workflowsClient.runWorkflow(inputs);
    logger.debug("Running workflow in history " + output.getHistoryId());
    return output;
}
Also used : WorkflowOutputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) WorkflowDetails(com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails)

Example 9 with WorkflowInputs

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

the class GalaxyWorkflowsIT method runSingleFileWorkflow.

/**
 * Starts the execution of a workflow with a single fastq file and the given workflow id.
 * @param inputFile  An input file to start the workflow.
 * @param inputFileType The file type of the input file.
 * @param workflowId  The id of the workflow to start.
 * @param workflowInputLabel The label of a workflow input in Galaxy.
 * @param toolParameters  A map of tool parameters to set.
 * @throws ExecutionManagerException If there was an error executing the workflow.
 */
private WorkflowOutputs runSingleFileWorkflow(Path inputFile, InputFileType inputFileType, String workflowId, String workflowInputLabel, Map<String, ToolParameter> toolParameters) throws ExecutionManagerException {
    checkNotNull(inputFile, "file is null");
    checkNotNull(inputFileType, "inputFileType is null");
    checkNotNull(workflowInputLabel, "workflowInputLabel is null");
    checkArgument(Files.exists(inputFile), "inputFile " + inputFile + " does not exist");
    History workflowHistory = galaxyHistory.newHistoryForWorkflow();
    WorkflowDetails workflowDetails = workflowsClient.showWorkflow(workflowId);
    // upload dataset to history
    Dataset inputDataset = galaxyHistory.fileToHistory(inputFile, inputFileType, workflowHistory);
    assertNotNull(inputDataset);
    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(inputDataset.getId(), WorkflowInputs.InputSourceType.HDA));
    if (toolParameters != null) {
        for (String toolId : toolParameters.keySet()) {
            ToolParameter toolParameter = toolParameters.get(toolId);
            inputs.setToolParameter(toolId, toolParameter);
        }
    }
    // execute workflow
    WorkflowOutputs output = workflowsClient.runWorkflow(inputs);
    logger.debug("Running workflow in history " + output.getHistoryId());
    return output;
}
Also used : WorkflowOutputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) WorkflowDetails(com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails) ToolParameter(com.github.jmchilton.blend4j.galaxy.beans.ToolParameter) History(com.github.jmchilton.blend4j.galaxy.beans.History)

Example 10 with WorkflowInputs

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

the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesParametersSuccessWithNoParameters.

/**
 * Tests out successfully preparing paired workflow input files for
 * execution, no parameters set.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IOException
 * @throws IridaWorkflowException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesParametersSuccessWithNoParameters() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
    History history = new History();
    history.setName("testPrepareAnalysisFilesParametersSuccessWithNoParameters");
    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);
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupPairSubmissionInDatabase(1L, pairSequenceFiles1A, pairSequenceFiles2A, referenceFilePath, validWorkflowIdPairedWithParameters, false);
    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 to default", "10", coverageMinValue);
    assertEquals("coverageMidValue should have been changed to default", ImmutableMap.of("coverageMid", "10"), toolParameters.get("conditional"));
    String coverageMaxValue = (String) toolParameters.get("coverageMin");
    assertEquals("coverageMaxValue should have been changed to default", "10", 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)

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