Search in sources :

Example 16 with WorkflowInputs

use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs 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)

Example 17 with WorkflowInputs

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

the class AnalysisWorkspaceServiceGalaxy method prepareReferenceFile.

/**
 * Prepares a reference file for input to the workflow.
 *
 * @param referenceFile
 *            The {@link ReferenceFile} for the workflow.
 * @param workflowHistory
 *            The {@link History} for the workflow.
 * @param referenceFileLabel
 *            The label for the reference file in the workflow.
 * @param workflowDetails
 *            The {@link WorkflowDetails} for the workflow.
 * @param inputs
 *            The {@link WorkflowInputs} object used to setup inputs for the
 *            workflow.
 * @throws UploadException
 *             If there's an exception when uploading files to the workflow
 *             engine.
 * @throws GalaxyDatasetException
 *             If there's an exception with Galaxy datasets.
 * @throws WorkflowException
 *             If there's an exception with workflow methods.
 */
private void prepareReferenceFile(ReferenceFile referenceFile, History workflowHistory, String referenceFileLabel, WorkflowDetails workflowDetails, WorkflowInputs inputs) throws UploadException, GalaxyDatasetException, WorkflowException {
    Dataset referenceDataset = galaxyHistoriesService.fileToHistory(referenceFile.getFile(), InputFileType.FASTA, workflowHistory);
    String workflowReferenceFileInputId = galaxyWorkflowService.getWorkflowInputId(workflowDetails, referenceFileLabel);
    inputs.setInput(workflowReferenceFileInputId, new WorkflowInputs.WorkflowInput(referenceDataset.getId(), WorkflowInputs.InputSourceType.HDA));
}
Also used : Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs)

Aggregations

WorkflowInputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs)17 WorkflowInputsGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy)13 Test (org.junit.Test)11 ImmutableMap (com.google.common.collect.ImmutableMap)7 Map (java.util.Map)7 History (com.github.jmchilton.blend4j.galaxy.beans.History)6 IridaToolParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter)5 IridaWorkflowParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter)5 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)4 PreparedWorkflowGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy)4 Dataset (com.github.jmchilton.blend4j.galaxy.beans.Dataset)4 WorkflowDetails (com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails)4 Path (java.nio.file.Path)4 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)3 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)3 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)3 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)3 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)3 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)3 WorkflowOutputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowOutputs)3