Search in sources :

Example 6 with LibrariesClient

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

the class AnalysisWorkspaceServiceGalaxyIT method setup.

/**
 * Sets up variables for testing.
 *
 * @throws URISyntaxException
 * @throws IOException
 * @throws IridaWorkflowLoadException
 */
@Before
public void setup() throws URISyntaxException, IOException, IridaWorkflowLoadException {
    Assume.assumeFalse(WindowsPlatformCondition.isWindows());
    Path sequenceFilePathReal = Paths.get(DatabaseSetupGalaxyITService.class.getResource("testData1.fastq").toURI());
    Path referenceFilePathReal = Paths.get(DatabaseSetupGalaxyITService.class.getResource("testReference.fasta").toURI());
    Path tempDir = Files.createTempDirectory(rootTempDirectory, "workspaceServiceGalaxyTest");
    sequenceFilePathA = tempDir.resolve("testDataA_R1_001.fastq");
    Files.copy(sequenceFilePathReal, sequenceFilePathA, StandardCopyOption.REPLACE_EXISTING);
    sequenceFilePath2A = tempDir.resolve("testDataA_R2_001.fastq");
    Files.copy(sequenceFilePathReal, sequenceFilePath2A, StandardCopyOption.REPLACE_EXISTING);
    sequenceFilePathB = tempDir.resolve("testDataB_R1_001.fastq");
    Files.copy(sequenceFilePathReal, sequenceFilePathB, StandardCopyOption.REPLACE_EXISTING);
    sequenceFilePath2B = tempDir.resolve("testDataB_R2_001.fastq");
    Files.copy(sequenceFilePathReal, sequenceFilePath2B, StandardCopyOption.REPLACE_EXISTING);
    sequenceFilePath3 = tempDir.resolve("testData3_R1_001.fastq");
    Files.copy(sequenceFilePathReal, sequenceFilePath3, StandardCopyOption.REPLACE_EXISTING);
    referenceFilePath = Files.createTempFile("testReference", ".fasta");
    Files.delete(referenceFilePath);
    Files.copy(referenceFilePathReal, referenceFilePath);
    singleFileSet = Sets.newHashSet(new SingleEndSequenceFile(new SequenceFile(sequenceFilePathA)));
    GalaxyInstance galaxyInstanceAdmin = localGalaxy.getGalaxyInstanceAdmin();
    HistoriesClient historiesClient = galaxyInstanceAdmin.getHistoriesClient();
    ToolsClient toolsClient = galaxyInstanceAdmin.getToolsClient();
    LibrariesClient librariesClient = galaxyInstanceAdmin.getLibrariesClient();
    GalaxyLibrariesService galaxyLibrariesService = new GalaxyLibrariesService(librariesClient, LIBRARY_POLLING_TIME, LIBRARY_TIMEOUT, 1);
    galaxyHistoriesService = new GalaxyHistoriesService(historiesClient, toolsClient, galaxyLibrariesService);
    pairSequenceFiles1A = new ArrayList<>();
    pairSequenceFiles1A.add(sequenceFilePathA);
    pairSequenceFiles2A = new ArrayList<>();
    pairSequenceFiles2A.add(sequenceFilePath2A);
    pairSequenceFiles1AB = new ArrayList<>();
    pairSequenceFiles1AB.add(sequenceFilePathA);
    pairSequenceFiles1AB.add(sequenceFilePathB);
    pairSequenceFiles2AB = new ArrayList<>();
    pairSequenceFiles2AB.add(sequenceFilePath2A);
    pairSequenceFiles2AB.add(sequenceFilePath2B);
}
Also used : Path(java.nio.file.Path) GalaxyHistoriesService(ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyHistoriesService) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) GalaxyInstance(com.github.jmchilton.blend4j.galaxy.GalaxyInstance) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) GalaxyLibrariesService(ca.corefacility.bioinformatics.irida.pipeline.upload.galaxy.GalaxyLibrariesService) Before(org.junit.Before)

Example 7 with LibrariesClient

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

the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesPairSuccess.

