Search in sources :

Example 46 with SequenceFilePair

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

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

the class AnalysisWorkspaceServiceGalaxyTest method testGetAnalysisResultsSuccessMultiSample.

/**
 * Tests successfully getting analysis results from Galaxy where there's
 * multiple samples but workflow should have only accepted single sample (no
 * label on name).
 *
 * @throws IridaWorkflowNotFoundException
 * @throws IOException
 * @throws ExecutionManagerException
 * @throws IridaWorkflowAnalysisTypeException
 */
@Test
public void testGetAnalysisResultsSuccessMultiSample() throws IridaWorkflowNotFoundException, IridaWorkflowAnalysisTypeException, ExecutionManagerException, IOException {
    Set<SingleEndSequenceFile> singleFiles = Sets.newHashSet(sampleSingleSequenceFileMap.values());
    Set<SequenceFilePair> pairedFiles = Sets.newHashSet(sampleSequenceFilePairMap.values());
    submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(pairedInputFiles).referenceFile(referenceFile).build();
    submission.setRemoteWorkflowId(WORKFLOW_ID);
    submission.setRemoteAnalysisId(HISTORY_ID);
    when(sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SingleEndSequenceFile.class)).thenReturn(singleFiles);
    when(sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SequenceFilePair.class)).thenReturn(pairedFiles);
    when(iridaWorkflowsService.getIridaWorkflow(workflowId)).thenReturn(iridaWorkflowSingle);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output1Filename, HISTORY_ID)).thenReturn(output1Dataset);
    when(galaxyHistoriesService.getDatasetForFileInHistory(output2Filename, HISTORY_ID)).thenReturn(output2Dataset);
    when(sequencingObjectService.getUniqueSamplesForSequencingObjects(singleFiles)).thenReturn(sampleSingleSequenceFileMap);
    when(sequencingObjectService.getUniqueSamplesForSequencingObjects(pairedFiles)).thenReturn(sampleSequenceFilePairMap);
    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) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 48 with SequenceFilePair

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

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

the class AnalysisWorkspaceServiceGalaxyTest method testPrepareAnalysisFilesPairedSuccess.

/**
 * Tests out successfully to preparing an analysis with paired files
 *
 * @throws ExecutionManagerException
 * @throws IridaWorkflowException
 */
