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