Search in sources :

Example 56 with SingleEndSequenceFile

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

the class AnalysisWorkspaceServiceGalaxyTest method testGetAnalysisResultsSuccessSingleEnd.

/**
 * Tests successfully getting analysis results from Galaxy with single end
 * input files.
 *
 * @throws IridaWorkflowNotFoundException
 * @throws IOException
 * @throws ExecutionManagerException
 * @throws IridaWorkflowAnalysisTypeException
 */
@Test
public void testGetAnalysisResultsSuccessSingleEnd() throws IridaWorkflowNotFoundException, IridaWorkflowAnalysisTypeException, ExecutionManagerException, IOException {
    Set<SingleEndSequenceFile> singleFiles = Sets.newHashSet(sampleSingleSequenceFileMap.values());
    submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(singleInputFiles).referenceFile(referenceFile).build();
    submission.setRemoteWorkflowId(WORKFLOW_ID);
    submission.setRemoteAnalysisId(HISTORY_ID);
    when(sequencingObjectService.getSequencingObjectsForAnalysisSubmission(submission)).thenReturn(Sets.newHashSet(singleFiles));
    when(iridaWorkflowsService.getIridaWorkflow(workflowId)).thenReturn(iridaWorkflowSingle);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output1Filename, HISTORY_ID)).thenReturn(output1Dataset);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output2Filename, HISTORY_ID)).thenReturn(output2Dataset);
    when(sequencingObjectService.getUniqueSamplesForSequencingObjects(singleFiles)).thenReturn(sampleSingleSequenceFileMap);
    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", "SampleA-output1.txt", analysis.getAnalysisOutputFile("output1").getLabel());
    assertEquals("missing output file for analysis", "SampleA-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) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 57 with SingleEndSequenceFile

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

the class ProjectSamplesControllerTest method testDownloadSamples.

@Test
public void testDownloadSamples() throws IOException {
    Project project = TestDataFactory.constructProject();
    Sample sample = TestDataFactory.constructSample();
    MockHttpServletResponse response = new MockHttpServletResponse();
    Path path = Paths.get(FILE_PATH);
    SequenceFile file = new SequenceFile(path);
    ImmutableList<SampleSequencingObjectJoin> filejoin = ImmutableList.of(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
    when(projectService.read(project.getId())).thenReturn(project);
    when(sampleService.readMultiple(ImmutableList.of(sample.getId()))).thenReturn(ImmutableList.of(sample));
    when(sequencingObjectService.getSequencingObjectsForSample(sample)).thenReturn(filejoin);
    controller.downloadSamples(project.getId(), ImmutableList.of(sample.getId()), response);
    verify(projectService).read(project.getId());
    verify(sampleService).readMultiple(ImmutableList.of(sample.getId()));
    verify(sequencingObjectService).getSequencingObjectsForSample(sample);
    assertTrue("Response should contain a \"Content-Disposition\" header.", response.containsHeader("Content-Disposition"));
    assertEquals("Content-Disposition should include the file name", "attachment; filename=\"test_project.zip\"", response.getHeader("Content-Disposition"));
    try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(response.getContentAsByteArray()))) {
        ZipEntry nextEntry = zipStream.getNextEntry();
        String fileName = nextEntry.getName();
        assertTrue("incorrect file in zip stream: " + file.getFileName(), fileName.endsWith(file.getFileName()));
    }
}
Also used : Path(java.nio.file.Path) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ZipInputStream(java.util.zip.ZipInputStream) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ByteArrayInputStream(java.io.ByteArrayInputStream) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ZipEntry(java.util.zip.ZipEntry) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 58 with SingleEndSequenceFile

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

the class ProjectSamplesControllerTest method testDownloadSamplesWithSameName.