/**
 * Tests out successfully preparing paired workflow input files for
 * execution.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IOException
 * @throws IridaWorkflowException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesPairSuccess() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
    History history = new History();
    history.setName("testPrepareAnalysisFilesPairSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdPaired);
    Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
    String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
    Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupPairSubmissionInDatabase(1L, pairSequenceFiles1A, pairSequenceFiles2A, referenceFilePath, validWorkflowIdPaired, false);
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
    assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
    WorkflowInputsGalaxy workflowInputsGalaxy = preparedWorkflow.getWorkflowInputs();
    assertNotNull("the returned workflow inputs should not be null", workflowInputsGalaxy);
    assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
    // verify correct library is created
    List<LibraryContent> libraryContents = librariesClient.getLibraryContents(preparedWorkflow.getRemoteDataId());
    Map<String, List<LibraryContent>> libraryContentsMap = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
    assertFalse("the returned library should exist in Galaxy", libraryContentsMap.isEmpty());
    String sequenceFile1ALibraryName = "/" + sequenceFilePathA.getFileName().toString();
    String sequenceFile2ALibraryName = "/" + sequenceFilePath2A.getFileName().toString();
    assertEquals("the returned library does not contain the correct number of elements", 3, libraryContentsMap.size());
    assertTrue("the returned library does not contain a root folder", libraryContentsMap.containsKey("/"));
    assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFile1ALibraryName));
    assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFile1ALibraryName).size());
    assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFile2ALibraryName));
    assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFile2ALibraryName).size());
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("the created history has an invalid number of elements", 4, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("the created history should contain the file " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("the created history should contain the file " + sequenceFilePath2A.toFile().getName(), contentsMap.containsKey(sequenceFilePath2A.toFile().getName()));
    assertTrue("the created history should contain the file " + referenceFilePath.toFile().getName(), contentsMap.containsKey(referenceFilePath.toFile().getName()));
    assertTrue("the created history should contain the collection with name " + INPUTS_PAIRED_NAME, contentsMap.containsKey(INPUTS_PAIRED_NAME));
    // make sure workflow inputs contains correct information
    Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
    assertEquals("the created workflow inputs has an invalid number of elements", 2, workflowInputsMap.size());
}
Also used : Path(java.nio.file.Path) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowInput(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 8 with LibrariesClient

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

the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesSingleSuccess.

/**
 * Tests out successfully preparing single workflow input files for
 * execution.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IOException
 * @throws IridaWorkflowException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesSingleSuccess() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
    History history = new History();
    history.setName("testPrepareAnalysisFilesSingleSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdSingle);
    Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
    String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
    Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupSubmissionInDatabase(1L, sequenceFilePathA, referenceFilePath, validWorkflowIdSingle, false);
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
    assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
    assertNotNull("the returned workflow inputs should not be null", preparedWorkflow.getWorkflowInputs());
    assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
    // verify correct library is created
    List<LibraryContent> libraryContents = librariesClient.getLibraryContents(preparedWorkflow.getRemoteDataId());
    Map<String, List<LibraryContent>> libraryContentsMap = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
    assertFalse("the returned library should exist in Galaxy", libraryContentsMap.isEmpty());
    String sequenceFileALibraryName = "/" + sequenceFilePathA.getFileName().toString();
    assertEquals("the returned library does not contain the correct number of elements", 2, libraryContentsMap.size());
    assertTrue("the returned library does not contain a root folder", libraryContentsMap.containsKey("/"));
    assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFileALibraryName));
    assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFileALibraryName).size());
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("the created history should contain 3 entries", 3, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("the created history should contain the file " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("the created history should contain the file " + referenceFilePath.toFile().getName(), contentsMap.containsKey(referenceFilePath.toFile().getName()));
    assertTrue("the created history should contain the collection with name " + INPUTS_SINGLE_NAME, contentsMap.containsKey(INPUTS_SINGLE_NAME));
    // make sure workflow inputs contains correct information
    Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
    assertEquals("the created workflow inputs has an invalid number of elements", 2, workflowInputsMap.size());
}
Also used : Path(java.nio.file.Path) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowInput(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput) 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