Search in sources :

Example 31 with Analysis

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyIT method testGetAnalysisResultsPhylogenomicsSuccess.

/**
 * Tests out successfully getting results for an analysis (phylogenomics).
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IridaWorkflowNotFoundException
 * @throws IOException
 * @throws IridaWorkflowAnalysisTypeException
 * @throws TimeoutException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testGetAnalysisResultsPhylogenomicsSuccess() throws InterruptedException, ExecutionManagerException, IridaWorkflowNotFoundException, IOException, IridaWorkflowAnalysisTypeException, TimeoutException {
    History history = new History();
    history.setName("testGetAnalysisResultsPhylogenomicsSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    ToolsClient toolsClient = localGalaxy.getGalaxyInstanceAdmin().getToolsClient();
    History createdHistory = historiesClient.create(history);
    // upload test outputs
    uploadFileToHistory(sequenceFilePathA, TABLE_NAME, createdHistory.getId(), toolsClient);
    uploadFileToHistory(sequenceFilePathA, MATRIX_NAME, createdHistory.getId(), toolsClient);
    uploadFileToHistory(sequenceFilePathA, TREE_NAME, createdHistory.getId(), toolsClient);
    // wait for history
    Util.waitUntilHistoryComplete(createdHistory.getId(), galaxyHistoriesService, 60);
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(phylogenomicsWorkflowId);
    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, phylogenomicsWorkflowId, false);
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    analysisSubmission.setAnalysisState(AnalysisState.COMPLETING);
    analysisSubmissionRepository.save(analysisSubmission);
    Analysis analysis = analysisWorkspaceService.getAnalysisResults(analysisSubmission);
    assertNotNull("the analysis results were not properly created", analysis);
    assertEquals("the Analysis results class is invalid", AnalysisType.PHYLOGENOMICS, analysis.getAnalysisType());
    assertEquals("the analysis results has an invalid number of output files", 3, analysis.getAnalysisOutputFiles().size());
    assertEquals("the analysis results output file has an invalid name", Paths.get(TABLE_NAME), analysis.getAnalysisOutputFile(TABLE_KEY).getFile().getFileName());
    assertEquals("the analysis results output file has an invalid label", TABLE_NAME, analysis.getAnalysisOutputFile(TABLE_KEY).getLabel());
    assertEquals("the analysis results output file has an invalid name", Paths.get(MATRIX_NAME), analysis.getAnalysisOutputFile(MATRIX_KEY).getFile().getFileName());
    assertEquals("the analysis results output file has an invalid label", MATRIX_NAME, analysis.getAnalysisOutputFile(MATRIX_KEY).getLabel());
    assertEquals("the analysis results output file has an invalid name", Paths.get(TREE_NAME), analysis.getAnalysisOutputFile(TREE_KEY).getFile().getFileName());
    assertEquals("the analysis results output file has an invalid label", TREE_NAME, analysis.getAnalysisOutputFile(TREE_KEY).getLabel());
}
Also used : Path(java.nio.file.Path) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 32 with Analysis

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyIT method testGetAnalysisResultsTestAnalysisDeleteSampleRunningSuccess.

/**
 * Tests out successfully getting results for an analysis (TestAnalysis)
 * when sequencing objects are present, but the sample was deleted while pipeline was running.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IridaWorkflowNotFoundException
 * @throws IOException
 * @throws IridaWorkflowAnalysisTypeException
 * @throws TimeoutException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testGetAnalysisResultsTestAnalysisDeleteSampleRunningSuccess() throws InterruptedException, ExecutionManagerException, IridaWorkflowNotFoundException, IOException, IridaWorkflowAnalysisTypeException, TimeoutException {
    History history = new History();
    history.setName("testGetAnalysisResultsTestAnalysisDeleteSampleRunningSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    ToolsClient toolsClient = localGalaxy.getGalaxyInstanceAdmin().getToolsClient();
    History createdHistory = historiesClient.create(history);
    // upload test outputs
    uploadFileToHistory(sequenceFilePathA, OUTPUT1_NAME, createdHistory.getId(), toolsClient);
    uploadFileToHistory(sequenceFilePathA, OUTPUT2_NAME, createdHistory.getId(), toolsClient);
    // wait for history
    Util.waitUntilHistoryComplete(createdHistory.getId(), galaxyHistoriesService, 60);
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdPairedSingleSample);
    Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
    String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
    Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
    List<Path> paths1 = new ArrayList<>();
    paths1.add(sequenceFilePathA);
    List<Path> paths2 = new ArrayList<>();
    paths2.add(sequenceFilePath2A);
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupPairSubmissionInDatabase(1L, paths1, paths2, referenceFilePath, validWorkflowIdPairedSingleSample, false);
    sampleRepository.delete(1L);
    assertTrue(!sampleService.exists(1L));
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    analysisSubmission.setAnalysisState(AnalysisState.COMPLETING);
    analysisSubmissionRepository.save(analysisSubmission);
    Analysis analysis = analysisWorkspaceService.getAnalysisResults(analysisSubmission);
    assertNotNull("the analysis results were not properly created", analysis);
    assertEquals("the Analysis results class is invalid", Analysis.class, analysis.getClass());
    assertEquals("the analysis results has an invalid number of output files", 2, analysis.getAnalysisOutputFiles().size());
    assertEquals("the analysis results output file has an invalid name", Paths.get(OUTPUT1_NAME), analysis.getAnalysisOutputFile(OUTPUT1_KEY).getFile().getFileName());
    assertEquals("the analysis results output file has an invalid label", OUTPUT1_NAME, analysis.getAnalysisOutputFile(OUTPUT1_KEY).getLabel());
    assertEquals("the analysis results output file has an invalid name", Paths.get(OUTPUT2_NAME), analysis.getAnalysisOutputFile(OUTPUT2_KEY).getFile().getFileName());
    assertEquals("the analysis results output file has an invalid label", OUTPUT2_NAME, analysis.getAnalysisOutputFile(OUTPUT2_KEY).getLabel());
}
Also used : Path(java.nio.file.Path) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ArrayList(java.util.ArrayList) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 33 with Analysis

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyIT method testGetAnalysisResultsTestAnalysisSinglePairedSuccess.

/**
 * Tests out successfully getting results for an analysis (TestAnalysis)
 * consisting of both single and paired sequence reads.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IridaWorkflowNotFoundException
 * @throws IOException
 * @throws IridaWorkflowAnalysisTypeException
 * @throws TimeoutException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testGetAnalysisResultsTestAnalysisSinglePairedSuccess() throws InterruptedException, ExecutionManagerException, IridaWorkflowNotFoundException, IOException, IridaWorkflowAnalysisTypeException, TimeoutException {
    History history = new History();
    history.setName("testGetAnalysisResultsTestAnalysisSinglePairedSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    ToolsClient toolsClient = localGalaxy.getGalaxyInstanceAdmin().getToolsClient();
    History createdHistory = historiesClient.create(history);
    // upload test outputs
    uploadFileToHistory(sequenceFilePathA, OUTPUT1_NAME, createdHistory.getId(), toolsClient);
    uploadFileToHistory(sequenceFilePathA, OUTPUT2_NAME, createdHistory.getId(), toolsClient);
    // wait for history
    Util.waitUntilHistoryComplete(createdHistory.getId(), galaxyHistoriesService, 60);
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdSinglePaired);
    Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
    String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
    Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
    List<Path> paths1 = new ArrayList<>();
    paths1.add(sequenceFilePathA);
    List<Path> paths2 = new ArrayList<>();
    paths2.add(sequenceFilePath2A);
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupSinglePairSubmissionInDatabaseSameSample(1L, paths1, paths2, sequenceFilePath3, referenceFilePath, validWorkflowIdSinglePaired);
    Set<SingleEndSequenceFile> singleFiles = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SingleEndSequenceFile.class);
    Set<SequenceFilePair> pairedFiles = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SequenceFilePair.class);
    assertEquals("invalid number of single end input files", 1, singleFiles.size());
    assertEquals("invalid number of paired end inputs", 1, pairedFiles.size());
    SequenceFilePair submittedSp = pairedFiles.iterator().next();
    Set<SequenceFile> submittedSf = submittedSp.getFiles();
    assertEquals("invalid number of files for paired input", 2, submittedSf.size());
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    analysisSubmission.setAnalysisState(AnalysisState.COMPLETING);
    analysisSubmissionRepository.save(analysisSubmission);
    Analysis analysis = analysisWorkspaceService.getAnalysisResults(analysisSubmission);
    assertNotNull("the analysis results were not properly created", analysis);
    assertEquals("the Analysis results class is invalid", Analysis.class, analysis.getClass());
    assertEquals("the analysis results has an invalid number of output files", 2, analysis.getAnalysisOutputFiles().size());
    assertEquals("the analysis results output file has an invalid name", Paths.get(OUTPUT1_NAME), analysis.getAnalysisOutputFile(OUTPUT1_KEY).getFile().getFileName());
    assertEquals("the analysis results output file has an invalid label", OUTPUT1_NAME, analysis.getAnalysisOutputFile(OUTPUT1_KEY).getLabel());
    assertEquals("the analysis results output file has an invalid name", Paths.get(OUTPUT2_NAME), analysis.getAnalysisOutputFile(OUTPUT2_KEY).getFile().getFileName());
    assertEquals("the analysis results output file has an invalid label", OUTPUT2_NAME, analysis.getAnalysisOutputFile(OUTPUT2_KEY).getLabel());
}
Also used : Path(java.nio.file.Path) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ArrayList(java.util.ArrayList) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 34 with Analysis

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyTest method testGetAnalysisResultsSuccessNoSample.

/**
 * Tests successfully getting analysis results from Galaxy where there's no
 * sample associated with the sequence files (no label is prefixed to output
 * file name).
 *
 * @throws IridaWorkflowNotFoundException
 * @throws IOException
 * @throws ExecutionManagerException
 * @throws IridaWorkflowAnalysisTypeException
 */
