Search in sources :

Example 16 with AnalysisFastQC

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC in project irida by phac-nml.

the class SampleSequenceFilesControllerTest method testGetQcForFile.

@Test
public void testGetQcForFile() throws IOException {
    Sample s = TestDataFactory.constructSample();
    SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
    AnalysisFastQC analysisFastQC = new AnalysisFastQC(AnalysisFastQC.builder());
    when(sampleService.read(s.getId())).thenReturn(s);
    when(sequencingObjectService.readSequencingObjectForSample(s, so.getId())).thenReturn(so);
    when(analysisService.getFastQCAnalysisForSequenceFile(so, so.getSequenceFile().getId())).thenReturn(analysisFastQC);
    ModelMap readQCForSequenceFile = controller.readQCForSequenceFile(s.getId(), RESTSampleSequenceFilesController.objectLabels.get(so.getClass()), so.getId(), so.getSequenceFile().getId());
    verify(sampleService).read(s.getId());
    verify(sequencingObjectService).readSequencingObjectForSample(s, so.getId());
    verify(analysisService).getFastQCAnalysisForSequenceFile(so, so.getSequenceFile().getId());
    assertTrue(readQCForSequenceFile.containsKey(RESTGenericController.RESOURCE_NAME));
    Object object = readQCForSequenceFile.get(RESTGenericController.RESOURCE_NAME);
    assertTrue(object instanceof AnalysisFastQC);
    AnalysisFastQC qc = (AnalysisFastQC) object;
    assertNotNull(qc.getLink(RESTSampleSequenceFilesController.REL_QC_SEQFILE));
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 17 with AnalysisFastQC

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC in project irida by phac-nml.

the class SequenceFileController method downloadSequenceFileImages.

/**
 * Get images specific for individual sequence files.
 *
 * @param sequencingObjectId ID for the {@link SequencingObject}
 * @param sequenceFileId     Id for the {@link SequenceFile}
 * @param type               The type of image to get.
 * @param response           {@link HttpServletResponse}
 * @param thumb              Whether to scale the image for a thumbnail
 * @throws IOException if we can't write the image out to the response.
 */
@RequestMapping(value = "/sequenceFiles/img/{sequencingObjectId}/file/{sequenceFileId}/{type}")
public void downloadSequenceFileImages(@PathVariable Long sequencingObjectId, @PathVariable Long sequenceFileId, @PathVariable String type, HttpServletResponse response, @RequestParam(defaultValue = "false") boolean thumb) throws IOException {
    SequencingObject sequencingObject = sequencingObjectService.read(sequencingObjectId);
    SequenceFile file = sequencingObject.getFileWithId(sequenceFileId);
    AnalysisFastQC fastQC = analysisService.getFastQCAnalysisForSequenceFile(sequencingObject, file.getId());
    if (fastQC != null) {
        byte[] chart = new byte[0];
        if (type.equals(IMG_PERBASE)) {
            chart = fastQC.getPerBaseQualityScoreChart();
        } else if (type.equals(IMG_PERSEQUENCE)) {
            chart = fastQC.getPerSequenceQualityScoreChart();
        } else if (type.equals(IMG_DUPLICATION_LEVEL)) {
            chart = fastQC.getDuplicationLevelChart();
        } else {
            throw new EntityNotFoundException("Image not found");
        }
        if (thumb) {
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(chart));
            BufferedImage thumbnail = Scalr.resize(image, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, 160, Scalr.OP_ANTIALIAS);
            ImageIO.write(thumbnail, "png", response.getOutputStream());
        } else {
            response.getOutputStream().write(chart);
        }
    }
    response.setContentType(MediaType.IMAGE_PNG_VALUE);
    response.flushBuffer();
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) BufferedImage(java.awt.image.BufferedImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with AnalysisFastQC

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC in project irida by phac-nml.

the class FastqcFileProcessorTest method testHandleFastqFile.

@Test
public void testHandleFastqFile() throws IOException, IllegalArgumentException, IllegalAccessException {
    // fastqc shouldn't barf on a fastq file.
    Path fastq = Files.createTempFile(null, null);
    Files.write(fastq, FASTQ_FILE_CONTENTS.getBytes());
    Runtime.getRuntime().addShutdownHook(new DeleteFileOnExit(fastq));
    ArgumentCaptor<SequenceFile> argument = ArgumentCaptor.forClass(SequenceFile.class);
    SequenceFile sf = new SequenceFile(fastq);
    sf.setId(1L);
    SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
    try {
        fileProcessor.process(so);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    verify(sequenceFileRepository).saveMetadata(argument.capture());
    SequenceFile updatedFile = argument.getValue();
    final Field fastqcAnalysis = ReflectionUtils.findField(SequenceFile.class, "fastqcAnalysis");
    ReflectionUtils.makeAccessible(fastqcAnalysis);
    AnalysisFastQC updated = (AnalysisFastQC) fastqcAnalysis.get(updatedFile);
    assertEquals("GC Content was not set correctly.", Short.valueOf((short) 50), updated.getGcContent());
    assertEquals("Filtered sequences was not 0.", Integer.valueOf(0), updated.getFilteredSequences());
    assertEquals("File type was not correct.", "Conventional base calls", updated.getFileType());
    assertEquals("Max length was not correct.", Integer.valueOf(SEQUENCE.length()), updated.getMaxLength());
    assertEquals("Min length was not correct.", Integer.valueOf(SEQUENCE.length()), updated.getMinLength());
    assertEquals("Total sequences was not correct.", Integer.valueOf(2), updated.getTotalSequences());
    assertEquals("Encoding was not correct.", "Illumina <1.3", updated.getEncoding());
    assertEquals("Total number of bases was not correct.", Long.valueOf(SEQUENCE.length() * 2), updated.getTotalBases());
    assertNotNull("Per-base quality score chart was not created.", updated.getPerBaseQualityScoreChart());
    assertTrue("Per-base quality score chart was created, but was empty.", ((byte[]) updated.getPerBaseQualityScoreChart()).length > 0);
    assertNotNull("Per-sequence quality score chart was not created.", updated.getPerSequenceQualityScoreChart());
    assertTrue("Per-sequence quality score chart was created, but was empty.", ((byte[]) updated.getPerSequenceQualityScoreChart()).length > 0);
    assertNotNull("Duplication level chart was not created.", updated.getDuplicationLevelChart());
    assertTrue("Duplication level chart was not created.", ((byte[]) updated.getDuplicationLevelChart()).length > 0);
    Iterator<OverrepresentedSequence> ovrs = updated.getOverrepresentedSequences().iterator();
    assertTrue("No overrepresented sequences added to analysis.", ovrs.hasNext());
    OverrepresentedSequence overrepresentedSequence = updated.getOverrepresentedSequences().iterator().next();
    assertEquals("Sequence was not the correct sequence.", SEQUENCE, overrepresentedSequence.getSequence());
    assertEquals("The count was not correct.", 2, overrepresentedSequence.getOverrepresentedSequenceCount());
    assertEquals("The percent was not correct.", BigDecimal.valueOf(100.), overrepresentedSequence.getPercentage());
}
Also used : Path(java.nio.file.Path) Field(java.lang.reflect.Field) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) IOException(java.io.IOException) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) OverrepresentedSequence(ca.corefacility.bioinformatics.irida.model.sequenceFile.OverrepresentedSequence) Test(org.junit.Test)

Aggregations

AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)18 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)14 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)12 Test (org.junit.Test)12 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)10 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)6 Path (java.nio.file.Path)6 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 CoverageQCEntry (ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry)4 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)4 QCEntry (ca.corefacility.bioinformatics.irida.model.sample.QCEntry)3 OverrepresentedSequence (ca.corefacility.bioinformatics.irida.model.sequenceFile.OverrepresentedSequence)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)2 BigDecimal (java.math.BigDecimal)2 ModelMap (org.springframework.ui.ModelMap)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 SequenceFileAnalysisException (ca.corefacility.bioinformatics.irida.exceptions.SequenceFileAnalysisException)1 AnalysisOutputFile (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)1