[Biojava-l] Reading and writting Fastq files

Michael Heuer heuermh at acm.org
Tue Mar 30 02:01:23 UTC 2010


FastqBuilder defaults to the Sanger variant, see

http://www.biojava.org/docs/api/org/biojava/bio/program/fastq/FastqBuilder.html#DEFAULT_VARIANT


In your code, you just need to specify the Illumina variant

FastqBuilder trimFastq = new FastqBuilder()
  .withVariant(FastqVariant.FASTQ_ILLUMINA)
  .withDescription(fastq.getDescription())
  .appendSequence(trimSeq)
  .appendQuality(trimQual);


Please let me know if you have any API or doc suggestions, as this stuff
has not been used much by anyone other than myself.

   michael


On Sun, 28 Mar 2010, xyz wrote:

> Do not worry. I wrote following code:
>
> import java.io.FileInputStream;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import org.biojava.bio.program.fastq.Fastq;
> import org.biojava.bio.program.fastq.FastqBuilder;
> import org.biojava.bio.program.fastq.FastqReader;
> import org.biojava.bio.program.fastq.FastqWriter;
> import org.biojava.bio.program.fastq.IlluminaFastqReader;
> import org.biojava.bio.program.fastq.IlluminaFastqWriter;
>
> public class Fastq2Fasta {
>
>   public static void main(String[] args) throws FileNotFoundException,
>   IOException {
>     FileInputStream inputFastq = new
>   FileInputStream("fastq2fasta.fastq"); FastqReader qReader = new
>   IlluminaFastqReader();
>
>     FileOutputStream outputFastq = new
>     FileOutputStream("fastq2fastaTrim.fastq"); FastqWriter qWriter =
>     new IlluminaFastqWriter();
>
>
>     for (Fastq fastq : qReader.read(inputFastq)) {
>       System.out.println(fastq.getDescription());
>       System.out.println(fastq.getSequence());
>       String trimSeq = fastq.getSequence().substring(0,
>     fastq.getSequence().length() - 6); System.out.println(trimSeq);
>       System.out.println(fastq.getQuality());
>       String trimQual = fastq.getQuality().substring(0,
>     fastq.getQuality().length() - 6); System.out.println(trimQual);
>
>       FastqBuilder trimFastq = new FastqBuilder();
>       trimFastq.withDescription(fastq.getDescription());
>       trimFastq.appendSequence(trimSeq);
>       trimFastq.appendQuality(trimQual);
>
>       qWriter.write(outputFastq, trimFastq.build());
>     }
>   }
> }
>
> and the input fastq file is:
> @HWI-EAS406:5:1:0:1390#0/1
> GGGTGATGGCCGCTGCCGATGGCGTCAAAACCCACC
> +HWI-EAS406:5:1:0:1390#0/1
> OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOAAAAAA
> @HWI-EAS406:5:1:0:1390#0/1
> GGGTGATGGCCGCTGCCGATGGCGTCAAATCCCACC
> +HWI-EAS406:5:1:0:1390#0/1
> PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPBBBBBB
> @HWI-EAS406:5:1:0:1390#0/1
> GGGTGATGGCCGCTGCCGATGGCGTCAAACCCCACC
> +HWI-EAS406:5:1:0:1390#0/1
> QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQCCCCCC
>
> Unfortunately, I get the following error:
> HWI-EAS406:5:1:0:1390#0/1
> GGGTGATGGCCGCTGCCGATGGCGTCAAAACCCACC
> GGGTGATGGCCGCTGCCGATGGCGTCAAAA
> OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOAAAAAA
> OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
> Exception in thread "main" java.io.IOException: sequence
> HWI-EAS406:5:1:0:1390#0/1 not fastq-illumina format, was fastq-sanger
> at
> org.biojava.bio.program.fastq.IlluminaFastqWriter.validate(IlluminaFastqWriter.java:41)
> at
> org.biojava.bio.program.fastq.AbstractFastqWriter.append(AbstractFastqWriter.java:67)
> at
> org.biojava.bio.program.fastq.AbstractFastqWriter.write(AbstractFastqWriter.java:143)
> at
> org.biojava.bio.program.fastq.AbstractFastqWriter.write(AbstractFastqWriter.java:125)
> at Fastq2Fasta.main(Fastq2Fasta.java:37) Java Result: 1
>
> What did I wrong?
>
> On Sun, 28 Mar 2010 00:27:16 -0400 (EDT)
> Michael Heuer wrote:
>
> >
> > Sorry, I haven't written up an example for the Biojava Cookbook yet.
> >
> > The FASTQ package javadoc API is at
> >
> > http://www.biojava.org/docs/api/org/biojava/bio/program/fastq/package-summary.html
> >
> > If you want to read Illumina format FASTQ files, use
> >
> > FastqReader reader = new IlluminaFastqReader();
> > for (Fastq fastq : reader.read(new File("in.fastq")))
> > {
> >   // ...
> > }
> >
> >    michael
>
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biojava-l
>




More information about the Biojava-l mailing list