Search in sources :

Example 46 with SequenceFile

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

the class SequencingObjectServiceImplIT method createSequenceFile.

private SequenceFile createSequenceFile(String name) throws IOException {
    Path sequenceFile = Files.createTempFile(name, ".fastq");
    Files.write(sequenceFile, FASTQ_FILE_CONTENTS);
    return new SequenceFile(sequenceFile);
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 47 with SequenceFile

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

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

the class SequencingObjectServiceImplIT method testCoverage.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testCoverage() throws IOException, InterruptedException {
    Project project = projectService.read(1L);
    project.setGenomeSize(3L);
    project.setMinimumCoverage(2);
    project = projectService.update(project);
    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);
    // Wait 10 seconds. file processing should have run by then.
    Thread.sleep(10000);
    Sample readSample = sampleService.read(s.getId());
    List<QCEntry> qcEntries = sampleService.getQCEntriesForSample(readSample);
    assertEquals("should be one qc entry", 1, qcEntries.size());
    QCEntry qcEntry = qcEntries.iterator().next();
    qcEntry.addProjectSettings(project);
    assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
    assertEquals("qc should have passed", QCEntryStatus.POSITIVE, qcEntry.getStatus());
    assertEquals("should be 6x coverage", "6x", qcEntry.getMessage());
    project.setMinimumCoverage(10);
    project = projectService.update(project);
    // Wait 10 seconds. file processing should have run by then.
    Thread.sleep(10000);
    qcEntries = sampleService.getQCEntriesForSample(readSample);
    assertEquals("should be one qc entry", 1, qcEntries.size());
    qcEntry = qcEntries.iterator().next();
    qcEntry.addProjectSettings(project);
    assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
    assertEquals("qc should have failed", QCEntryStatus.NEGATIVE, qcEntry.getStatus());
}
Also used : Path(java.nio.file.Path) Project(ca.corefacility.bioinformatics.irida.model.project.Project) 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 49 with SequenceFile

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

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

the class ExportUploadServiceTest method testUploadSubmission.

@Test
public void testUploadSubmission() throws UploadException, IOException {
    NcbiExportSubmission submission = createFakeSubmission();
    String ftpHost = "localhost";
    String ftpUser = "test";
    String ftpPassword = "password";
    String baseDirectory = "/home/test/submit/Test";
    FakeFtpServer server = new FakeFtpServer();
    server.addUserAccount(new UserAccount(ftpUser, ftpPassword, "/home/test"));
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry(baseDirectory));
    server.setFileSystem(fileSystem);
    // finds an open port
    server.setServerControlPort(0);
    ExportUploadService exportUploadService = new ExportUploadService(null, null, new TestEmailController());
    try {
        server.start();
        int ftpPort = server.getServerControlPort();
        exportUploadService.setConnectionDetails(ftpHost, ftpPort, ftpUser, ftpPassword, baseDirectory);
        String xml = "<xml></xml>";
        exportUploadService.uploadSubmission(submission, xml);
    } finally {
        server.stop();
    }
    @SuppressWarnings("unchecked") List<String> listNames = fileSystem.listNames(baseDirectory);
    assertEquals("submission directory exists", 1, listNames.size());
    String createdDirectory = baseDirectory + "/" + listNames.iterator().next();
    assertTrue("submission.xml created", fileSystem.exists(createdDirectory + "/submission.xml"));
    assertTrue("submit.ready created", fileSystem.exists(createdDirectory + "/submit.ready"));
    SequenceFile createdFile = submission.getBioSampleFiles().iterator().next().getFiles().iterator().next().getSequenceFile();
    assertTrue("seqfile created", fileSystem.exists(createdDirectory + "/" + createdFile.getId() + ".fastq"));
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) UserAccount(org.mockftpserver.fake.UserAccount) 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