Search in sources :

Example 21 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingRunServiceImplIT method testAddSequenceFileToMiseqRun.

private void testAddSequenceFileToMiseqRun() throws IOException, InterruptedException {
    SequencingRun miseqRun = miseqRunService.read(1L);
    // we can't actually know a file name in the XML file that we use to
    // populate the database for these tests, so the files don't exist
    // anywhere. Create a new temp file and update that in the database
    // prior to adding a file to a miseq run so that we have something there
    // that we can link to.
    Path sequenceFile = Files.createTempFile(null, null);
    Files.write(sequenceFile, FASTQ_FILE_CONTENTS);
    SequenceFile sf = new SequenceFile(sequenceFile);
    SequencingObject so = new SingleEndSequenceFile(sf);
    so = objectService.create(so);
    miseqRunService.addSequencingObjectToSequencingRun(miseqRun, so);
    SequencingRun saved = miseqRunService.read(1L);
    SequencingObject readObject = objectService.read(so.getId());
    Set<SequencingObject> sequencingObjectsForSequencingRun = objectService.getSequencingObjectsForSequencingRun(saved);
    assertTrue("Saved miseq run should have seqence file", sequencingObjectsForSequencingRun.contains(so));
    if (SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN"))) {
        AnalysisFastQC analysis = null;
        do {
            try {
                readObject = objectService.read(so.getId());
                SequenceFile readFile = readObject.getFiles().iterator().next();
                analysis = analysisService.getFastQCAnalysisForSequenceFile(readObject, readFile.getId());
            } catch (final EntityNotFoundException e) {
                logger.info("Fastqc still isn't finished, sleeping a bit.");
                Thread.sleep(1000);
            }
        } while (analysis == null);
        assertNotNull("FastQC analysis should have been created for uploaded file.", analysis);
    }
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)

Example 22 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingObjectServiceTest method testCreateSequenceFileInSampleWrongType.

@Test(expected = IllegalArgumentException.class)
public void testCreateSequenceFileInSampleWrongType() throws IOException {
    Sample s = new Sample();
    SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
    SequencingRun run = new MiseqRun(LayoutType.PAIRED_END, "workflow");
    so.setSequencingRun(run);
    when(repository.save(so)).thenReturn(so);
    service.createSequencingObjectInSample(so, s);
}
Also used : MiseqRun(ca.corefacility.bioinformatics.irida.model.run.MiseqRun) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 23 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingObjectServiceTest method testCreateSequenceFilePairInSampleWrongType.

@Test(expected = IllegalArgumentException.class)
public void testCreateSequenceFilePairInSampleWrongType() throws IOException {
    Sample s = new Sample();
    SequencingRun run = new MiseqRun(LayoutType.SINGLE_END, "workflow");
    SequenceFilePair so = TestDataFactory.constructSequenceFilePair();
    so.setSequencingRun(run);
    when(repository.save(so)).thenReturn(so);
    service.createSequencingObjectInSample(so, s);
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) MiseqRun(ca.corefacility.bioinformatics.irida.model.run.MiseqRun) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Test(org.junit.Test)

Example 24 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingRunServiceImpl method delete.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@PreAuthorize("hasRole('ROLE_ADMIN')")
public void delete(Long id) {
    Set<Sample> referencedSamples = new HashSet<>();
    logger.trace("Getting samples for SequencingRun " + id);
    // Get the Files from the SequencingRun to delete
    SequencingRun read = read(id);
    Set<SequencingObject> findSequencingObjectsForSequencingRun = objectRepository.findSequencingObjectsForSequencingRun(read);
    // For each file in the run
    for (SequencingObject sequencingObject : findSequencingObjectsForSequencingRun) {
        // get the sample the file is in. If the sample is empty when this
        // is complete it will be removed
        SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(sequencingObject);
        if (sampleForSequencingObject != null) {
            logger.trace("Sample " + sampleForSequencingObject.getSubject().getId() + " is used in this run");
            referencedSamples.add(sampleForSequencingObject.getSubject());
        }
        // Get the analysis submissions this file is included in
        Set<AnalysisSubmission> submissions = submissionRepository.findAnalysisSubmissionsForSequecingObject(sequencingObject);
        // If there are no submissions, we can delete the pair and file
        if (submissions.isEmpty()) {
            logger.trace("Deleting file " + sequencingObject.getId());
            objectRepository.delete(sequencingObject);
        } else {
            logger.trace("Keeping file " + sequencingObject.getId() + " because it's used in an analysis");
            if (sampleForSequencingObject != null) {
                // otherwise we'll just remove it from the sample
                ssoRepository.delete(sampleForSequencingObject);
            }
            sequencingObject.setSequencingRun(null);
            objectRepository.save(sequencingObject);
        }
    }
    // Delete the run
    logger.trace("Deleting SequencingRun " + id);
    super.delete(id);
    // Search if samples are empty. If they are, delete the sample.
    for (Sample sample : referencedSamples) {
        List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(sample);
        if (sequencesForSample.isEmpty()) {
            logger.trace("Sample " + sample.getId() + " is empty.  Deleting sample");
            sampleRepository.delete(sample.getId());
        }
    }
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) HashSet(java.util.HashSet) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingRunController method listSequencingRuns.

/**
 * Get a list of all the sequencing runs
 *
 * @param params a {@link DataTablesParams} of the sort and paging options
 * @param locale the locale used by the browser for the current request.
 * @return A DatatablesResponse of DTSequencingRun of the runs
 */
@RequestMapping(value = "/ajax/list")
@ResponseBody
public DataTablesResponse listSequencingRuns(@DataTablesRequest DataTablesParams params, Locale locale) {
    Sort sort = params.getSort();
    Page<SequencingRun> list = sequencingRunService.list(params.getCurrentPage(), params.getLength(), sort);
    List<DTSequencingRun> runs = list.getContent().stream().map(s -> new DTSequencingRun(s, messageSource.getMessage(UPLOAD_STATUS_MESSAGE_BASE + s.getUploadStatus().toString(), null, locale))).collect(Collectors.toList());
    return new DataTablesResponse(params, list, runs);
}
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) DTSequencingRun(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTSequencingRun) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) DTSequencingRun(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTSequencingRun) Sort(org.springframework.data.domain.Sort) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)25 Test (org.junit.Test)17 WithMockUser (org.springframework.security.test.context.support.WithMockUser)13 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)9 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)8 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)8 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)8 MiseqRun (ca.corefacility.bioinformatics.irida.model.run.MiseqRun)7 Path (java.nio.file.Path)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)3 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)3 ModelMap (org.springframework.ui.ModelMap)3 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)2 CoverageQCEntry (ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry)2 FileProcessorErrorQCEntry (ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry)2 QCEntry (ca.corefacility.bioinformatics.irida.model.sample.QCEntry)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)2