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