use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile in project irida by phac-nml.
the class AnalysisController method getOutputFile.
/**
* Read some lines or text from an {@link AnalysisOutputFile}.
*
* @param id {@link AnalysisSubmission} id
* @param fileId {@link AnalysisOutputFile} id
* @param limit Optional limit to number of lines to read from file
* @param start Optional line to start reading from
* @param end Optional line to stop reading at
* @param seek Optional file byte position to seek to and begin reading
* @param chunk Optional number of bytes to read from file
* @param response HTTP response object
* @return JSON with file text or lines as well as information about the file.
*/
@RequestMapping(value = "/ajax/{id}/outputs/{fileId}", method = RequestMethod.GET)
@ResponseBody
public AnalysisOutputFileInfo getOutputFile(@PathVariable Long id, @PathVariable Long fileId, @RequestParam(defaultValue = "100", required = false) Long limit, @RequestParam(required = false) Long start, @RequestParam(required = false) Long end, @RequestParam(defaultValue = "0", required = false) Long seek, @RequestParam(required = false) Long chunk, HttpServletResponse response) {
AnalysisSubmission submission = analysisSubmissionService.read(id);
Analysis analysis = submission.getAnalysis();
final Optional<AnalysisOutputFile> analysisOutputFile = analysis.getAnalysisOutputFiles().stream().filter(x -> Objects.equals(x.getId(), fileId)).findFirst();
if (analysisOutputFile.isPresent()) {
final AnalysisOutputFile aof = analysisOutputFile.get();
final Path aofFile = aof.getFile();
final ToolExecution tool = aof.getCreatedByTool();
final AnalysisOutputFileInfo contents = new AnalysisOutputFileInfo();
contents.setId(aof.getId());
contents.setAnalysisSubmissionId(submission.getId());
contents.setAnalysisId(analysis.getId());
contents.setFilename(aofFile.getFileName().toString());
contents.setFileExt(FileUtilities.getFileExt(aofFile.getFileName().toString()));
contents.setFileSizeBytes(aof.getFile().toFile().length());
contents.setToolName(tool.getToolName());
contents.setToolVersion(tool.getToolVersion());
try {
final File file = aofFile.toFile();
final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
randomAccessFile.seek(seek);
if (seek == 0) {
if (chunk != null && chunk > 0) {
contents.setText(FileUtilities.readChunk(randomAccessFile, seek, chunk));
contents.setChunk(chunk);
contents.setStartSeek(seek);
} else {
final BufferedReader reader = new BufferedReader(new FileReader(randomAccessFile.getFD()));
final List<String> lines = FileUtilities.readLinesLimit(reader, limit, start, end);
contents.setLines(lines);
contents.setLimit((long) lines.size());
contents.setStart(start);
contents.setEnd(start + lines.size());
}
} else {
if (chunk != null && chunk > 0) {
contents.setText(FileUtilities.readChunk(randomAccessFile, seek, chunk));
contents.setChunk(chunk);
contents.setStartSeek(seek);
} else {
final List<String> lines = FileUtilities.readLinesFromFilePointer(randomAccessFile, limit);
contents.setLines(lines);
contents.setStartSeek(seek);
contents.setStart(start);
contents.setLimit((long) lines.size());
}
}
contents.setFilePointer(randomAccessFile.getFilePointer());
} catch (IOException e) {
logger.error("Could not read output file '" + aof.getId() + "' " + e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
contents.setError("Could not read output file");
}
return contents;
} else {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return null;
}
}
use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile in project irida by phac-nml.
the class AnalysisController method getAjaxDownloadAnalysisSubmissionIndividualFile.
/**
* Download single output files from an {@link AnalysisSubmission}
*
* @param analysisSubmissionId Id for a {@link AnalysisSubmission}
* @param fileId the id of the file to download
* @param response {@link HttpServletResponse}
*/
@RequestMapping(value = "/ajax/download/{analysisSubmissionId}/file/{fileId}")
public void getAjaxDownloadAnalysisSubmissionIndividualFile(@PathVariable Long analysisSubmissionId, @PathVariable Long fileId, HttpServletResponse response) {
AnalysisSubmission analysisSubmission = analysisSubmissionService.read(analysisSubmissionId);
Analysis analysis = analysisSubmission.getAnalysis();
Set<AnalysisOutputFile> files = analysis.getAnalysisOutputFiles();
Optional<AnalysisOutputFile> optFile = files.stream().filter(f -> f.getId().equals(fileId)).findAny();
if (!optFile.isPresent()) {
throw new EntityNotFoundException("Could not find file with id " + fileId);
}
FileUtilities.createSingleFileResponse(response, optFile.get());
}
use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile in project irida by phac-nml.
the class AnalysisController method getAjaxDownloadAnalysisSubmission.
/**
* Download all output files from an {@link AnalysisSubmission}
*
* @param analysisSubmissionId Id for a {@link AnalysisSubmission}
* @param response {@link HttpServletResponse}
*/
@RequestMapping(value = "/ajax/download/{analysisSubmissionId}", produces = MediaType.APPLICATION_JSON_VALUE)
public void getAjaxDownloadAnalysisSubmission(@PathVariable Long analysisSubmissionId, HttpServletResponse response) {
AnalysisSubmission analysisSubmission = analysisSubmissionService.read(analysisSubmissionId);
Analysis analysis = analysisSubmission.getAnalysis();
Set<AnalysisOutputFile> files = analysis.getAnalysisOutputFiles();
FileUtilities.createAnalysisOutputFileZippedResponse(response, analysisSubmission.getName(), files);
}
use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile in project irida by phac-nml.
the class AnalysisController method tree.
// ************************************************************************************************
// Analysis view setup
// ************************************************************************************************
/**
* Construct the model parameters for an {@link AnalysisType#PHYLOGENOMICS}
* {@link Analysis}
*
* @param submission The analysis submission
* @param model The model to add parameters
* @throws IOException If the tree file couldn't be read
*/
private void tree(AnalysisSubmission submission, Model model) throws IOException {
final String treeFileKey = "tree";
Analysis analysis = submission.getAnalysis();
AnalysisOutputFile file = analysis.getAnalysisOutputFile(treeFileKey);
List<String> lines = Files.readAllLines(file.getFile());
model.addAttribute("analysis", analysis);
model.addAttribute("newick", lines.get(0));
// inform the view to display the tree preview
model.addAttribute("preview", "tree");
}
use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile in project irida by phac-nml.
the class AnalysisController method getAnalysisOutputFileInfo.
/**
* Get {@link AnalysisOutputFileInfo}.
*
* @param submission {@link AnalysisSubmission} of {@code analysis}
* @param analysis {@link Analysis} to get {@link AnalysisOutputFile}s from
* @param outputName Workflow output name
* @return {@link AnalysisOutputFile} info
*/
private AnalysisOutputFileInfo getAnalysisOutputFileInfo(AnalysisSubmission submission, Analysis analysis, String outputName) {
final ImmutableSet<String> BLACKLIST_FILE_EXT = ImmutableSet.of("zip");
// set of file extensions for indicating whether the first line of the file should be read
final ImmutableSet<String> FILE_EXT_READ_FIRST_LINE = ImmutableSet.of("tsv", "txt", "tabular", "csv", "tab");
final AnalysisOutputFile aof = analysis.getAnalysisOutputFile(outputName);
final Long aofId = aof.getId();
final String aofFilename = aof.getFile().getFileName().toString();
final String fileExt = FileUtilities.getFileExt(aofFilename);
if (BLACKLIST_FILE_EXT.contains(fileExt)) {
return null;
}
final ToolExecution tool = aof.getCreatedByTool();
final String toolName = tool.getToolName();
final String toolVersion = tool.getToolVersion();
final AnalysisOutputFileInfo info = new AnalysisOutputFileInfo();
info.setId(aofId);
info.setAnalysisSubmissionId(submission.getId());
info.setAnalysisId(analysis.getId());
info.setOutputName(outputName);
info.setFilename(aofFilename);
info.setFileSizeBytes(aof.getFile().toFile().length());
info.setToolName(toolName);
info.setToolVersion(toolVersion);
info.setFileExt(fileExt);
if (FILE_EXT_READ_FIRST_LINE.contains(fileExt)) {
addFirstLine(info, aof);
}
return info;
}
Aggregations