Search in sources :

Example 31 with SequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.

the class GzipFileProcessorTest method handleCompressedFileWithoutGzExtension.

@Test
public void handleCompressedFileWithoutGzExtension() throws IOException {
    // the file processor should decompress the file, then update the
    // sequence file in the database.
    SequenceFile sf = constructSequenceFile();
    SequenceFile sfUpdated = new SequenceFile();
    sfUpdated.setFile(sf.getFile());
    final Long id = 1L;
    sf.setId(id);
    // compress the file, update the sequence file reference
    Path uncompressed = sf.getFile();
    Path compressed = Files.createTempFile(null, null);
    GZIPOutputStream out = new GZIPOutputStream(Files.newOutputStream(compressed));
    Files.copy(uncompressed, out);
    out.close();
    sf.setFile(compressed);
    SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
    fileProcessor.process(so);
    ArgumentCaptor<SequenceFile> argument = ArgumentCaptor.forClass(SequenceFile.class);
    verify(sequenceFileRepository).save(argument.capture());
    SequenceFile modified = argument.getValue();
    String uncompressedFileContents = new String(Files.readAllBytes(modified.getFile()));
    assertEquals("uncompressed file and file in database should be the same.", FILE_CONTENTS, uncompressedFileContents);
    Files.delete(uncompressed);
    if (Files.exists(compressed)) {
        Files.delete(compressed);
    }
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) GZIPOutputStream(java.util.zip.GZIPOutputStream) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 32 with SequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.

the class RESTSampleSequenceFilesController method getSampleSequenceFiles.

/**
 * Get the {@link SequenceFile} entities associated with a specific
 * {@link Sample}.
 *
 * @param sampleId
 *            the identifier for the {@link Sample}.
 * @return the {@link SequenceFile} entities associated with the
 *         {@link Sample}.
 */
@RequestMapping(value = "/api/samples/{sampleId}/sequenceFiles", method = RequestMethod.GET)
public ModelMap getSampleSequenceFiles(@PathVariable Long sampleId) {
    ModelMap modelMap = new ModelMap();
    logger.debug("Reading seq files for sample " + sampleId);
    Sample sample = sampleService.read(sampleId);
    Collection<SampleSequencingObjectJoin> sequencingObjectsForSample = sequencingObjectService.getSequencingObjectsForSample(sample);
    ResourceCollection<SequenceFile> resources = new ResourceCollection<>();
    /*
		 * Note: This is a kind of antiquated seeing we should be referencing
		 * sequencing objects instead. At the very least the link we're pointing
		 * to here should be going through the sequencing object
		 */
    for (SampleSequencingObjectJoin r : sequencingObjectsForSample) {
        for (SequenceFile sf : r.getObject().getFiles()) {
            String fileLabel = objectLabels.get(r.getObject().getClass());
            sf.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sampleId, fileLabel, r.getObject().getId(), sf.getId())).withSelfRel());
            resources.add(sf);
        }
    }
    // add a link to this collection
    resources.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withSelfRel());
    // add a link back to the sample
    resources.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(RESTSampleSequenceFilesController.REL_SAMPLE));
    resources.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).listSequencingObjectsOfTypeForSample(sample.getId(), RESTSampleSequenceFilesController.objectLabels.get(SequenceFilePair.class))).withRel(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILE_PAIRS));
    resources.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).listSequencingObjectsOfTypeForSample(sample.getId(), RESTSampleSequenceFilesController.objectLabels.get(SingleEndSequenceFile.class))).withRel(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILE_UNPAIRED));
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
    return modelMap;
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with SequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.

the class RESTSampleSequenceFilesController method readSequenceFileForSequencingObject.

