Search in sources :

Example 56 with SequencingObject

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

the class SequenceFileController method downloadSequenceFileImages.

/**
 * Get images specific for individual sequence files.
 *
 * @param sequencingObjectId ID for the {@link SequencingObject}
 * @param sequenceFileId     Id for the {@link SequenceFile}
 * @param type               The type of image to get.
 * @param response           {@link HttpServletResponse}
 * @param thumb              Whether to scale the image for a thumbnail
 * @throws IOException if we can't write the image out to the response.
 */
@RequestMapping(value = "/sequenceFiles/img/{sequencingObjectId}/file/{sequenceFileId}/{type}")
public void downloadSequenceFileImages(@PathVariable Long sequencingObjectId, @PathVariable Long sequenceFileId, @PathVariable String type, HttpServletResponse response, @RequestParam(defaultValue = "false") boolean thumb) throws IOException {
    SequencingObject sequencingObject = sequencingObjectService.read(sequencingObjectId);
    SequenceFile file = sequencingObject.getFileWithId(sequenceFileId);
    AnalysisFastQC fastQC = analysisService.getFastQCAnalysisForSequenceFile(sequencingObject, file.getId());
    if (fastQC != null) {
        byte[] chart = new byte[0];
        if (type.equals(IMG_PERBASE)) {
            chart = fastQC.getPerBaseQualityScoreChart();
        } else if (type.equals(IMG_PERSEQUENCE)) {
            chart = fastQC.getPerSequenceQualityScoreChart();
        } else if (type.equals(IMG_DUPLICATION_LEVEL)) {
            chart = fastQC.getDuplicationLevelChart();
        } else {
            throw new EntityNotFoundException("Image not found");
        }
        if (thumb) {
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(chart));
            BufferedImage thumbnail = Scalr.resize(image, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, 160, Scalr.OP_ANTIALIAS);
            ImageIO.write(thumbnail, "png", response.getOutputStream());
        } else {
            response.getOutputStream().write(chart);
        }
    }
    response.setContentType(MediaType.IMAGE_PNG_VALUE);
    response.flushBuffer();
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) BufferedImage(java.awt.image.BufferedImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with SequencingObject

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

the class SequenceFileController method downloadSequenceFile.

/**
 * Downloads a sequence file.
 *
 * @param sequencingObjectId ID for the {@link SequencingObject}
 * @param sequenceFileId     Id for the {@link SequenceFile}
 * @param response           {@link HttpServletResponse}
 * @throws IOException if we can't write the file to the response.
 */
@RequestMapping("/sequenceFiles/download/{sequencingObjectId}/file/{sequenceFileId}")
public void downloadSequenceFile(@PathVariable Long sequencingObjectId, @PathVariable Long sequenceFileId, HttpServletResponse response) throws IOException {
    SequencingObject sequencingObject = sequencingObjectService.read(sequencingObjectId);
    SequenceFile sequenceFile = sequencingObject.getFileWithId(sequenceFileId);
    Path path = sequenceFile.getFile();
    response.setHeader("Content-Disposition", "attachment; filename=\"" + sequenceFile.getLabel() + "\"");
    Files.copy(path, response.getOutputStream());
    response.flushBuffer();
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 58 with SequencingObject

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

the class ReadAnalysisSubmissionPermission method customPermissionAllowed.

/**
 * {@inheritDoc}
 */
@Override
protected boolean customPermissionAllowed(Authentication authentication, AnalysisSubmission analysisSubmission) {
    logger.trace("Testing permission for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
    User u = userRepository.loadUserByUsername(authentication.getName());
    if (analysisSubmission.getSubmitter().equals(u)) {
        logger.trace("Permission GRANTED for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
        return true;
    }
    /*
		 * If the user isn't set it might be shared to a project they have
		 * access to. Check the shared projects.
		 */
    List<ProjectAnalysisSubmissionJoin> projectsForSubmission = pasRepository.getProjectsForSubmission(analysisSubmission);
    boolean canReadProject = projectsForSubmission.stream().anyMatch(p -> readProjectPermission.customPermissionAllowed(authentication, p.getSubject()));
    if (canReadProject) {
        logger.trace("Permission GRANTED for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
        return true;
    }
    /*
		 * If the user isn't set it might be an automated submission. Check if
		 * this analysis is the auto assembly or sistr for a file and if they
		 * can read the file
		 */
    Set<SequencingObject> pairedInputFiles = sequencingObjectRepository.findSequencingObjectsForAnalysisSubmission(analysisSubmission);
    boolean anyMatch = pairedInputFiles.stream().filter(o -> {
        AnalysisSubmission a = o.getAutomatedAssembly();
        AnalysisSubmission s = o.getSistrTyping();
        // check auto assembly
        boolean allowed = false;
        if (a != null) {
            allowed = a.equals(analysisSubmission);
        }
        // if not check sistr
        if (!allowed && s != null) {
            allowed = s.equals(analysisSubmission);
        }
        return allowed;
    }).anyMatch(p -> seqObjectPermission.customPermissionAllowed(authentication, p));
    if (anyMatch) {
        logger.trace("Permission GRANTED for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
        return true;
    }
    logger.trace("Permission DENIED for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
    return false;
}
Also used : UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) Logger(org.slf4j.Logger) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) ReadProjectPermission(ca.corefacility.bioinformatics.irida.security.permissions.project.ReadProjectPermission) List(java.util.List) Component(org.springframework.stereotype.Component) BasePermission(ca.corefacility.bioinformatics.irida.security.permissions.BasePermission) ReadSequencingObjectPermission(ca.corefacility.bioinformatics.irida.security.permissions.files.ReadSequencingObjectPermission) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectAnalysisSubmissionJoinRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.ProjectAnalysisSubmissionJoinRepository) Authentication(org.springframework.security.core.Authentication) AnalysisSubmissionRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.AnalysisSubmissionRepository) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) User(ca.corefacility.bioinformatics.irida.model.user.User) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)

Example 59 with SequencingObject

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

the class AnalysisSubmissionRepositoryIT method setup.

/**
 * Sets up objects for test.
 *
 * @throws IOException
 */
@Before
public void setup() throws IOException {
    singleEndFile = (SingleEndSequenceFile) objectRepository.findOne(2L);
    sequenceFile = singleEndFile.getFileWithId(1L);
    assertNotNull(sequenceFile);
    Set<SequencingObject> singleFiles = Sets.newHashSet(singleEndFile);
    SingleEndSequenceFile singleEndFile2 = (SingleEndSequenceFile) objectRepository.findOne(3L);
    SequenceFile sequenceFile2 = singleEndFile2.getFileWithId(2L);
    assertNotNull(sequenceFile2);
    Set<SequencingObject> singleFiles2 = Sets.newHashSet(singleEndFile2);
    sequenceFilePair = (SequenceFilePair) objectRepository.findOne(1L);
    assertNotNull(sequenceFilePair);
    referenceFile = referenceFileRepository.findOne(1L);
    assertNotNull(referenceFile);
    referenceFile2 = referenceFileRepository.findOne(2L);
    submitter1 = userRepository.findOne(1L);
    submitter2 = userRepository.findOne(2L);
    analysisSubmission = AnalysisSubmission.builder(workflowId).name(analysisName).inputFiles(singleFiles).referenceFile(referenceFile).build();
    analysisSubmission.setRemoteAnalysisId(analysisId);
    analysisSubmission.setAnalysisState(AnalysisState.SUBMITTING);
    analysisSubmission.setSubmitter(submitter1);
    analysisSubmission.setAnalysisCleanedState(AnalysisCleanedState.NOT_CLEANED);
    analysisSubmission2 = AnalysisSubmission.builder(workflowId).name(analysisName2).inputFiles(singleFiles2).referenceFile(referenceFile).build();
    analysisSubmission2.setRemoteAnalysisId(analysisId2);
    analysisSubmission2.setAnalysisState(AnalysisState.SUBMITTING);
    analysisSubmission2.setSubmitter(submitter2);
    analysisSubmission2.setAnalysisCleanedState(AnalysisCleanedState.NOT_CLEANED);
    analysisSubmission2b = AnalysisSubmission.builder(workflowId).name(analysisName2).inputFiles(singleFiles2).referenceFile(referenceFile2).build();
    analysisSubmission2b.setRemoteAnalysisId(analysisId2);
    analysisSubmission2b.setAnalysisState(AnalysisState.SUBMITTING);
    analysisSubmission2b.setSubmitter(submitter2);
    analysisSubmission2b.setAnalysisCleanedState(AnalysisCleanedState.NOT_CLEANED);
}
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) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Before(org.junit.Before)