@Test
public void testGetAnalysisResultsSuccessNoSample() throws IridaWorkflowNotFoundException, IridaWorkflowAnalysisTypeException, ExecutionManagerException, IOException {
    submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(pairedInputFiles).referenceFile(referenceFile).build();
    submission.setRemoteWorkflowId(WORKFLOW_ID);
    submission.setRemoteAnalysisId(HISTORY_ID);
    when(iridaWorkflowsService.getIridaWorkflow(workflowId)).thenReturn(iridaWorkflowSingle);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output1Filename, HISTORY_ID)).thenReturn(output1Dataset);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output2Filename, HISTORY_ID)).thenReturn(output2Dataset);
    Analysis analysis = workflowPreparation.getAnalysisResults(submission);
    assertNotNull("analysis is not valid", analysis);
    assertEquals("invalid number of output files", 2, analysis.getAnalysisOutputFiles().size());
    assertEquals("missing output file for analysis", Paths.get("output1.txt"), analysis.getAnalysisOutputFile("output1").getFile().getFileName());
    // labels should now not have sample associated with them.
    assertEquals("missing label for analysis output file", "output1.txt", analysis.getAnalysisOutputFile("output1").getLabel());
    assertEquals("missing output file for analysis", "output2.txt", analysis.getAnalysisOutputFile("output2").getLabel());
    verify(galaxyHistoriesService).getDatasetForFileInHistory("output1.txt", HISTORY_ID);
    verify(galaxyHistoriesService).getDatasetForFileInHistory("output2.txt", HISTORY_ID);
}
Also used : Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) Test(org.junit.Test)

