Search in sources :

Example 1 with SequencingObject

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

the class SequencingRunController method getPageDetails.

private Model getPageDetails(Long runId, Model model) {
    SequencingRun run = sequencingRunService.read(runId);
    Set<SequencingObject> sequencingObjectsForSequencingRun = objectService.getSequencingObjectsForSequencingRun(run);
    int fileCount = sequencingObjectsForSequencingRun.stream().mapToInt(o -> o.getFiles().size()).sum();
    model.addAttribute("sequencingObjects", sequencingObjectsForSequencingRun);
    model.addAttribute("fileCount", fileCount);
    model.addAttribute("run", run);
    return model;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) java.util(java.util) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) ImmutableMap(com.google.common.collect.ImmutableMap) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) DTSequencingRun(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTSequencingRun) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) SequencingRunService(ca.corefacility.bioinformatics.irida.service.SequencingRunService) Page(org.springframework.data.domain.Page) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Collectors(java.util.stream.Collectors) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Model(org.springframework.ui.Model) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) User(ca.corefacility.bioinformatics.irida.model.user.User) Sort(org.springframework.data.domain.Sort) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) MessageSource(org.springframework.context.MessageSource) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) DTSequencingRun(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTSequencingRun) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun)

Example 2 with SequencingObject

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

the class SamplesController method getConcatenatePage.

/**
 * Get the page for concatenating {@link SequencingObject}s in a
 * {@link Sample}
 *
 * @param sampleId
 *            the {@link Sample} to get files for
 * @param model
 *            model for the view
 * @return name of the files concatenate page
 */
@RequestMapping(value = { "/samples/{sampleId}/concatenate", "/projects/{projectId}/samples/{sampleId}/concatenate" }, method = RequestMethod.GET)
public String getConcatenatePage(@PathVariable Long sampleId, Model model) {
    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);
    List<SequencingObject> filePairs = filePairJoins.stream().map(SampleSequencingObjectJoin::getObject).collect(Collectors.toList());
    // SequenceFile
    model.addAttribute("paired_end", filePairs);
    model.addAttribute("single_end", singleFileJoins);
    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 FILES_CONCATENATE_PAGE;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)

Example 3 with SequencingObject

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

the class SamplesController method concatenateSequenceFiles.

/**
 * Concatenate a collection of {@link SequencingObject}s
 *
 * @param sampleId
 *            the id of the {@link Sample} to concatenate in
 * @param objectIds
 *            the {@link SequencingObject} ids
 * @param filename
 *            base of the new filename to create
 * @param removeOriginals
 *            boolean whether to remove the original files
 * @param model
 *            model for the view
 * @param request
 *            the incoming {@link HttpServletRequest}
 * @return redirect to the files page if successul
 */
@RequestMapping(value = { "/samples/{sampleId}/sequenceFiles/concatenate", "/projects/{projectId}/samples/{sampleId}/sequenceFiles/concatenate" }, method = RequestMethod.POST)
public String concatenateSequenceFiles(@PathVariable Long sampleId, @RequestParam(name = "seq") Set<Long> objectIds, @RequestParam(name = "filename") String filename, @RequestParam(name = "remove", defaultValue = "false", required = false) boolean removeOriginals, Model model, HttpServletRequest request) {
    Sample sample = sampleService.read(sampleId);
    Iterable<SequencingObject> readMultiple = sequencingObjectService.readMultiple(objectIds);
    try {
        sequencingObjectService.concatenateSequences(Lists.newArrayList(readMultiple), filename, sample, removeOriginals);
    } catch (ConcatenateException ex) {
        logger.error("Error concatenating files: ", ex);
        model.addAttribute("concatenateError", true);
        return getConcatenatePage(sampleId, model);
    }
    final String url = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    final String redirectUrl = url.substring(0, url.indexOf("/concatenate"));
    return "redirect:" + redirectUrl;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException)

Example 4 with SequencingObject

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

the class SequenceFileController method createDefaultPageInfo.

/**
 * Populates the model with the default information for a file.
 *
 * @param sequenceFileId
 *            Id for the sequence file.
 * @param model
 *            {@link Model}
 */
