use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.
the class PipelineController method ajaxStartPipeline.
// ************************************************************************************************
// AJAX
// ************************************************************************************************
/**
* Launch a pipeline
*
* @param locale the locale that the browser is using for the current request.
* @param parameters DTO of pipeline start parameters
* @return a JSON response with the status and any messages.
*/
@RequestMapping(value = "/ajax/start", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> ajaxStartPipeline(Locale locale, @RequestBody final PipelineStartParameters parameters) {
try {
IridaWorkflow flow = workflowsService.getIridaWorkflow(parameters.getWorkflowId());
IridaWorkflowDescription description = flow.getWorkflowDescription();
// The pipeline needs to have a name.
String name = parameters.getName();
if (Strings.isNullOrEmpty(name)) {
return ImmutableMap.of("error", messageSource.getMessage("workflow.no-name-provided", null, locale));
}
// Check to see if a reference file is required.
Long ref = parameters.getRef();
if (description.requiresReference() && ref == null) {
return ImmutableMap.of("error", messageSource.getMessage("pipeline.error.no-reference.pipeline-start", null, locale));
}
// Get a list of the files to submit
List<SingleEndSequenceFile> singleEndFiles = new ArrayList<>();
List<SequenceFilePair> sequenceFilePairs = new ArrayList<>();
List<Long> single = parameters.getSingle();
if (single != null) {
Iterable<SequencingObject> readMultiple = sequencingObjectService.readMultiple(single);
readMultiple.forEach(f -> {
if (!(f instanceof SingleEndSequenceFile)) {
throw new IllegalArgumentException("file " + f.getId() + " not a SingleEndSequenceFile");
}
singleEndFiles.add((SingleEndSequenceFile) f);
});
// Check the single files for duplicates in a sample, throws SampleAnalysisDuplicateException
sequencingObjectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(singleEndFiles));
}
List<Long> paired = parameters.getPaired();
if (paired != null) {
Iterable<SequencingObject> readMultiple = sequencingObjectService.readMultiple(paired);
readMultiple.forEach(f -> {
if (!(f instanceof SequenceFilePair)) {
throw new IllegalArgumentException("file " + f.getId() + " not a SequenceFilePair");
}
sequenceFilePairs.add((SequenceFilePair) f);
});
// Check the pair files for duplicates in a sample, throws SampleAnalysisDuplicateException
sequencingObjectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(sequenceFilePairs));
}
// Get the pipeline parameters
Map<String, String> params = new HashMap<>();
IridaWorkflowNamedParameters namedParameters = null;
Map<String, Object> selectedParameters = parameters.getSelectedParameters();
if (selectedParameters != null) {
try {
final String selectedParametersId = selectedParameters.get("id").toString();
if (!DEFAULT_WORKFLOW_PARAMETERS_ID.equals(selectedParametersId) && !CUSTOM_UNSAVED_WORKFLOW_PARAMETERS_ID.equals(selectedParametersId)) {
// this means that a named parameter set was selected
// and unmodified, so load up that named parameter set
// to pass along.
namedParameters = namedParameterService.read(Long.valueOf(selectedParametersId));
} else {
@SuppressWarnings("unchecked") final List<Map<String, String>> unnamedParameters = (List<Map<String, String>>) selectedParameters.get("parameters");
for (final Map<String, String> parameter : unnamedParameters) {
params.put(parameter.get("name"), parameter.get("value"));
}
}
} catch (Exception e) {
return ImmutableMap.of("parameterError", messageSource.getMessage("pipeline.parameters.error", null, locale));
}
}
List<Project> projectsToShare = new ArrayList<>();
List<Long> sharedProjects = parameters.getSharedProjects();
if (sharedProjects != null && !sharedProjects.isEmpty()) {
projectsToShare = Lists.newArrayList(projectService.readMultiple(sharedProjects));
}
String analysisDescription = parameters.getDescription();
Boolean writeResultsToSamples = parameters.getWriteResultsToSamples();
if (description.getInputs().requiresSingleSample()) {
analysisSubmissionService.createSingleSampleSubmission(flow, ref, singleEndFiles, sequenceFilePairs, params, namedParameters, name, analysisDescription, projectsToShare, writeResultsToSamples);
} else {
analysisSubmissionService.createMultipleSampleSubmission(flow, ref, singleEndFiles, sequenceFilePairs, params, namedParameters, name, analysisDescription, projectsToShare, writeResultsToSamples);
}
} catch (IridaWorkflowNotFoundException e) {
logger.error("Cannot find IridaWorkflow [" + parameters.getWorkflowId() + "]", e);
return ImmutableMap.of("pipelineError", messageSource.getMessage("pipeline.error.invalid-pipeline", null, locale));
} catch (DuplicateSampleException e) {
logger.error("Multiple files for Sample found", e);
return ImmutableMap.of("pipelineError", messageSource.getMessage("pipeline.error.duplicate-samples", null, locale));
}
return ImmutableMap.of("success", true);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.
the class SequencingObjectConcatenatorFactoryTest method testGetConcatenatorPairCollection.
@Test
public void testGetConcatenatorPairCollection() {
Set<SequenceFilePair> fileSet = Sets.newHashSet(new SequenceFilePair());
SequencingObjectConcatenator<?> concatenator = SequencingObjectConcatenatorFactory.getConcatenator(fileSet);
assertTrue(concatenator instanceof SequenceFilePairConcatenator);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.
the class SequencingObjectConcatenatorFactoryTest method testGetConcatenatorMixedError.
@Test(expected = IllegalArgumentException.class)
public void testGetConcatenatorMixedError() {
Set<SequencingObject> fileSet = Sets.newHashSet(new SequenceFilePair(), new SingleEndSequenceFile(null));
SequencingObjectConcatenatorFactory.getConcatenator(fileSet);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair in project irida by phac-nml.
the class AssemblyFileProcessorTest method testAssemblyDisabled.
@Test
public void testAssemblyDisabled() {
Long sequenceFileId = 1L;
SequenceFilePair pair = new SequenceFilePair();
Sample sample = new Sample();
Project project = new Project();
project.setAssembleUploads(false);
when(objectRepository.findOne(sequenceFileId)).thenReturn(pair);
when(ssoRepository.getSampleForSequencingObject(pair)).thenReturn(new SampleSequencingObjectJoin(sample, pair));
when(psjRepository.getProjectForSample(sample)).thenReturn(ImmutableList.of(new ProjectSampleJoin(project, sample, true)));
assertFalse("processor should not want to assemble file", processor.shouldProcessFile(sequenceFileId));
verifyZeroInteractions(submissionRepository);
}
Aggregations