use of ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile 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 ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile in project irida by phac-nml.
the class SequenceFilePair method getForwardSequenceFile.
/**
* Gets the forward {@link SequenceFile} from the pair.
*
* @return The forward {@link SequenceFile} from the pair.
*/
public SequenceFile getForwardSequenceFile() {
IridaSequenceFile[] pair = getFiles().toArray(new IridaSequenceFile[getFiles().size()]);
String[] filenames = { pair[0].getFile().getFileName().toString(), pair[1].getFile().getFileName().toString() };
int index = StringUtils.indexOfDifference(filenames[0], filenames[1]);
if (Stream.of(forwardMatches).anyMatch(x -> String.valueOf(filenames[0].charAt(index)).equals(x))) {
return (SequenceFile) pair[0];
} else if (Stream.of(forwardMatches).anyMatch(x -> String.valueOf(filenames[1].charAt(index)).equals(x))) {
return (SequenceFile) pair[1];
} else {
throw new NoSuchElementException();
}
}
use of ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile in project irida by phac-nml.
the class SequenceFilePair method getReverseSequenceFile.
/**
* Gets the reverse {@link SequenceFile} from the pair.
*
* @return The reverse {@link SequenceFile} from the pair.
*/
public SequenceFile getReverseSequenceFile() {
IridaSequenceFile[] pair = getFiles().toArray(new IridaSequenceFile[getFiles().size()]);
String[] filenames = { pair[0].getFile().getFileName().toString(), pair[1].getFile().getFileName().toString() };
int index = StringUtils.indexOfDifference(filenames[0], filenames[1]);
if (Stream.of(reverseMatches).anyMatch(x -> String.valueOf(filenames[0].charAt(index)).equals(x))) {
return (SequenceFile) pair[0];
} else if (Stream.of(reverseMatches).anyMatch(x -> String.valueOf(filenames[1].charAt(index)).equals(x))) {
return (SequenceFile) pair[1];
} else {
throw new NoSuchElementException();
}
}
Aggregations