use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class SequencingRunServiceImplIT method testAddSequenceFileToMiseqRun.
private void testAddSequenceFileToMiseqRun() throws IOException, InterruptedException {
SequencingRun miseqRun = miseqRunService.read(1L);
// we can't actually know a file name in the XML file that we use to
// populate the database for these tests, so the files don't exist
// anywhere. Create a new temp file and update that in the database
// prior to adding a file to a miseq run so that we have something there
// that we can link to.
Path sequenceFile = Files.createTempFile(null, null);
Files.write(sequenceFile, FASTQ_FILE_CONTENTS);
SequenceFile sf = new SequenceFile(sequenceFile);
SequencingObject so = new SingleEndSequenceFile(sf);
so = objectService.create(so);
miseqRunService.addSequencingObjectToSequencingRun(miseqRun, so);
SequencingRun saved = miseqRunService.read(1L);
SequencingObject readObject = objectService.read(so.getId());
Set<SequencingObject> sequencingObjectsForSequencingRun = objectService.getSequencingObjectsForSequencingRun(saved);
assertTrue("Saved miseq run should have seqence file", sequencingObjectsForSequencingRun.contains(so));
if (SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN"))) {
AnalysisFastQC analysis = null;
do {
try {
readObject = objectService.read(so.getId());
SequenceFile readFile = readObject.getFiles().iterator().next();
analysis = analysisService.getFastQCAnalysisForSequenceFile(readObject, readFile.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 uploaded file.", analysis);
}
}
use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class SequencingObjectServiceTest method testCreateSequenceFileInSampleWrongType.
@Test(expected = IllegalArgumentException.class)
public void testCreateSequenceFileInSampleWrongType() throws IOException {
Sample s = new Sample();
SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
SequencingRun run = new MiseqRun(LayoutType.PAIRED_END, "workflow");
so.setSequencingRun(run);
when(repository.save(so)).thenReturn(so);
service.createSequencingObjectInSample(so, s);
}
use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class SequencingObjectServiceTest method testCreateSequenceFilePairInSampleWrongType.
@Test(expected = IllegalArgumentException.class)
public void testCreateSequenceFilePairInSampleWrongType() throws IOException {
Sample s = new Sample();
SequencingRun run = new MiseqRun(LayoutType.SINGLE_END, "workflow");
SequenceFilePair so = TestDataFactory.constructSequenceFilePair();
so.setSequencingRun(run);
when(repository.save(so)).thenReturn(so);
service.createSequencingObjectInSample(so, s);
}
use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class SequencingRunServiceImpl method delete.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@PreAuthorize("hasRole('ROLE_ADMIN')")
public void delete(Long id) {
Set<Sample> referencedSamples = new HashSet<>();
logger.trace("Getting samples for SequencingRun " + id);
// Get the Files from the SequencingRun to delete
SequencingRun read = read(id);
Set<SequencingObject> findSequencingObjectsForSequencingRun = objectRepository.findSequencingObjectsForSequencingRun(read);
// For each file in the run
for (SequencingObject sequencingObject : findSequencingObjectsForSequencingRun) {
// get the sample the file is in. If the sample is empty when this
// is complete it will be removed
SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(sequencingObject);
if (sampleForSequencingObject != null) {
logger.trace("Sample " + sampleForSequencingObject.getSubject().getId() + " is used in this run");
referencedSamples.add(sampleForSequencingObject.getSubject());
}
// Get the analysis submissions this file is included in
Set<AnalysisSubmission> submissions = submissionRepository.findAnalysisSubmissionsForSequecingObject(sequencingObject);
// If there are no submissions, we can delete the pair and file
if (submissions.isEmpty()) {
logger.trace("Deleting file " + sequencingObject.getId());
objectRepository.delete(sequencingObject);
} else {
logger.trace("Keeping file " + sequencingObject.getId() + " because it's used in an analysis");
if (sampleForSequencingObject != null) {
// otherwise we'll just remove it from the sample
ssoRepository.delete(sampleForSequencingObject);
}
sequencingObject.setSequencingRun(null);
objectRepository.save(sequencingObject);
}
}
// Delete the run
logger.trace("Deleting SequencingRun " + id);
super.delete(id);
// Search if samples are empty. If they are, delete the sample.
for (Sample sample : referencedSamples) {
List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(sample);
if (sequencesForSample.isEmpty()) {
logger.trace("Sample " + sample.getId() + " is empty. Deleting sample");
sampleRepository.delete(sample.getId());
}
}
}
use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class SequencingRunController method listSequencingRuns.
/**
* Get a list of all the sequencing runs
*
* @param params a {@link DataTablesParams} of the sort and paging options
* @param locale the locale used by the browser for the current request.
* @return A DatatablesResponse of DTSequencingRun of the runs
*/
@RequestMapping(value = "/ajax/list")
@ResponseBody
public DataTablesResponse listSequencingRuns(@DataTablesRequest DataTablesParams params, Locale locale) {
Sort sort = params.getSort();
Page<SequencingRun> list = sequencingRunService.list(params.getCurrentPage(), params.getLength(), sort);
List<DTSequencingRun> runs = list.getContent().stream().map(s -> new DTSequencingRun(s, messageSource.getMessage(UPLOAD_STATUS_MESSAGE_BASE + s.getUploadStatus().toString(), null, locale))).collect(Collectors.toList());
return new DataTablesResponse(params, list, runs);
}
Aggregations