Search in sources :

Example 1 with ConcatenateException

use of ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException in project irida by phac-nml.

the class SamplesController method concatenateSequenceFiles.

/**
 * Concatenate a collection of {@link SequencingObject}s
 *
 * @param sampleId
 *            the id of the {@link Sample} to concatenate in
 * @param objectIds
 *            the {@link SequencingObject} ids
 * @param filename
 *            base of the new filename to create
 * @param removeOriginals
 *            boolean whether to remove the original files
 * @param model
 *            model for the view
 * @param request
 *            the incoming {@link HttpServletRequest}
 * @return redirect to the files page if successul
 */
@RequestMapping(value = { "/samples/{sampleId}/sequenceFiles/concatenate", "/projects/{projectId}/samples/{sampleId}/sequenceFiles/concatenate" }, method = RequestMethod.POST)
public String concatenateSequenceFiles(@PathVariable Long sampleId, @RequestParam(name = "seq") Set<Long> objectIds, @RequestParam(name = "filename") String filename, @RequestParam(name = "remove", defaultValue = "false", required = false) boolean removeOriginals, Model model, HttpServletRequest request) {
    Sample sample = sampleService.read(sampleId);
    Iterable<SequencingObject> readMultiple = sequencingObjectService.readMultiple(objectIds);
    try {
        sequencingObjectService.concatenateSequences(Lists.newArrayList(readMultiple), filename, sample, removeOriginals);
    } catch (ConcatenateException ex) {
        logger.error("Error concatenating files: ", ex);
        model.addAttribute("concatenateError", true);
        return getConcatenatePage(sampleId, model);
    }
    final String url = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    final String redirectUrl = url.substring(0, url.indexOf("/concatenate"));
    return "redirect:" + redirectUrl;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException)

Example 2 with ConcatenateException

use of ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException in project irida by phac-nml.

the class SequenceFilePairConcatenator method concatenateFiles.

/**
 * {@inheritDoc}
 */
@Override
public SequenceFilePair concatenateFiles(List<? extends SequencingObject> toConcatenate, String filename) throws ConcatenateException {
    // create the filenames with F/R for the forward and reverse files
    String forwardName = filename + "_R1.fastq";
    String reverseName = filename + "_R2.fastq";
    Path forwardFile;
    Path reverseFile;
    try {
        // create a temp directory for the new files
        Path tempDirectory = Files.createTempDirectory(null);
        forwardFile = tempDirectory.resolve(forwardName);
        reverseFile = tempDirectory.resolve(reverseName);
        // create temp files
        forwardFile = Files.createFile(forwardFile);
        reverseFile = Files.createFile(reverseFile);
    } catch (IOException e) {
        throw new ConcatenateException("Could not create temporary files", e);
    }
    // for each file concatenate the forward and reverse files
    for (SequencingObject f : toConcatenate) {
        SequenceFilePair pair = (SequenceFilePair) f;
        SequenceFile forwardSequenceFile = pair.getForwardSequenceFile();
        SequenceFile reverseSequenceFile = pair.getReverseSequenceFile();
        appendToFile(forwardFile, forwardSequenceFile);
        appendToFile(reverseFile, reverseSequenceFile);
    }
    // create new SequenceFiles
    SequenceFile forward = new SequenceFile(forwardFile);
    SequenceFile reverse = new SequenceFile(reverseFile);
    // create the new pair
    SequenceFilePair sequenceFilePair = new SequenceFilePair(forward, reverse);
    return sequenceFilePair;
}
Also used : Path(java.nio.file.Path) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) IOException(java.io.IOException) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException)

Example 3 with ConcatenateException

use of ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException in project irida by phac-nml.

the class SingleEndSequenceFileConcatenator method concatenateFiles.

/**
 * {@inheritDoc}
 */
@Override
public SingleEndSequenceFile concatenateFiles(List<? extends SequencingObject> toConcatenate, String filename) throws ConcatenateException {
    Path tempFile;
    // create the filename with extension
    filename = filename + ".fastq";
    try {
        // create a temp directory and temp file
        Path tempDirectory = Files.createTempDirectory(null);
        tempFile = tempDirectory.resolve(filename);
        tempFile = Files.createFile(tempFile);
    } catch (IOException e) {
        throw new ConcatenateException("Could not create temporary files", e);
    }
    // for each file concatenate the file
    for (SequencingObject f : toConcatenate) {
        SingleEndSequenceFile single = (SingleEndSequenceFile) f;
        SequenceFile forwardSequenceFile = single.getSequenceFile();
        appendToFile(tempFile, forwardSequenceFile);
    }
    // create the new sequencefile and object
    SequenceFile forward = new SequenceFile(tempFile);
    SingleEndSequenceFile seqObject = new SingleEndSequenceFile(forward);
    return seqObject;
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) IOException(java.io.IOException) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Aggregations

ConcatenateException (ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException)3 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)3 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)1 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)1 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)1