use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class ProjectSamplesController method downloadSamples.
/**
* Download a set of sequence files from selected samples within a project
*
* @param projectId Id for a {@link Project}
* @param ids List of ids ofr {@link Sample} within the project
* @param response {@link HttpServletResponse}
* @throws IOException if we fail to read a file from the filesystem.
*/
@RequestMapping(value = "/projects/{projectId}/download/files")
public void downloadSamples(@PathVariable Long projectId, @RequestParam(value = "ids[]") List<Long> ids, HttpServletResponse response) throws IOException {
Project project = projectService.read(projectId);
List<Sample> samples = (List<Sample>) sampleService.readMultiple(ids);
// Add the appropriate headers
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=\"" + project.getName() + ".zip\"");
response.setHeader("Transfer-Encoding", "chunked");
// storing used file names to ensure we don't have a conflict
Set<String> usedFileNames = new HashSet<>();
try (ZipOutputStream outputStream = new ZipOutputStream(response.getOutputStream())) {
for (Sample sample : samples) {
Collection<SampleSequencingObjectJoin> sequencingObjectsForSample = sequencingObjectService.getSequencingObjectsForSample(sample);
for (SampleSequencingObjectJoin join : sequencingObjectsForSample) {
for (SequenceFile file : join.getObject().getFiles()) {
Path path = file.getFile();
String fileName = project.getName() + "/" + sample.getSampleName() + "/" + path.getFileName().toString();
if (usedFileNames.contains(fileName)) {
fileName = handleDuplicate(fileName, usedFileNames);
}
final ZipEntry entry = new ZipEntry(fileName);
// set the file creation time on the zip entry to be
// whatever the creation time is on the filesystem
final BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
entry.setCreationTime(attr.creationTime());
entry.setLastModifiedTime(attr.creationTime());
outputStream.putNextEntry(entry);
usedFileNames.add(fileName);
Files.copy(path, outputStream);
outputStream.closeEntry();
}
}
}
outputStream.finish();
} catch (IOException e) {
// this generally means that the user has cancelled the download
// from their web browser; we can safely ignore this
logger.debug("This *probably* means that the user cancelled the download, " + "but it might be something else, see the stack trace below for more information.", e);
} catch (Exception e) {
logger.error("Download failed...", e);
} finally {
// close the response outputStream so that we're not leaking
// streams.
response.getOutputStream().close();
}
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SamplesController method createSequenceFile.
/**
* Private method to move the sequence file into the correct directory and
* create the {@link SequenceFile} object.
*
* @param file
* {@link MultipartFile} sequence file uploaded.
*
* @return {@link SequenceFile}
* @throws IOException
* Exception thrown if there is an error handling the file.
*/
private SequenceFile createSequenceFile(MultipartFile file) throws IOException {
Path temp = Files.createTempDirectory(null);
Path target = temp.resolve(file.getOriginalFilename());
file.transferTo(target.toFile());
return new SequenceFile(target);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SamplesController method createSequenceFilePairsInSample.
/**
* Create {@link SequenceFile}'s then add them as {@link SequenceFilePair}
* to a {@link Sample}
*
* @param pair
* {@link List} of {@link MultipartFile}
* @param sample
* {@link Sample} to add the pair to.
* @throws IOException
*/
private void createSequenceFilePairsInSample(List<MultipartFile> pair, Sample sample) throws IOException {
SequenceFile firstFile = createSequenceFile(pair.get(0));
SequenceFile secondFile = createSequenceFile(pair.get(1));
sequencingObjectService.createSequencingObjectInSample(new SequenceFilePair(firstFile, secondFile), sample);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class CartController method getSequenceFileList.
/**
* Get {@link SequenceFile}s as a List from a {@link Sample} for JSON serialization
*
* @param samples
* The {@link Sample} set
* @return A List<Map<String,Object>> containing the relevant SequenceFile
* information
*/
private List<Map<String, Object>> getSequenceFileList(Sample sample) {
Collection<SampleSequencingObjectJoin> sequencingObjectsForSample = sequencingObjectService.getSequencingObjectsForSample(sample);
List<Map<String, Object>> sequenceFiles = new ArrayList<>();
for (SampleSequencingObjectJoin join : sequencingObjectsForSample) {
for (SequenceFile seq : join.getObject().getFiles()) {
String objectType = RESTSampleSequenceFilesController.objectLabels.get(join.getObject().getClass());
String seqFileLoc = linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sample.getId(), objectType, join.getObject().getId(), seq.getId())).withSelfRel().getHref();
Map<String, Object> seqMap = ImmutableMap.of("selfRef", seqFileLoc);
sequenceFiles.add(seqMap);
}
}
return sequenceFiles;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SequenceFileController method createDefaultPageInfo.
/**
* Populates the model with the default information for a file.
*
* @param sequenceFileId
* Id for the sequence file.
* @param model
* {@link Model}
*/
private void createDefaultPageInfo(Long sequencingObjectId, Long sequenceFileId, Model model) {
SequencingObject seqObject = sequencingObjectService.read(sequencingObjectId);
SequenceFile file = seqObject.getFileWithId(sequenceFileId);
AnalysisFastQC fastQC = analysisService.getFastQCAnalysisForSequenceFile(seqObject, file.getId());
model.addAttribute("sequencingObject", seqObject);
model.addAttribute("file", file);
model.addAttribute("created", dateFormatter.print(file.getCreatedDate(), LocaleContextHolder.getLocale()));
model.addAttribute("fastQC", fastQC);
}
Aggregations