Search in sources :

Example 61 with SequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile 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 62 with SequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile 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)

Example 63 with SequenceFile

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

the class ChecksumFileProcessor method process.

/**
 * Create an sha256sum for the files in a {@link SequencingObject} and save
 * it with the file.
 *
 * @param sequencingObject
 *            the {@link SequencingObject} to modify
 * @throws FileProcessorException
 *             a {@link FileProcessorException} if the file could not be
 *             processed
 */
@Override
public void process(SequencingObject sequencingObject) {
    Set<SequenceFile> files = sequencingObject.getFiles();
    for (SequenceFile file : files) {
        try (InputStream is = Files.newInputStream(file.getFile())) {
            String shaDigest = DigestUtils.sha256Hex(is);
            logger.trace("Checksum generated for file " + file.getId() + ": " + shaDigest);
            file.setUploadSha256(shaDigest);
            fileRepository.saveMetadata(file);
        } catch (IOException e) {
            throw new FileProcessorException("could not calculate checksum", e);
        }
    }
}
Also used : FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 64 with SequenceFile

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

the class SequenceFileRemoteRepositoryImpl method downloadRemoteSequenceFile.

/**
 * {@inheritDoc}
 */
@Override
public Path downloadRemoteSequenceFile(String uri, RemoteAPI remoteAPI, MediaType... mediaTypes) {
    SequenceFile file = read(uri, remoteAPI);
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    // add the sequence file message converter
    List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
    converters.add(new SequenceFileMessageConverter(file.getFileName()));
    restTemplate.setMessageConverters(converters);
    // add the application/fastq accept header
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAccept(Arrays.asList(mediaTypes));
    HttpEntity<Path> requestEntity = new HttpEntity<Path>(requestHeaders);
    // get the file
    ResponseEntity<Path> exchange = restTemplate.exchange(uri, HttpMethod.GET, requestEntity, Path.class);
    return exchange.getBody();
}
Also used : SequenceFileMessageConverter(ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.SequenceFileMessageConverter) Path(java.nio.file.Path) HttpHeaders(org.springframework.http.HttpHeaders) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) HttpEntity(org.springframework.http.HttpEntity) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) OAuthTokenRestTemplate(ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)

Example 65 with SequenceFile

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

the class RESTSampleSequenceFilesController method addSequenceFilePairLinks.

/**
 * add the forward and reverse file links and a link to the pair's sample
 *
 * @param pair
 *            The {@link SequenceFilePair} to enhance
 * @param sampleId
 *            the id of the {@link Sample} the pair is in
 * @return The {@link SequenceFilePair} with added links
 */
private static SequenceFilePair addSequenceFilePairLinks(SequenceFilePair pair, Long sampleId) {
    SequenceFile forward = pair.getForwardSequenceFile();
    String forwardLink = forward.getLink("self").getHref();
    SequenceFile reverse = pair.getReverseSequenceFile();
    String reverseLink = reverse.getLink("self").getHref();
    pair.add(new Link(forwardLink, REL_PAIR_FORWARD));
    pair.add(new Link(reverseLink, REL_PAIR_REVERSE));
    return pair;
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Link(org.springframework.hateoas.Link)

Aggregations

SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)111 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)84 Test (org.junit.Test)61 Path (java.nio.file.Path)50 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)39 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)31 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)25 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 Project (ca.corefacility.bioinformatics.irida.model.project.Project)15 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)13 IOException (java.io.IOException)11 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)9 ArrayList (java.util.ArrayList)9 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 Link (org.springframework.hateoas.Link)8 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)7 OutputStream (java.io.OutputStream)7 Before (org.junit.Before)7