/**
 * Read a single {@link SequenceFile} for a given {@link Sample} and
 * {@link SequencingObject}
 *
 * @param sampleId
 *            ID of the {@link Sample}
 * @param objectType
 *            type of {@link SequencingObject}
 * @param objectId
 *            id of the {@link SequencingObject}
 * @param fileId
 *            ID of the {@link SequenceFile} to read
 * @return a {@link SequenceFile}
 */
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}/{objectId}/files/{fileId}", method = RequestMethod.GET)
public ModelMap readSequenceFileForSequencingObject(@PathVariable Long sampleId, @PathVariable String objectType, @PathVariable Long objectId, @PathVariable Long fileId) {
    ModelMap modelMap = new ModelMap();
    Sample sample = sampleService.read(sampleId);
    SequencingObject readSequenceFilePairForSample = sequencingObjectService.readSequencingObjectForSample(sample, objectId);
    Optional<SequenceFile> findFirst = readSequenceFilePairForSample.getFiles().stream().filter(f -> f.getId().equals(fileId)).findFirst();
    if (!findFirst.isPresent()) {
        throw new EntityNotFoundException("File with id " + fileId + " is not associated with this sequencing object");
    }
    SequenceFile file = findFirst.get();
    file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withRel(REL_SAMPLE_SEQUENCE_FILES));
    file.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(REL_SAMPLE));
    file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequencingObject(sampleId, objectType, objectId)).withRel(REL_SEQ_OBJECT));
    file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readQCForSequenceFile(sampleId, objectType, objectId, fileId)).withRel(REL_SEQ_QC));
    file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sampleId, objectType, objectId, fileId)).withSelfRel());
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, file);
    return modelMap;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) LoggerFactory(org.slf4j.LoggerFactory) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ControllerLinkBuilder.methodOn(org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn) Controller(org.springframework.stereotype.Controller) RequestPart(org.springframework.web.bind.annotation.RequestPart) RESTAnalysisSubmissionController(ca.corefacility.bioinformatics.irida.web.controller.api.RESTAnalysisSubmissionController) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ModelMap(org.springframework.ui.ModelMap) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) HttpHeaders(com.google.common.net.HttpHeaders) Objects(com.google.common.base.Objects) Path(java.nio.file.Path) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) BiMap(com.google.common.collect.BiMap) Link(org.springframework.hateoas.Link) Logger(org.slf4j.Logger) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) Files(java.nio.file.Files) RESTProjectSamplesController(ca.corefacility.bioinformatics.irida.web.controller.api.projects.RESTProjectSamplesController) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SequencingRunService(ca.corefacility.bioinformatics.irida.service.SequencingRunService) RESTGenericController(ca.corefacility.bioinformatics.irida.web.controller.api.RESTGenericController) HttpStatus(org.springframework.http.HttpStatus) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) Optional(java.util.Optional) MultipartFile(org.springframework.web.multipart.MultipartFile) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisService(ca.corefacility.bioinformatics.irida.service.AnalysisService) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with SequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.

the class FastaView method renderMergedOutputModel.

/**
 * {@inheritDoc}
 */
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    SequenceFile sfr = (SequenceFile) model.get(RESTGenericController.RESOURCE_NAME);
    Path fileContent = sfr.getFile();
    String filename = fileContent.getFileName().toString();
    logger.trace("Sending file to client [" + filename + "]");
    response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"");
    response.setHeader(HttpHeaders.CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
    response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(Files.size(fileContent)));
    OutputStream os = response.getOutputStream();
    Files.copy(fileContent, os);
    os.flush();
    os.close();
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) OutputStream(java.io.OutputStream)

Example 35 with SequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.

the class GenbankView method renderMergedOutputModel.

/**
 * {@inheritDoc}
 */
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    SequenceFile sfr = (SequenceFile) model.get(RESTGenericController.RESOURCE_NAME);
    Path fileContent = sfr.getFile();
    String filename = fileContent.getFileName().toString();
    logger.trace("Sending file to client [" + filename + "]");
    response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"");
    response.setHeader(HttpHeaders.CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
    response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(Files.size(fileContent)));
    OutputStream os = response.getOutputStream();
    Files.copy(fileContent, os);
    os.flush();
    os.close();
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) OutputStream(java.io.OutputStream)

Aggregations

SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)111 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)84 Test (org.junit.Test)61 Path (java.nio.file.Path)50 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)39 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)31 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)25 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 Project (ca.corefacility.bioinformatics.irida.model.project.Project)15 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)13 IOException (java.io.IOException)11 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)9 ArrayList (java.util.ArrayList)9 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 Link (org.springframework.hateoas.Link)8 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)7 OutputStream (java.io.OutputStream)7 Before (org.junit.Before)7