Search in sources :

Example 1 with GenomeAssembly

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");
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException) IOException(java.io.IOException) ConstraintViolationException(javax.validation.ConstraintViolationException)

Example 2 with GenomeAssembly

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());
}
Also used : Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 3 with GenomeAssembly

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;
}
Also used : SampleGenomeAssemblyJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with GenomeAssembly

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);
}
Also used : GenomeAssemblyFromAnalysis(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssemblyFromAnalysis) SampleGenomeAssemblyJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly)

Example 5 with GenomeAssembly

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);
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

GenomeAssembly (ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly)8 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)8 SampleGenomeAssemblyJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin)3 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)3 Test (org.junit.Test)3 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)2 Path (java.nio.file.Path)2 Authentication (org.springframework.security.core.Authentication)2 ConcatenateException (ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException)1 GenomeAssemblyFromAnalysis (ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssemblyFromAnalysis)1 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)1 Project (ca.corefacility.bioinformatics.irida.model.project.Project)1 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)1 IOException (java.io.IOException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1