Search in sources :

Example 6 with SequencingObject

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

the class CoverageFileProcessorTest method testBadCoverage.

@Test
public void testBadCoverage() {
    Project p = new Project();
    p.setGenomeSize(100L);
    p.setMinimumCoverage(5);
    SequenceFile file = new SequenceFile();
    SequencingObject o = new SingleEndSequenceFile(file);
    AnalysisFastQC fqc = mock(AnalysisFastQC.class);
    Long baseCount = 300L;
    when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
    when(fqc.getTotalBases()).thenReturn(baseCount);
    processor.process(o);
    ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
    verify(qcEntryRepository, times(0)).delete(any(QCEntry.class));
    verify(qcEntryRepository).save(qcCaptor.capture());
    CoverageQCEntry qc = qcCaptor.getValue();
    qc.addProjectSettings(p);
    assertEquals("should show 3 times coverage", 3, qc.getCoverage());
    assertEquals("should be bad coverage", QCEntryStatus.NEGATIVE, qc.getStatus());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 7 with SequencingObject

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

the class CoverageFileProcessorTest method testRemoveExistingEntry.

@Test
public void testRemoveExistingEntry() {
    Project p = new Project();
    p.setGenomeSize(100L);
    p.setMinimumCoverage(2);
    SequenceFile file = new SequenceFile();
    SequencingObject o = new SingleEndSequenceFile(file);
    AnalysisFastQC fqc = mock(AnalysisFastQC.class);
    Long baseCount = 300L;
    QCEntry existingQc = new CoverageQCEntry();
    o.setQcEntries(Sets.newHashSet(existingQc));
    when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
    when(fqc.getTotalBases()).thenReturn(baseCount);
    processor.process(o);
    ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
    verify(qcEntryRepository).delete(existingQc);
    verify(qcEntryRepository).save(qcCaptor.capture());
    CoverageQCEntry qc = qcCaptor.getValue();
    qc.addProjectSettings(p);
    assertEquals("should show 3 times coverage", 3, qc.getCoverage());
    assertEquals("should be positive coverage", QCEntryStatus.POSITIVE, qc.getStatus());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 8 with SequencingObject

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

the class CoverageFileProcessorTest method testGoodCoverage.

@Test
public void testGoodCoverage() {
    Project p = new Project();
    p.setGenomeSize(100L);
    p.setMinimumCoverage(2);
    SequenceFile file = new SequenceFile();
    SequencingObject o = new SingleEndSequenceFile(file);
    AnalysisFastQC fqc = mock(AnalysisFastQC.class);
    Long baseCount = 300L;
    when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
    when(fqc.getTotalBases()).thenReturn(baseCount);
    processor.process(o);
    ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
    verify(qcEntryRepository, times(0)).delete(any(QCEntry.class));
    verify(qcEntryRepository).save(qcCaptor.capture());
    CoverageQCEntry qc = qcCaptor.getValue();
    qc.addProjectSettings(p);
    assertEquals("should show 3 times coverage", 3, qc.getCoverage());
    assertEquals("should be positive coverage", QCEntryStatus.POSITIVE, qc.getStatus());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 9 with SequencingObject

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

the class RESTSampleSequenceFilesController method listSequencingObjectsOfTypeForSample.

/**
 * List all {@link SequencingObject}s of a given type for a {@link Sample}
 *
 * @param sampleId
 *            ID of the {@link Sample} to read from
 * @param objectType
 *            {@link SequencingObject} type
 * @return The {@link SequencingObject}s of the given type for the
 *         {@link Sample}
 */
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}", method = RequestMethod.GET)
public ModelMap listSequencingObjectsOfTypeForSample(@PathVariable Long sampleId, @PathVariable String objectType) {
    ModelMap modelMap = new ModelMap();
    logger.debug("Reading seq file  for sample " + sampleId);
    Sample sample = sampleService.read(sampleId);
    Class<? extends SequencingObject> type = objectLabels.inverse().get(objectType);
    Collection<SampleSequencingObjectJoin> unpairedSequenceFilesForSample = sequencingObjectService.getSequencesForSampleOfType(sample, type);
    ResourceCollection<SequencingObject> resources = new ResourceCollection<>(unpairedSequenceFilesForSample.size());
    for (SampleSequencingObjectJoin join : unpairedSequenceFilesForSample) {
        SequencingObject sequencingObject = join.getObject();
        sequencingObject = addSequencingObjectLinks(sequencingObject, sampleId);
        resources.add(sequencingObject);
    }
    // add a link to this collection
    resources.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).listSequencingObjectsOfTypeForSample(sampleId, objectType)).withSelfRel());
    // add a link back to the sample
    resources.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(RESTSampleSequenceFilesController.REL_SAMPLE));
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
    return modelMap;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with SequencingObject

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

