use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.
the class AnalysisWorkspaceServiceGalaxyTest method testPrepareAnalysisFilesSinglePairedSuccess.
/**
* Tests out successfully to preparing an analysis with both single and
* paired files
*
* @throws ExecutionManagerException
* @throws IridaWorkflowException
*/
@SuppressWarnings("unchecked")
@Test
public void testPrepareAnalysisFilesSinglePairedSuccess() throws ExecutionManagerException, IridaWorkflowException {
Set<SingleEndSequenceFile> singleFiles = Sets.newHashSet(sampleSingleSequenceFileMap.values());
Set<SequenceFilePair> pairedFiles = Sets.newHashSet(sampleSequenceFilePairMap.values());
Set<SequencingObject> joinedInput = Sets.newHashSet(singleFiles);
joinedInput.addAll(pairedFiles);
submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(joinedInput).referenceFile(referenceFile).build();
submission.setRemoteAnalysisId(HISTORY_ID);
submission.setRemoteWorkflowId(WORKFLOW_ID);
when(sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SingleEndSequenceFile.class)).thenReturn(singleFiles);
when(sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SequenceFilePair.class)).thenReturn(pairedFiles);
when(iridaWorkflowsService.getIridaWorkflow(workflowId)).thenReturn(iridaWorkflowSinglePaired);
when(galaxyHistoriesService.findById(HISTORY_ID)).thenReturn(workflowHistory);
when(galaxyLibrariesService.buildEmptyLibrary(any(GalaxyProjectName.class))).thenReturn(workflowLibrary);
when(sequencingObjectService.getUniqueSamplesForSequencingObjects(singleFiles)).thenReturn(sampleSingleSequenceFileMap);
when(sequencingObjectService.getUniqueSamplesForSequencingObjects(pairedFiles)).thenReturn(sampleSequenceFilePairMap);
when(galaxyHistoriesService.fileToHistory(refFile, InputFileType.FASTA, workflowHistory)).thenReturn(refDataset);
when(galaxyWorkflowService.getWorkflowDetails(WORKFLOW_ID)).thenReturn(workflowDetails);
when(analysisParameterServiceGalaxy.prepareAnalysisParameters(any(Map.class), any(IridaWorkflow.class))).thenReturn(new WorkflowInputsGalaxy(new WorkflowInputs()));
when(galaxyWorkflowService.getWorkflowInputId(workflowDetails, SEQUENCE_FILE_SINGLE_LABEL)).thenReturn(SEQUENCE_FILE_SINGLE_ID);
when(galaxyWorkflowService.getWorkflowInputId(workflowDetails, SEQUENCE_FILE_PAIRED_LABEL)).thenReturn(SEQUENCE_FILE_PAIRED_ID);
when(galaxyWorkflowService.getWorkflowInputId(workflowDetails, REFERENCE_FILE_LABEL)).thenReturn(REFERENCE_FILE_ID);
when(analysisCollectionServiceGalaxy.uploadSequenceFilesSingleEnd(any(Map.class), eq(workflowHistory), eq(workflowLibrary))).thenReturn(collectionResponseSingle);
when(analysisCollectionServiceGalaxy.uploadSequenceFilesPaired(any(Map.class), eq(workflowHistory), eq(workflowLibrary))).thenReturn(collectionResponsePaired);
PreparedWorkflowGalaxy preparedWorkflow = workflowPreparation.prepareAnalysisFiles(submission);
assertEquals("preparedWorflow history id not equal to " + HISTORY_ID, HISTORY_ID, preparedWorkflow.getRemoteAnalysisId());
assertEquals("preparedWorkflow library is invalid", LIBRARY_ID, preparedWorkflow.getRemoteDataId());
assertNotNull("workflowInputs in preparedWorkflow is null", preparedWorkflow.getWorkflowInputs());
Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
assertEquals("invalid number of workflow inputs", 3, workflowInputsMap.size());
assertTrue("workflow inputs should contain reference entry", workflowInputsMap.containsKey(REFERENCE_FILE_ID));
assertTrue("workflow inputs should contain sequence file single entry", workflowInputsMap.containsKey(SEQUENCE_FILE_SINGLE_ID));
assertTrue("workflow inputs should contain sequence file paired entry", workflowInputsMap.containsKey(SEQUENCE_FILE_PAIRED_ID));
verify(analysisCollectionServiceGalaxy).uploadSequenceFilesSingleEnd(any(Map.class), any(History.class), any(Library.class));
verify(analysisCollectionServiceGalaxy).uploadSequenceFilesPaired(any(Map.class), any(History.class), any(Library.class));
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.
the class SamplesControllerTest method testUploadSequenceFilePairs.
@Test
public void testUploadSequenceFilePairs() throws IOException {
Sample sample = TestDataFactory.constructSample();
when(sampleService.read(sample.getId())).thenReturn(sample);
List<MultipartFile> fileList = createMultipartFileList(MULTIPARTFILE_PAIR_PATHS);
ArgumentCaptor<SequenceFilePair> sequenceFileArgumentCaptor = ArgumentCaptor.forClass(SequenceFilePair.class);
HttpServletResponse response = new MockHttpServletResponse();
controller.uploadSequenceFiles(sample.getId(), fileList, response);
assertEquals("Response is ok", HttpServletResponse.SC_OK, response.getStatus());
verify(sequencingObjectService).createSequencingObjectInSample(sequenceFileArgumentCaptor.capture(), eq(sample));
assertEquals("Should have the correct file name", "pair_test_R1_001.fastq", sequenceFileArgumentCaptor.getValue().getForwardSequenceFile().getLabel());
assertEquals("Should have the correct file name", "pair_test_R2_001.fastq", sequenceFileArgumentCaptor.getValue().getReverseSequenceFile().getLabel());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair 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.SequenceFilePair in project irida by phac-nml.
the class ReadAnalysisSubmissionPermissionTest method testPermitSISTR.
@Test
public void testPermitSISTR() {
String username = "aaron";
User u = new User();
u.setUsername(username);
Authentication auth = new UsernamePasswordAuthenticationToken("aaron", "password1");
Project p = new Project();
SequenceFilePair pair = new SequenceFilePair();
AnalysisSubmission analysisSubmission = AnalysisSubmission.builder(workflowId).name("test").inputFiles(ImmutableSet.of(pair)).referenceFile(referenceFile).build();
analysisSubmission.setSubmitter(new User());
pair.setSistrTyping(analysisSubmission);
/*
* testing that analysis is shared with a project that user isn't a part
* of
*/
when(pasRepository.getProjectsForSubmission(analysisSubmission)).thenReturn(ImmutableList.of(new ProjectAnalysisSubmissionJoin(p, analysisSubmission)));
when(readProjectPermission.customPermissionAllowed(auth, p)).thenReturn(false);
when(userRepository.loadUserByUsername(username)).thenReturn(u);
when(analysisSubmissionRepository.findOne(1L)).thenReturn(analysisSubmission);
when(seqObjectPermission.customPermissionAllowed(auth, pair)).thenReturn(true);
when(sequencingObjectRepository.findSequencingObjectsForAnalysisSubmission(analysisSubmission)).thenReturn(ImmutableSet.of(pair));
assertTrue("permission should be granted.", readAnalysisSubmissionPermission.isAllowed(auth, 1L));
verify(userRepository).loadUserByUsername(username);
verify(analysisSubmissionRepository).findOne(1L);
verify(seqObjectPermission).customPermissionAllowed(auth, pair);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.
the class DatabaseSetupGalaxyITService method setupPairSubmissionInDatabase.
/**
* Sets up an {@link AnalysisSubmission} with a list of paired sequence
* files and saves all dependencies in database.
*
* @param sampleId
* The id of the sample to associate with the given sequence
* file.
* @param sequenceFilePaths1
* A list of paths for the first part of the pair.
* @param sequenceFilePaths2
* A list of paths for the second part of the pair. The path to
* an input sequence file for this test.
* @param referenceFilePath
* The path to an input reference file for this test.
* @param parameters
* The input parameters.
* @param iridaWorkflowId
* The id of an irida workflow.
* @param state
* {@link AnalysisState} of the submission
* @return An {@link AnalysisSubmission} which has been saved to the
* database.
*/
public AnalysisSubmission setupPairSubmissionInDatabase(long sampleId, List<Path> sequenceFilePaths1, List<Path> sequenceFilePaths2, Path referenceFilePath, Map<String, String> parameters, UUID iridaWorkflowId, AnalysisState state) {
List<SequenceFilePair> sequenceFilePairs = setupSampleSequenceFileInDatabase(sampleId, sequenceFilePaths1, sequenceFilePaths2);
ReferenceFile referenceFile = referenceFileRepository.save(new ReferenceFile(referenceFilePath));
AnalysisSubmission submission = AnalysisSubmission.builder(iridaWorkflowId).name("paired analysis").inputFiles(Sets.newHashSet(sequenceFilePairs)).referenceFile(referenceFile).inputParameters(parameters).build();
submission.setAnalysisState(state);
analysisSubmissionService.create(submission);
return analysisSubmissionRepository.findOne(submission.getId());
}
Aggregations