Search in sources :

Example 1 with LibrariesClient

use of com.github.jmchilton.blend4j.galaxy.LibrariesClient in project irida by phac-nml.

the class GalaxyHistoriesServiceIT method setupLibraries.

/**
 * Sets up library for test.
 * @param testLibrary  The library to upload a file to.
 * @param galaxyInstanceAdmin  The Galaxy Instance to connect to Galaxy.
 * @return Returns the id of the file in a library.
 * @throws CreateLibraryException
 * @throws ExecutionManagerObjectNotFoundException
 */
private String setupLibraries(Library testLibrary, GalaxyInstance galaxyInstanceAdmin) throws CreateLibraryException, ExecutionManagerObjectNotFoundException {
    LibrariesClient librariesClient = galaxyInstanceAdmin.getLibrariesClient();
    LibraryContent rootFolder = librariesClient.getRootFolder(testLibrary.getId());
    assertNotNull(rootFolder);
    FilesystemPathsLibraryUpload upload = new FilesystemPathsLibraryUpload();
    upload.setFolderId(rootFolder.getId());
    upload.setContent(dataFile.toFile().getAbsolutePath());
    upload.setName(dataFile.toFile().getName());
    upload.setLinkData(true);
    upload.setFileType(FILE_TYPE.toString());
    assertEquals(ClientResponse.Status.OK, librariesClient.uploadFilesystemPathsRequest(testLibrary.getId(), upload).getClientResponseStatus());
    List<LibraryContent> libraryContents = librariesClient.getLibraryContents(testLibrary.getId());
    Map<String, List<LibraryContent>> libraryContent = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
    LibraryContent fileContent = libraryContent.get("/" + dataFile.toFile().getName()).get(0);
    assertNotNull(fileContent);
    return fileContent.getId();
}
Also used : LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) List(java.util.List) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) FilesystemPathsLibraryUpload(com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload)

Example 2 with LibrariesClient

use of com.github.jmchilton.blend4j.galaxy.LibrariesClient in project irida by phac-nml.

the class GalaxyHistoriesServiceIT method setup.

/**
 * Sets up files for history tests.
 * @throws URISyntaxException
 * @throws IOException
 * @throws CreateLibraryException
 * @throws ExecutionManagerObjectNotFoundException
 */
@Before
public void setup() throws URISyntaxException, IOException, CreateLibraryException, ExecutionManagerObjectNotFoundException {
    setupDataFiles();
    galaxyInstanceAdmin = localGalaxy.getGalaxyInstanceAdmin();
    HistoriesClient historiesClient = galaxyInstanceAdmin.getHistoriesClient();
    ToolsClient toolsClient = galaxyInstanceAdmin.getToolsClient();
    LibrariesClient librariesClient = galaxyInstanceAdmin.getLibrariesClient();
    galaxyLibrariesService = new GalaxyLibrariesService(librariesClient, LIBRARY_POLLING_TIME, LIBRARY_TIMEOUT, 1);
    galaxyHistory = new GalaxyHistoriesService(historiesClient, toolsClient, galaxyLibrariesService);
}
Also used : GalaxyHistoriesService(ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyHistoriesService) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) GalaxyLibrariesService(ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyLibrariesService) Before(org.junit.Before)

Example 3 with LibrariesClient

use of com.github.jmchilton.blend4j.galaxy.LibrariesClient 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 4 with LibrariesClient

use of com.github.jmchilton.blend4j.galaxy.LibrariesClient 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)

Example 5 with LibrariesClient

use of com.github.jmchilton.blend4j.galaxy.LibrariesClient in project irida by phac-nml.

the class AnalysisCollectionServiceGalaxyIT method testUploadSequenceFilesSingleSuccess.

/**
 * Tests successfully uploading a single end sequence file to Galaxy and
 * constructing a collection.
 *
 * @throws ExecutionManagerException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testUploadSequenceFilesSingleSuccess() throws ExecutionManagerException {
    History history = new History();
    history.setName("testUploadSequenceFilesSingleSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    Library library = new Library();
    library.setName("testUploadSequenceFilesSingleSuccess");
    Library createdLibrary = librariesClient.createLibrary(library);
    Set<SingleEndSequenceFile> sequenceFiles = Sets.newHashSet(databaseSetupGalaxyITService.setupSequencingObjectInDatabase(1L, sequenceFilePathA));
    Map<Sample, IridaSingleEndSequenceFile> sampleSequenceFiles = new HashMap<>(sequencingObjectService.getUniqueSamplesForSequencingObjects(sequenceFiles));
    Sample sample1 = sampleRepository.findOne(1L);
    CollectionResponse collectionResponse = analysisCollectionServiceGalaxy.uploadSequenceFilesSingleEnd(sampleSequenceFiles, createdHistory, createdLibrary);
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("historyContents should have size 2", 2, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("sequenceFile should have been uploaded to history", contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("dataset collection with name " + INPUTS_SINGLE_NAME + " should have been created in history", contentsMap.containsKey(INPUTS_SINGLE_NAME));
    // verify correct collection has been created
    assertEquals("constructed dataset collection should have been " + DatasetCollectionType.LIST + " but is instead " + collectionResponse.getCollectionType(), DatasetCollectionType.LIST.toString(), collectionResponse.getCollectionType());
    List<CollectionElementResponse> collectionElements = collectionResponse.getElements();
    assertEquals("dataset collection should have only 1 element", 1, collectionElements.size());
    Map<String, CollectionElementResponse> collectionElementsMap = collectionElementsAsMap(collectionElements);
    assertTrue("dataset collection should have an element with the name " + sample1.getSampleName(), collectionElementsMap.containsKey(sample1.getSampleName()));
    CollectionElementResponse sample1Response = collectionElementsMap.get(sample1.getSampleName());
    assertEquals("invalid type for dataset element", HISTORY_DATASET_NAME, sample1Response.getElementType());
}
Also used : CollectionElementResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionElementResponse) 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) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) IridaSingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSingleEndSequenceFile) IridaSingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSingleEndSequenceFile) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

LibrariesClient (com.github.jmchilton.blend4j.galaxy.LibrariesClient)8 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)7 History (com.github.jmchilton.blend4j.galaxy.beans.History)5 Test (org.junit.Test)5 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)3 Library (com.github.jmchilton.blend4j.galaxy.beans.Library)3 LibraryContent (com.github.jmchilton.blend4j.galaxy.beans.LibraryContent)3 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 List (java.util.List)3 IridaSequenceFilePair (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair)2 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)2 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)2 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)2 PreparedWorkflowGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy)2 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)2 GalaxyHistoriesService (ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyHistoriesService)2 GalaxyLibrariesService (ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyLibrariesService)2