use of ca.corefacility.bioinformatics.irida.exceptions.UploadException in project irida by phac-nml.
the class GalaxyHistoriesService method filesToLibraryToHistory.
/**
* Uploads a set of files to a given history through the given library.
*
* @param paths
* The set of paths to upload.
* @param fileType
* The file type of the file to upload.
* @param history
* The history to upload the file into.
* @param library
* The library to initially upload the file into.
* @param dataStorage
* The type of DataStorage strategy to use.
* @return An {@link Map} of paths and ids for each dataset object in this
* history.
* @throws UploadException
* If there was an issue uploading the file to Galaxy.
*/
public Map<Path, String> filesToLibraryToHistory(Set<Path> paths, InputFileType fileType, History history, Library library, DataStorage dataStorage) throws UploadException {
checkNotNull(paths, "paths is null");
Map<Path, String> datasetIdsMap = new HashMap<>();
Map<Path, String> datasetLibraryIdsMap = librariesService.filesToLibraryWait(paths, fileType, library, dataStorage);
if (datasetLibraryIdsMap.size() != paths.size()) {
throw new UploadException("Error: datasets uploaded to a Galaxy library are not the same size (" + datasetLibraryIdsMap.size() + ") as the paths to upload (" + paths.size() + ")");
}
try {
for (Path path : datasetLibraryIdsMap.keySet()) {
String datasetLibraryId = datasetLibraryIdsMap.get(path);
HistoryDetails historyDetails = libraryDatasetToHistory(datasetLibraryId, history);
logger.debug("Transfered library dataset " + datasetLibraryId + " to history " + history.getId() + " dataset id " + historyDetails.getId());
datasetIdsMap.put(path, historyDetails.getId());
}
} catch (RuntimeException e) {
throw new UploadException(e);
}
return datasetIdsMap;
}
use of ca.corefacility.bioinformatics.irida.exceptions.UploadException in project irida by phac-nml.
the class GalaxyHistoriesService method fileToHistory.
/**
* Uploads a file to a given history.
* @param path The path to the file to upload.
* @param fileType The file type of the file to upload.
* @param history The history to upload the file into.
* @return A Dataset object for the uploaded file.
* @throws UploadException If there was an issue uploading the file to Galaxy.
* @throws GalaxyDatasetException If there was an issue finding the corresponding Dataset for the file
* in the history.
*/
public Dataset fileToHistory(Path path, InputFileType fileType, History history) throws UploadException, GalaxyDatasetException {
checkNotNull(path, "path is null");
checkNotNull(fileType, "fileType is null");
checkNotNull(history, "history is null");
checkNotNull(history.getId(), "history id is null");
checkState(path.toFile().exists(), "path " + path + " does not exist");
File file = path.toFile();
FileUploadRequest uploadRequest = new FileUploadRequest(history.getId(), file);
uploadRequest.setFileType(fileType.toString());
ClientResponse clientResponse = toolsClient.uploadRequest(uploadRequest);
if (clientResponse == null) {
throw new UploadException("Could not upload " + file + " to history " + history.getId() + " ClientResponse is null");
} else if (!ClientResponse.Status.OK.equals(clientResponse.getClientResponseStatus())) {
String message = "Could not upload " + file + " to history " + history.getId() + " ClientResponse: " + clientResponse.getClientResponseStatus() + " " + clientResponse.getEntity(String.class);
logger.error(message);
throw new UploadException(message);
} else {
return getDatasetForFileInHistory(file.getName(), history.getId());
}
}
use of ca.corefacility.bioinformatics.irida.exceptions.UploadException in project irida by phac-nml.
the class AnalysisCollectionServiceGalaxy method uploadSequenceFilesSingleEnd.
/**
* Uploads a list of single sequence files belonging to the given samples to
* Galaxy.
*
* @param sampleSequenceFiles
* A map between {@link Sample} and
* {@link IridaSingleEndSequenceFile}.
* @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 uploadSequenceFilesSingleEnd(Map<Sample, ? extends IridaSingleEndSequenceFile> sampleSequenceFiles, History workflowHistory, Library workflowLibrary) throws ExecutionManagerException {
CollectionDescription description = new CollectionDescription();
description.setCollectionType(DatasetCollectionType.LIST.toString());
description.setName(COLLECTION_NAME_SINGLE);
Map<Path, Sample> samplesMap = new HashMap<>();
for (Sample sample : sampleSequenceFiles.keySet()) {
IridaSingleEndSequenceFile sequenceFile = sampleSequenceFiles.get(sample);
samplesMap.put(sequenceFile.getSequenceFile().getFile(), sample);
}
// upload files to library and then to a history
Set<Path> pathsToUpload = samplesMap.keySet();
Map<Path, String> pathHistoryDatasetId = galaxyHistoriesService.filesToLibraryToHistory(pathsToUpload, InputFileType.FASTQ_SANGER, workflowHistory, workflowLibrary, DataStorage.LOCAL);
for (Path sequenceFilePath : samplesMap.keySet()) {
if (!pathHistoryDatasetId.containsKey(sequenceFilePath)) {
throw new UploadException("Error, no corresponding history item found for " + sequenceFilePath);
}
Sample sample = samplesMap.get(sequenceFilePath);
String datasetHistoryId = pathHistoryDatasetId.get(sequenceFilePath);
HistoryDatasetElement datasetElement = new HistoryDatasetElement();
datasetElement.setId(datasetHistoryId);
datasetElement.setName(sample.getSampleName());
description.addDatasetElement(datasetElement);
}
return galaxyHistoriesService.constructCollection(description, workflowHistory);
}
use of ca.corefacility.bioinformatics.irida.exceptions.UploadException in project irida by phac-nml.
the class ExportUploadService method uploadSubmission.
/**
* Upload an {@link NcbiExportSubmission}'s files and submission xml to the
* configured ftp site
*
* @param submission
* The {@link NcbiExportSubmission} to upload
* @param xml
* The submission xml to upload
* @return true/false if upload was successful
* @throws UploadException
* if the upload failed
*/
public NcbiExportSubmission uploadSubmission(NcbiExportSubmission submission, String xml) throws UploadException {
FTPClient client = null;
try {
client = getFtpClient();
// create submission directory name
String directoryName = submission.getId().toString() + "-" + new Date().getTime();
// cd to submission base directory
if (!client.changeWorkingDirectory(baseDirectory)) {
throw new UploadException("Couldn't change to base directory " + baseDirectory + " : " + client.getReplyString());
}
// create new submission directory
if (!client.makeDirectory(directoryName)) {
throw new UploadException("Couldn't create new upload directory " + directoryName + " : " + client.getReplyString());
}
// cd to submission directory
if (!client.changeWorkingDirectory(directoryName)) {
throw new UploadException("Couldn't change to upload directory " + directoryName + " : " + client.getReplyString());
}
// set the directory saved
String directoryPath = baseDirectory + "/" + directoryName;
submission.setDirectoryPath(directoryPath);
// upload submission.xml file
uploadString(client, "submission.xml", xml);
// upload biosample files
for (NcbiBioSampleFiles bsFile : submission.getBioSampleFiles()) {
// upload single end files
for (SingleEndSequenceFile file : bsFile.getFiles()) {
// Just using file IDs as the basename for uploaded files to
// avoid accidentally sending sensitive sample names to NCBI
String filename = file.getSequenceFile().getId() + ".fastq";
uploadPath(client, filename, file.getSequenceFile().getFile());
}
// upload paired end files
for (SequenceFilePair pair : bsFile.getPairs()) {
// upload forward
SequenceFile file = pair.getForwardSequenceFile();
// Just using file IDs as the basename for uploaded files to
// avoid accidentally sending sensitive sample names to NCBI
String filename = file.getId() + ".fastq";
uploadPath(client, filename, file.getFile());
// upload reverse
file = pair.getReverseSequenceFile();
filename = file.getId() + ".fastq";
uploadPath(client, filename, file.getFile());
}
}
// create submit.ready file
uploadString(client, "submit.ready", "");
} catch (IOException e) {
logger.error("Error in upload", e);
throw new UploadException("Could not upload run", e);
} finally {
disconnectFtpCient(client);
}
return submission;
}
Aggregations