use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin in project irida by phac-nml.
the class AssemblySampleUpdaterIT method testUpdateSuccess.
@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testUpdateSuccess() {
AnalysisSubmission a = analysisSubmissionRepository.findOne(1L);
Sample s = sampleRepository.findOne(2L);
assertEquals("Should be no join between sample and assembly", 0, sampleGenomeAssemblyJoinRepository.count());
assemblySampleUpdater.update(Sets.newHashSet(s), a);
assertEquals("Should exist a join between sample and assembly", 1, sampleGenomeAssemblyJoinRepository.count());
SampleGenomeAssemblyJoin j = sampleGenomeAssemblyJoinRepository.findAll().iterator().next();
assertEquals("Should have joined sample 2L", (Long) 2L, j.getSubject().getId());
assertNotNull("Should have joined an assembly", j.getObject().getId());
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin in project irida by phac-nml.
the class SampleServiceImpl method removeGenomeAssemblyFromSample.
/**
* {@inheritDoc}
*/
@Transactional
@PreAuthorize("hasPermission(#sample, 'canUpdateSample')")
@Override
public void removeGenomeAssemblyFromSample(Sample sample, Long genomeAssemblyId) {
SampleGenomeAssemblyJoin join = sampleGenomeAssemblyJoinRepository.findBySampleAndAssemblyId(sample.getId(), genomeAssemblyId);
if (join != null) {
logger.debug("Removing genome assembly [" + genomeAssemblyId + "] from sample [" + sample.getId() + "]");
sampleGenomeAssemblyJoinRepository.delete(join.getId());
} else {
logger.trace("Genome assembly [" + genomeAssemblyId + "] is not associated with sample [" + sample.getId() + "]. Ignoring.");
}
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin 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.joins.impl.SampleGenomeAssemblyJoin in project irida by phac-nml.
the class AssemblySampleUpdater method update.
/**
* {@inheritDoc}
*/
@Override
public void update(Collection<Sample> samples, AnalysisSubmission analysis) {
checkArgument(samples.size() == 1, "Error: expected only 1 sample, but got " + samples.size() + " samples");
Sample sample = samples.iterator().next();
GenomeAssembly genomeAssembly = genomeAssemblyRepository.save(new GenomeAssemblyFromAnalysis(analysis));
SampleGenomeAssemblyJoin sampleGenomeAssemblyJoin = new SampleGenomeAssemblyJoin(sample, genomeAssembly);
logger.trace("Saving join for sample [" + sample.getId() + "] to analysis submission [" + analysis.getId() + "]");
sampleGenomeAssemblyJoinRepository.save(sampleGenomeAssemblyJoin);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin in project irida by phac-nml.
the class SampleServiceImplIT method testGetAssembliesForSampleSuccess.
@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testGetAssembliesForSampleSuccess() {
Sample s = sampleService.read(1L);
Collection<SampleGenomeAssemblyJoin> joins = sampleService.getAssembliesForSample(s);
assertEquals("should have same size for assemblies", 1, joins.size());
SampleGenomeAssemblyJoin join = joins.iterator().next();
assertEquals("Should be same sample", s.getId(), join.getSubject().getId());
assertEquals("Should be same assembly", new Long(1L), join.getObject().getId());
}
Aggregations