Search in sources :

Example 6 with Dataset

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

the class GalaxyWorkflowsIT method testExecuteWorkflowChangeToolParameter.

/**
 * Tests executing a single workflow in Galaxy and changing a single tool
 * parameter.
 *
 * @throws ExecutionManagerException
 */
@Test
public void testExecuteWorkflowChangeToolParameter() throws ExecutionManagerException {
    String toolId = "Grep1";
    String workflowId = localGalaxy.getSingleInputWorkflowId();
    String workflowInputLabel = localGalaxy.getSingleInputWorkflowLabel();
    Map<String, ToolParameter> toolParameters = ImmutableMap.of(toolId, new ToolParameter("pattern", "^#"));
    WorkflowOutputs workflowOutput = runSingleFileWorkflow(dataFile1, FILE_TYPE, workflowId, workflowInputLabel, toolParameters);
    assertNotNull("workflowOutput should not be null", workflowOutput);
    assertNotNull("workflowOutput history id should not be null", workflowOutput.getHistoryId());
    // history should exist
    HistoryDetails historyDetails = historiesClient.showHistory(workflowOutput.getHistoryId());
    assertNotNull("historyDetails for the history for the workflow should not be null", historyDetails);
    // outputs should exist
    assertNotNull("outputIds for the workflow should not be null", workflowOutput.getOutputIds());
    assertTrue("there should exist output dataset ids for the workflow", workflowOutput.getOutputIds().size() > 0);
    // each output dataset should exist
    for (String outputId : workflowOutput.getOutputIds()) {
        Dataset dataset = historiesClient.showDataset(workflowOutput.getHistoryId(), outputId);
        assertNotNull("the output dataset should exist", dataset);
        HistoryContentsProvenance provenance = historiesClient.showProvenance(workflowOutput.getHistoryId(), dataset.getId());
        if (toolId.equals(provenance.getToolId())) {
            Map<String, Object> parametersMap = provenance.getParameters();
            assertEquals("pattern parameter is correct", "\"^#\"", parametersMap.get("pattern"));
        }
    }
    // test get workflow status
    GalaxyWorkflowStatus workflowStatus = galaxyHistory.getStatusForHistory(workflowOutput.getHistoryId());
    float proportionComplete = workflowStatus.getProportionComplete();
    assertTrue("the workflow proportion complete should be between 0 and 1", 0.0f <= proportionComplete && proportionComplete <= 1.0f);
}
Also used : WorkflowOutputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs) HistoryDetails(com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) ToolParameter(com.github.jmchilton.blend4j.galaxy.beans.ToolParameter) GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) Test(org.junit.Test)

Example 7 with Dataset

use of com.github.jmchilton.blend4j.galaxy.beans.Dataset 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 8 with Dataset

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

the class GalaxyHistoriesServiceTest method setup.

/**
 * Sets up objects for history tests.
 * @throws URISyntaxException
 */
@Before
public void setup() throws URISyntaxException {
    MockitoAnnotations.initMocks(this);
    when(okayResponse.getClientResponseStatus()).thenReturn(ClientResponse.Status.OK);
    when(invalidResponse.getClientResponseStatus()).thenReturn(ClientResponse.Status.FORBIDDEN);
    galaxyHistory = new GalaxyHistoriesService(historiesClient, toolsClient, galaxyLibrariesService);
    dataFile = Paths.get(this.getClass().getResource("testData1.fastq").toURI());
    history = new History();
    history.setId(HISTORY_ID);
    datasetHistoryContents = buildHistoryContentsList(FILENAME, DATA_ID);
    datasetForFile = new Dataset();
    datasetForFile.setName(FILENAME);
    datasetForFile.setId(DATA_ID);
    datasetForFile.setUrl("datasets/" + DATA_ID + "/display");
    datasetForFile.setGalaxyUrl("http://fakehost");
    datasetForFile.setApiKey("1");
}
Also used : GalaxyHistoriesService(ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyHistoriesService) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) HistoryDataset(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset) History(com.github.jmchilton.blend4j.galaxy.beans.History) Before(org.junit.Before)

Example 9 with Dataset

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

the class AnalysisWorkspaceServiceGalaxy method getAnalysisResults.

/**
 * {@inheritDoc}
 */
