Search in sources :

Example 21 with Dataset

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

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

the class GalaxyWorkflowsIT method uploadFilesListToHistory.

/**
 * Uploads a list of files into the given history.
 * @param dataFiles  The list of files to upload.
 * @param inputFileType  The type of files to upload.
 * @param history  The history to upload the files into.String
 * @return  A list of Datasets describing each uploaded file.
 * @throws UploadException  If an error occured uploading the file.
 * @throws GalaxyDatasetException If there was an issue finding the corresponding dataset for
 * 	the file in the history
 */
private List<Dataset> uploadFilesListToHistory(List<Path> dataFiles, InputFileType inputFileType, History history) throws UploadException, GalaxyDatasetException {
    checkNotNull(dataFiles, "dataFiles is null");
    checkNotNull(inputFileType, "inputFileType is null");
    checkNotNull(history, "history is null");
    List<Dataset> inputDatasets = new LinkedList<Dataset>();
    for (Path file : dataFiles) {
        Dataset inputDataset = galaxyHistory.fileToHistory(file, inputFileType, history);
        inputDatasets.add(inputDataset);
    }
    return inputDatasets;
}
Also used : Path(java.nio.file.Path) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) LinkedList(java.util.LinkedList)

Example 23 with Dataset

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

the class GalaxyHistoriesServiceTest method testFileToHistorySuccess.

/**
 * Tests uploading a file to a history.
 * @throws UploadException
 * @throws GalaxyDatasetException
 */
@Test
public void testFileToHistorySuccess() throws UploadException, GalaxyDatasetException {
    String filename = dataFile.toFile().getName();
    History createdHistory = new History();
    Dataset dataset = new Dataset();
    createdHistory.setId(HISTORY_ID);
    List<HistoryContents> historyContentsList = buildHistoryContentsList(filename, DATA_ID);
    when(toolsClient.uploadRequest(any(FileUploadRequest.class))).thenReturn(okayResponse);
    when(historiesClient.showHistoryContents(HISTORY_ID)).thenReturn(historyContentsList);
    when(historiesClient.showDataset(HISTORY_ID, DATA_ID)).thenReturn(dataset);
    assertEquals(dataset, galaxyHistory.fileToHistory(dataFile, FILE_TYPE, createdHistory));
}
Also used : FileUploadRequest(com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) HistoryDataset(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) History(com.github.jmchilton.blend4j.galaxy.beans.History) Test(org.junit.Test)

Example 24 with Dataset

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

the class GalaxyHistoriesServiceTest method testGetDatasetForFileInHistory.

/**
 * Tests getting a valid history dataset given a file name and history.
 * @throws GalaxyDatasetException
 */
@Test
public void testGetDatasetForFileInHistory() throws GalaxyDatasetException {
    Dataset dataset = new Dataset();
    when(historiesClient.showHistoryContents(HISTORY_ID)).thenReturn(datasetHistoryContents);
    when(historiesClient.showDataset(HISTORY_ID, DATA_ID)).thenReturn(dataset);
    assertNotNull(galaxyHistory.getDatasetForFileInHistory(FILENAME, HISTORY_ID));
}
Also used : Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) HistoryDataset(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset) Test(org.junit.Test)

Example 25 with Dataset

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

the class AnalysisCollectionServiceGalaxyIT method testUploadSequenceFilesPairedSuccess.

