Search in sources :

Example 1 with SequenceFilePair

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.

the class AnalysisController method getDetailsPage.

/**
 * View details about an individual analysis submission
 *
 * @param submissionId the ID of the submission
 * @param model        Model for the view
 * @param locale       User's locale
 * @return name of the details page view
 */
@RequestMapping(value = "/{submissionId}", produces = MediaType.TEXT_HTML_VALUE)
public String getDetailsPage(@PathVariable Long submissionId, Model model, Locale locale) {
    logger.trace("reading analysis submission " + submissionId);
    AnalysisSubmission submission = analysisSubmissionService.read(submissionId);
    model.addAttribute("analysisSubmission", submission);
    UUID workflowUUID = submission.getWorkflowId();
    logger.trace("Workflow ID is " + workflowUUID);
    IridaWorkflow iridaWorkflow;
    try {
        iridaWorkflow = workflowsService.getIridaWorkflow(workflowUUID);
    } catch (IridaWorkflowNotFoundException e) {
        logger.error("Error finding workflow, ", e);
        throw new EntityNotFoundException("Couldn't find workflow for submission " + submission.getId(), e);
    }
    // Get the name of the workflow
    AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
    model.addAttribute("analysisType", analysisType);
    String viewName = getViewForAnalysisType(analysisType);
    String workflowName = messageSource.getMessage("workflow." + analysisType.toString() + ".title", null, locale);
    model.addAttribute("workflowName", workflowName);
    model.addAttribute("version", iridaWorkflow.getWorkflowDescription().getVersion());
    // Input files
    // - Paired
    Set<SequenceFilePair> inputFilePairs = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SequenceFilePair.class);
    model.addAttribute("paired_end", inputFilePairs);
    // Check if user can update analysis
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    model.addAttribute("updatePermission", updateAnalysisPermission.isAllowed(authentication, submission));
    if (iridaWorkflow.getWorkflowDescription().requiresReference() && submission.getReferenceFile().isPresent()) {
        logger.debug("Adding reference file to page for submission with id [" + submission.getId() + "].");
        model.addAttribute("referenceFile", submission.getReferenceFile().get());
    } else {
        logger.debug("No reference file required for workflow.");
    }
    /*
		 * Preview information
		 */
    try {
        if (submission.getAnalysisState().equals(AnalysisState.COMPLETED)) {
            if (analysisType.equals(AnalysisType.PHYLOGENOMICS)) {
                tree(submission, model);
            } else if (analysisType.equals(AnalysisType.SISTR_TYPING)) {
                model.addAttribute("sistr", true);
            }
        }
    } catch (IOException e) {
        logger.error("Couldn't get preview for analysis", e);
    }
    return viewName;
}
Also used : IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Authentication(org.springframework.security.core.Authentication) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 2 with SequenceFilePair

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.

the class SamplesController method createSequenceFilePairsInSample.

/**
 * Create {@link SequenceFile}'s then add them as {@link SequenceFilePair}
 * to a {@link Sample}
 *
 * @param pair
 *            {@link List} of {@link MultipartFile}
 * @param sample
 *            {@link Sample} to add the pair to.
 * @throws IOException
 */
