Search in sources :

Example 1 with IridaSequenceFilePair

use of ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair in project irida by phac-nml.

the class AnalysisCollectionServiceGalaxyIT method testUploadSequenceFilesPairedFailForward.

/**
 * Tests failing to upload a paired-end sequence file to Galaxy and
 * constructing a collection due to no found forward file.
 *
 * @throws ExecutionManagerException
 */
@Test(expected = NoSuchElementException.class)
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testUploadSequenceFilesPairedFailForward() throws ExecutionManagerException {
    History history = new History();
    history.setName("testUploadSequenceFilesPairedFailForward");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    Library library = new Library();
    library.setName("testUploadSequenceFilesPairedFailForward");
    Library createdLibrary = librariesClient.createLibrary(library);
    Set<SequenceFilePair> sequenceFiles = Sets.newHashSet(databaseSetupGalaxyITService.setupSampleSequenceFileInDatabase(1L, pairSequenceFiles1AInvalidName, pairSequenceFiles2A));
    Map<Sample, IridaSequenceFilePair> sampleSequenceFilePairs = new HashMap<>(sequencingObjectService.getUniqueSamplesForSequencingObjects(sequenceFiles));
    analysisCollectionServiceGalaxy.uploadSequenceFilesPaired(sampleSequenceFilePairs, createdHistory, createdLibrary);
}
Also used : IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 2 with IridaSequenceFilePair

use of ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair 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 3 with IridaSequenceFilePair

use of ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair in project irida by phac-nml.

the class AnalysisCollectionServiceGalaxyIT method testUploadSequenceFilesPairedSuccess.

/**
 * Tests successfully uploading a paired-end sequence file to Galaxy and
 * constructing a collection.
 *
 * @throws ExecutionManagerException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testUploadSequenceFilesPairedSuccess() throws ExecutionManagerException {
    History history = new History();
    history.setName("testUploadSequenceFilesPaired");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    Library library = new Library();
    library.setName("testUploadSequenceFilesPaired");
    Library createdLibrary = librariesClient.createLibrary(library);
    Set<SequenceFilePair> sequenceFiles = Sets.newHashSet(databaseSetupGalaxyITService.setupSampleSequenceFileInDatabase(1L, pairSequenceFiles1A, pairSequenceFiles2A));
    Map<Sample, IridaSequenceFilePair> sampleSequenceFilePairs = new HashMap<>(sequencingObjectService.getUniqueSamplesForSequencingObjects(sequenceFiles));
    Sample sample1 = sampleRepository.findOne(1L);
    CollectionResponse collectionResponse = analysisCollectionServiceGalaxy.uploadSequenceFilesPaired(sampleSequenceFilePairs, createdHistory, createdLibrary);
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("history does not have correct number of files", 3, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("the history should have a sequence file with name " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("the history should have a file with name " + sequenceFilePath2A.toFile().getName(), contentsMap.containsKey(sequenceFilePath2A.toFile().getName()));
    assertTrue("the history should have a dataset collection with name " + INPUTS_PAIRED_NAME, contentsMap.containsKey(INPUTS_PAIRED_NAME));
    // verify correct collection has been created
    assertEquals("invalid type of dataset collection created", DatasetCollectionType.LIST_PAIRED.toString(), collectionResponse.getCollectionType());
    List<CollectionElementResponse> collectionElements = collectionResponse.getElements();
    assertEquals("invalid number of elements in the dataset collection", 1, collectionElements.size());
    Map<String, CollectionElementResponse> collectionElementsMap = collectionElementsAsMap(collectionElements);
    assertTrue("the dataset collection element should have name " + sample1.getSampleName(), collectionElementsMap.containsKey(sample1.getSampleName()));
    CollectionElementResponse sample1Response = collectionElementsMap.get(sample1.getSampleName());
    // verify collection has 2 files (paired end data)
    ElementResponse subElements = sample1Response.getResponseElement();
    assertEquals("invalid class for sub-element in dataset collection", CollectionResponse.class, subElements.getClass());
    CollectionResponse subElementsCollection = (CollectionResponse) subElements;
    assertEquals("invalid type for sub-element in dataset collection", DatasetCollectionType.PAIRED.toString(), subElementsCollection.getCollectionType());
    List<CollectionElementResponse> subCollectionElements = subElementsCollection.getElements();
    assertEquals("invalid number of files for paired dataset collection element", 2, subCollectionElements.size());
    Map<String, CollectionElementResponse> subCollectionElementsMap = collectionElementsAsMap(subCollectionElements);
    assertTrue("dataset collection should have a sub-element with name " + FORWARD_NAME, subCollectionElementsMap.containsKey(FORWARD_NAME));
    assertTrue("dataset collection should have a sub-element with name " + REVERSE_NAME, subCollectionElementsMap.containsKey(REVERSE_NAME));
    // verify paired-end files are correct type in collection
    CollectionElementResponse sequenceFile1 = subCollectionElementsMap.get(FORWARD_NAME);
    CollectionElementResponse sequenceFile2 = subCollectionElementsMap.get(REVERSE_NAME);
    assertEquals("the " + FORWARD_NAME + " sub-element should be a history dataset", HISTORY_DATASET_NAME, sequenceFile1.getElementType());
    assertEquals("the " + REVERSE_NAME + " sub-element should be a history dataset", HISTORY_DATASET_NAME, sequenceFile2.getElementType());
    // verify paired-end files are in correct order in collection
    ElementResponse sequenceFile1Response = sequenceFile1.getResponseElement();
    assertEquals("the " + FORWARD_NAME + " element is not of the correct type", Dataset.class, sequenceFile1Response.getClass());
    ElementResponse sequenceFile2Response = sequenceFile2.getResponseElement();
    assertEquals("the " + REVERSE_NAME + " element is not of the correct type", Dataset.class, sequenceFile2Response.getClass());
    Dataset sequenceFile1Dataset = (Dataset) sequenceFile1Response;
    assertEquals("forward file in Galaxy is named incorrectly", sequenceFilePathA.getFileName().toString(), sequenceFile1Dataset.getName());
    Dataset sequenceFile2Dataset = (Dataset) sequenceFile2Response;
    assertEquals("reverse file in Galaxy is named incorrectly", sequenceFilePath2A.getFileName().toString(), sequenceFile2Dataset.getName());
}
Also used : CollectionElementResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionElementResponse) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) CollectionElementResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionElementResponse) ElementResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.ElementResponse) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

IridaSequenceFilePair (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)3 HashMap (java.util.HashMap)3 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)2 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)2 LibrariesClient (com.github.jmchilton.blend4j.galaxy.LibrariesClient)2 History (com.github.jmchilton.blend4j.galaxy.beans.History)2 Library (com.github.jmchilton.blend4j.galaxy.beans.Library)2 Test (org.junit.Test)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)1 IridaSequenceFile (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile)1 Dataset (com.github.jmchilton.blend4j.galaxy.beans.Dataset)1 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)1 CollectionDescription (com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription)1 CollectionElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionElement)1 HistoryDatasetElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement)1 CollectionElementResponse (com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionElementResponse)1 CollectionResponse (com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse)1 ElementResponse (com.github.jmchilton.blend4j.galaxy.beans.collection.response.ElementResponse)1