[Biojava-l] converting fastq format

Daniel Katzel dkatzel at gmail.com
Wed Sep 16 03:28:28 UTC 2015


Sorry if this has been asked many times, but I couldn't find it when
searching the mailing list or popular forums. When I follow the BioJava
cookbook to convert a Sanger fastq file into an illumina fastq I get
validation errors.

The cookbook

http://biojava.org/wiki/BioJava:CookBook3:FASTQ#Convert_between_FASTQ_variants_using_streaming_API

says this will work:

FastqReader fastqReader = new IlluminaFastqReader();final FastqWriter
fastqWriter = new SangerFastqWriter();final FileWriter
<http://www.google.com/search?hl=en&q=allinurl%3Afilewriter+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
fileWriter = new FileWriter
<http://www.google.com/search?hl=en&q=allinurl%3Afilewriter+java.sun.com&btnI=I%27m%20Feeling%20Lucky>(new
File <http://www.google.com/search?hl=en&q=allinurl%3Afile+java.sun.com&btnI=I%27m%20Feeling%20Lucky>("sanger.fastq"))));
InputStream in = ...

fastqReader.stream(in, new StreamListener()
  {
    @Override
    public void fastq(final Fastq fastq)
    {
      fastqWriter.append(fileWriter, fastq);
    }
  });


But instead it throws this error:

Caused by: java.io.IOException: sequence SRR062634.1
HWI-EAS110_103327062:6:1:1092:8469/1 not fastq-illumina format, was
fastq-sanger
        at
org.biojava.nbio.sequencing.io.fastq.IlluminaFastqWriter.validate(IlluminaFastqWriter.java:43)
        at
org.biojava.nbio.sequencing.io.fastq.AbstractFastqWriter.append(AbstractFastqWriter.java:62)
        at
org.biojava.nbio.sequencing.io.fastq.AbstractFastqWriter.append(AbstractFastqWriter.java:46)


My workaround was to create a new Fastq instance inside the
StreamListener#fastq() method to manually convert the quality chars


 char[] oldQual = fastq.getQuality().toCharArray();
                    char[] newQual = new char[oldQual.length];
                    for(int i=0; i< oldQual.length; i++){
                        newQual[i] =
FastqVariant.FASTQ_ILLUMINA.quality(FastqVariant.FASTQ_SANGER.qualityScore(oldQual[i]));
                    }

                    Fastq newFastq = new
FastqBuilder().withDescription(fastq.getDescription())
                                    .withSequence(fastq.getSequence())
                                    .withQuality(new String(newQual))

.withVariant(FastqVariant.FASTQ_ILLUMINA)
                                    .build();
                    try {
                        fastqWriter.append(writer, newFastq);
                    } catch (IOException e) {
                       throw new UncheckedIOException(e);
                    }


Is that the correct way to do it? Is there a better way?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biojava-l/attachments/20150915/26cdbe29/attachment.html>


More information about the Biojava-l mailing list