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);
}
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);
}
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());
}
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);
}
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"));
}
Aggregations