Search in sources :

Example 1 with DuplicateSampleException

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;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) DuplicateSampleException(ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with DuplicateSampleException

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);
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) HashMap(java.util.HashMap) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) ArrayList(java.util.ArrayList) IridaWorkflowNamedParameters(ca.corefacility.bioinformatics.irida.model.workflow.submission.IridaWorkflowNamedParameters) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) DuplicateSampleException(ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) List(java.util.List) ArrayList(java.util.ArrayList) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) IridaWorkflowParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException) IOException(java.io.IOException) DuplicateSampleException(ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) Project(ca.corefacility.bioinformatics.irida.model.project.Project) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DuplicateSampleException (ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException)2 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)2 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)2 HashMap (java.util.HashMap)2 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)1 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)1 IridaWorkflowParameterException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)1 Project (ca.corefacility.bioinformatics.irida.model.project.Project)1 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)1 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)1 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)1 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)1 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)1 IridaWorkflowNamedParameters (ca.corefacility.bioinformatics.irida.model.workflow.submission.IridaWorkflowNamedParameters)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1