use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class CoverageFileProcessor method process.
@Override
public void process(SequencingObject sequencingObject) {
logger.trace("Counting coverage for file " + sequencingObject);
if (sequencingObject.getQcEntries() != null) {
// remove any existing coverage entries
sequencingObject.getQcEntries().stream().filter(q -> q instanceof CoverageQCEntry).forEach(q -> qcEntryRepository.delete(q));
}
// count the total bases
long totalBases = sequencingObject.getFiles().stream().mapToLong(f -> {
AnalysisFastQC fastqc = analysisRepository.findFastqcAnalysisForSequenceFile(f);
return fastqc.getTotalBases();
}).sum();
// save the entry
CoverageQCEntry coverageQCEntry = new CoverageQCEntry(sequencingObject, totalBases);
qcEntryRepository.save(coverageQCEntry);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class DefaultFileProcessingChain method getSettledSequencingObject.
/**
* Checks the {@link SequenceFile}s for the given {@link SequencingObject}
* to see if it's files are in the place they should be. Since there's lots
* of saves going on during the {@link FileProcessingChain} the transaction
* might not be complete in the time the file is first read.
*
* @param sequencingObjectId
* the id of the {@link SequencingObject} to check
* @return the settled {@link SequencingObject}
* @throws FileProcessorTimeoutException
* if the files don't settle in the configured timeout
*/
private SequencingObject getSettledSequencingObject(Long sequencingObjectId) throws FileProcessorTimeoutException {
boolean filesNotSettled = true;
Integer waiting = 0;
SequencingObject sequencingObject;
do {
if (waiting > timeout) {
throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out. File id " + sequencingObjectId);
}
waiting++;
try {
Thread.sleep(sleepDuration);
} catch (InterruptedException e) {
}
sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
Set<SequenceFile> files = sequencingObject.getFiles();
filesNotSettled = files.stream().anyMatch(f -> {
return !Files.exists(f.getFile());
});
} while (filesNotSettled);
return sequencingObject;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class SistrTypingFileProcessor method shouldTypeWithSISTR.
/**
* Check whether any {@link Project} associated with the
* {@link SequencingObject} is set to type with SISTR.
*
* @param object {@link SequencingObject} to check to type with SISTR.
* @return true if it should type with SISTR, false otherwise
*/
private Project.AutomatedSISTRSetting shouldTypeWithSISTR(SequencingObject object) {
Project.AutomatedSISTRSetting type = Project.AutomatedSISTRSetting.OFF;
SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(object);
/*
* This is something that should only ever happen in tests, but added
* check with a warning
*/
if (sampleForSequencingObject != null) {
List<Join<Project, Sample>> projectForSample = psjRepository.getProjectForSample(sampleForSequencingObject.getSubject());
Set<Project.AutomatedSISTRSetting> sistrOptions = projectForSample.stream().map(j -> j.getSubject().getSistrTypingUploads()).collect(Collectors.toSet());
if (sistrOptions.contains(Project.AutomatedSISTRSetting.AUTO_METADATA)) {
return Project.AutomatedSISTRSetting.AUTO_METADATA;
} else if (sistrOptions.contains(Project.AutomatedSISTRSetting.AUTO))
return Project.AutomatedSISTRSetting.AUTO;
} else {
logger.warn("Cannot find sample for sequencing object. Not typing with SISTR");
}
return type;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject 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.SequencingObject 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;
}
Aggregations