@Override
public Analysis getAnalysisResults(AnalysisSubmission analysisSubmission) throws ExecutionManagerException, IridaWorkflowNotFoundException, IOException, IridaWorkflowAnalysisTypeException {
    checkNotNull(analysisSubmission, "analysisSubmission is null");
    checkNotNull(analysisSubmission.getWorkflowId(), "workflowId is null");
    checkNotNull(analysisSubmission.getRemoteWorkflowId(), "remoteWorkflowId is null");
    Path outputDirectory = Files.createTempDirectory("analysis-output");
    logger.trace("Created temporary directory " + outputDirectory + " for analysis output files");
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(analysisSubmission.getWorkflowId());
    String analysisId = analysisSubmission.getRemoteAnalysisId();
    Map<String, IridaWorkflowOutput> outputsMap = iridaWorkflow.getWorkflowDescription().getOutputsMap();
    String labelPrefix = getLabelPrefix(analysisSubmission, iridaWorkflow);
    Map<String, AnalysisOutputFile> analysisOutputFiles = Maps.newHashMap();
    for (String analysisOutputName : outputsMap.keySet()) {
        String outputFileName = outputsMap.get(analysisOutputName).getFileName();
        Dataset outputDataset = galaxyHistoriesService.getDatasetForFileInHistory(outputFileName, analysisId);
        AnalysisOutputFile analysisOutput = buildOutputFile(analysisId, labelPrefix, outputDataset, outputDirectory);
        analysisOutputFiles.put(analysisOutputName, analysisOutput);
    }
    AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
    return new Analysis(analysisId, analysisOutputFiles, analysisType);
}
Also used : Path(java.nio.file.Path) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflowOutput(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowOutput) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)

Example 10 with Dataset

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

the class GalaxyHistoriesService method getDatasetForFileInHistory.

/**
 * Gets a Dataset object for a file with the given name in the given history.
 * @param filename  The name of the file to get a Dataset object for.
 * @param historyId  The history id to look for the dataset.
 * @return The corresponding dataset for the given file name.
 * @throws GalaxyDatasetException If there was an issue when searching for a dataset.
 */
public Dataset getDatasetForFileInHistory(String filename, String historyId) throws GalaxyDatasetException {
    checkNotNull(filename, "filename is null");
    checkNotNull(historyId, "historyId is null");
    List<HistoryContents> historyContentsList = historiesClient.showHistoryContents(historyId);
    List<HistoryContents> matchingHistoryContents = historyContentsList.stream().filter((historyContents) -> filename.equals(historyContents.getName())).collect(Collectors.toList());
    // if more than one matching history item
    if (matchingHistoryContents.size() > 1) {
        String historyIds = "[";
        for (HistoryContents content : matchingHistoryContents) {
            historyIds += content.getId() + ",";
        }
        historyIds += "]";
        throw new GalaxyDatasetException("Found " + matchingHistoryContents.size() + " datasets for file " + filename + ": " + historyIds);
    } else if (matchingHistoryContents.size() == 1) {
        String dataId = matchingHistoryContents.get(0).getId();
        if (dataId != null) {
            Dataset dataset = historiesClient.showDataset(historyId, dataId);
            if (dataset != null) {
                return dataset;
            }
        }
    }
    throw new GalaxyDatasetNotFoundException("dataset for file " + filename + " not found in Galaxy history " + historyId);
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) DeleteGalaxyObjectFailedException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.DeleteGalaxyObjectFailedException) ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggerFactory(org.slf4j.LoggerFactory) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) HashMap(java.util.HashMap) HistoryDeleteResponse(com.github.jmchilton.blend4j.galaxy.beans.HistoryDeleteResponse) NoGalaxyHistoryException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.NoGalaxyHistoryException) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) GalaxyDatasetException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.GalaxyDatasetException) Map(java.util.Map) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) Source(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset.Source) ExecutionManagerDownloadException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerDownloadException) Path(java.nio.file.Path) DataStorage(ca.corefacility.bioinformatics.irida.pipeline.upload.DataStorage) Logger(org.slf4j.Logger) HistoryDataset(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) IOException(java.io.IOException) FileUploadRequest(com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) InputFileType(ca.corefacility.bioinformatics.irida.model.workflow.execution.InputFileType) File(java.io.File) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) Preconditions.checkState(com.google.common.base.Preconditions.checkState) WorkflowException(ca.corefacility.bioinformatics.irida.exceptions.WorkflowException) GalaxyDatasetNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.GalaxyDatasetNotFoundException) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) List(java.util.List) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) History(com.github.jmchilton.blend4j.galaxy.beans.History) CollectionDescription(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription) HistoryDetails(com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) Optional(java.util.Optional) ExecutionManagerObjectNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerObjectNotFoundException) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) GalaxyDatasetException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.GalaxyDatasetException) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) HistoryDataset(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset) GalaxyDatasetNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.GalaxyDatasetNotFoundException)

Aggregations

Dataset (com.github.jmchilton.blend4j.galaxy.beans.Dataset)26 History (com.github.jmchilton.blend4j.galaxy.beans.History)17 Test (org.junit.Test)17 Path (java.nio.file.Path)10 WorkflowOutputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs)6 GalaxyWorkflowStatus (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus)4 HistoryDataset (com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset)4 HistoryDetails (com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails)4 Library (com.github.jmchilton.blend4j.galaxy.beans.Library)4 WorkflowInputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs)4 CollectionDescription (com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription)4 CollectionResponse (com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse)4 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)3 WorkflowDetails (com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails)3 HistoryDatasetElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement)3 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)2 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)2 FileUploadRequest (com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest)2 HistoryContentsProvenance (com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance)2 ToolParameter (com.github.jmchilton.blend4j.galaxy.beans.ToolParameter)2