Search in sources :

Example 1 with HistoryDatasetElement

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

the class GalaxyHistoriesServiceIT method testConstructCollectionSuccess.

/**
 * Tests out successfully constructing a collection of datasets.
 * @throws ExecutionManagerException
 */
@Test
public void testConstructCollectionSuccess() throws ExecutionManagerException {
    History history = galaxyHistory.newHistoryForWorkflow();
    Dataset dataset1 = galaxyHistory.fileToHistory(dataFile, FILE_TYPE, history);
    Dataset dataset2 = galaxyHistory.fileToHistory(dataFile2, FILE_TYPE, history);
    assertNotNull(dataset1);
    assertNotNull(dataset2);
    String collectionName = "collection";
    CollectionDescription description = new CollectionDescription();
    description.setName(collectionName);
    description.setCollectionType(DatasetCollectionType.LIST.toString());
    HistoryDatasetElement element1 = new HistoryDatasetElement();
    element1.setId(dataset1.getId());
    element1.setName(dataset1.getName());
    description.addDatasetElement(element1);
    HistoryDatasetElement element2 = new HistoryDatasetElement();
    element2.setId(dataset2.getId());
    element2.setName(dataset2.getName());
    description.addDatasetElement(element2);
    CollectionResponse collectionResponse = galaxyHistory.constructCollection(description, history);
    assertNotNull(collectionResponse);
    assertEquals(DatasetCollectionType.LIST.toString(), collectionResponse.getCollectionType());
    assertEquals(history.getId(), collectionResponse.getHistoryId());
    assertEquals(2, collectionResponse.getElements().size());
}
Also used : Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) CollectionDescription(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription) HistoryDatasetElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement) History(com.github.jmchilton.blend4j.galaxy.beans.History) Test(org.junit.Test)

Example 2 with HistoryDatasetElement

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

the class GalaxyHistoriesServiceTest method testConstructCollectionSuccess.

/**
 * Tests successfull construction of a dataset collection.
 * @throws ExecutionManagerException
 */
@Test
public void testConstructCollectionSuccess() throws ExecutionManagerException {
    CollectionResponse collectionResponse = new CollectionResponse();
    History history = new History();
    history.setId(HISTORY_ID);
    HistoryDatasetElement datasetElement = new HistoryDatasetElement();
    datasetElement.setId(DATA_ID);
    CollectionDescription description = new CollectionDescription();
    description.addDatasetElement(datasetElement);
    when(historiesClient.createDatasetCollection(eq(HISTORY_ID), any(CollectionDescription.class))).thenReturn(collectionResponse);
    assertEquals(collectionResponse, galaxyHistory.constructCollection(description, history));
}
Also used : CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) CollectionDescription(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription) HistoryDatasetElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement) History(com.github.jmchilton.blend4j.galaxy.beans.History) Test(org.junit.Test)

Example 3 with HistoryDatasetElement

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

the class AnalysisCollectionServiceGalaxy method uploadSequenceFilesPaired.

/**
 * Uploads a list of paired sequence files belonging to the given samples to
 * Galaxy.
 *
 * @param sampleSequenceFilesPaired
 *            A map between {@link Sample} and {@link SequenceFilePair}.
 * @param workflowHistory
 *            The history to upload the sequence files into.
 * @param workflowLibrary
 *            A temporary library to upload files into.
 * @return A CollectionResponse for the dataset collection constructed from
 *         the given files.
 * @throws ExecutionManagerException
 *             If there was an error uploading the files.
 */
public CollectionResponse uploadSequenceFilesPaired(Map<Sample, ? extends IridaSequenceFilePair> sampleSequenceFilesPaired, History workflowHistory, Library workflowLibrary) throws ExecutionManagerException {
    CollectionDescription description = new CollectionDescription();
    description.setCollectionType(DatasetCollectionType.LIST_PAIRED.toString());
    description.setName(COLLECTION_NAME_PAIRED);
    Map<Sample, Path> samplesMapPairForward = new HashMap<>();
    Map<Sample, Path> samplesMapPairReverse = new HashMap<>();
    Set<Path> pathsToUpload = new HashSet<>();
    for (Sample sample : sampleSequenceFilesPaired.keySet()) {
        IridaSequenceFilePair sequenceFilePair = sampleSequenceFilesPaired.get(sample);
        IridaSequenceFile fileForward = sequenceFilePair.getForwardSequenceFile();
        IridaSequenceFile fileReverse = sequenceFilePair.getReverseSequenceFile();
        samplesMapPairForward.put(sample, fileForward.getFile());
        samplesMapPairReverse.put(sample, fileReverse.getFile());
        pathsToUpload.add(fileForward.getFile());
        pathsToUpload.add(fileReverse.getFile());
    }
    // upload files to library and then to a history
    Map<Path, String> pathHistoryDatasetId = galaxyHistoriesService.filesToLibraryToHistory(pathsToUpload, InputFileType.FASTQ_SANGER, workflowHistory, workflowLibrary, DataStorage.LOCAL);
    for (Sample sample : sampleSequenceFilesPaired.keySet()) {
        Path fileForward = samplesMapPairForward.get(sample);
        Path fileReverse = samplesMapPairReverse.get(sample);
        if (!pathHistoryDatasetId.containsKey(fileForward)) {
            throw new UploadException("Error, no corresponding history item found for " + fileForward);
        } else if (!pathHistoryDatasetId.containsKey(fileReverse)) {
            throw new UploadException("Error, no corresponding history item found for " + fileReverse);
        } else {
            String datasetHistoryIdForward = pathHistoryDatasetId.get(fileForward);
            String datasetHistoryIdReverse = pathHistoryDatasetId.get(fileReverse);
            CollectionElement pairedElement = new CollectionElement();
            pairedElement.setName(sample.getSampleName());
            pairedElement.setCollectionType(DatasetCollectionType.PAIRED.toString());
            HistoryDatasetElement datasetElementForward = new HistoryDatasetElement();
            datasetElementForward.setId(datasetHistoryIdForward);
            datasetElementForward.setName(FORWARD_NAME);
            pairedElement.addCollectionElement(datasetElementForward);
            HistoryDatasetElement datasetElementReverse = new HistoryDatasetElement();
            datasetElementReverse.setId(datasetHistoryIdReverse);
            datasetElementReverse.setName(REVERSE_NAME);
            pairedElement.addCollectionElement(datasetElementReverse);
            description.addDatasetElement(pairedElement);
        }
    }
    return galaxyHistoriesService.constructCollection(description, workflowHistory);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) CollectionDescription(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription) HistoryDatasetElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement) IridaSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile) CollectionElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionElement) HashSet(java.util.HashSet)

