Search in sources :

Example 71 with SingleEndSequenceFile

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

the class SequencingObjectServiceImplIT method testCreateSequenceFileInSample.

@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateSequenceFileInSample() throws IOException, InterruptedException {
    Sample s = sampleService.read(1L);
    SequenceFile sf = new SequenceFile();
    Path sequenceFile = Files.createTempFile("TEMPORARY-SEQUENCE-FILE", ".gz");
    OutputStream gzOut = new GZIPOutputStream(Files.newOutputStream(sequenceFile));
    gzOut.write(FASTQ_FILE_CONTENTS);
    gzOut.close();
    sf.setFile(sequenceFile);
    SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
    objectService.createSequencingObjectInSample(so, s);
    SequencingRun mr = sequencingRunService.read(1L);
    sequencingRunService.addSequencingObjectToSequencingRun(mr, so);
    // Sleeping for a bit to let file processing run
    Thread.sleep(10000);
    Sample readSample = sampleService.read(s.getId());
    List<QCEntry> qcEntries = sampleService.getQCEntriesForSample(readSample);
    assertEquals("should be one qc entries", 1, qcEntries.size());
    QCEntry qcEntry = qcEntries.iterator().next();
    assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
    CoverageQCEntry coverage = (CoverageQCEntry) qcEntry;
    assertEquals("should be 18 bases", 18, coverage.getTotalBases());
}
Also used : Path(java.nio.file.Path) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) GZIPOutputStream(java.util.zip.GZIPOutputStream) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 72 with SingleEndSequenceFile

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

the class SequencingObjectServiceImplIT method testCreateCompressedSequenceFile.

@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateCompressedSequenceFile() throws IOException, InterruptedException {
    final Long expectedRevisionNumber = 2L;
    SequenceFile sf = new SequenceFile();
    Path sequenceFile = Files.createTempFile("TEMPORARY-SEQUENCE-FILE", ".gz");
    OutputStream gzOut = new GZIPOutputStream(Files.newOutputStream(sequenceFile));
    gzOut.write(FASTQ_FILE_CONTENTS);
    gzOut.close();
    sf.setFile(sequenceFile);
    SingleEndSequenceFile singleEndSequenceFile = new SingleEndSequenceFile(sf);
    logger.trace("About to save the file.");
    SequencingObject sequencingObject = 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
    // 2; the file was gzipped)
    // get the MOST RECENT version of the sequence file from the database
    // (it will have been modified outside of the create method.)
    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());
    assertFalse("File name is still gzipped.", sf.getFile().getFileName().toString().endsWith(".gz"));
    AnalysisFastQC analysis = asRole(Role.ROLE_ADMIN, "admin").analysisService.getFastQCAnalysisForSequenceFile(readObject, sf.getId());
    // verify the file checksum was taken properly
    assertEquals("checksum should be equal", ZIPPED_CHECKSUM, sf.getUploadSha256());
    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
    String filename = sequenceFile.getFileName().toString();
    filename = filename.substring(0, filename.lastIndexOf('.'));
    Path idDirectory = baseDirectory.resolve(Paths.get(sf.getId().toString()));
    assertTrue("Revision directory doesn't exist.", Files.exists(idDirectory.resolve(Paths.get(sf.getFileRevisionNumber().toString(), filename))));
    // 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", 2, fileCount);
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) BigDecimal(java.math.BigDecimal) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) GZIPOutputStream(java.util.zip.GZIPOutputStream) OverrepresentedSequence(ca.corefacility.bioinformatics.irida.model.sequenceFile.OverrepresentedSequence) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 73 with SingleEndSequenceFile

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

the class SequencingRunServiceImplIT method testAddSequenceFileToMiseqRun.

private void testAddSequenceFileToMiseqRun() throws IOException, InterruptedException {
    SequencingRun miseqRun = miseqRunService.read(1L);
    // we can't actually know a file name in the XML file that we use to
    // populate the database for these tests, so the files don't exist
    // anywhere. Create a new temp file and update that in the database
    // prior to adding a file to a miseq run so that we have something there
    // that we can link to.
    Path sequenceFile = Files.createTempFile(null, null);
    Files.write(sequenceFile, FASTQ_FILE_CONTENTS);
    SequenceFile sf = new SequenceFile(sequenceFile);
    SequencingObject so = new SingleEndSequenceFile(sf);
    so = objectService.create(so);
    miseqRunService.addSequencingObjectToSequencingRun(miseqRun, so);
    SequencingRun saved = miseqRunService.read(1L);
    SequencingObject readObject = objectService.read(so.getId());
    Set<SequencingObject> sequencingObjectsForSequencingRun = objectService.getSequencingObjectsForSequencingRun(saved);
    assertTrue("Saved miseq run should have seqence file", sequencingObjectsForSequencingRun.contains(so));
    if (SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN"))) {
        AnalysisFastQC analysis = null;
        do {
            try {
                readObject = objectService.read(so.getId());
                SequenceFile readFile = readObject.getFiles().iterator().next();
                analysis = analysisService.getFastQCAnalysisForSequenceFile(readObject, readFile.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 uploaded file.", analysis);
    }
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)

Example 74 with SingleEndSequenceFile

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

the class SequencingObjectServiceTest method testCreateSequenceFileInSampleWrongType.

@Test(expected = IllegalArgumentException.class)
public void testCreateSequenceFileInSampleWrongType() throws IOException {
    Sample s = new Sample();
    SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
    SequencingRun run = new MiseqRun(LayoutType.PAIRED_END, "workflow");
    so.setSequencingRun(run);
    when(repository.save(so)).thenReturn(so);
    service.createSequencingObjectInSample(so, s);
}
Also used : MiseqRun(ca.corefacility.bioinformatics.irida.model.run.MiseqRun) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 75 with SingleEndSequenceFile

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

the class SequencingObjectServiceTest method testCreateSequenceFileInSample.

@Test
public void testCreateSequenceFileInSample() throws IOException {
    Sample s = new Sample();
    SingleEndSequenceFile sf = TestDataFactory.constructSingleEndSequenceFile();
    when(repository.save(sf)).thenReturn(sf);
    service.createSequencingObjectInSample(sf, s);
    verify(sequenceFileRepository, times(1)).save(any(SequenceFile.class));
    // verify that we're only actually running one file processor on the new
    // sequence file.
    verify(executor, times(1)).execute(any(Runnable.class));
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Aggregations

SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)99 Test (org.junit.Test)72 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)61 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)44 Path (java.nio.file.Path)33 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)24 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)22 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Project (ca.corefacility.bioinformatics.irida.model.project.Project)17 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)17 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)12 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)11 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)10 ArrayList (java.util.ArrayList)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)8 History (com.github.jmchilton.blend4j.galaxy.beans.History)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 ModelMap (org.springframework.ui.ModelMap)8