use of ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly in project irida by phac-nml.
the class SamplesController method removeGenomeAssemblyFromSample.
/**
* Remove a given {@link GenomeAssembly} from a sample
*
* @param attributes
* the redirect attributes where we can add flash-scoped messages
* for the client.
* @param sampleId
* the {@link Sample} id
* @param assemblyId
* The {@link GenomeAssembly}.
* @param request
* {@link HttpServletRequest}
* @param locale
* the locale specified by the browser.
* @return map stating the request was successful
*/
@RequestMapping(value = "/samples/{sampleId}/files/assembly/delete", method = RequestMethod.POST)
public String removeGenomeAssemblyFromSample(RedirectAttributes attributes, @PathVariable Long sampleId, @RequestParam Long assemblyId, HttpServletRequest request, Locale locale) {
Sample sample = sampleService.read(sampleId);
GenomeAssembly genomeAssembly = sampleService.getGenomeAssemblyForSample(sample, assemblyId);
try {
sampleService.removeGenomeAssemblyFromSample(sample, assemblyId);
attributes.addFlashAttribute("fileDeleted", true);
attributes.addFlashAttribute("fileDeletedMessage", messageSource.getMessage("samples.files.assembly.removed.message", new Object[] { genomeAssembly.getLabel() }, locale));
} catch (Exception e) {
logger.error("Could not remove assembly from sample=" + sample, e);
attributes.addFlashAttribute("fileDeleted", true);
attributes.addFlashAttribute("fileDeletedError", messageSource.getMessage("samples.files.assembly.remove.error", new Object[] { sample.getSampleName() }, locale));
}
return "redirect:" + request.getHeader("referer");
}
use of ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly in project irida by phac-nml.
the class SampleServiceImplIT method testGetGenomeAssemblyForSampleSuccess.
@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testGetGenomeAssemblyForSampleSuccess() throws AnalysisAlreadySetException {
Path expectedAssemblyPath = outputFileBaseDirectory.resolve("testfile.fasta");
Sample s = sampleService.read(1L);
GenomeAssembly genomeAssembly = sampleService.getGenomeAssemblyForSample(s, 1L);
assertEquals("should have same path for assembly", expectedAssemblyPath, genomeAssembly.getFile());
}
use of ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly 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.assembly.GenomeAssembly 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.assembly.GenomeAssembly in project irida by phac-nml.
the class SamplesControllerTest method testDownloadAssembly.
@Test
public void testDownloadAssembly() throws IOException {
HttpServletResponse response = new MockHttpServletResponse();
Long sampleId = 1L;
Long assemblyId = 3L;
SequenceFile file = new SequenceFile(Paths.get("/tmp"));
file.setId(2L);
Sample sample = new Sample();
GenomeAssembly genomeAssembly = TestDataFactory.constructGenomeAssembly();
when(sampleService.read(sampleId)).thenReturn(sample);
when(sampleService.getGenomeAssemblyForSample(sample, assemblyId)).thenReturn(genomeAssembly);
when(readSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
controller.downloadAssembly(sampleId, assemblyId, response);
verify(sampleService).read(sampleId);
verify(sampleService).getGenomeAssemblyForSample(sample, assemblyId);
}
Aggregations