use of org.biojava3.core.exceptions.CompoundNotFoundError in project irida by phac-nml.
the class BioJavaSequenceFileUtilitiesImpl method countSequenceFileLengthInBases.
/**
* {@inheritDoc}
*/
@Override
public Long countSequenceFileLengthInBases(final Path file) throws UnsupportedReferenceFileContentError {
Long totalLength = 0L;
logger.trace("Calculating length for file: " + file);
try (final InputStream stream = Files.newInputStream(file)) {
final LinkedHashMap<String, DNASequence> readFastaDNASequence = FastaReaderHelper.readFastaDNASequence(stream);
for (Entry<String, DNASequence> entry : readFastaDNASequence.entrySet()) {
logger.trace("Calculating for sequence " + entry.getValue().getAccession());
int length = entry.getValue().getLength();
totalLength += length;
}
} catch (final CompoundNotFoundError e) {
logger.error("Cannot handle non-DNA files, or files with ambiguous bases.", e);
throw new UnsupportedReferenceFileContentError("Cannot handle reference files with non-DNA or ambiguous characters.", e);
} catch (Throwable e) {
logger.error("Cannot calculate reference file length " + file, e);
throw new IllegalArgumentException("Cannot parse reference file " + file, e);
}
return totalLength;
}
Aggregations