private void createDefaultPageInfo(Long sequencingObjectId, Long sequenceFileId, Model model) {
    SequencingObject seqObject = sequencingObjectService.read(sequencingObjectId);
    SequenceFile file = seqObject.getFileWithId(sequenceFileId);
    AnalysisFastQC fastQC = analysisService.getFastQCAnalysisForSequenceFile(seqObject, file.getId());
    model.addAttribute("sequencingObject", seqObject);
    model.addAttribute("file", file);
    model.addAttribute("created", dateFormatter.print(file.getCreatedDate(), LocaleContextHolder.getLocale()));
    model.addAttribute("fastQC", fastQC);
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)

Example 5 with SequencingObject

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

the class SampleServiceImplTest method testMergeSamples.

@Test
public void testMergeSamples() {
    // For every sample in toMerge, the service should:
    // 1. call SequenceFileRepository to get the sequence files in that
    // sample,
    // 2. call SequenceFileRepository to add the sequence files to
    // mergeInto,
    // 3. call SampleRepository to persist the sample as deleted.
    final int SIZE = 3;
    Sample s = s(1L);
    Project project = p(1L);
    Sample[] toMerge = new Sample[SIZE];
    SequenceFile[] toMerge_sf = new SequenceFile[SIZE];
    SequencingObject[] toMerge_so = new SequencingObject[SIZE];
    SampleSequencingObjectJoin[] s_so_joins = new SampleSequencingObjectJoin[SIZE];
    SampleSequencingObjectJoin[] s_so_original = new SampleSequencingObjectJoin[SIZE];
    ProjectSampleJoin[] p_s_joins = new ProjectSampleJoin[SIZE];
    List<Sample> mergeSamples = new ArrayList<>();
    for (long i = 0; i < SIZE; i++) {
        int p = (int) i;
        toMerge[p] = s(i + 2);
        mergeSamples.add(toMerge[p]);
        toMerge_sf[p] = sf(i + 2);
        toMerge_so[p] = so(i + 2);
        s_so_joins[p] = new SampleSequencingObjectJoin(s, toMerge_so[p]);
        p_s_joins[p] = new ProjectSampleJoin(project, toMerge[p], true);
        List<Join<Project, Sample>> projectSampleJoins = new ArrayList<>();
        projectSampleJoins.add(p_s_joins[p]);
        List<SampleSequencingObjectJoin> sampleSeqObjectJoins = new ArrayList<>();
        SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(toMerge[p], toMerge_so[p]);
        sampleSeqObjectJoins.add(join);
        s_so_original[p] = join;
        when(ssoRepository.getSequencesForSample(toMerge[p])).thenReturn(null);
        when(ssoRepository.getSequencesForSample(toMerge[p])).thenReturn(sampleSeqObjectJoins);
        when(ssoRepository.save(s_so_joins[p])).thenReturn(s_so_joins[p]);
        when(ssoRepository.readObjectForSample(toMerge[p], toMerge_so[p].getId())).thenReturn(join);
        when(psjRepository.getProjectForSample(toMerge[p])).thenReturn(projectSampleJoins);
        // for deletion
        when(psjRepository.readSampleForProject(project, toMerge[p])).thenReturn(p_s_joins[p]);
    }
    List<Join<Project, Sample>> joins = new ArrayList<>();
    joins.add(new ProjectSampleJoin(project, s, true));
    when(psjRepository.getProjectForSample(s)).thenReturn(joins);
    Sample saved = sampleService.mergeSamples(project, s, mergeSamples);
    verify(psjRepository).getProjectForSample(s);
    for (int i = 0; i < SIZE; i++) {
        verify(ssoRepository).getSequencesForSample(toMerge[i]);
        verify(ssoRepository).save(s_so_joins[i]);
        verify(ssoRepository).delete(s_so_original[i]);
        verify(sampleRepository).delete(toMerge[i].getId());
        verify(psjRepository).getProjectForSample(toMerge[i]);
        verify(psjRepository).delete(p_s_joins[i]);
    }
    assertEquals("The saved sample should be the same as the sample to merge into.", s, saved);
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Aggregations

SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)61 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)29 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)25 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)24 Test (org.junit.Test)24 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)16 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)14 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Project (ca.corefacility.bioinformatics.irida.model.project.Project)11 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 Path (java.nio.file.Path)8 ModelMap (org.springframework.ui.ModelMap)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Transactional (org.springframework.transaction.annotation.Transactional)6 IOException (java.io.IOException)5 List (java.util.List)5 Logger (org.slf4j.Logger)5