use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class ExportUploadService method uploadSubmission.
/**
* Upload an {@link NcbiExportSubmission}'s files and submission xml to the
* configured ftp site
*
* @param submission
* The {@link NcbiExportSubmission} to upload
* @param xml
* The submission xml to upload
* @return true/false if upload was successful
* @throws UploadException
* if the upload failed
*/
public NcbiExportSubmission uploadSubmission(NcbiExportSubmission submission, String xml) throws UploadException {
FTPClient client = null;
try {
client = getFtpClient();
// create submission directory name
String directoryName = submission.getId().toString() + "-" + new Date().getTime();
// cd to submission base directory
if (!client.changeWorkingDirectory(baseDirectory)) {
throw new UploadException("Couldn't change to base directory " + baseDirectory + " : " + client.getReplyString());
}
// create new submission directory
if (!client.makeDirectory(directoryName)) {
throw new UploadException("Couldn't create new upload directory " + directoryName + " : " + client.getReplyString());
}
// cd to submission directory
if (!client.changeWorkingDirectory(directoryName)) {
throw new UploadException("Couldn't change to upload directory " + directoryName + " : " + client.getReplyString());
}
// set the directory saved
String directoryPath = baseDirectory + "/" + directoryName;
submission.setDirectoryPath(directoryPath);
// upload submission.xml file
uploadString(client, "submission.xml", xml);
// upload biosample files
for (NcbiBioSampleFiles bsFile : submission.getBioSampleFiles()) {
// upload single end files
for (SingleEndSequenceFile file : bsFile.getFiles()) {
// Just using file IDs as the basename for uploaded files to
// avoid accidentally sending sensitive sample names to NCBI
String filename = file.getSequenceFile().getId() + ".fastq";
uploadPath(client, filename, file.getSequenceFile().getFile());
}
// upload paired end files
for (SequenceFilePair pair : bsFile.getPairs()) {
// upload forward
SequenceFile file = pair.getForwardSequenceFile();
// Just using file IDs as the basename for uploaded files to
// avoid accidentally sending sensitive sample names to NCBI
String filename = file.getId() + ".fastq";
uploadPath(client, filename, file.getFile());
// upload reverse
file = pair.getReverseSequenceFile();
filename = file.getId() + ".fastq";
uploadPath(client, filename, file.getFile());
}
}
// create submit.ready file
uploadString(client, "submit.ready", "");
} catch (IOException e) {
logger.error("Error in upload", e);
throw new UploadException("Could not upload run", e);
} finally {
disconnectFtpCient(client);
}
return submission;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SequencingObjectServiceImpl method getUniqueSamplesForSequencingObjects.
/**
* {@inheritDoc}
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN') or hasPermission(#sequenceFiles, 'canReadSequencingObject')")
@Override
public <T extends SequencingObject> Map<Sample, T> getUniqueSamplesForSequencingObjects(Set<T> sequenceFiles) throws DuplicateSampleException {
Map<Sample, T> sequenceFilesSampleMap = new HashMap<>();
for (T seqObj : sequenceFiles) {
SequenceFile file = seqObj.getFiles().iterator().next();
SampleSequencingObjectJoin join = ssoRepository.getSampleForSequencingObject(seqObj);
if (join == null) {
throw new EntityNotFoundException("No sample associated with sequence file " + seqObj.getClass() + "[id=" + seqObj.getId() + "]");
} else {
Sample sample = join.getSubject();
if (sequenceFilesSampleMap.containsKey(sample)) {
SequencingObject previousFile = sequenceFilesSampleMap.get(sample);
throw new DuplicateSampleException("Sequence files " + file + ", " + previousFile + " have the same sample " + sample);
} else {
sequenceFilesSampleMap.put(sample, seqObj);
}
}
}
return sequenceFilesSampleMap;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SamplesController method createSequenceFileInSample.
/**
* Create a {@link SequenceFile} and add it to a {@link Sample}
*
* @param file
* {@link MultipartFile}
* @param sample
* {@link Sample} to add the file to.
* @throws IOException
*/
private void createSequenceFileInSample(MultipartFile file, Sample sample) throws IOException {
SequenceFile sequenceFile = createSequenceFile(file);
sequencingObjectService.createSequencingObjectInSample(new SingleEndSequenceFile(sequenceFile), sample);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile 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.SequenceFile 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();
}
Aggregations