Re: converting fastq format
Michael Heuer <[email protected]> Wed, 16 Sep 2015 10:26:41 -0500
| Newsgroups | gmane.comp.java.bio.general |
|---|---|
| Message-ID | <CAOjYwMzRrUKhrcVagMMYs8cCOL6GC4oQX2KPcDNpEOR7Up2xHA@mail.gmail.com> |
Hello Daniel, The whole point of the FASTQ APIs in biojava is to support conversions as you are trying to do, so you shouldn't have to do it yourself. I would also be interested in seeing (some of) your input data. If you've found a historical edge case, or something that otherwise bends the rules, we could add it to the repo as another test case. michael On Wed, Sep 16, 2015 at 2:22 AM, Peter Cock <[email protected]> wrote: > Hi Daniel, > > I can't help you on the BioJava specifics, but do your input files really > have Illumina's old FASTQ quality encoding? Can you show use the > first couple of records which is usually enough to guess. > > http://dx.doi.org/10.1093/nar/gkp1137 > > Peter > > On Wed, Sep 16, 2015 at 4:28 AM, Daniel Katzel <[email protected]> wrote: > > 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 fileWriter = new FileWriter(new File("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 > > > > _______________________________________________ > > Biojava-l mailing list - [email protected] > > http://mailman.open-bio.org/mailman/listinfo/biojava-l > _______________________________________________ > Biojava-l mailing list - [email protected] > http://mailman.open-bio.org/mailman/listinfo/biojava-l > _______________________________________________ Biojava-l mailing list - [email protected] http://mailman.open-bio.org/mailman/listinfo/biojava-l