Search in sources :

Example 6 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class ProjectSampleMetadataController method saveProjectSampleMetadata.

/**
 * Save uploaded metadata to the
 *
 * @param locale
 * 		{@link Locale} of the current user.
 * @param session
 * 		{@link HttpSession}
 * @param projectId
 * 		{@link Long} identifier for the current project
 *
 * @return {@link Map} of potential errors.
 */
@RequestMapping(value = "/upload/save", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> saveProjectSampleMetadata(Locale locale, HttpSession session, @PathVariable long projectId) {
    Map<String, Object> errors = new HashMap<>();
    Project project = projectService.read(projectId);
    SampleMetadataStorage stored = (SampleMetadataStorage) session.getAttribute("pm-" + projectId);
    if (stored == null) {
        errors.put("stored-error", true);
    }
    List<Sample> samplesToUpdate = new ArrayList<>();
    List<Map<String, String>> found = stored.getFound();
    if (found != null) {
        // Lets try to get a sample
        String sampleNameColumn = stored.getSampleNameColumn();
        List<String> errorList = new ArrayList<>();
        try {
            for (Map<String, String> row : found) {
                String name = row.get(sampleNameColumn);
                Sample sample = sampleService.getSampleBySampleName(project, name);
                row.remove(sampleNameColumn);
                Map<MetadataTemplateField, MetadataEntry> newData = new HashMap<>();
                // Need to overwrite duplicate keys
                for (Entry<String, String> entry : row.entrySet()) {
                    MetadataTemplateField key = metadataTemplateService.readMetadataFieldByLabel(entry.getKey());
                    if (key == null) {
                        key = metadataTemplateService.saveMetadataField(new MetadataTemplateField(entry.getKey(), "text"));
                    }
                    newData.put(key, new MetadataEntry(entry.getValue(), "text"));
                }
                sample.mergeMetadata(newData);
                // Save metadata back to the sample
                samplesToUpdate.add(sample);
            }
            sampleService.updateMultiple(samplesToUpdate);
        } catch (EntityNotFoundException e) {
            // This really should not happen, but hey, you never know!
            errorList.add(messageSource.getMessage("metadata.results.save.sample-not-found", new Object[] { e.getMessage() }, locale));
        }
        if (errorList.size() > 0) {
            errors.put("save-errors", errorList);
        }
    } else {
        errors.put("found-error", messageSource.getMessage("metadata.results.save.found-error", new Object[] {}, locale));
    }
    if (errors.size() == 0) {
        return ImmutableMap.of("success", messageSource.getMessage("metadata.results.save.success", new Object[] { found.size() }, locale));
    }
    return errors;
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SampleMetadataStorage(ca.corefacility.bioinformatics.irida.ria.utilities.SampleMetadataStorage) MetadataEntry(ca.corefacility.bioinformatics.irida.model.sample.metadata.MetadataEntry) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SamplesController method getConcatenatePage.

/**
 * Get the page for concatenating {@link SequencingObject}s in a
 * {@link Sample}
 *
 * @param sampleId
 *            the {@link Sample} to get files for
 * @param model
 *            model for the view
 * @return name of the files concatenate page
 */
@RequestMapping(value = { "/samples/{sampleId}/concatenate", "/projects/{projectId}/samples/{sampleId}/concatenate" }, method = RequestMethod.GET)
public String getConcatenatePage(@PathVariable Long sampleId, Model model) {
    Sample sample = sampleService.read(sampleId);
    model.addAttribute("sampleId", sampleId);
    Collection<SampleSequencingObjectJoin> filePairJoins = sequencingObjectService.getSequencesForSampleOfType(sample, SequenceFilePair.class);
    Collection<SampleSequencingObjectJoin> singleFileJoins = sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
    List<SequencingObject> filePairs = filePairJoins.stream().map(SampleSequencingObjectJoin::getObject).collect(Collectors.toList());
    // SequenceFile
    model.addAttribute("paired_end", filePairs);
    model.addAttribute("single_end", singleFileJoins);
    model.addAttribute(MODEL_ATTR_SAMPLE, sample);
    model.addAttribute(MODEL_ATTR_CAN_MANAGE_SAMPLE, isProjectManagerForSample(sample));
    model.addAttribute(MODEL_ATTR_ACTIVE_NAV, ACTIVE_NAV_FILES);
    return FILES_CONCATENATE_PAGE;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)

Example 8 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SamplesController method removeGenomeAssemblyFromSample.

/**
 * Remove a given {@link GenomeAssembly} from a sample
 *
 * @param attributes
 *            the redirect attributes where we can add flash-scoped messages
 *            for the client.
 * @param sampleId
 *            the {@link Sample} id
 * @param assemblyId
 *            The {@link GenomeAssembly}.
 * @param request
 *            {@link HttpServletRequest}
 * @param locale
 *            the locale specified by the browser.
 * @return map stating the request was successful
 */
@RequestMapping(value = "/samples/{sampleId}/files/assembly/delete", method = RequestMethod.POST)
public String removeGenomeAssemblyFromSample(RedirectAttributes attributes, @PathVariable Long sampleId, @RequestParam Long assemblyId, HttpServletRequest request, Locale locale) {
    Sample sample = sampleService.read(sampleId);
    GenomeAssembly genomeAssembly = sampleService.getGenomeAssemblyForSample(sample, assemblyId);
    try {
        sampleService.removeGenomeAssemblyFromSample(sample, assemblyId);
        attributes.addFlashAttribute("fileDeleted", true);
        attributes.addFlashAttribute("fileDeletedMessage", messageSource.getMessage("samples.files.assembly.removed.message", new Object[] { genomeAssembly.getLabel() }, locale));
    } catch (Exception e) {
        logger.error("Could not remove assembly from sample=" + sample, e);
        attributes.addFlashAttribute("fileDeleted", true);
        attributes.addFlashAttribute("fileDeletedError", messageSource.getMessage("samples.files.assembly.remove.error", new Object[] { sample.getSampleName() }, locale));
    }
    return "redirect:" + request.getHeader("referer");
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException) IOException(java.io.IOException) ConstraintViolationException(javax.validation.ConstraintViolationException)

Example 9 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SamplesController method getSampleSpecificPage.

/**
 **********************************************************************************************
 * PAGE REQUESTS
 ***********************************************************************************************
 */
/**
 * Get the samples details page.
 *
 * @param model
 *            Spring {@link Model}
 * @param sampleId
 *            The id for the sample
 * @return The name of the page.
 */
@RequestMapping(value = { "/samples/{sampleId}/details", "/projects/{projectId}/samples/{sampleId}/details" })
public String getSampleSpecificPage(final Model model, @PathVariable Long sampleId) {
    logger.debug("Getting sample page for sample [" + sampleId + "]");
    Sample sample = sampleService.read(sampleId);
    model.addAttribute(MODEL_ATTR_SAMPLE, sample);
    model.addAttribute(MODEL_ATTR_ACTIVE_NAV, ACTIVE_NAV_DETAILS);
    model.addAttribute(MODEL_ATTR_CAN_MANAGE_SAMPLE, isProjectManagerForSample(sample));
    return SAMPLE_PAGE;
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample)

Example 10 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SamplesController method concatenateSequenceFiles.

/**
 * Concatenate a collection of {@link SequencingObject}s
 *
 * @param sampleId
 *            the id of the {@link Sample} to concatenate in
 * @param objectIds
 *            the {@link SequencingObject} ids
 * @param filename
 *            base of the new filename to create
 * @param removeOriginals
 *            boolean whether to remove the original files
 * @param model
 *            model for the view
 * @param request
 *            the incoming {@link HttpServletRequest}
 * @return redirect to the files page if successul
 */
@RequestMapping(value = { "/samples/{sampleId}/sequenceFiles/concatenate", "/projects/{projectId}/samples/{sampleId}/sequenceFiles/concatenate" }, method = RequestMethod.POST)
public String concatenateSequenceFiles(@PathVariable Long sampleId, @RequestParam(name = "seq") Set<Long> objectIds, @RequestParam(name = "filename") String filename, @RequestParam(name = "remove", defaultValue = "false", required = false) boolean removeOriginals, Model model, HttpServletRequest request) {
    Sample sample = sampleService.read(sampleId);
    Iterable<SequencingObject> readMultiple = sequencingObjectService.readMultiple(objectIds);
    try {
        sequencingObjectService.concatenateSequences(Lists.newArrayList(readMultiple), filename, sample, removeOriginals);
    } catch (ConcatenateException ex) {
        logger.error("Error concatenating files: ", ex);
        model.addAttribute("concatenateError", true);
        return getConcatenatePage(sampleId, model);
    }
    final String url = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    final String redirectUrl = url.substring(0, url.indexOf("/concatenate"));
    return "redirect:" + redirectUrl;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException)

Aggregations

Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)243 Test (org.junit.Test)162 Project (ca.corefacility.bioinformatics.irida.model.project.Project)114 WithMockUser (org.springframework.security.test.context.support.WithMockUser)71 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)62 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)53 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)53 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)41 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)33 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)33 Path (java.nio.file.Path)28 ModelMap (org.springframework.ui.ModelMap)28 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)23 ArrayList (java.util.ArrayList)22 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)17 User (ca.corefacility.bioinformatics.irida.model.user.User)14 HashMap (java.util.HashMap)14 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)13