Search in sources :

Example 1 with SampleGenomeAssemblyJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin in project irida by phac-nml.

the class AssemblySampleUpdaterIT method testUpdateSuccess.

@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testUpdateSuccess() {
    AnalysisSubmission a = analysisSubmissionRepository.findOne(1L);
    Sample s = sampleRepository.findOne(2L);
    assertEquals("Should be no join between sample and assembly", 0, sampleGenomeAssemblyJoinRepository.count());
    assemblySampleUpdater.update(Sets.newHashSet(s), a);
    assertEquals("Should exist a join between sample and assembly", 1, sampleGenomeAssemblyJoinRepository.count());
    SampleGenomeAssemblyJoin j = sampleGenomeAssemblyJoinRepository.findAll().iterator().next();
    assertEquals("Should have joined sample 2L", (Long) 2L, j.getSubject().getId());
    assertNotNull("Should have joined an assembly", j.getObject().getId());
}
Also used : SampleGenomeAssemblyJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 2 with SampleGenomeAssemblyJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin in project irida by phac-nml.

the class SampleServiceImpl method removeGenomeAssemblyFromSample.

/**
 * {@inheritDoc}
 */
@Transactional
@PreAuthorize("hasPermission(#sample, 'canUpdateSample')")
@Override
public void removeGenomeAssemblyFromSample(Sample sample, Long genomeAssemblyId) {
    SampleGenomeAssemblyJoin join = sampleGenomeAssemblyJoinRepository.findBySampleAndAssemblyId(sample.getId(), genomeAssemblyId);
    if (join != null) {
        logger.debug("Removing genome assembly [" + genomeAssemblyId + "] from sample [" + sample.getId() + "]");
        sampleGenomeAssemblyJoinRepository.delete(join.getId());
    } else {
        logger.trace("Genome assembly [" + genomeAssemblyId + "] is not associated with sample [" + sample.getId() + "]. Ignoring.");
    }
}
Also used : SampleGenomeAssemblyJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SampleGenomeAssemblyJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin 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 SampleGenomeAssemblyJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin 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 SampleGenomeAssemblyJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin in project irida by phac-nml.

the class SampleServiceImplIT method testGetAssembliesForSampleSuccess.

@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testGetAssembliesForSampleSuccess() {
    Sample s = sampleService.read(1L);
    Collection<SampleGenomeAssemblyJoin> joins = sampleService.getAssembliesForSample(s);
    assertEquals("should have same size for assemblies", 1, joins.size());
    SampleGenomeAssemblyJoin join = joins.iterator().next();
    assertEquals("Should be same sample", s.getId(), join.getSubject().getId());
    assertEquals("Should be same assembly", new Long(1L), join.getObject().getId());
}
Also used : SampleGenomeAssemblyJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

SampleGenomeAssemblyJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin)6 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)5 GenomeAssembly (ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly)3 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)2 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)2 Test (org.junit.Test)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 Transactional (org.springframework.transaction.annotation.Transactional)2 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 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)1