the class RESTSampleSequenceFilesController method readSequenceFileForSequencingObject.

/**
 * Read a single {@link SequenceFile} for a given {@link Sample} and
 * {@link SequencingObject}
 *
 * @param sampleId
 *            ID of the {@link Sample}
 * @param objectType
 *            type of {@link SequencingObject}
 * @param objectId
 *            id of the {@link SequencingObject}
 * @param fileId
 *            ID of the {@link SequenceFile} to read
 * @return a {@link SequenceFile}
 */
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}/{objectId}/files/{fileId}", method = RequestMethod.GET)
public ModelMap readSequenceFileForSequencingObject(@PathVariable Long sampleId, @PathVariable String objectType, @PathVariable Long objectId, @PathVariable Long fileId) {
    ModelMap modelMap = new ModelMap();
    Sample sample = sampleService.read(sampleId);
    SequencingObject readSequenceFilePairForSample = sequencingObjectService.readSequencingObjectForSample(sample, objectId);
    Optional<SequenceFile> findFirst = readSequenceFilePairForSample.getFiles().stream().filter(f -> f.getId().equals(fileId)).findFirst();
    if (!findFirst.isPresent()) {
        throw new EntityNotFoundException("File with id " + fileId + " is not associated with this sequencing object");
    }
    SequenceFile file = findFirst.get();
    file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withRel(REL_SAMPLE_SEQUENCE_FILES));
    file.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(REL_SAMPLE));
    file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequencingObject(sampleId, objectType, objectId)).withRel(REL_SEQ_OBJECT));
    file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readQCForSequenceFile(sampleId, objectType, objectId, fileId)).withRel(REL_SEQ_QC));
    file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sampleId, objectType, objectId, fileId)).withSelfRel());
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, file);
    return modelMap;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) LoggerFactory(org.slf4j.LoggerFactory) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ControllerLinkBuilder.methodOn(org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn) Controller(org.springframework.stereotype.Controller) RequestPart(org.springframework.web.bind.annotation.RequestPart) RESTAnalysisSubmissionController(ca.corefacility.bioinformatics.irida.web.controller.api.RESTAnalysisSubmissionController) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ModelMap(org.springframework.ui.ModelMap) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) HttpHeaders(com.google.common.net.HttpHeaders) Objects(com.google.common.base.Objects) Path(java.nio.file.Path) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) BiMap(com.google.common.collect.BiMap) Link(org.springframework.hateoas.Link) Logger(org.slf4j.Logger) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) Files(java.nio.file.Files) RESTProjectSamplesController(ca.corefacility.bioinformatics.irida.web.controller.api.projects.RESTProjectSamplesController) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SequencingRunService(ca.corefacility.bioinformatics.irida.service.SequencingRunService) RESTGenericController(ca.corefacility.bioinformatics.irida.web.controller.api.RESTGenericController) HttpStatus(org.springframework.http.HttpStatus) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) Optional(java.util.Optional) MultipartFile(org.springframework.web.multipart.MultipartFile) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisService(ca.corefacility.bioinformatics.irida.service.AnalysisService) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)61 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)29 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)25 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)24 Test (org.junit.Test)24 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)16 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)14 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Project (ca.corefacility.bioinformatics.irida.model.project.Project)11 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 Path (java.nio.file.Path)8 ModelMap (org.springframework.ui.ModelMap)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Transactional (org.springframework.transaction.annotation.Transactional)6 IOException (java.io.IOException)5 List (java.util.List)5 Logger (org.slf4j.Logger)5