Search in sources :

Example 6 with GenomeAssembly

use of ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly in project irida by phac-nml.

the class SamplesControllerTest method testRemoveGenomeAssemblyFromSample.

@Test
public void testRemoveGenomeAssemblyFromSample() {
    Long sampleId = 1L;
    Long assemblyId = 2L;
    GenomeAssembly genomeAssembly = TestDataFactory.constructGenomeAssembly();
    Sample sample = new Sample();
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sampleService.getGenomeAssemblyForSample(sample, assemblyId)).thenReturn(genomeAssembly);
    when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
    RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
    HttpServletRequest request = new MockHttpServletRequest();
    controller.removeGenomeAssemblyFromSample(attributes, sampleId, assemblyId, request, Locale.US);
    verify(sampleService).removeGenomeAssemblyFromSample(sample, assemblyId);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) Test(org.junit.Test)

Example 7 with GenomeAssembly

use of ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly in project irida by phac-nml.

the class SamplesController method downloadAssembly.

/**
 * Downloads an {@link GenomeAssembly} associated with a sample.
 *
 * @param sampleId
 *            Id for the sample containing the assembly to download.
 * @param assemblyId
 *            The id for the assembly.
 * @param response
 *            {@link HttpServletResponse}
 * @throws IOException
 *             if we can't write the file to the response.
 */
@RequestMapping("/samples/download/{sampleId}/assembly/{assemblyId}")
public void downloadAssembly(@PathVariable Long sampleId, @PathVariable Long assemblyId, HttpServletResponse response) throws IOException {
    Sample sample = sampleService.read(sampleId);
    GenomeAssembly genomeAssembly = sampleService.getGenomeAssemblyForSample(sample, assemblyId);
    Path path = genomeAssembly.getFile();
    response.setHeader("Content-Disposition", "attachment; filename=\"" + genomeAssembly.getLabel() + "\"");
    Files.copy(path, response.getOutputStream());
    response.flushBuffer();
}
Also used : Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly)

Example 8 with GenomeAssembly

use of ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly in project irida by phac-nml.

the class SamplesController method getSampleFiles.

/**
 * Get the page that shows the files belonging to that sample.
 *
 * @param model
 *            Spring {@link Model}
 * @param projectId
 *            the id of the {@link Project} the sample is in
 * @param sampleId
 *            Sample id
 * @return a Map representing all files (pairs and singles) for the sample.
 */
@RequestMapping(value = { "/projects/{projectId}/samples/{sampleId}/sequenceFiles" })
public String getSampleFiles(final Model model, @PathVariable Long projectId, @PathVariable Long sampleId) {
    Sample sample = sampleService.read(sampleId);
    model.addAttribute("sampleId", sampleId);
    Collection<SampleSequencingObjectJoin> filePairJoins = sequencingObjectService.getSequencesForSampleOfType(sample, SequenceFilePair.class);
    Collection<SampleSequencingObjectJoin> singleFileJoins = sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
    Collection<SampleGenomeAssemblyJoin> genomeAssemblyJoins = sampleService.getAssembliesForSample(sample);
    logger.trace("Assembly joins " + genomeAssemblyJoins);
    List<GenomeAssembly> genomeAssemblies = genomeAssemblyJoins.stream().map(SampleGenomeAssemblyJoin::getObject).collect(Collectors.toList());
    List<SequencingObject> filePairs = filePairJoins.stream().map(SampleSequencingObjectJoin::getObject).collect(Collectors.toList());
    // get the project if available
    Project project = null;
    if (projectId != null) {
        project = projectService.read(projectId);
    }
    // add project to qc entries and filter any unavailable entries
    for (SequencingObject f : filePairs) {
        enhanceQcEntries(f, project);
    }
    for (SampleSequencingObjectJoin f : singleFileJoins) {
        enhanceQcEntries(f.getObject(), project);
    }
    // SequenceFile
    model.addAttribute("paired_end", filePairs);
    model.addAttribute("single_end", singleFileJoins);
    // assemblies
    model.addAttribute("assemblies", genomeAssemblies);
    model.addAttribute(MODEL_ATTR_SAMPLE, sample);
    model.addAttribute(MODEL_ATTR_CAN_MANAGE_SAMPLE, isProjectManagerForSample(sample));
    model.addAttribute(MODEL_ATTR_ACTIVE_NAV, ACTIVE_NAV_FILES);
    return SAMPLE_FILES_PAGE;
}
Also used : SampleGenomeAssemblyJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) 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)

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