use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class RESTSequencingRunSequenceFilesController method addSequenceFileToMiseqRun.
/**
* Add a relationship between a {@link MiseqRun} and a {@link SequenceFile}.
*
* @param sequencingrunId
* the id of the run to add sequence file to.
* @param representation
* the JSON key-value pair that contains the identifier for the
* sequenceFile
* @param response
* a reference to the response.
* @return a response indicating that the collection was modified.
*/
@RequestMapping(value = "/api/sequencingrun/{sequencingrunId}/sequenceFiles", method = RequestMethod.POST)
public ModelMap addSequenceFileToMiseqRun(@PathVariable Long sequencingrunId, @RequestBody Map<String, String> representation, HttpServletResponse response) {
ModelMap modelMap = new ModelMap();
String stringId = representation.get(SEQUENCEFILE_ID_KEY);
long seqId = Long.parseLong(stringId);
// first, get the SequenceFile
SequencingObject sequencingObject = sequencingObjectService.read(seqId);
// then, get the miseq run
SequencingRun run = miseqRunService.read(sequencingrunId);
// then add the user to the project with the specified role.
miseqRunService.addSequencingObjectToSequencingRun(run, sequencingObject);
MiseqRun miseqRun;
if (run instanceof MiseqRun) {
miseqRun = (MiseqRun) run;
} else {
throw new IllegalArgumentException("The sequencing run ID must correspond to a a valid MiSeq sequence");
}
Link seqFileLocation = linkTo(RESTSequencingRunController.class).slash(sequencingrunId).slash("sequenceFiles").slash(seqId).withSelfRel();
miseqRun.add(seqFileLocation);
modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, miseqRun);
response.addHeader(HttpHeaders.LOCATION, seqFileLocation.getHref());
response.setStatus(HttpStatus.CREATED.value());
return modelMap;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject 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.SequencingObject 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.SequencingObject in project irida by phac-nml.
the class DatabaseSetupGalaxyITService method setupSinglePairSubmissionInDatabaseDifferentSample.
/**
* Sets up an {@link AnalysisSubmission} with a list of paired sequence
* files and a single sequence file under a different sample and saves all
* dependencies in database.
*
* @param sampleIdPaired
* The id of the sample to associate with the paired sequence
* files.
* @param sampleIdSingle
* The id of the sample to associate with the single 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 singleSequenceFile
* A single sequence file to add.
* @param referenceFilePath
* The path to an input reference file for this test.
* @param iridaWorkflowId
* The id of an irida workflow.
* @return An {@link AnalysisSubmission} which has been saved to the
* database.
*/
public AnalysisSubmission setupSinglePairSubmissionInDatabaseDifferentSample(long sampleIdPaired, long sampleIdSingle, List<Path> sequenceFilePaths1, List<Path> sequenceFilePaths2, Path singleSequenceFile, Path referenceFilePath, UUID iridaWorkflowId) {
SingleEndSequenceFile singleEndFile = (SingleEndSequenceFile) setupSequencingObjectInDatabase(sampleIdSingle, singleSequenceFile).get(0);
List<SequenceFilePair> sequenceFilePairs = setupSampleSequenceFileInDatabase(sampleIdPaired, sequenceFilePaths1, sequenceFilePaths2);
Set<SequencingObject> inputs = Sets.newHashSet(sequenceFilePairs);
inputs.add(singleEndFile);
ReferenceFile referenceFile = referenceFileRepository.save(new ReferenceFile(referenceFilePath));
AnalysisSubmission submission = AnalysisSubmission.builder(iridaWorkflowId).name("paired analysis").inputFiles(inputs).referenceFile(referenceFile).build();
analysisSubmissionService.create(submission);
return analysisSubmissionRepository.findOne(submission.getId());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class SequencingRunControllerTest method testGetFilesPage.
@SuppressWarnings("rawtypes")
@Test
public void testGetFilesPage() throws IOException {
Long runId = 1L;
ExtendedModelMap model = new ExtendedModelMap();
SequencingRun sequencingRunEntity = new MiseqRun(SequencingRun.LayoutType.PAIRED_END, "");
ImmutableSet<SequencingObject> files = ImmutableSet.of(new SingleEndSequenceFile(new SequenceFile()));
when(sequencingRunService.read(runId)).thenReturn(sequencingRunEntity);
when(objectService.getSequencingObjectsForSequencingRun(sequencingRunEntity)).thenReturn(files);
String filesPage = controller.getFilesPage(runId, model);
assertEquals(SequencingRunController.FILES_VIEW, filesPage);
assertFalse(((Collection) model.get("sequencingObjects")).isEmpty());
assertEquals(sequencingRunEntity, model.get("run"));
assertTrue(model.containsKey("fileCount"));
verify(sequencingRunService).read(runId);
verify(objectService).getSequencingObjectsForSequencingRun(sequencingRunEntity);
}
Aggregations