private void createSequenceFilePairsInSample(List<MultipartFile> pair, Sample sample) throws IOException {
    SequenceFile firstFile = createSequenceFile(pair.get(0));
    SequenceFile secondFile = createSequenceFile(pair.get(1));
    sequencingObjectService.createSequencingObjectInSample(new SequenceFilePair(firstFile, secondFile), sample);
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 3 with SequenceFilePair

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.

the class TestDataFactory method constructSequenceFilePair.

/**
 * Construct a simple {@link SequenceFilePair} object
 *
 * @return a {@link SequenceFilePair}
 * @throws IOException
 *             if the temp files couldn't be created
 */
public static SequenceFilePair constructSequenceFilePair() throws IOException {
    SequenceFile sf1 = constructSequenceFile();
    SequenceFile sf2 = constructSequenceFile();
    SequenceFilePair pair = new SequenceFilePair(sf1, sf2);
    pair.setId(1L);
    return pair;
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 4 with SequenceFilePair

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.

the class SampleSequenceFilesControllerTest method testAddNewSequenceFilePairToSampleMismatchedRunIDs.

@Test(expected = IllegalArgumentException.class)
public void testAddNewSequenceFilePairToSampleMismatchedRunIDs() throws IOException {
    Project p = TestDataFactory.constructProject();
    Sample s = TestDataFactory.constructSample();
    SequenceFilePair pair = TestDataFactory.constructSequenceFilePair();
    SampleSequencingObjectJoin sso = new SampleSequencingObjectJoin(s, pair);
    SequenceFileResource resource1 = new SequenceFileResource();
    SequenceFileResource resource2 = new SequenceFileResource();
    resource1.setMiseqRunId(1L);
    resource2.setMiseqRunId(2L);
    Path f1 = Files.createTempFile(null, null);
    Path f2 = Files.createTempFile(null, null);
    MockMultipartFile mmf1 = new MockMultipartFile("filename1", "filename1", "blurgh1", FileCopyUtils.copyToByteArray(f1.toFile()));
    MockMultipartFile mmf2 = new MockMultipartFile("filename2", "filename2", "blurgh2", FileCopyUtils.copyToByteArray(f2.toFile()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    when(sampleService.getSampleForProject(p, s.getId())).thenReturn(new ProjectSampleJoin(p, s, true));
    when(sequencingObjectService.createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s))).thenReturn(sso);
    controller.addNewSequenceFilePairToSample(s.getId(), mmf1, resource1, mmf2, resource2, response);
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 5 with SequenceFilePair

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.

the class SampleSequenceFilesControllerTest method testAddNewSequenceFilePairToSample.

@Test
public void testAddNewSequenceFilePairToSample() throws IOException {
    Sample s = TestDataFactory.constructSample();
    String file1Name = "file1_R1_01.fastq.gz";
    String file2Name = "file2_R2_01.fastq.gz";
    SequenceFilePair pair = TestDataFactory.constructSequenceFilePair();
    Iterator<SequenceFile> iterator = pair.getFiles().iterator();
    SequenceFile sf1 = iterator.next();
    SequenceFile sf2 = iterator.next();
    sf1.setFile(Paths.get(file1Name));
    sf2.setFile(Paths.get(file2Name));
    sf1.setId(3245L);
    SampleSequencingObjectJoin sso = new SampleSequencingObjectJoin(s, pair);
    SequenceFileResource resource1 = new SequenceFileResource();
    SequenceFileResource resource2 = new SequenceFileResource();
    Path f1 = Files.createTempFile(null, null);
    Path f2 = Files.createTempFile(null, null);
    MockMultipartFile mmf1 = new MockMultipartFile(file1Name, file1Name, "blurgh1", FileCopyUtils.copyToByteArray(f1.toFile()));
    MockMultipartFile mmf2 = new MockMultipartFile(file2Name, file2Name, "blurgh2", FileCopyUtils.copyToByteArray(f2.toFile()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    // mock out the service calls
    when(sampleService.read(s.getId())).thenReturn(s);
    when(sequencingObjectService.createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s))).thenReturn(sso);
    ModelMap modelMap = controller.addNewSequenceFilePairToSample(s.getId(), mmf1, resource1, mmf2, resource2, response);
    verify(sampleService).read(s.getId());
    verify(sequencingObjectService).createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s));
    Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
    assertNotNull("Object should not be null", o);
    assertTrue("Object should be an instance of SequenceFilePair", o instanceof SequenceFilePair);
    SequenceFilePair returnVal = (SequenceFilePair) o;
    Link selfCollection = returnVal.getLink(Link.REL_SELF);
    Link sampleRC = returnVal.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
    Link sampleSequenceFiles = returnVal.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
    String sampleLocation = "http://localhost/api/samples/" + s.getId();
    String pairLocation = sampleLocation + "/pairs/" + pair.getId();
    assertEquals("Pair location should be correct", pairLocation, selfCollection.getHref());
    assertEquals("Sample location should be correct", sampleLocation, sampleRC.getHref());
    assertEquals("Sequence file location should be correct", sampleLocation + "/sequenceFiles", sampleSequenceFiles.getHref());
    String sequenceFileLocation1 = pairLocation + "/files/" + sf1.getId();
    String sequenceFileLocation2 = pairLocation + "/files/" + sf2.getId();
    String[] sequenceFileLocs = new String[] { sequenceFileLocation1, sequenceFileLocation2 };
    String locationHeader = response.getHeader(HttpHeaders.LOCATION);
    assertEquals("The location header should have the self rel", pairLocation, locationHeader);
    Iterator<SequenceFile> filesIterator = returnVal.getFiles().iterator();
    for (int i = 0; i < 2; i++) {
        SequenceFile returnedFile = filesIterator.next();
        Link self = returnedFile.getLink(Link.REL_SELF);
        assertNotNull("Self link should not be null", self);
        assertEquals("Self reference should be correct", sequenceFileLocs[i], self.getHref());
    }
    assertEquals("HTTP status must be CREATED", HttpStatus.CREATED.value(), response.getStatus());
    Files.delete(f1);
    Files.delete(f2);
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Aggregations

SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)59 Test (org.junit.Test)33 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)28 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)23 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)22 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)19 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)13 Project (ca.corefacility.bioinformatics.irida.model.project.Project)12 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)12 WithMockUser (org.springframework.security.test.context.support.WithMockUser)12 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)11 Path (java.nio.file.Path)11 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)9 History (com.github.jmchilton.blend4j.galaxy.beans.History)8 User (ca.corefacility.bioinformatics.irida.model.user.User)7 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)7 ArrayList (java.util.ArrayList)7 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)5 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)5 ImmutableMap (com.google.common.collect.ImmutableMap)5