Example 60 with SequencingObject

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

the class AnalysisSubmissionRepositoryIT method testCreateAnalysisSingleAndPaired.

/**
 * Tests creating an analysis with both single and paired files and no
 * reference genome.
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testCreateAnalysisSingleAndPaired() {
    AnalysisSubmission analysisSubmissionPaired = AnalysisSubmission.builder(workflowId).name("submission paired 1").inputFiles(Sets.newHashSet(sequenceFilePair, singleEndFile)).build();
    analysisSubmissionPaired.setSubmitter(submitter1);
    AnalysisSubmission savedSubmission = analysisSubmissionRepository.save(analysisSubmissionPaired);
    Set<SequencingObject> inputsSaved = objectRepository.findSequencingObjectsForAnalysisSubmission(savedSubmission);
    assertTrue("should have single end file in collection", inputsSaved.contains(singleEndFile));
    assertTrue("should have pair file in collection", inputsSaved.contains(sequenceFilePair));
    assertFalse(savedSubmission.getReferenceFile().isPresent());
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)61 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)29 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)25 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)24 Test (org.junit.Test)24 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)16 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)14 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Project (ca.corefacility.bioinformatics.irida.model.project.Project)11 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 Path (java.nio.file.Path)8 ModelMap (org.springframework.ui.ModelMap)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Transactional (org.springframework.transaction.annotation.Transactional)6 IOException (java.io.IOException)5 List (java.util.List)5 Logger (org.slf4j.Logger)5