@Test
public void testDownloadSamplesWithSameName() throws IOException {
    Project project = TestDataFactory.constructProject();
    Sample sample = TestDataFactory.constructSample();
    MockHttpServletResponse response = new MockHttpServletResponse();
    Path path = Paths.get(FILE_PATH);
    SequenceFile file = new SequenceFile(path);
    ImmutableList<SampleSequencingObjectJoin> filejoin = ImmutableList.of(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)), new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)), new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
    when(projectService.read(project.getId())).thenReturn(project);
    when(sampleService.readMultiple(ImmutableList.of(sample.getId()))).thenReturn(ImmutableList.of(sample));
    when(sequencingObjectService.getSequencingObjectsForSample(sample)).thenReturn(filejoin);
    controller.downloadSamples(project.getId(), ImmutableList.of(sample.getId()), response);
    verify(projectService).read(project.getId());
    verify(sampleService).readMultiple(ImmutableList.of(sample.getId()));
    verify(sequencingObjectService).getSequencingObjectsForSample(sample);
    assertTrue("Response should contain a \"Content-Disposition\" header.", response.containsHeader("Content-Disposition"));
    assertEquals("Content-Disposition should include the file name", "attachment; filename=\"test_project.zip\"", response.getHeader("Content-Disposition"));
    try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(response.getContentAsByteArray()))) {
        Set<String> names = new HashSet<>();
        ZipEntry nextEntry = zipStream.getNextEntry();
        while (nextEntry != null) {
            names.add(nextEntry.getName());
            nextEntry = zipStream.getNextEntry();
        }
        assertEquals("should be 3 unique filenames", 3, names.size());
    }
}
Also used : Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ZipEntry(java.util.zip.ZipEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ZipInputStream(java.util.zip.ZipInputStream) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 59 with SingleEndSequenceFile

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

the class SamplesControllerTest method testUploadSequenceFilePairsAndSingle.

@Test
public void testUploadSequenceFilePairsAndSingle() throws IOException {
    Sample sample = TestDataFactory.constructSample();
    when(sampleService.read(sample.getId())).thenReturn(sample);
    List<MultipartFile> fileList = createMultipartFileList(ArrayUtils.addAll(MULTIPARTFILE_PATHS, MULTIPARTFILE_PAIR_PATHS));
    ArgumentCaptor<SequencingObject> sequenceFileArgumentCaptor = ArgumentCaptor.forClass(SequencingObject.class);
    HttpServletResponse response = new MockHttpServletResponse();
    controller.uploadSequenceFiles(sample.getId(), fileList, response);
    assertEquals("Response is ok", HttpServletResponse.SC_OK, response.getStatus());
    verify(sequencingObjectService, times(3)).createSequencingObjectInSample(sequenceFileArgumentCaptor.capture(), eq(sample));
    List<SequencingObject> allValues = sequenceFileArgumentCaptor.getAllValues();
    assertEquals("Should have created 2 single end sequence files", 2, allValues.stream().filter(o -> o instanceof SingleEndSequenceFile).count());
    assertEquals("Should have created 1 file pair", 1, allValues.stream().filter(o -> o instanceof SequenceFilePair).count());
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 60 with SingleEndSequenceFile

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

the class SamplesControllerTest method testGetSampleFilesNoAccess.

@SuppressWarnings("unchecked")
@Test
public void testGetSampleFilesNoAccess() throws IOException {
    ExtendedModelMap model = new ExtendedModelMap();
    Long sampleId = 1L;
    Sample sample = new Sample();
    SequenceFile file = new SequenceFile(Paths.get("/tmp"));
    file.setId(2L);
    Project project = new Project();
    List<SampleSequencingObjectJoin> files = Lists.newArrayList(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class)).thenReturn(files);
    when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(false);
    when(projectService.getProjectsForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
    String sampleFiles = controller.getSampleFilesWithoutProject(model, sampleId);
    assertEquals(SamplesController.SAMPLE_FILES_PAGE, sampleFiles);
    assertFalse((boolean) model.get(SamplesController.MODEL_ATTR_CAN_MANAGE_SAMPLE));
    verify(sampleService).read(sampleId);
    verify(sequencingObjectService).getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
    verify(sequencingObjectService).getSequencesForSampleOfType(sample, SequenceFilePair.class);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Aggregations

SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)99 Test (org.junit.Test)72 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)61 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)44 Path (java.nio.file.Path)33 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)24 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)22 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Project (ca.corefacility.bioinformatics.irida.model.project.Project)17 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)17 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)12 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)11 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)10 ArrayList (java.util.ArrayList)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)8 History (com.github.jmchilton.blend4j.galaxy.beans.History)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 ModelMap (org.springframework.ui.ModelMap)8