Search in sources :

Example 81 with SequenceFile

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

the class DatabaseSetupGalaxyITService method setupSampleSequenceFileInDatabase.

/**
 * Attaches the given sequence file paths as pairs (using parallel lists) to
 * a particular sample id.
 *
 * @param sampleId
 *            The id of the sample to attach a sequence file to.
 * @param sequenceFiles1
 *            A list of the first part of each pairs to setup.
 * @param sequenceFiles2
 *            A list of the second part of each pairs to setup.
 * @return A {@link List} of {@link SequenceFilePair} objects with the given
 *         sequence file paths attached and saved in the database.
 */
public List<SequenceFilePair> setupSampleSequenceFileInDatabase(long sampleId, List<Path> sequenceFiles1, List<Path> sequenceFiles2) {
    checkArgument(sequenceFiles1.size() == sequenceFiles2.size(), "sequenceFiles lists are unequal");
    Sample sample = sampleService.read(sampleId);
    List<SequenceFilePair> returnedSequenceFilePairs = new ArrayList<>();
    for (int i = 0; i < sequenceFiles1.size(); i++) {
        SequenceFile sf1 = new SequenceFile(sequenceFiles1.get(i));
        SequenceFile sf2 = new SequenceFile(sequenceFiles2.get(i));
        SequenceFilePair pair = new SequenceFilePair(sf1, sf2);
        sequencingObjectService.createSequencingObjectInSample(pair, sample);
        waitForFilesToSettle(pair);
        returnedSequenceFilePairs.add((SequenceFilePair) sequencingObjectService.read(pair.getId()));
    }
    return returnedSequenceFilePairs;
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList)

Example 82 with SequenceFile

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

the class SequencingRunControllerTest method testGetFilesPage.

@SuppressWarnings("rawtypes")
@Test
public void testGetFilesPage() throws IOException {
    Long runId = 1L;
    ExtendedModelMap model = new ExtendedModelMap();
    SequencingRun sequencingRunEntity = new MiseqRun(SequencingRun.LayoutType.PAIRED_END, "");
    ImmutableSet<SequencingObject> files = ImmutableSet.of(new SingleEndSequenceFile(new SequenceFile()));
    when(sequencingRunService.read(runId)).thenReturn(sequencingRunEntity);
    when(objectService.getSequencingObjectsForSequencingRun(sequencingRunEntity)).thenReturn(files);
    String filesPage = controller.getFilesPage(runId, model);
    assertEquals(SequencingRunController.FILES_VIEW, filesPage);
    assertFalse(((Collection) model.get("sequencingObjects")).isEmpty());
    assertEquals(sequencingRunEntity, model.get("run"));
    assertTrue(model.containsKey("fileCount"));
    verify(sequencingRunService).read(runId);
    verify(objectService).getSequencingObjectsForSequencingRun(sequencingRunEntity);
}
Also used : MiseqRun(ca.corefacility.bioinformatics.irida.model.run.MiseqRun) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 83 with SequenceFile

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

the class TestDataFactory method generateSequencingObjectsForSample.

public static List<SampleSequencingObjectJoin> generateSequencingObjectsForSample(Sample sample) {
    List<SampleSequencingObjectJoin> join = new ArrayList<>();
    for (long i = 0; i < 5; i++) {
        Path path = Paths.get("/tmp/sequence-files/fake-file" + Math.random() + ".fast");
        SequenceFile file = new SequenceFile(path);
        file.setId(i);
        SingleEndSequenceFile obj = new SingleEndSequenceFile(file);
        obj.setId(i);
        join.add(new SampleSequencingObjectJoin(sample, obj));
    }
    return join;
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ArrayList(java.util.ArrayList) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 84 with SequenceFile

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

the class SequencingObjectServiceImplIT method testCreateCorruptSequenceFileInSample.

@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateCorruptSequenceFileInSample() throws IOException, InterruptedException {
    Sample s = sampleService.read(1L);
    SequenceFile sf = new SequenceFile();
    Path sequenceFile = Files.createTempFile("TEMPORARY-SEQUENCE-FILE", ".gz");
    OutputStream gzOut = Files.newOutputStream(sequenceFile);
    gzOut.write("not a file".getBytes());
    gzOut.close();
    sf.setFile(sequenceFile);
    SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
    objectService.createSequencingObjectInSample(so, s);
    // Wait 5 seconds. file processing should have failed by then.
    Thread.sleep(5000);
    Sample readSample = sampleService.read(s.getId());
    List<QCEntry> qcEntries = sampleService.getQCEntriesForSample(readSample);
    assertFalse("should be a qc entry", qcEntries.isEmpty());
    QCEntry qc = qcEntries.iterator().next();
    assertTrue("should be a FileProcessorErrorQCEntry", qc instanceof FileProcessorErrorQCEntry);
}
Also used : Path(java.nio.file.Path) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) 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 85 with SequenceFile

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

Aggregations

SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)111 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)84 Test (org.junit.Test)61 Path (java.nio.file.Path)50 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)39 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)31 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)25 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 Project (ca.corefacility.bioinformatics.irida.model.project.Project)15 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)13 IOException (java.io.IOException)11 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)9 ArrayList (java.util.ArrayList)9 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 Link (org.springframework.hateoas.Link)8 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)7 OutputStream (java.io.OutputStream)7 Before (org.junit.Before)7