
org.biojava.nbio.genome.io.fastq.FastqParser Maven / Gradle / Ivy
The newest version!
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
package org.biojava.nbio.genome.io.fastq;
import com.google.common.io.CharStreams;
import com.google.common.io.LineProcessor;
import java.io.IOException;
/**
* Low-level event based parser for FASTQ formatted sequences.
*
* @since 3.0.3
*/
final class FastqParser
{
/**
* Parse the specified readable.
*
* @param readable readable, must not be null
* @param listener low-level event based parser callback, must not be null
* @throws IOException if an I/O error occurs
*/
static void parse(final Readable readable, final ParseListener listener)
throws IOException
{
if (readable == null)
{
throw new IllegalArgumentException("readable must not be null");
}
FastqParserLineProcessor lineProcessor = new FastqParserLineProcessor(listener);
CharStreams.readLines(readable, lineProcessor);
if (lineProcessor.getState() == State.COMPLETE)
{
listener.complete();
lineProcessor.setState(State.DESCRIPTION);
}
if (lineProcessor.getState() != State.DESCRIPTION)
{
throw new IOException("truncated sequence"); // at line " + lineNumber);
}
}
/**
* FASTQ formatted sequence parser line processor.
*/
private static final class FastqParserLineProcessor implements LineProcessor
© 2015 - 2025 Weber Informatics LLC | Privacy Policy