2020 */
2121package org .biojava .nbio .sequencing .io .fastq ;
2222
23- import java .io .*;
23+ import java .io .BufferedWriter ;
24+ import java .io .File ;
25+ import java .io .FileWriter ;
26+ import java .io .IOException ;
27+ import java .io .OutputStream ;
28+ import java .io .OutputStreamWriter ;
29+ import java .io .Writer ;
30+
2431import java .util .Arrays ;
2532
2633/**
@@ -33,12 +40,14 @@ abstract class AbstractFastqWriter
3340{
3441
3542 /**
36- * Validate the specified FASTQ formatted sequence for writing .
43+ * Convert the specified FASTQ formatted sequence if necessary .
3744 *
38- * @param fastq FASTQ formatted sequence to validate, will not be null
39- * @throws IOException if the specified FASTQ formatted sequence is not valid for writing
45+ * @since 4.2
46+ * @param fastq FASTQ formatted sequence to convert, must not be null
47+ * @return the specified FASTQ formatted sequence or a new FASTA formatted
48+ * sequence if conversion is necessary
4049 */
41- protected abstract void validate (final Fastq fastq ) throws IOException ;
50+ protected abstract Fastq convert (final Fastq fastq );
4251
4352 @ Override
4453 public final <T extends Appendable > T append (final T appendable , final Fastq ... fastq ) throws IOException
@@ -59,16 +68,15 @@ public final <T extends Appendable> T append(final T appendable, final Iterable<
5968 }
6069 for (Fastq f : fastq )
6170 {
62- validate (f );
6371 if (f != null )
6472 {
73+ Fastq converted = convert (f );
6574 appendable .append ("@" );
66- appendable .append (f .getDescription ());
67- appendable .append ("\n " );
68- appendable .append (f .getSequence ());
75+ appendable .append (converted .getDescription ());
6976 appendable .append ("\n " );
70- appendable .append ("+\n " );
71- appendable .append (f .getQuality ());
77+ appendable .append (converted .getSequence ());
78+ appendable .append ("\n +\n " );
79+ appendable .append (converted .getQuality ());
7280 appendable .append ("\n " );
7381 }
7482 }
@@ -152,4 +160,4 @@ public final void write(final OutputStream outputStream, final Iterable<Fastq> f
152160 }
153161 }
154162 }
155- }
163+ }
0 commit comments