Example 35 with Analysis

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyTest method testGetAnalysisResultsSuccessPairedEnd.

/**
 * Tests successfully getting analysis results from Galaxy with paired end
 * input files.
 *
 * @throws IridaWorkflowNotFoundException
 * @throws IOException
 * @throws ExecutionManagerException
 * @throws IridaWorkflowAnalysisTypeException
 */
@Test
public void testGetAnalysisResultsSuccessPairedEnd() throws IridaWorkflowNotFoundException, IridaWorkflowAnalysisTypeException, ExecutionManagerException, IOException {
    Set<SequenceFilePair> pairedFiles = Sets.newHashSet(sampleSequenceFilePairMap.values());
    submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(pairedInputFiles).referenceFile(referenceFile).build();
    submission.setRemoteWorkflowId(WORKFLOW_ID);
    submission.setRemoteAnalysisId(HISTORY_ID);
    when(iridaWorkflowsService.getIridaWorkflow(workflowId)).thenReturn(iridaWorkflowSingle);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output1Filename, HISTORY_ID)).thenReturn(output1Dataset);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output2Filename, HISTORY_ID)).thenReturn(output2Dataset);
    when(sequencingObjectService.getSequencingObjectsForAnalysisSubmission(submission)).thenReturn(Sets.newHashSet(pairedFiles));
    when(sequencingObjectService.getUniqueSamplesForSequencingObjects(pairedFiles)).thenReturn(sampleSequenceFilePairMap);
    Analysis analysis = workflowPreparation.getAnalysisResults(submission);
    assertNotNull("analysis is not valid", analysis);
    assertEquals("invalid number of output files", 2, analysis.getAnalysisOutputFiles().size());
    assertEquals("missing output file for analysis", Paths.get("output1.txt"), analysis.getAnalysisOutputFile("output1").getFile().getFileName());
    assertEquals("missing label for analysis output file", "SampleB-output1.txt", analysis.getAnalysisOutputFile("output1").getLabel());
    assertEquals("missing output file for analysis", "SampleB-output2.txt", analysis.getAnalysisOutputFile("output2").getLabel());
    verify(galaxyHistoriesService).getDatasetForFileInHistory("output1.txt", HISTORY_ID);
    verify(galaxyHistoriesService).getDatasetForFileInHistory("output2.txt", HISTORY_ID);
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) Test(org.junit.Test)

Aggregations

Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)41 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)30 Test (org.junit.Test)28 AnalysisOutputFile (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)21 WithMockUser (org.springframework.security.test.context.support.WithMockUser)19 Path (java.nio.file.Path)17 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)14 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)12 ToolExecution (ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution)12 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)11 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)9 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)7 ToolsClient (com.github.jmchilton.blend4j.galaxy.ToolsClient)7 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)7 History (com.github.jmchilton.blend4j.galaxy.beans.History)7 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)7 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)6 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)5 Scanner (java.util.Scanner)5 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)4