Search in sources :

Example 1 with CollectionElement

use of com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionElement 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 2 with CollectionElement

use of com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionElement 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)2 CollectionElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionElement)2 HistoryDatasetElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement)2 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)1 UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)1 IridaSequenceFile (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile)1 IridaSequenceFilePair (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair)1 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)1 Dataset (com.github.jmchilton.blend4j.galaxy.beans.Dataset)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1