use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject 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.sequenceFile.SequencingObject in project irida by phac-nml.
the class AnalysisWorkspaceServiceGalaxyTest method testGetAnalysisResultsSuccessSinglePairedEnd.
/**
* Tests successfully getting analysis results from Galaxy with
* single/paired end input files.
*
* @throws IridaWorkflowNotFoundException
* @throws IOException
* @throws ExecutionManagerException
* @throws IridaWorkflowAnalysisTypeException
*/
@Test
public void testGetAnalysisResultsSuccessSinglePairedEnd() throws IridaWorkflowNotFoundException, IridaWorkflowAnalysisTypeException, ExecutionManagerException, IOException {
Set<SingleEndSequenceFile> singleFiles = Sets.newHashSet(sampleSingleSequenceFileMap.values());
Set<SequenceFilePair> pairedFiles = Sets.newHashSet(sampleSequenceFilePairMap.values());
Set<SequencingObject> joinedFiles = Sets.newHashSet(singleFiles);
joinedFiles.addAll(pairedFiles);
Map<Sample, SequencingObject> joinedMap = Maps.newHashMap(sampleSingleSequenceFileMap);
joinedMap.putAll(sampleSequenceFilePairMap);
submission = AnalysisSubmission.builder(workflowIdMultiSamples).name("my analysis").inputFiles(singleInputFiles).inputFiles(pairedInputFiles).referenceFile(referenceFile).build();
submission.setRemoteWorkflowId(WORKFLOW_ID);
submission.setRemoteAnalysisId(HISTORY_ID);
when(sequencingObjectService.getSequencingObjectsForAnalysisSubmission(submission)).thenReturn(joinedFiles);
when(iridaWorkflowsService.getIridaWorkflow(workflowIdMultiSamples)).thenReturn(iridaWorkflowSinglePairedMultipleSamples);
when(galaxyHistoriesService.getDatasetForFileInHistory(output1Filename, HISTORY_ID)).thenReturn(output1Dataset);
when(galaxyHistoriesService.getDatasetForFileInHistory(output2Filename, HISTORY_ID)).thenReturn(output2Dataset);
when(sequencingObjectService.getUniqueSamplesForSequencingObjects(joinedFiles)).thenReturn(joinedMap);
Analysis analysis = workflowPreparation.getAnalysisResults(submission);
assertNotNull("analysis is not valid", analysis);
assertEquals("invalid number of output files", 2, analysis.getAnalysisOutputFiles().size());
assertEquals("missing output file for analysis", Paths.get("output1.txt"), analysis.getAnalysisOutputFile("output1").getFile().getFileName());
// labels should now not have sample associated with them.
assertEquals("missing label for analysis output file", "output1.txt", analysis.getAnalysisOutputFile("output1").getLabel());
assertEquals("missing output file for analysis", "output2.txt", analysis.getAnalysisOutputFile("output2").getLabel());
verify(galaxyHistoriesService).getDatasetForFileInHistory("output1.txt", HISTORY_ID);
verify(galaxyHistoriesService).getDatasetForFileInHistory("output2.txt", HISTORY_ID);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class SampleServiceImplTest method so.
private SequencingObject so(Long id) {
SequencingObject so = new SingleEndSequenceFile(sf(id));
so.setId(id);
return so;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class SequencingObjectServiceImpl method concatenateSequences.
/**
* {@inheritDoc}
*/
@Override
@PreAuthorize("hasPermission(#toJoin, 'canReadSequencingObject') and hasPermission(#targetSample, 'canUpdateSample')")
@Transactional
public SampleSequencingObjectJoin concatenateSequences(List<SequencingObject> toJoin, String filename, Sample targetSample, boolean removeOriginals) throws ConcatenateException {
SequencingObjectConcatenator<? extends SequencingObject> concatenator = SequencingObjectConcatenatorFactory.getConcatenator(toJoin);
SequencingObject concatenated = concatenator.concatenateFiles(toJoin, filename);
SampleSequencingObjectJoin created = createSequencingObjectInSample(concatenated, targetSample);
concatenationRepository.save(new SequenceConcatenation(created.getObject(), toJoin));
if (removeOriginals) {
for (SequencingObject obj : toJoin) {
SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(obj);
ssoRepository.delete(sampleForSequencingObject);
}
}
return created;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class SequencingObjectServiceImpl method getUniqueSamplesForSequencingObjects.
/**
* {@inheritDoc}
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN') or hasPermission(#sequenceFiles, 'canReadSequencingObject')")
@Override
public <T extends SequencingObject> Map<Sample, T> getUniqueSamplesForSequencingObjects(Set<T> sequenceFiles) throws DuplicateSampleException {
Map<Sample, T> sequenceFilesSampleMap = new HashMap<>();
for (T seqObj : sequenceFiles) {
SequenceFile file = seqObj.getFiles().iterator().next();
SampleSequencingObjectJoin join = ssoRepository.getSampleForSequencingObject(seqObj);
if (join == null) {
throw new EntityNotFoundException("No sample associated with sequence file " + seqObj.getClass() + "[id=" + seqObj.getId() + "]");
} else {
Sample sample = join.getSubject();
if (sequenceFilesSampleMap.containsKey(sample)) {
SequencingObject previousFile = sequenceFilesSampleMap.get(sample);
throw new DuplicateSampleException("Sequence files " + file + ", " + previousFile + " have the same sample " + sample);
} else {
sequenceFilesSampleMap.put(sample, seqObj);
}
}
}
return sequenceFilesSampleMap;
}
Aggregations