Search in sources :

Example 6 with AnalysisFastQC

use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC 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 7 with AnalysisFastQC

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

the class SequencingObjectServiceImplIT method testCreateNotCompressedSequenceFile.

@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateNotCompressedSequenceFile() throws IOException, InterruptedException {
    final Long expectedRevisionNumber = 1L;
    SequenceFile sf = createSequenceFile("file1");
    Path sequenceFile = sf.getFile();
    SingleEndSequenceFile singleEndSequenceFile = new SingleEndSequenceFile(sf);
    logger.trace("About to save the file.");
    SequencingObject sequencingObject = asRole(Role.ROLE_SEQUENCER, "fbristow").objectService.create(singleEndSequenceFile);
    logger.trace("Finished saving the file.");
    assertNotNull("ID wasn't assigned.", sequencingObject.getId());
    // Sleeping for a bit to let file processing run
    Thread.sleep(10000);
    // figure out what the version number of the sequence file is (should be
    // 1; the file wasn't gzipped, but fastqc will have modified it.)
    SequencingObject readObject = null;
    do {
        readObject = asRole(Role.ROLE_ADMIN, "admin").objectService.read(sequencingObject.getId());
        sf = readObject.getFiles().iterator().next();
        if (sf.getFileRevisionNumber() < expectedRevisionNumber) {
            logger.info("Still waiting on thread to finish, having a bit of a sleep.");
            Thread.sleep(1000);
        }
    } while (sf.getFileRevisionNumber() < expectedRevisionNumber);
    assertEquals("Wrong version number after processing.", expectedRevisionNumber, sf.getFileRevisionNumber());
    // verify the file checksum was taken properly
    assertEquals("checksum should be equal", CHECKSUM, sf.getUploadSha256());
    AnalysisFastQC analysis = asRole(Role.ROLE_ADMIN, "admin").analysisService.getFastQCAnalysisForSequenceFile(readObject, sf.getId());
    assertNotNull("FastQCAnalysis should have been created for the file.", analysis);
    Set<OverrepresentedSequence> overrepresentedSequences = analysis.getOverrepresentedSequences();
    assertNotNull("No overrepresented sequences were found.", overrepresentedSequences);
    assertEquals("Wrong number of overrepresented sequences were found.", 1, overrepresentedSequences.size());
    OverrepresentedSequence overrepresentedSequence = overrepresentedSequences.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.", new BigDecimal("100.00"), overrepresentedSequence.getPercentage());
    // confirm that the file structure is correct
    Path idDirectory = baseDirectory.resolve(Paths.get(sf.getId().toString()));
    assertTrue("Revision directory doesn't exist.", Files.exists(idDirectory.resolve(Paths.get(sf.getFileRevisionNumber().toString(), sequenceFile.getFileName().toString()))));
    // no other files or directories should be beneath the ID directory
    int fileCount = 0;
    Iterator<Path> dir = Files.newDirectoryStream(idDirectory).iterator();
    while (dir.hasNext()) {
        dir.next();
        fileCount++;
    }
    assertEquals("Wrong number of directories beneath the id directory", 1, fileCount);
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) OverrepresentedSequence(ca.corefacility.bioinformatics.irida.model.sequenceFile.OverrepresentedSequence) BigDecimal(java.math.BigDecimal) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 8 with AnalysisFastQC

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

the class SequencingRunServiceImplIT method testAddDetachedRunToSequenceFile.

/**
 * This test simulates a bug that happens from the REST API when uploading
 * sequence files to samples, where a new sequence file is created, then
 * detached from a transaction.
 *
 * @throws IOException
 * @throws InterruptedException
 */
@Test
@WithMockUser(username = "fbristow", password = "password1", roles = "ADMIN")
public void testAddDetachedRunToSequenceFile() throws IOException, InterruptedException {
    final String SEQUENCE = "ACGTACGTN";
    final byte[] FASTQ_FILE_CONTENTS = ("@testread\n" + SEQUENCE + "\n+\n?????????\n@testread2\n" + SEQUENCE + "\n+\n?????????").getBytes();
    Path p = Files.createTempFile(null, null);
    Files.write(p, FASTQ_FILE_CONTENTS);
    SequenceFile sf = new SequenceFile();
    sf.setFile(p);
    SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
    Sample sample = sampleService.read(1L);
    SequencingRun run = miseqRunService.read(2L);
    objectService.createSequencingObjectInSample(so, sample);
    miseqRunService.addSequencingObjectToSequencingRun(run, so);
    AnalysisFastQC analysis = null;
    do {
        try {
            analysis = analysisService.getFastQCAnalysisForSequenceFile(so, sf.getId());
        } catch (final EntityNotFoundException e) {
            logger.info("Fastqc still isn't finished, sleeping a bit.");
            Thread.sleep(1000);
        }
    } while (analysis == null);
    assertNotNull("FastQC analysis should have been created for sequence file.", analysis);
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 9 with AnalysisFastQC

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

the class SampleServiceImpl method getTotalBasesForSample.

/**
 * {@inheritDoc}
 */
@Override
@Transactional(readOnly = true)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#sample, 'canReadSample')")
public Long getTotalBasesForSample(Sample sample) throws SequenceFileAnalysisException {
    checkNotNull(sample, "sample is null");
    long totalBases = 0;
    List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(sample);
    for (SampleSequencingObjectJoin join : sequencesForSample) {
        for (SequenceFile sequenceFile : join.getObject().getFiles()) {
            final AnalysisFastQC sequenceFileFastQC = analysisRepository.findFastqcAnalysisForSequenceFile(sequenceFile);
            if (sequenceFileFastQC == null || sequenceFileFastQC.getTotalBases() == null) {
                throw new SequenceFileAnalysisException("Missing FastQC analysis for SequenceFile [" + sequenceFile.getId() + "]");
            }
            totalBases += sequenceFileFastQC.getTotalBases();
        }
    }
    return totalBases;
}
Also used : SequenceFileAnalysisException(ca.corefacility.bioinformatics.irida.exceptions.SequenceFileAnalysisException) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with AnalysisFastQC

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

the class CoverageFileProcessor method process.

@Override
public void process(SequencingObject sequencingObject) {
    logger.trace("Counting coverage for file " + sequencingObject);
    if (sequencingObject.getQcEntries() != null) {
        // remove any existing coverage entries
        sequencingObject.getQcEntries().stream().filter(q -> q instanceof CoverageQCEntry).forEach(q -> qcEntryRepository.delete(q));
    }
    // count the total bases
    long totalBases = sequencingObject.getFiles().stream().mapToLong(f -> {
        AnalysisFastQC fastqc = analysisRepository.findFastqcAnalysisForSequenceFile(f);
        return fastqc.getTotalBases();
    }).sum();
    // save the entry
    CoverageQCEntry coverageQCEntry = new CoverageQCEntry(sequencingObject, totalBases);
    qcEntryRepository.save(coverageQCEntry);
}
Also used : Component(org.springframework.stereotype.Component) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Autowired(org.springframework.beans.factory.annotation.Autowired) AnalysisRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.AnalysisRepository) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Project(ca.corefacility.bioinformatics.irida.model.project.Project) QCEntryRepository(ca.corefacility.bioinformatics.irida.repositories.sample.QCEntryRepository) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)

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