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);
}
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);
}
}
Aggregations