Search in sources :

Example 1 with CompoundNotFoundError

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;
}
Also used : DNASequence(org.biojava3.core.sequence.DNASequence) InputStream(java.io.InputStream) UnsupportedReferenceFileContentError(ca.corefacility.bioinformatics.irida.exceptions.UnsupportedReferenceFileContentError) CompoundNotFoundError(org.biojava3.core.exceptions.CompoundNotFoundError)

Aggregations

UnsupportedReferenceFileContentError (ca.corefacility.bioinformatics.irida.exceptions.UnsupportedReferenceFileContentError)1 InputStream (java.io.InputStream)1 CompoundNotFoundError (org.biojava3.core.exceptions.CompoundNotFoundError)1 DNASequence (org.biojava3.core.sequence.DNASequence)1