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