Search in sources :

Example 6 with WorkflowInputsGalaxy

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy 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 WorkflowInputsGalaxy

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyTest method testPrepareAnalysisFilesSingleSuccess.

/**
 * Tests out successfully to preparing an analysis with single files.
 *
 * @throws ExecutionManagerException
 * @throws IridaWorkflowException
 */
@SuppressWarnings("unchecked")
@Test
public void testPrepareAnalysisFilesSingleSuccess() throws ExecutionManagerException, IridaWorkflowException {
    Set<SingleEndSequenceFile> singleFiles = Sets.newHashSet(sampleSingleSequenceFileMap.values());
    submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(Sets.newHashSet(singleFiles)).referenceFile(referenceFile).build();
    submission.setRemoteAnalysisId(HISTORY_ID);
    submission.setRemoteWorkflowId(WORKFLOW_ID);
    when(sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SingleEndSequenceFile.class)).thenReturn(singleFiles);
    when(iridaWorkflowsService.getIridaWorkflow(workflowId)).thenReturn(iridaWorkflowSingle);
    when(galaxyHistoriesService.findById(HISTORY_ID)).thenReturn(workflowHistory);
    when(galaxyLibrariesService.buildEmptyLibrary(any(GalaxyProjectName.class))).thenReturn(workflowLibrary);
    when(sequencingObjectService.getUniqueSamplesForSequencingObjects(singleFiles)).thenReturn(sampleSingleSequenceFileMap);
    when(galaxyHistoriesService.fileToHistory(refFile, InputFileType.FASTA, workflowHistory)).thenReturn(refDataset);
    when(galaxyWorkflowService.getWorkflowDetails(WORKFLOW_ID)).thenReturn(workflowDetails);
    when(analysisParameterServiceGalaxy.prepareAnalysisParameters(any(Map.class), any(IridaWorkflow.class))).thenReturn(new WorkflowInputsGalaxy(new WorkflowInputs()));
    when(galaxyWorkflowService.getWorkflowInputId(workflowDetails, SEQUENCE_FILE_SINGLE_LABEL)).thenReturn(SEQUENCE_FILE_SINGLE_ID);
    when(galaxyWorkflowService.getWorkflowInputId(workflowDetails, REFERENCE_FILE_LABEL)).thenReturn(REFERENCE_FILE_ID);
    when(analysisCollectionServiceGalaxy.uploadSequenceFilesSingleEnd(any(Map.class), eq(workflowHistory), eq(workflowLibrary))).thenReturn(collectionResponseSingle);
    PreparedWorkflowGalaxy preparedWorkflow = workflowPreparation.prepareAnalysisFiles(submission);
    assertEquals("preparedWorflow history id not equal to " + HISTORY_ID, HISTORY_ID, preparedWorkflow.getRemoteAnalysisId());
    assertEquals("preparedWorkflow library is invalid", LIBRARY_ID, preparedWorkflow.getRemoteDataId());
    assertNotNull("workflowInputs in preparedWorkflow is null", preparedWorkflow.getWorkflowInputs());
    Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
    assertEquals("workflow inputs has invalid size", 2, workflowInputsMap.size());
    assertTrue("workflow inputs should contain reference file entry", workflowInputsMap.containsKey(REFERENCE_FILE_ID));
    assertTrue("workflow inputs should contain sequence file single entry", workflowInputsMap.containsKey(SEQUENCE_FILE_SINGLE_ID));
    verify(analysisCollectionServiceGalaxy).uploadSequenceFilesSingleEnd(any(Map.class), any(History.class), any(Library.class));
    verify(analysisCollectionServiceGalaxy, never()).uploadSequenceFilesPaired(any(Map.class), any(History.class), any(Library.class));
}
Also used : IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) GalaxyProjectName(ca.corefacility.bioinformatics.irida.model.upload.galaxy.GalaxyProjectName) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) WorkflowInput(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 8 with WorkflowInputsGalaxy

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy 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 9 with WorkflowInputsGalaxy

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy in project irida by phac-nml.

the class AnalysisExecutionServiceGalaxyAsync method executeAnalysis.

/**
 * Executes the passed prepared {@link AnalysisSubmission} in an execution
 * manager.
 *
 * @param analysisSubmission
 *            The {@link AnalysisSubmission} to execute.
 * @return A {@link Future} with an {@link AnalysisSubmission} for the
 *         analysis submitted.
 * @throws ExecutionManagerException
 *             If there was an exception submitting the analysis to the
 *             execution manager.
 * @throws IridaWorkflowException If there was an issue with the IRIDA workflow.
 */
@RunAsUser("#analysisSubmission.getSubmitter()")
public Future<AnalysisSubmission> executeAnalysis(AnalysisSubmission analysisSubmission) throws ExecutionManagerException, IridaWorkflowException {
    checkNotNull(analysisSubmission, "analysisSubmission is null");
    checkNotNull(analysisSubmission.getRemoteAnalysisId(), "remote analyis id is null");
    checkNotNull(analysisSubmission.getWorkflowId(), "workflowId is null");
    logger.debug("Running submission for " + analysisSubmission);
    logger.trace("Preparing files for " + analysisSubmission);
    PreparedWorkflowGalaxy preparedWorkflow = workspaceService.prepareAnalysisFiles(analysisSubmission);
    WorkflowInputsGalaxy input = preparedWorkflow.getWorkflowInputs();
    String libraryId = preparedWorkflow.getRemoteDataId();
    logger.trace("Executing " + analysisSubmission);
    galaxyWorkflowService.runWorkflow(input);
    analysisSubmission.setAnalysisState(AnalysisState.RUNNING);
    analysisSubmission.setRemoteInputDataId(libraryId);
    analysisSubmission = analysisSubmissionService.update(analysisSubmission);
    return new AsyncResult<>(analysisSubmission);
}
Also used : PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) RunAsUser(ca.corefacility.bioinformatics.irida.service.analysis.annotations.RunAsUser)

Example 10 with WorkflowInputsGalaxy

use of ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy 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

WorkflowInputsGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy)19 Test (org.junit.Test)16 WorkflowInputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs)13 PreparedWorkflowGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy)10 ImmutableMap (com.google.common.collect.ImmutableMap)10 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)9 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 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)5 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)5 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)5 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)5 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)5 WorkflowInput (com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput)5 Path (java.nio.file.Path)5 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)4 GalaxyProjectName (ca.corefacility.bioinformatics.irida.model.upload.galaxy.GalaxyProjectName)4