use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.
the class AnalysisParameterServiceGalaxyTest method testPrepareParametersDefaultSuccess.
/**
* Tests preparing workflow parameters and using the default value defined.
*
* @throws IridaWorkflowParameterException
*/
@Test
public void testPrepareParametersDefaultSuccess() throws IridaWorkflowParameterException {
Map<String, String> parameters = Maps.newHashMap();
WorkflowInputsGalaxy workflowInputsGalaxy = analysisParameterService.prepareAnalysisParameters(parameters, iridaWorkflow);
assertNotNull("workflowInputsGalaxy is null", workflowInputsGalaxy);
WorkflowInputs workflowInputs = workflowInputsGalaxy.getInputsObject();
Map<Object, Map<String, Object>> workflowParameters = workflowInputs.getParameters();
Map<String, Object> tool1Parameters = workflowParameters.get("galaxy-tool1");
assertNotNull("parameters for galaxy-tool1 should not be null", tool1Parameters);
assertEquals("galaxy-tool1,parameter1 is not valid", "0", tool1Parameters.get("parameter1"));
}
use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.
the class AnalysisParameterServiceGalaxy method prepareAnalysisParameters.
/**
* {@inheritDoc}
*/
@Override
public WorkflowInputsGalaxy prepareAnalysisParameters(Map<String, String> parameters, IridaWorkflow iridaWorkflow) throws IridaWorkflowParameterException {
checkNotNull(parameters, "parameters is null");
checkNotNull(iridaWorkflow, "iridaWorkflow is null");
WorkflowInputs inputs = new WorkflowInputs();
Set<String> parameterNamesUsed = Sets.newHashSet();
if (!iridaWorkflow.getWorkflowDescription().acceptsParameters()) {
if (parameters.isEmpty()) {
logger.debug("workflow " + iridaWorkflow + " does not accept parameters and no parameters passed.");
} else {
throw new IridaWorkflowNoParameterException("The workflow " + iridaWorkflow + " does not accept parameters but parameters " + parameters + " were passed.");
}
} else {
List<IridaWorkflowParameter> iridaParameters = iridaWorkflow.getWorkflowDescription().getParameters();
ParameterBuilderGalaxy parameterBuilder = new ParameterBuilderGalaxy();
for (IridaWorkflowParameter iridaParameter : iridaParameters) {
String parameterName = iridaParameter.getName();
String value = parameters.get(parameterName);
parameterNamesUsed.add(parameterName);
if (ignoreDefaultValue(parameters, parameterName)) {
logger.debug("Parameter with name=" + parameterName + " will ignore the default value=" + iridaParameter.getDefaultValue());
} else {
if (useDefaultValue(parameters, parameterName)) {
value = iridaParameter.getDefaultValue();
logger.debug("Parameter with name=" + parameterName + ", for workflow=" + iridaWorkflow + ", has no value set, using defaultValue=" + value);
}
for (IridaToolParameter iridaToolParameter : iridaParameter.getToolParameters()) {
String toolId = iridaToolParameter.getToolId();
String galaxyParameterName = iridaToolParameter.getParameterName();
parameterBuilder.addParameter(toolId, galaxyParameterName, value);
logger.debug("Setting parameter iridaName=" + parameterName + ", galaxyToolId=" + toolId + ", galaxyParameterName=" + galaxyParameterName + ", value=" + value);
}
}
}
for (ParameterBuilderGalaxy.ParameterId parameterId : parameterBuilder.getParameterIds()) {
inputs.setToolParameter(parameterId.getToolId(), parameterId.getStartName(), parameterBuilder.getMappingForParameterId(parameterId));
}
}
Set<String> parameterNamesUnused = Sets.difference(parameters.keySet(), parameterNamesUsed);
if (!parameterNamesUnused.isEmpty()) {
throw new IridaWorkflowParameterException("The set of parameters " + parameterNamesUnused + " are not defined in " + iridaWorkflow);
} else {
return new WorkflowInputsGalaxy(inputs);
}
}
use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.
the class GalaxyWorkflowsIT method runSingleFileTabularWorkflow.
/**
* Runs a test workflow with the given parameters and input file.
*
* @param workflowId
* The id of the workflow to run.
* @param workflowInputLabel
* The lable of the input for the workflow.
* @param history
* The history to run the workflow in.
* @param inputFile
* The file to run the workflow on.
* @param toolName
* The toolName of a parameter to override.
* @param toolParameter
* The overridden tool parameter.
* @return A {@link WorkflowOutputs} for this workflow.
* @throws ExecutionManagerException
*/
private WorkflowOutputs runSingleFileTabularWorkflow(String workflowId, String workflowInputLabel, History history, Path inputFile, String toolName, ToolParameter toolParameter) throws ExecutionManagerException {
checkArgument(Files.exists(inputFile), "inputFile " + inputFile + " does not exist");
WorkflowDetails workflowDetails = workflowsClient.showWorkflow(workflowId);
// upload dataset to history
Dataset inputDataset = fileToHistory(inputFile, "tabular", history.getId());
assertNotNull(inputDataset);
String workflowInputId = galaxyWorkflowService.getWorkflowInputId(workflowDetails, workflowInputLabel);
WorkflowInputs inputs = new WorkflowInputs();
inputs.setDestination(new WorkflowInputs.ExistingHistory(history.getId()));
inputs.setWorkflowId(workflowDetails.getId());
inputs.setInput(workflowInputId, new WorkflowInputs.WorkflowInput(inputDataset.getId(), WorkflowInputs.InputSourceType.HDA));
inputs.setToolParameter(toolName, toolParameter);
// execute workflow
WorkflowOutputs output = workflowsClient.runWorkflow(inputs);
logger.debug("Running workflow in history " + output.getHistoryId());
return output;
}
use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.
the class GalaxyWorkflowsIT method runSingleFileWorkflow.
/**
* Starts the execution of a workflow with a single fastq file and the given workflow id.
* @param inputFile An input file to start the workflow.
* @param inputFileType The file type of the input file.
* @param workflowId The id of the workflow to start.
* @param workflowInputLabel The label of a workflow input in Galaxy.
* @param toolParameters A map of tool parameters to set.
* @throws ExecutionManagerException If there was an error executing the workflow.
*/
private WorkflowOutputs runSingleFileWorkflow(Path inputFile, InputFileType inputFileType, String workflowId, String workflowInputLabel, Map<String, ToolParameter> toolParameters) throws ExecutionManagerException {
checkNotNull(inputFile, "file is null");
checkNotNull(inputFileType, "inputFileType is null");
checkNotNull(workflowInputLabel, "workflowInputLabel is null");
checkArgument(Files.exists(inputFile), "inputFile " + inputFile + " does not exist");
History workflowHistory = galaxyHistory.newHistoryForWorkflow();
WorkflowDetails workflowDetails = workflowsClient.showWorkflow(workflowId);
// upload dataset to history
Dataset inputDataset = galaxyHistory.fileToHistory(inputFile, inputFileType, workflowHistory);
assertNotNull(inputDataset);
String workflowInputId = galaxyWorkflowService.getWorkflowInputId(workflowDetails, workflowInputLabel);
WorkflowInputs inputs = new WorkflowInputs();
inputs.setDestination(new WorkflowInputs.ExistingHistory(workflowHistory.getId()));
inputs.setWorkflowId(workflowDetails.getId());
inputs.setInput(workflowInputId, new WorkflowInputs.WorkflowInput(inputDataset.getId(), WorkflowInputs.InputSourceType.HDA));
if (toolParameters != null) {
for (String toolId : toolParameters.keySet()) {
ToolParameter toolParameter = toolParameters.get(toolId);
inputs.setToolParameter(toolId, toolParameter);
}
}
// execute workflow
WorkflowOutputs output = workflowsClient.runWorkflow(inputs);
logger.debug("Running workflow in history " + output.getHistoryId());
return output;
}
use of com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs in project irida by phac-nml.
the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesParametersSuccessWithNoParameters.
/**
* Tests out successfully preparing paired workflow input files for
* execution, no parameters set.
*
* @throws InterruptedException
* @throws ExecutionManagerException
* @throws IOException
* @throws IridaWorkflowException
*/
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesParametersSuccessWithNoParameters() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
History history = new History();
history.setName("testPrepareAnalysisFilesParametersSuccessWithNoParameters");
HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
History createdHistory = historiesClient.create(history);
IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdPairedWithParameters);
Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupPairSubmissionInDatabase(1L, pairSequenceFiles1A, pairSequenceFiles2A, referenceFilePath, validWorkflowIdPairedWithParameters, false);
analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
WorkflowInputsGalaxy workflowInputsGalaxy = preparedWorkflow.getWorkflowInputs();
assertNotNull("the returned workflow inputs should not be null", workflowInputsGalaxy);
assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
// verify correct files have been uploaded
List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
assertEquals("the created history has an invalid number of elements", 4, historyContents.size());
WorkflowInputs workflowInputs = preparedWorkflow.getWorkflowInputs().getInputsObject();
assertNotNull("created workflowInputs is null", workflowInputs);
Map<String, Object> toolParameters = workflowInputs.getParameters().get("core_pipeline_outputs_paired_with_parameters");
assertNotNull("toolParameters is null", toolParameters);
String coverageMinValue = (String) toolParameters.get("coverageMin");
assertEquals("coverageMinValue should have been changed to default", "10", coverageMinValue);
assertEquals("coverageMidValue should have been changed to default", ImmutableMap.of("coverageMid", "10"), toolParameters.get("conditional"));
String coverageMaxValue = (String) toolParameters.get("coverageMin");
assertEquals("coverageMaxValue should have been changed to default", "10", coverageMaxValue);
}
Aggregations