Search in sources :

Example 6 with CollectionResponse

use of com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse in project irida by phac-nml.

the class AnalysisCollectionServiceGalaxyIT method testUploadSequenceFilesSingleSuccess.

/**
 * Tests successfully uploading a single end sequence file to Galaxy and
 * constructing a collection.
 *
 * @throws ExecutionManagerException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testUploadSequenceFilesSingleSuccess() throws ExecutionManagerException {
    History history = new History();
    history.setName("testUploadSequenceFilesSingleSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    Library library = new Library();
    library.setName("testUploadSequenceFilesSingleSuccess");
    Library createdLibrary = librariesClient.createLibrary(library);
    Set<SingleEndSequenceFile> sequenceFiles = Sets.newHashSet(databaseSetupGalaxyITService.setupSequencingObjectInDatabase(1L, sequenceFilePathA));
    Map<Sample, IridaSingleEndSequenceFile> sampleSequenceFiles = new HashMap<>(sequencingObjectService.getUniqueSamplesForSequencingObjects(sequenceFiles));
    Sample sample1 = sampleRepository.findOne(1L);
    CollectionResponse collectionResponse = analysisCollectionServiceGalaxy.uploadSequenceFilesSingleEnd(sampleSequenceFiles, createdHistory, createdLibrary);
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("historyContents should have size 2", 2, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("sequenceFile should have been uploaded to history", contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("dataset collection with name " + INPUTS_SINGLE_NAME + " should have been created in history", contentsMap.containsKey(INPUTS_SINGLE_NAME));
    // verify correct collection has been created
    assertEquals("constructed dataset collection should have been " + DatasetCollectionType.LIST + " but is instead " + collectionResponse.getCollectionType(), DatasetCollectionType.LIST.toString(), collectionResponse.getCollectionType());
    List<CollectionElementResponse> collectionElements = collectionResponse.getElements();
    assertEquals("dataset collection should have only 1 element", 1, collectionElements.size());
    Map<String, CollectionElementResponse> collectionElementsMap = collectionElementsAsMap(collectionElements);
    assertTrue("dataset collection should have an element with the name " + sample1.getSampleName(), collectionElementsMap.containsKey(sample1.getSampleName()));
    CollectionElementResponse sample1Response = collectionElementsMap.get(sample1.getSampleName());
    assertEquals("invalid type for dataset element", HISTORY_DATASET_NAME, sample1Response.getElementType());
}
Also used : CollectionElementResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionElementResponse) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) IridaSingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSingleEndSequenceFile) IridaSingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSingleEndSequenceFile) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 7 with CollectionResponse

use of com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse 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

CollectionResponse (com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse)7 History (com.github.jmchilton.blend4j.galaxy.beans.History)6 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 Test (org.junit.Test)4 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)3 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)3 Dataset (com.github.jmchilton.blend4j.galaxy.beans.Dataset)3 Library (com.github.jmchilton.blend4j.galaxy.beans.Library)3 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)2 LibrariesClient (com.github.jmchilton.blend4j.galaxy.LibrariesClient)2 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)2 WorkflowDetails (com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails)2 WorkflowInputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs)2 CollectionDescription (com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription)2 HistoryDatasetElement (com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement)2 CollectionElementResponse (com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionElementResponse)2 HashMap (java.util.HashMap)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 SampleAnalysisDuplicateException (ca.corefacility.bioinformatics.irida.exceptions.SampleAnalysisDuplicateException)1 IridaSequenceFilePair (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair)1