use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class SamplesControllerTest method testGetSampleFiles.
@SuppressWarnings("unchecked")
@Test
public void testGetSampleFiles() throws IOException {
ExtendedModelMap model = new ExtendedModelMap();
Long sampleId = 1L;
Sample sample = new Sample();
SequenceFile file = new SequenceFile(Paths.get("/tmp"));
file.setId(2L);
Project project = new Project();
List<SampleSequencingObjectJoin> files = Lists.newArrayList(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
when(sampleService.read(sampleId)).thenReturn(sample);
when(sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class)).thenReturn(files);
when(projectService.getProjectsForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
String sampleFiles = controller.getSampleFilesWithoutProject(model, sampleId);
assertEquals(SamplesController.SAMPLE_FILES_PAGE, sampleFiles);
assertTrue((boolean) model.get(SamplesController.MODEL_ATTR_CAN_MANAGE_SAMPLE));
verify(sampleService).read(sampleId);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SequenceFilePair.class);
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class SamplesControllerTest method testGetSampleFilesAsAdmin.
@Test
public void testGetSampleFilesAsAdmin() throws IOException {
ExtendedModelMap model = new ExtendedModelMap();
Long sampleId = 1L;
Sample sample = new Sample();
SequenceFile file = new SequenceFile(Paths.get("/tmp"));
file.setId(2L);
List<SampleSequencingObjectJoin> files = Lists.newArrayList(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
when(sampleService.read(sampleId)).thenReturn(sample);
when(sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class)).thenReturn(files);
when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
String sampleFiles = controller.getSampleFilesWithoutProject(model, sampleId);
assertEquals(SamplesController.SAMPLE_FILES_PAGE, sampleFiles);
assertTrue((boolean) model.get(SamplesController.MODEL_ATTR_CAN_MANAGE_SAMPLE));
verify(sampleService).read(sampleId);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SequenceFilePair.class);
verifyZeroInteractions(projectService);
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class SampleServiceImpl method getTotalBasesForSample.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = true)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#sample, 'canReadSample')")
public Long getTotalBasesForSample(Sample sample) throws SequenceFileAnalysisException {
checkNotNull(sample, "sample is null");
long totalBases = 0;
List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(sample);
for (SampleSequencingObjectJoin join : sequencesForSample) {
for (SequenceFile sequenceFile : join.getObject().getFiles()) {
final AnalysisFastQC sequenceFileFastQC = analysisRepository.findFastqcAnalysisForSequenceFile(sequenceFile);
if (sequenceFileFastQC == null || sequenceFileFastQC.getTotalBases() == null) {
throw new SequenceFileAnalysisException("Missing FastQC analysis for SequenceFile [" + sequenceFile.getId() + "]");
}
totalBases += sequenceFileFastQC.getTotalBases();
}
}
return totalBases;
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class SampleServiceImpl method mergeSamples.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@PreAuthorize("hasPermission(#project, 'isProjectOwner') and hasPermission(#mergeInto, 'canUpdateSample') and hasPermission(#toMerge, 'canUpdateSample')")
public Sample mergeSamples(Project project, Sample mergeInto, Collection<Sample> toMerge) {
// confirm that all samples are part of the same project:
confirmProjectSampleJoin(project, mergeInto);
logger.debug("Merging samples " + toMerge.stream().map(t -> t.getId()).collect(Collectors.toList()) + " into sample [" + mergeInto.getId() + "]");
for (Sample s : toMerge) {
confirmProjectSampleJoin(project, s);
List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(s);
for (SampleSequencingObjectJoin join : sequencesForSample) {
SequencingObject sequencingObject = join.getObject();
ssoRepository.delete(join);
addSequencingObjectToSample(mergeInto, sequencingObject);
}
Collection<SampleGenomeAssemblyJoin> genomeAssemblyJoins = getAssembliesForSample(s);
for (SampleGenomeAssemblyJoin join : genomeAssemblyJoins) {
GenomeAssembly genomeAssembly = join.getObject();
logger.trace("Removing genome assembly [" + genomeAssembly.getId() + "] from sample [" + s.getId() + "]");
sampleGenomeAssemblyJoinRepository.delete(join);
logger.trace("Adding genome assembly [" + genomeAssembly.getId() + "] to sample [" + mergeInto.getId() + "]");
SampleGenomeAssemblyJoin newJoin = new SampleGenomeAssemblyJoin(mergeInto, genomeAssembly);
sampleGenomeAssemblyJoinRepository.save(newJoin);
}
// have to remove the sample to be deleted from its project:
ProjectSampleJoin readSampleForProject = psjRepository.readSampleForProject(project, s);
psjRepository.delete(readSampleForProject);
sampleRepository.delete(s.getId());
}
return mergeInto;
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class RESTAnalysisSubmissionController method getAnalysisInputUnpairedFiles.
/**
* get the {@link SequenceFile}s not in {@link SequenceFilePair}s used for
* the {@link AnalysisSubmission}
*
* @param identifier
* the {@link AnalysisSubmission} id
* @return list of {@link SequenceFile}s
*/
@RequestMapping("/{identifier}/sequenceFiles/unpaired")
public ModelMap getAnalysisInputUnpairedFiles(@PathVariable Long identifier) {
ModelMap map = new ModelMap();
AnalysisSubmission analysisSubmission = analysisSubmissionService.read(identifier);
Set<SingleEndSequenceFile> inputFilesSingleEnd = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SingleEndSequenceFile.class);
ResourceCollection<SequencingObject> resources = new ResourceCollection<>(inputFilesSingleEnd.size());
for (SingleEndSequenceFile file : inputFilesSingleEnd) {
SampleSequencingObjectJoin join = sampleService.getSampleForSequencingObject(file);
if (join != null) {
SequencingObject sequencingObject = join.getObject();
RESTSampleSequenceFilesController.addSequencingObjectLinks(sequencingObject, join.getSubject().getId());
resources.add(sequencingObject);
}
}
resources.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisInputUnpairedFiles(identifier)).withSelfRel());
map.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
return map;
}
Aggregations