Search in sources :

Example 21 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class SamplesControllerTest method testGetSampleFiles.

@SuppressWarnings("unchecked")
@Test
public void testGetSampleFiles() throws IOException {
    ExtendedModelMap model = new ExtendedModelMap();
    Long sampleId = 1L;
    Sample sample = new Sample();
    SequenceFile file = new SequenceFile(Paths.get("/tmp"));
    file.setId(2L);
    Project project = new Project();
    List<SampleSequencingObjectJoin> files = Lists.newArrayList(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class)).thenReturn(files);
    when(projectService.getProjectsForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
    when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
    String sampleFiles = controller.getSampleFilesWithoutProject(model, sampleId);
    assertEquals(SamplesController.SAMPLE_FILES_PAGE, sampleFiles);
    assertTrue((boolean) model.get(SamplesController.MODEL_ATTR_CAN_MANAGE_SAMPLE));
    verify(sampleService).read(sampleId);
    verify(sequencingObjectService).getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
    verify(sequencingObjectService).getSequencesForSampleOfType(sample, SequenceFilePair.class);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) 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) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 22 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class SamplesControllerTest method testGetSampleFilesAsAdmin.

@Test
public void testGetSampleFilesAsAdmin() throws IOException {
    ExtendedModelMap model = new ExtendedModelMap();
    Long sampleId = 1L;
    Sample sample = new Sample();
    SequenceFile file = new SequenceFile(Paths.get("/tmp"));
    file.setId(2L);
    List<SampleSequencingObjectJoin> files = Lists.newArrayList(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class)).thenReturn(files);
    when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
    String sampleFiles = controller.getSampleFilesWithoutProject(model, sampleId);
    assertEquals(SamplesController.SAMPLE_FILES_PAGE, sampleFiles);
    assertTrue((boolean) model.get(SamplesController.MODEL_ATTR_CAN_MANAGE_SAMPLE));
    verify(sampleService).read(sampleId);
    verify(sequencingObjectService).getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
    verify(sequencingObjectService).getSequencesForSampleOfType(sample, SequenceFilePair.class);
    verifyZeroInteractions(projectService);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) 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) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 23 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class SampleServiceImpl method getTotalBasesForSample.

/**
 * {@inheritDoc}
 */
@Override
@Transactional(readOnly = true)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#sample, 'canReadSample')")
public Long getTotalBasesForSample(Sample sample) throws SequenceFileAnalysisException {
    checkNotNull(sample, "sample is null");
    long totalBases = 0;
    List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(sample);
    for (SampleSequencingObjectJoin join : sequencesForSample) {
        for (SequenceFile sequenceFile : join.getObject().getFiles()) {
            final AnalysisFastQC sequenceFileFastQC = analysisRepository.findFastqcAnalysisForSequenceFile(sequenceFile);
            if (sequenceFileFastQC == null || sequenceFileFastQC.getTotalBases() == null) {
                throw new SequenceFileAnalysisException("Missing FastQC analysis for SequenceFile [" + sequenceFile.getId() + "]");
            }
            totalBases += sequenceFileFastQC.getTotalBases();
        }
    }
    return totalBases;
}
Also used : SequenceFileAnalysisException(ca.corefacility.bioinformatics.irida.exceptions.SequenceFileAnalysisException) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin 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 25 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class RESTAnalysisSubmissionController method getAnalysisInputUnpairedFiles.

/**
 * get the {@link SequenceFile}s not in {@link SequenceFilePair}s used for
 * the {@link AnalysisSubmission}
 *
 * @param identifier
 *            the {@link AnalysisSubmission} id
 * @return list of {@link SequenceFile}s
 */
@RequestMapping("/{identifier}/sequenceFiles/unpaired")
public ModelMap getAnalysisInputUnpairedFiles(@PathVariable Long identifier) {
    ModelMap map = new ModelMap();
    AnalysisSubmission analysisSubmission = analysisSubmissionService.read(identifier);
    Set<SingleEndSequenceFile> inputFilesSingleEnd = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SingleEndSequenceFile.class);
    ResourceCollection<SequencingObject> resources = new ResourceCollection<>(inputFilesSingleEnd.size());
    for (SingleEndSequenceFile file : inputFilesSingleEnd) {
        SampleSequencingObjectJoin join = sampleService.getSampleForSequencingObject(file);
        if (join != null) {
            SequencingObject sequencingObject = join.getObject();
            RESTSampleSequenceFilesController.addSequencingObjectLinks(sequencingObject, join.getSubject().getId());
            resources.add(sequencingObject);
        }
    }
    resources.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisInputUnpairedFiles(identifier)).withSelfRel());
    map.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
    return map;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)54 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)45 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)30 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)30 Test (org.junit.Test)29 Project (ca.corefacility.bioinformatics.irida.model.project.Project)21 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)16 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)14 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)11 Path (java.nio.file.Path)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ModelMap (org.springframework.ui.ModelMap)9 ArrayList (java.util.ArrayList)8 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)7 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)5 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)4 User (ca.corefacility.bioinformatics.irida.model.user.User)4