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;
}
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;
}
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");
}
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;
}
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;
}
Aggregations