<div dir="ltr"><div><div>Sorry if this has been asked many times, but I couldn&#39;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.<br><br></div>The cookbook <br><br><a href="http://biojava.org/wiki/BioJava:CookBook3:FASTQ#Convert_between_FASTQ_variants_using_streaming_API">http://biojava.org/wiki/BioJava:CookBook3:FASTQ#Convert_between_FASTQ_variants_using_streaming_API</a> <br><br></div>says this will work:<br><br><pre class="" style="font-family:monospace">FastqReader fastqReader <span style="color:rgb(51,153,51)">=</span> <span style="color:rgb(0,0,0);font-weight:bold">new</span> IlluminaFastqReader<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(51,153,51)">;</span>
<span style="color:rgb(0,0,0);font-weight:bold">final</span> FastqWriter fastqWriter <span style="color:rgb(51,153,51)">=</span> <span style="color:rgb(0,0,0);font-weight:bold">new</span> SangerFastqWriter<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(51,153,51)">;</span>
<span style="color:rgb(0,0,0);font-weight:bold">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afilewriter+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color:rgb(0,51,153)">FileWriter</span></a> fileWriter <span style="color:rgb(51,153,51)">=</span> <span style="color:rgb(0,0,0);font-weight:bold">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afilewriter+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color:rgb(0,51,153)">FileWriter</span></a><span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,0,0);font-weight:bold">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color:rgb(0,51,153)">File</span></a><span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,0,255)">&quot;sanger.fastq&quot;</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(51,153,51)">;</span>
InputStream in = ...<br>
fastqReader.<span style="color:rgb(0,102,51)">stream</span><span style="color:rgb(0,153,0)">(</span>in, <span style="color:rgb(0,0,0);font-weight:bold">new</span> StreamListener<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,153,0)">)</span>
  <span style="color:rgb(0,153,0)">{</span>
    @Override
    <span style="color:rgb(0,0,0);font-weight:bold">public</span> <span style="color:rgb(0,0,102);font-weight:bold">void</span> fastq<span style="color:rgb(0,153,0)">(</span><span style="color:rgb(0,0,0);font-weight:bold">final</span> Fastq fastq<span style="color:rgb(0,153,0)">)</span>
    <span style="color:rgb(0,153,0)">{</span>
      fastqWriter.<span style="color:rgb(0,102,51)">append</span><span style="color:rgb(0,153,0)">(</span>fileWriter, fastq<span style="color:rgb(0,153,0)">)</span><span style="color:rgb(51,153,51)">;</span>
    <span style="color:rgb(0,153,0)">}</span>
  <span style="color:rgb(0,153,0)">}</span><span style="color:rgb(0,153,0)">)</span><span style="color:rgb(51,153,51)">;<br><br><br></span></pre>But instead it throws this error:<br><br>Caused by: java.io.IOException: sequence SRR062634.1 HWI-EAS110_103327062:6:1:1092:8469/1 not fastq-illumina format, was fastq-sanger<br>        at org.biojava.nbio.sequencing.io.fastq.IlluminaFastqWriter.validate(IlluminaFastqWriter.java:43)<br>        at org.biojava.nbio.sequencing.io.fastq.AbstractFastqWriter.append(AbstractFastqWriter.java:62)<br>        at org.biojava.nbio.sequencing.io.fastq.AbstractFastqWriter.append(AbstractFastqWriter.java:46)<br><div><pre class=""><span style="font-family:arial,helvetica,sans-serif"><br></span></pre><pre class=""><span style="font-family:arial,helvetica,sans-serif">My workaround was to create a new Fastq instance inside the StreamListener#fastq() method to manually convert the quality chars<br><br><br></span></pre> char[] oldQual = fastq.getQuality().toCharArray();<br>                    char[] newQual = new char[oldQual.length];<br>                    for(int i=0; i&lt; oldQual.length; i++){<br>                        newQual[i] = FastqVariant.FASTQ_ILLUMINA.quality(FastqVariant.FASTQ_SANGER.qualityScore(oldQual[i]));<br>                    }<br>                   <br>                    Fastq newFastq = new FastqBuilder().withDescription(fastq.getDescription())<br>                                    .withSequence(fastq.getSequence())<br>                                    .withQuality(new String(newQual))<br>                                    .withVariant(FastqVariant.FASTQ_ILLUMINA)<br>                                    .build();<br>                    try {<br>                        fastqWriter.append(writer, newFastq);<br>                    } catch (IOException e) {<br>                       throw new UncheckedIOException(e);<br>                    }<br><br><br></div><div>Is that the correct way to do it? Is there a better way?<br><br></div><div>Thanks<br></div></div>