Example 4 with HistoryDatasetElement

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

the class GalaxyHistoriesServiceIT method testConstructCollectionFail.

/**
 * Tests out failure to construct a collection of datasets.
 * @throws ExecutionManagerException
 */
@Test(expected = ExecutionManagerException.class)
public void testConstructCollectionFail() throws ExecutionManagerException {
    History history = galaxyHistory.newHistoryForWorkflow();
    Dataset dataset1 = galaxyHistory.fileToHistory(dataFile, FILE_TYPE, history);
    Dataset datasetInvalid = new Dataset();
    datasetInvalid.setId("invalidId");
    assertNotNull(dataset1);
    String collectionName = "collectionInvalid";
    CollectionDescription description = new CollectionDescription();
    description.setName(collectionName);
    description.setCollectionType(DatasetCollectionType.LIST.toString());
    HistoryDatasetElement element1 = new HistoryDatasetElement();
    element1.setId(dataset1.getId());
    element1.setName(dataset1.getName());
    description.addDatasetElement(element1);
    HistoryDatasetElement elementInvalid = new HistoryDatasetElement();
    elementInvalid.setId(datasetInvalid.getId());
    elementInvalid.setName(datasetInvalid.getName());
    description.addDatasetElement(elementInvalid);
    galaxyHistory.constructCollection(description, history);
}
Also used : Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) CollectionDescription(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription) HistoryDatasetElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement) History(com.github.jmchilton.blend4j.galaxy.beans.History) Test(org.junit.Test)

Example 5 with HistoryDatasetElement

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

the class GalaxyWorkflowsIT method constructPairedFileCollection.

/**
 * Constructs a collection containing a list of files from the given datasets.
 * @param inputDatasetsForward  The forward datasets to construct a collection from.
 * @param inputDatasetsReverse  The reverse datasets to construct a collection from.
 * @param history  The history to construct the collection within.
 * @return  A CollectionResponse describing the dataset collection.
 * @throws ExecutionManagerException  If an exception occured constructing the collection.
 */
public CollectionResponse constructPairedFileCollection(List<Dataset> inputDatasetsForward, List<Dataset> inputDatasetsReverse, History history) throws ExecutionManagerException {
    checkNotNull(inputDatasetsForward, "inputDatasetsForward is null");
    checkNotNull(inputDatasetsReverse, "inputDatasetsReverse is null");
    checkNotNull(history, "history is null");
    checkNotNull(history.getId(), "history does not have an associated id");
    checkArgument(inputDatasetsForward.size() == inputDatasetsReverse.size(), "inputDatasets do not have equal sizes");
    CollectionDescription collectionDescription = new CollectionDescription();
    collectionDescription.setCollectionType(DatasetCollectionType.LIST_PAIRED.toString());
    collectionDescription.setName(COLLECTION_NAME);
    for (int i = 0; i < inputDatasetsForward.size(); i++) {
        Dataset datasetForward = inputDatasetsForward.get(i);
        Dataset datasetReverse = inputDatasetsReverse.get(i);
        HistoryDatasetElement elementForward = new HistoryDatasetElement();
        elementForward.setId(datasetForward.getId());
        elementForward.setName(FORWARD_PAIR_NAME);
        HistoryDatasetElement elementReverse = new HistoryDatasetElement();
        elementReverse.setId(datasetReverse.getId());
        elementReverse.setName(REVERSE_PAIR_NAME);
        // Create an object to link together the forward and reverse reads for file2
        CollectionElement element = new CollectionElement();
        element.setName(BASE_NAME + i);
        element.setCollectionType(DatasetCollectionType.PAIRED.toString());
        element.addCollectionElement(elementForward);
        element.addCollectionElement(elementReverse);
        collectionDescription.addDatasetElement(element);
    }
    try {
        return historiesClient.createDatasetCollection(history.getId(), collectionDescription);
    } catch (RuntimeException e) {
        throw new ExecutionManagerException("Could not construct dataset collection", e);
    }
}
Also used : Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) CollectionDescription(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription) HistoryDatasetElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement) CollectionElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionElement) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)

Aggregations

CollectionDescription (com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription)7 HistoryDatasetElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement)7 History (com.github.jmchilton.blend4j.galaxy.beans.History)4 Test (org.junit.Test)4 Dataset (com.github.jmchilton.blend4j.galaxy.beans.Dataset)3 UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 CollectionElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionElement)2 CollectionResponse (com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)1 IridaSequenceFile (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile)1 IridaSequenceFilePair (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair)1 IridaSingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.irida.IridaSingleEndSequenceFile)1 HashSet (java.util.HashSet)1