Search in sources :

Example 41 with SequencingObject

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

the class SequencingObjectServiceImplIT method testConcatenateSequenceFiles.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testConcatenateSequenceFiles() throws IOException, InterruptedException, ConcatenateException {
    String newFileName = "newname";
    Sample sample = sampleService.read(1L);
    SequenceFile file1 = createSequenceFile("file1");
    SequenceFile file2 = createSequenceFile("file2");
    long originalLength = file1.getFile().toFile().length();
    SequencingObject so1 = new SingleEndSequenceFile(file1);
    SequencingObject so2 = new SingleEndSequenceFile(file2);
    SampleSequencingObjectJoin join1 = objectService.createSequencingObjectInSample(so1, sample);
    SampleSequencingObjectJoin join2 = objectService.createSequencingObjectInSample(so2, sample);
    // Wait 5 seconds. file processing should have run by then.
    Thread.sleep(5000);
    // re-read the original files so file processing will be complete
    so1 = objectService.read(join1.getObject().getId());
    so2 = objectService.read(join2.getObject().getId());
    Collection<SampleSequencingObjectJoin> originalSeqs = objectService.getSequencingObjectsForSample(sample);
    List<SequencingObject> fileSet = Lists.newArrayList(so1, so2);
    SampleSequencingObjectJoin concatenateSequences = objectService.concatenateSequences(fileSet, newFileName, sample, false);
    // Wait 5 seconds. file processing should have run by then.
    Thread.sleep(5000);
    Collection<SampleSequencingObjectJoin> newSeqs = objectService.getSequencingObjectsForSample(sample);
    // re-read the concatenated file so file processing will be complete
    concatenateSequences = sampleService.getSampleForSequencingObject(concatenateSequences.getObject());
    assertTrue("new seq collection should contain originals", newSeqs.containsAll(originalSeqs));
    assertTrue("new seq collection should contain new object", newSeqs.contains(concatenateSequences));
    assertEquals("new seq collection should have 1 more object", originalSeqs.size() + 1, newSeqs.size());
    SequencingObject newSeqObject = concatenateSequences.getObject();
    SequenceFile newFile = newSeqObject.getFiles().iterator().next();
    assertTrue("new file should contain new name", newFile.getFileName().contains(newFileName));
    long newFileSize = newFile.getFile().toFile().length();
    assertEquals("new file should be 2x size of originals", originalLength * 2, newFileSize);
}
Also used : 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) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 42 with SequencingObject

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

the class SequencingObjectServiceImplIT method testAddSequenceFilePairAsSequencer.

@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testAddSequenceFilePairAsSequencer() throws IOException {
    SequenceFile file1 = createSequenceFile("file1");
    SequenceFile file2 = createSequenceFile("file2");
    SequenceFilePair sequenceFilePair = new SequenceFilePair(file1, file2);
    SequencingObject createSequenceFilePair = objectService.create(sequenceFilePair);
    assertTrue(createSequenceFilePair.getFiles().contains(file1));
    assertTrue(createSequenceFilePair.getFiles().contains(file2));
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 43 with SequencingObject

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

the class SequencingObjectServiceImplIT method testGetUniqueSamplesForSequencingObjectsFailNoSample.

/**
 * Tests failure when a sample for one sequencing object does not exist.
 */
@Test(expected = EntityNotFoundException.class)
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetUniqueSamplesForSequencingObjectsFailNoSample() {
    SequencingObject s1 = objectService.read(1L);
    SequencingObject s2 = objectService.read(2L);
    sampleRepository.delete(1L);
    objectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(s1, s2));
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 44 with SequencingObject

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

the class SequencingObjectServiceImplIT method testReadOptionalProperties.

@Test
@WithMockUser(username = "fbristow1", roles = "USER")
public void testReadOptionalProperties() {
    SequencingObject sequencingObject = objectService.read(2L);
    SequenceFile read = sequencingObject.getFileWithId(1L);
    assertEquals("5", read.getOptionalProperty("samplePlate"));
    assertEquals("10", read.getOptionalProperty("sampleWell"));
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 45 with SequencingObject

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject 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)

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