Search in sources :

Example 46 with SequencingObject

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject 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 47 with SequencingObject

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

the class AnalysisWorkspaceServiceGalaxyTest method testGetAnalysisResultsSuccessSinglePairedEnd.

/**
 * Tests successfully getting analysis results from Galaxy with
 * single/paired end input files.
 *
 * @throws IridaWorkflowNotFoundException
 * @throws IOException
 * @throws ExecutionManagerException
 * @throws IridaWorkflowAnalysisTypeException
 */
@Test
public void testGetAnalysisResultsSuccessSinglePairedEnd() throws IridaWorkflowNotFoundException, IridaWorkflowAnalysisTypeException, ExecutionManagerException, IOException {
    Set<SingleEndSequenceFile> singleFiles = Sets.newHashSet(sampleSingleSequenceFileMap.values());
    Set<SequenceFilePair> pairedFiles = Sets.newHashSet(sampleSequenceFilePairMap.values());
    Set<SequencingObject> joinedFiles = Sets.newHashSet(singleFiles);
    joinedFiles.addAll(pairedFiles);
    Map<Sample, SequencingObject> joinedMap = Maps.newHashMap(sampleSingleSequenceFileMap);
    joinedMap.putAll(sampleSequenceFilePairMap);
    submission = AnalysisSubmission.builder(workflowIdMultiSamples).name("my analysis").inputFiles(singleInputFiles).inputFiles(pairedInputFiles).referenceFile(referenceFile).build();
    submission.setRemoteWorkflowId(WORKFLOW_ID);
    submission.setRemoteAnalysisId(HISTORY_ID);
    when(sequencingObjectService.getSequencingObjectsForAnalysisSubmission(submission)).thenReturn(joinedFiles);
    when(iridaWorkflowsService.getIridaWorkflow(workflowIdMultiSamples)).thenReturn(iridaWorkflowSinglePairedMultipleSamples);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output1Filename, HISTORY_ID)).thenReturn(output1Dataset);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output2Filename, HISTORY_ID)).thenReturn(output2Dataset);
    when(sequencingObjectService.getUniqueSamplesForSequencingObjects(joinedFiles)).thenReturn(joinedMap);
    Analysis analysis = workflowPreparation.getAnalysisResults(submission);
    assertNotNull("analysis is not valid", analysis);
    assertEquals("invalid number of output files", 2, analysis.getAnalysisOutputFiles().size());
    assertEquals("missing output file for analysis", Paths.get("output1.txt"), analysis.getAnalysisOutputFile("output1").getFile().getFileName());
    // labels should now not have sample associated with them.
    assertEquals("missing label for analysis output file", "output1.txt", analysis.getAnalysisOutputFile("output1").getLabel());
    assertEquals("missing output file for analysis", "output2.txt", analysis.getAnalysisOutputFile("output2").getLabel());
    verify(galaxyHistoriesService).getDatasetForFileInHistory("output1.txt", HISTORY_ID);
    verify(galaxyHistoriesService).getDatasetForFileInHistory("output2.txt", HISTORY_ID);
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 48 with SequencingObject

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

the class SampleServiceImplTest method so.

private SequencingObject so(Long id) {
    SequencingObject so = new SingleEndSequenceFile(sf(id));
    so.setId(id);
    return so;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 49 with SequencingObject

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

the class SequencingObjectServiceImpl method concatenateSequences.

/**
 * {@inheritDoc}
 */
@Override
@PreAuthorize("hasPermission(#toJoin, 'canReadSequencingObject') and hasPermission(#targetSample, 'canUpdateSample')")
@Transactional
public SampleSequencingObjectJoin concatenateSequences(List<SequencingObject> toJoin, String filename, Sample targetSample, boolean removeOriginals) throws ConcatenateException {
    SequencingObjectConcatenator<? extends SequencingObject> concatenator = SequencingObjectConcatenatorFactory.getConcatenator(toJoin);
    SequencingObject concatenated = concatenator.concatenateFiles(toJoin, filename);
    SampleSequencingObjectJoin created = createSequencingObjectInSample(concatenated, targetSample);
    concatenationRepository.save(new SequenceConcatenation(created.getObject(), toJoin));
    if (removeOriginals) {
        for (SequencingObject obj : toJoin) {
            SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(obj);
            ssoRepository.delete(sampleForSequencingObject);
        }
    }
    return created;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceConcatenation(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceConcatenation) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with SequencingObject

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

the class SequencingObjectServiceImpl method getUniqueSamplesForSequencingObjects.

/**
 * {@inheritDoc}
 */
@PreAuthorize("hasAnyRole('ROLE_ADMIN') or hasPermission(#sequenceFiles, 'canReadSequencingObject')")
@Override
public <T extends SequencingObject> Map<Sample, T> getUniqueSamplesForSequencingObjects(Set<T> sequenceFiles) throws DuplicateSampleException {
    Map<Sample, T> sequenceFilesSampleMap = new HashMap<>();
    for (T seqObj : sequenceFiles) {
        SequenceFile file = seqObj.getFiles().iterator().next();
        SampleSequencingObjectJoin join = ssoRepository.getSampleForSequencingObject(seqObj);
        if (join == null) {
            throw new EntityNotFoundException("No sample associated with sequence file " + seqObj.getClass() + "[id=" + seqObj.getId() + "]");
        } else {
            Sample sample = join.getSubject();
            if (sequenceFilesSampleMap.containsKey(sample)) {
                SequencingObject previousFile = sequenceFilesSampleMap.get(sample);
                throw new DuplicateSampleException("Sequence files " + file + ", " + previousFile + " have the same sample " + sample);
            } else {
                sequenceFilesSampleMap.put(sample, seqObj);
            }
        }
    }
    return sequenceFilesSampleMap;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) DuplicateSampleException(ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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