Search in sources :

Example 16 with SequencingObject

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

the class SequencingObjectServiceImplIT method testGetSequenceFilePairForSample.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetSequenceFilePairForSample() {
    Sample s = sampleService.read(2L);
    Set<Long> fileIds = Sets.newHashSet(3L, 4L);
    Collection<SampleSequencingObjectJoin> sequenceFilePairsForSample = objectService.getSequencesForSampleOfType(s, SequenceFilePair.class);
    assertEquals(1, sequenceFilePairsForSample.size());
    SequencingObject pair = sequenceFilePairsForSample.iterator().next().getObject();
    for (SequenceFile file : pair.getFiles()) {
        assertTrue("file id should be in set", fileIds.contains(file.getId()));
        fileIds.remove(file.getId());
    }
    assertTrue("all file ids should have been found", fileIds.isEmpty());
}
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) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 17 with SequencingObject

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

the class SequencingObjectServiceImplIT method testGetUniqueSamplesForSequencingObjectsSuccess.

/**
 * Tests to make sure we get a properly constructed map of samples to sequencing objects.
 */
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetUniqueSamplesForSequencingObjectsSuccess() {
    SequencingObject s1 = objectService.read(1L);
    SequencingObject s2 = objectService.read(2L);
    Sample sa1 = sampleService.read(1L);
    Sample sa2 = sampleService.read(2L);
    Map<Sample, SequencingObject> sampleMap = objectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(s1, s2));
    assertEquals("Incorrect number of results returned in sample map", 2, sampleMap.size());
    assertEquals("Incorrect sequencing object mapped to sample", s2.getId(), sampleMap.get(sa1).getId());
    assertEquals("Incorrect sequencing object mapped to sample", s1.getId(), sampleMap.get(sa2).getId());
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 18 with SequencingObject

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

the class SequencingObjectServiceImplIT method testGetUniqueSamplesForSequencingObjectsFailDuplicateSample.

/**
 * Tests failure for duplicate samples in sequencing objects.
 */
@Test(expected = DuplicateSampleException.class)
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetUniqueSamplesForSequencingObjectsFailDuplicateSample() {
    SequencingObject s1 = objectService.read(1L);
    SequencingObject s4 = objectService.read(4L);
    objectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(s1, s4));
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 19 with SequencingObject

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

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

the class SamplesControllerTest method testRemoveFileFromSample.

@Test
public void testRemoveFileFromSample() {
    Long sampleId = 1L;
    Long fileId = 2L;
    Sample sample = new Sample();
    SequencingObject file = new SingleEndSequenceFile(new SequenceFile(Paths.get("/tmp")));
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sequencingObjectService.readSequencingObjectForSample(sample, fileId)).thenReturn(file);
    RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
    HttpServletRequest request = new MockHttpServletRequest();
    controller.removeSequencingObjectFromSample(attributes, sampleId, fileId, request, Locale.US);
    verify(sampleService).removeSequencingObjectFromSample(sample, file);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) 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) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) 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