use of ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException in project irida by phac-nml.
the class SequencingObjectServiceImpl method getUniqueSamplesForSequencingObjects.
/**
* {@inheritDoc}
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN') or hasPermission(#sequenceFiles, 'canReadSequencingObject')")
@Override
public <T extends SequencingObject> Map<Sample, T> getUniqueSamplesForSequencingObjects(Set<T> sequenceFiles) throws DuplicateSampleException {
Map<Sample, T> sequenceFilesSampleMap = new HashMap<>();
for (T seqObj : sequenceFiles) {
SequenceFile file = seqObj.getFiles().iterator().next();
SampleSequencingObjectJoin join = ssoRepository.getSampleForSequencingObject(seqObj);
if (join == null) {
throw new EntityNotFoundException("No sample associated with sequence file " + seqObj.getClass() + "[id=" + seqObj.getId() + "]");
} else {
Sample sample = join.getSubject();
if (sequenceFilesSampleMap.containsKey(sample)) {
SequencingObject previousFile = sequenceFilesSampleMap.get(sample);
throw new DuplicateSampleException("Sequence files " + file + ", " + previousFile + " have the same sample " + sample);
} else {
sequenceFilesSampleMap.put(sample, seqObj);
}
}
}
return sequenceFilesSampleMap;
}
use of ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException 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);
}
Aggregations