/**
 * Tests successfully uploading a paired-end sequence file to Galaxy and
 * constructing a collection.
 *
 * @throws ExecutionManagerException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testUploadSequenceFilesPairedSuccess() throws ExecutionManagerException {
    History history = new History();
    history.setName("testUploadSequenceFilesPaired");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    Library library = new Library();
    library.setName("testUploadSequenceFilesPaired");
    Library createdLibrary = librariesClient.createLibrary(library);
    Set<SequenceFilePair> sequenceFiles = Sets.newHashSet(databaseSetupGalaxyITService.setupSampleSequenceFileInDatabase(1L, pairSequenceFiles1A, pairSequenceFiles2A));
    Map<Sample, IridaSequenceFilePair> sampleSequenceFilePairs = new HashMap<>(sequencingObjectService.getUniqueSamplesForSequencingObjects(sequenceFiles));
    Sample sample1 = sampleRepository.findOne(1L);
    CollectionResponse collectionResponse = analysisCollectionServiceGalaxy.uploadSequenceFilesPaired(sampleSequenceFilePairs, createdHistory, createdLibrary);
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("history does not have correct number of files", 3, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("the history should have a sequence file with name " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("the history should have a file with name " + sequenceFilePath2A.toFile().getName(), contentsMap.containsKey(sequenceFilePath2A.toFile().getName()));
    assertTrue("the history should have a dataset collection with name " + INPUTS_PAIRED_NAME, contentsMap.containsKey(INPUTS_PAIRED_NAME));
    // verify correct collection has been created
    assertEquals("invalid type of dataset collection created", DatasetCollectionType.LIST_PAIRED.toString(), collectionResponse.getCollectionType());
    List<CollectionElementResponse> collectionElements = collectionResponse.getElements();
    assertEquals("invalid number of elements in the dataset collection", 1, collectionElements.size());
    Map<String, CollectionElementResponse> collectionElementsMap = collectionElementsAsMap(collectionElements);
    assertTrue("the dataset collection element should have name " + sample1.getSampleName(), collectionElementsMap.containsKey(sample1.getSampleName()));
    CollectionElementResponse sample1Response = collectionElementsMap.get(sample1.getSampleName());
    // verify collection has 2 files (paired end data)
    ElementResponse subElements = sample1Response.getResponseElement();
    assertEquals("invalid class for sub-element in dataset collection", CollectionResponse.class, subElements.getClass());
    CollectionResponse subElementsCollection = (CollectionResponse) subElements;
    assertEquals("invalid type for sub-element in dataset collection", DatasetCollectionType.PAIRED.toString(), subElementsCollection.getCollectionType());
    List<CollectionElementResponse> subCollectionElements = subElementsCollection.getElements();
    assertEquals("invalid number of files for paired dataset collection element", 2, subCollectionElements.size());
    Map<String, CollectionElementResponse> subCollectionElementsMap = collectionElementsAsMap(subCollectionElements);
    assertTrue("dataset collection should have a sub-element with name " + FORWARD_NAME, subCollectionElementsMap.containsKey(FORWARD_NAME));
    assertTrue("dataset collection should have a sub-element with name " + REVERSE_NAME, subCollectionElementsMap.containsKey(REVERSE_NAME));
    // verify paired-end files are correct type in collection
    CollectionElementResponse sequenceFile1 = subCollectionElementsMap.get(FORWARD_NAME);
    CollectionElementResponse sequenceFile2 = subCollectionElementsMap.get(REVERSE_NAME);
    assertEquals("the " + FORWARD_NAME + " sub-element should be a history dataset", HISTORY_DATASET_NAME, sequenceFile1.getElementType());
    assertEquals("the " + REVERSE_NAME + " sub-element should be a history dataset", HISTORY_DATASET_NAME, sequenceFile2.getElementType());
    // verify paired-end files are in correct order in collection
    ElementResponse sequenceFile1Response = sequenceFile1.getResponseElement();
    assertEquals("the " + FORWARD_NAME + " element is not of the correct type", Dataset.class, sequenceFile1Response.getClass());
    ElementResponse sequenceFile2Response = sequenceFile2.getResponseElement();
    assertEquals("the " + REVERSE_NAME + " element is not of the correct type", Dataset.class, sequenceFile2Response.getClass());
    Dataset sequenceFile1Dataset = (Dataset) sequenceFile1Response;
    assertEquals("forward file in Galaxy is named incorrectly", sequenceFilePathA.getFileName().toString(), sequenceFile1Dataset.getName());
    Dataset sequenceFile2Dataset = (Dataset) sequenceFile2Response;
    assertEquals("reverse file in Galaxy is named incorrectly", sequenceFilePath2A.getFileName().toString(), sequenceFile2Dataset.getName());
}
Also used : CollectionElementResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionElementResponse) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) CollectionElementResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionElementResponse) ElementResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.ElementResponse) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

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