@SuppressWarnings("unchecked")
@Test
public void testPrepareAnalysisFilesPairedSuccess() throws ExecutionManagerException, IridaWorkflowException {
    Set<SequenceFilePair> pairedFiles = Sets.newHashSet(sampleSequenceFilePairMap.values());
    submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(Sets.newHashSet(pairedFiles)).referenceFile(referenceFile).build();
    submission.setRemoteAnalysisId(HISTORY_ID);
    submission.setRemoteWorkflowId(WORKFLOW_ID);
    when(sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SequenceFilePair.class)).thenReturn(pairedFiles);
    when(iridaWorkflowsService.getIridaWorkflow(workflowId)).thenReturn(iridaWorkflowPaired);
    when(galaxyHistoriesService.findById(HISTORY_ID)).thenReturn(workflowHistory);
    when(galaxyLibrariesService.buildEmptyLibrary(any(GalaxyProjectName.class))).thenReturn(workflowLibrary);
    when(sequencingObjectService.getUniqueSamplesForSequencingObjects(pairedFiles)).thenReturn(sampleSequenceFilePairMap);
    when(galaxyHistoriesService.fileToHistory(refFile, InputFileType.FASTA, workflowHistory)).thenReturn(refDataset);
    when(galaxyWorkflowService.getWorkflowDetails(WORKFLOW_ID)).thenReturn(workflowDetails);
    when(analysisParameterServiceGalaxy.prepareAnalysisParameters(any(Map.class), any(IridaWorkflow.class))).thenReturn(new WorkflowInputsGalaxy(new WorkflowInputs()));
    when(galaxyWorkflowService.getWorkflowInputId(workflowDetails, SEQUENCE_FILE_PAIRED_LABEL)).thenReturn(SEQUENCE_FILE_PAIRED_ID);
    when(galaxyWorkflowService.getWorkflowInputId(workflowDetails, REFERENCE_FILE_LABEL)).thenReturn(REFERENCE_FILE_ID);
    when(analysisCollectionServiceGalaxy.uploadSequenceFilesPaired(any(Map.class), eq(workflowHistory), eq(workflowLibrary))).thenReturn(collectionResponsePaired);
    PreparedWorkflowGalaxy preparedWorkflow = workflowPreparation.prepareAnalysisFiles(submission);
    assertEquals("preparedWorflow history id not equal to " + HISTORY_ID, HISTORY_ID, preparedWorkflow.getRemoteAnalysisId());
    assertEquals("preparedWorkflow library is invalid", LIBRARY_ID, preparedWorkflow.getRemoteDataId());
    assertNotNull("workflowInputs in preparedWorkflow is null", preparedWorkflow.getWorkflowInputs());
    Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
    assertEquals("workflow inputs has invalid size", 2, workflowInputsMap.size());
    assertTrue("workflow inputs should contain reference file entry", workflowInputsMap.containsKey(REFERENCE_FILE_ID));
    assertTrue("workflow inputs should contain sequence file paired entry", workflowInputsMap.containsKey(SEQUENCE_FILE_PAIRED_ID));
    verify(analysisCollectionServiceGalaxy, never()).uploadSequenceFilesSingleEnd(any(Map.class), any(History.class), any(Library.class));
    verify(analysisCollectionServiceGalaxy).uploadSequenceFilesPaired(any(Map.class), any(History.class), any(Library.class));
}
Also used : IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) GalaxyProjectName(ca.corefacility.bioinformatics.irida.model.upload.galaxy.GalaxyProjectName) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) WorkflowInput(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 50 with SequenceFilePair

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

the class AnalysisWorkspaceServiceGalaxy method prepareAnalysisFiles.

/**
 * {@inheritDoc}
 */
@Override
public PreparedWorkflowGalaxy prepareAnalysisFiles(AnalysisSubmission analysisSubmission) throws ExecutionManagerException, IridaWorkflowException {
    checkNotNull(analysisSubmission, "analysisSubmission is null");
    checkNotNull(analysisSubmission.getRemoteAnalysisId(), "analysisId is null");
    checkNotNull(analysisSubmission.getWorkflowId(), "workflowId is null");
    checkNotNull(analysisSubmission.getRemoteWorkflowId(), "remoteWorkflowId is null");
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(analysisSubmission.getWorkflowId());
    IridaWorkflowInput workflowInput = iridaWorkflow.getWorkflowDescription().getInputs();
    Set<SingleEndSequenceFile> singleEndFiles = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SingleEndSequenceFile.class);
    Set<SequenceFilePair> pairedEndFiles = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SequenceFilePair.class);
    if (iridaWorkflow.getWorkflowDescription().requiresReference()) {
        checkArgument(analysisSubmission.getReferenceFile().isPresent(), "workflow requires reference but none defined in submission");
    } else {
        checkArgument(!analysisSubmission.getReferenceFile().isPresent(), "workflow does not require a reference and a reference file is set in the submission");
    }
    if (!iridaWorkflow.getWorkflowDescription().acceptsSingleSequenceFiles()) {
        checkArgument(singleEndFiles.isEmpty(), "workflow does not accept single sequence files, but single sequence files are passed as input to " + analysisSubmission);
    }
    if (!iridaWorkflow.getWorkflowDescription().acceptsPairedSequenceFiles()) {
        checkArgument(pairedEndFiles.isEmpty(), "workflow does not accept paired sequence files, but paired sequence files are passed as input to " + analysisSubmission);
    }
    String temporaryLibraryName = AnalysisSubmission.class.getSimpleName() + "-" + UUID.randomUUID().toString();
    History workflowHistory = galaxyHistoriesService.findById(analysisSubmission.getRemoteAnalysisId());
    Library workflowLibrary = galaxyLibrariesService.buildEmptyLibrary(new GalaxyProjectName(temporaryLibraryName));
    // get unique files for pairs and single files
    Map<Sample, SingleEndSequenceFile> singleFiles = sequencingObjectService.getUniqueSamplesForSequencingObjects(singleEndFiles);
    Map<Sample, SequenceFilePair> pairedFiles = sequencingObjectService.getUniqueSamplesForSequencingObjects(pairedEndFiles);
    // check that there aren't common sample names between single and paired
    if (samplesInCommon(singleFiles, pairedFiles)) {
        throw new SampleAnalysisDuplicateException("Single and paired input files share a common sample for submission " + analysisSubmission);
    }
    String workflowId = analysisSubmission.getRemoteWorkflowId();
    WorkflowDetails workflowDetails = galaxyWorkflowService.getWorkflowDetails(workflowId);
    WorkflowInputsGalaxy workflowInputsGalaxy = analysisParameterServiceGalaxy.prepareAnalysisParameters(analysisSubmission.getInputParameters(), iridaWorkflow);
    WorkflowInputs inputs = workflowInputsGalaxy.getInputsObject();
    inputs.setDestination(new WorkflowInputs.ExistingHistory(workflowHistory.getId()));
    inputs.setWorkflowId(workflowDetails.getId());
    if (!singleFiles.isEmpty()) {
        String sequenceFilesLabelSingle = workflowInput.getSequenceReadsSingle().get();
        String workflowSequenceFileSingleInputId = galaxyWorkflowService.getWorkflowInputId(workflowDetails, sequenceFilesLabelSingle);
        CollectionResponse collectionResponseSingle = analysisCollectionServiceGalaxy.uploadSequenceFilesSingleEnd(singleFiles, workflowHistory, workflowLibrary);
        inputs.setInput(workflowSequenceFileSingleInputId, new WorkflowInputs.WorkflowInput(collectionResponseSingle.getId(), WorkflowInputs.InputSourceType.HDCA));
    }
    if (!pairedFiles.isEmpty()) {
        String sequenceFilesLabelPaired = workflowInput.getSequenceReadsPaired().get();
        String workflowSequenceFilePairedInputId = galaxyWorkflowService.getWorkflowInputId(workflowDetails, sequenceFilesLabelPaired);
        CollectionResponse collectionResponsePaired = analysisCollectionServiceGalaxy.uploadSequenceFilesPaired(pairedFiles, workflowHistory, workflowLibrary);
        inputs.setInput(workflowSequenceFilePairedInputId, new WorkflowInputs.WorkflowInput(collectionResponsePaired.getId(), WorkflowInputs.InputSourceType.HDCA));
    }
    String analysisId = workflowHistory.getId();
    if (iridaWorkflow.getWorkflowDescription().requiresReference()) {
        String referenceFileLabel = workflowInput.getReference().get();
        prepareReferenceFile(analysisSubmission.getReferenceFile().get(), workflowHistory, referenceFileLabel, workflowDetails, inputs);
    }
    return new PreparedWorkflowGalaxy(analysisId, workflowLibrary.getId(), new WorkflowInputsGalaxy(inputs));
}
Also used : IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) IridaWorkflowInput(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowInput) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) GalaxyProjectName(ca.corefacility.bioinformatics.irida.model.upload.galaxy.GalaxyProjectName) History(com.github.jmchilton.blend4j.galaxy.beans.History) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SampleAnalysisDuplicateException(ca.corefacility.bioinformatics.irida.exceptions.SampleAnalysisDuplicateException) WorkflowDetails(com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) Library(com.github.jmchilton.blend4j.galaxy.beans.Library)

Aggregations

SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)59 Test (org.junit.Test)33 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)28 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)23 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)22 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)19 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)13 Project (ca.corefacility.bioinformatics.irida.model.project.Project)12 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)12 WithMockUser (org.springframework.security.test.context.support.WithMockUser)12 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)11 Path (java.nio.file.Path)11 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)9 History (com.github.jmchilton.blend4j.galaxy.beans.History)8 User (ca.corefacility.bioinformatics.irida.model.user.User)7 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)7 ArrayList (java.util.ArrayList)7 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)5 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)5 ImmutableMap (com.google.common.collect.ImmutableMap)5