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);
}
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()));
}
}
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());
}
}
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());
}
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);
}
Aggregations