Search in sources :

Example 6 with UploadException

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;
}
Also used : Path(java.nio.file.Path) HistoryDetails(com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails) HashMap(java.util.HashMap) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException)

Example 7 with UploadException

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());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileUploadRequest(com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) File(java.io.File)

Example 8 with UploadException

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);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) 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) IridaSingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSingleEndSequenceFile) HistoryDatasetElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement)

Example 9 with UploadException

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;
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) NcbiBioSampleFiles(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) IOException(java.io.IOException) FTPClient(org.apache.commons.net.ftp.FTPClient) Date(java.util.Date) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Aggregations

UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)9 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 NcbiXmlParseException (ca.corefacility.bioinformatics.irida.exceptions.NcbiXmlParseException)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 CollectionDescription (com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription)2 HistoryDatasetElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 ConnectException (java.net.ConnectException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 SAXException (org.xml.sax.SAXException)2 UploadErrorException (ca.corefacility.bioinformatics.irida.exceptions.UploadErrorException)1 UploadTimeoutException (ca.corefacility.bioinformatics.irida.exceptions.UploadTimeoutException)1 CreateLibraryException (ca.corefacility.bioinformatics.irida.exceptions.galaxy.CreateLibraryException)1 DeleteGalaxyObjectFailedException (ca.corefacility.bioinformatics.irida.exceptions.galaxy.DeleteGalaxyObjectFailedException)1 NcbiBioSampleFiles (ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles)1 IridaSequenceFile (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile)1