Skip to content

Commit 579b40f

Browse files
committed
Add copy ctr to FASTQ builder.
1 parent e924213 commit 579b40f

18 files changed

+293
-228
lines changed

sequencing/src/main/java/org/biojava/bio/program/fastq/AbstractFastqReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public final void stream(final Readable readable, final StreamListener listener)
7070
StreamingFastqParser.stream(readable, getVariant(), listener);
7171
}
7272

73-
/** {@inheritDoc} */
73+
@Override
7474
public final Iterable<Fastq> read(final File file) throws IOException
7575
{
7676
if (file == null)
@@ -99,7 +99,7 @@ public final Iterable<Fastq> read(final File file) throws IOException
9999
return collect.getResult();
100100
}
101101

102-
/** {@inheritDoc} */
102+
@Override
103103
public final Iterable<Fastq> read(final URL url) throws IOException
104104
{
105105
if (url == null)
@@ -128,7 +128,7 @@ public final Iterable<Fastq> read(final URL url) throws IOException
128128
return collect.getResult();
129129
}
130130

131-
/** {@inheritDoc} */
131+
@Override
132132
public final Iterable<Fastq> read(final InputStream inputStream) throws IOException
133133
{
134134
if (inputStream == null)
@@ -163,9 +163,9 @@ public final Iterable<Fastq> read(final InputStream inputStream) throws IOExcept
163163
private static final class Collect implements StreamListener
164164
{
165165
/** List of FASTQ formatted sequences. */
166-
private final List<Fastq> result = Lists.newLinkedList();
166+
private final List<Fastq> result = Lists.newArrayList();
167167

168-
/** {@inheritDoc} */
168+
@Override
169169
public void fastq(final Fastq fastq)
170170
{
171171
result.add(fastq);

sequencing/src/main/java/org/biojava/bio/program/fastq/AbstractFastqWriter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ abstract class AbstractFastqWriter
4949
*/
5050
protected abstract Fastq convert(final Fastq fastq);
5151

52-
/** {@inheritDoc} */
52+
@Override
5353
public final <T extends Appendable> T append(final T appendable, final Fastq... fastq) throws IOException
5454
{
5555
return append(appendable, Arrays.asList(fastq));
5656
}
5757

58-
/** {@inheritDoc} */
58+
@Override
5959
public final <T extends Appendable> T append(final T appendable, final Iterable<Fastq> fastq) throws IOException
6060
{
6161
if (appendable == null)
@@ -83,13 +83,13 @@ public final <T extends Appendable> T append(final T appendable, final Iterable<
8383
return appendable;
8484
}
8585

86-
/** {@inheritDoc} */
86+
@Override
8787
public final void write(final File file, final Fastq... fastq) throws IOException
8888
{
8989
write(file, Arrays.asList(fastq));
9090
}
9191

92-
/** {@inheritDoc} */
92+
@Override
9393
public final void write(final File file, final Iterable<Fastq> fastq) throws IOException
9494
{
9595
if (file == null)
@@ -122,13 +122,13 @@ public final void write(final File file, final Iterable<Fastq> fastq) throws IOE
122122
}
123123
}
124124

125-
/** {@inheritDoc} */
125+
@Override
126126
public final void write(final OutputStream outputStream, final Fastq... fastq) throws IOException
127127
{
128128
write(outputStream, Arrays.asList(fastq));
129129
}
130130

131-
/** {@inheritDoc} */
131+
@Override
132132
public final void write(final OutputStream outputStream, final Iterable<Fastq> fastq) throws IOException
133133
{
134134
if (outputStream == null)

sequencing/src/main/java/org/biojava/bio/program/fastq/Fastq.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,19 @@ public static final FastqBuilder builder()
145145
{
146146
return new FastqBuilder();
147147
}
148+
149+
/**
150+
* Create and return a new FastqBuilder configured from the
151+
* specified FASTQ formatted sequence.
152+
* The FastqBuilder will not be null.
153+
*
154+
* @since 1.9.5
155+
* @param fastq FASTQ formatted sequence, must not be null
156+
* @return a new FastqBuilder configured from the specifed FASTQ
157+
* formatted sequence
158+
*/
159+
public static final FastqBuilder builder(final Fastq fastq)
160+
{
161+
return new FastqBuilder(fastq);
162+
}
148163
}

sequencing/src/main/java/org/biojava/bio/program/fastq/FastqBuilder.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ public FastqBuilder()
5151
// empty
5252
}
5353

54+
/**
55+
* Create a new FASTQ formatted sequence builder configured
56+
* from the specified FASTQ formatted sequence.
57+
*
58+
* @since 1.9.5
59+
* @param fastq FASTQ formatted sequence, must not be null
60+
*/
61+
public FastqBuilder(final Fastq fastq)
62+
{
63+
if (fastq == null)
64+
{
65+
throw new IllegalArgumentException("fastq must not be null");
66+
}
67+
withDescription(fastq.getDescription());
68+
withSequence(fastq.getSequence());
69+
withQuality(fastq.getQuality());
70+
withVariant(fastq.getVariant());
71+
}
72+
5473

5574
/**
5675
* Return the description for this FASTQ formatted sequence builder.
@@ -224,4 +243,4 @@ public Fastq build()
224243
Fastq fastq = new Fastq(description, sequence.toString(), quality.toString(), variant);
225244
return fastq;
226245
}
227-
}
246+
}

sequencing/src/main/java/org/biojava/bio/program/fastq/FastqParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ private void setState(final State state)
115115
this.state = state;
116116
}
117117

118-
/** {@inheritDoc} */
118+
@Override
119119
public Object getResult()
120120
{
121121
return null;
122122
}
123123

124-
/** {@inheritDoc} */
124+
@Override
125125
public boolean processLine(final String line) throws IOException
126126
{
127127
String sequence = null;

sequencing/src/main/java/org/biojava/bio/program/fastq/FastqReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ public interface FastqReader
8080
* @throws IOException if an I/O error occurs
8181
*/
8282
Iterable<Fastq> read(InputStream inputStream) throws IOException;
83-
}
83+
}

sequencing/src/main/java/org/biojava/bio/program/fastq/IlluminaFastqReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public final class IlluminaFastqReader
2929
extends AbstractFastqReader
3030
{
3131

32-
/** {@inheritDoc} */
32+
@Override
3333
protected FastqVariant getVariant()
3434
{
3535
return FastqVariant.FASTQ_ILLUMINA;
3636
}
37-
}
37+
}

sequencing/src/main/java/org/biojava/bio/program/fastq/SangerFastqReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public final class SangerFastqReader
2929
extends AbstractFastqReader
3030
{
3131

32-
/** {@inheritDoc} */
32+
@Override
3333
protected FastqVariant getVariant()
3434
{
3535
return FastqVariant.FASTQ_SANGER;
3636
}
37-
}
37+
}

sequencing/src/main/java/org/biojava/bio/program/fastq/SolexaFastqReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public final class SolexaFastqReader
2929
extends AbstractFastqReader
3030
{
3131

32-
/** {@inheritDoc} */
32+
@Override
3333
protected FastqVariant getVariant()
3434
{
3535
return FastqVariant.FASTQ_SOLEXA;
3636
}
37-
}
37+
}

sequencing/src/main/java/org/biojava/bio/program/fastq/StreamingFastqParser.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ static void stream(final Readable readable, final FastqVariant variant, final St
5959
final FastqBuilder builder = new FastqBuilder().withVariant(variant);
6060
FastqParser.parse(readable, new ParseListener()
6161
{
62-
/** {@inheritDoc} */
62+
@Override
6363
public void description(final String description) throws IOException
6464
{
6565
builder.withDescription(description);
6666
}
6767

68-
/** {@inheritDoc} */
68+
@Override
6969
public void sequence(final String sequence) throws IOException
7070
{
7171
builder.withSequence(sequence);
7272
}
7373

74-
/** {@inheritDoc} */
74+
@Override
7575
public void appendSequence(final String sequence) throws IOException
7676
{
7777
builder.appendSequence(sequence);
7878
}
7979

80-
/** {@inheritDoc} */
80+
@Override
8181
public void repeatDescription(final String repeatDescription) throws IOException
8282
{
8383
String description = builder.getDescription();
@@ -111,21 +111,21 @@ private void validateQuality(final String quality) throws IOException
111111
}
112112
}
113113

114-
/** {@inheritDoc} */
114+
@Override
115115
public void quality(final String quality) throws IOException
116116
{
117117
validateQuality(quality);
118118
builder.withQuality(quality);
119119
}
120120

121-
/** {@inheritDoc} */
121+
@Override
122122
public void appendQuality(final String quality) throws IOException
123123
{
124124
validateQuality(quality);
125125
builder.appendQuality(quality);
126126
}
127127

128-
/** {@inheritDoc} */
128+
@Override
129129
public void complete() throws IOException
130130
{
131131
try
@@ -134,8 +134,7 @@ public void complete() throws IOException
134134
}
135135
catch (IllegalStateException e)
136136
{
137-
throw new IOException("caught an IllegalStateException " + e.getMessage());
138-
//throw new IOException("caught an IllegalStateException", e); jdk 1.6+
137+
throw new IOException("caught an IllegalStateException", e);
139138
}
140139
}
141140
});

sequencing/src/test/java/org/biojava/bio/program/fastq/FastqBuilderTest.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,38 @@ public void testConstructor()
3535
assertNotNull(fastqBuilder);
3636
}
3737

38+
public void testConstructorFastq()
39+
{
40+
FastqBuilder fastqBuilder = new FastqBuilder()
41+
.withDescription("description")
42+
.withSequence("sequence")
43+
.withQuality("quality_")
44+
.withVariant(FastqVariant.FASTQ_SOLEXA);
45+
Fastq fastq = fastqBuilder.build();
46+
47+
FastqBuilder fastqBuilder2 = new FastqBuilder(fastq);
48+
assertNotNull(fastqBuilder2);
49+
50+
Fastq fastq2 = fastqBuilder2.build();
51+
assertEquals(fastq.getDescription(), fastq2.getDescription());
52+
assertEquals(fastq.getSequence(), fastq2.getSequence());
53+
assertEquals(fastq.getQuality(), fastq2.getQuality());
54+
assertEquals(fastq.getVariant(), fastq2.getVariant());
55+
}
56+
57+
public void testConstructorNullFastq()
58+
{
59+
try
60+
{
61+
new FastqBuilder(null);
62+
fail("ctr(null) expected IllegalArgumentException");
63+
}
64+
catch (IllegalArgumentException e)
65+
{
66+
// expected
67+
}
68+
}
69+
3870
public void testBuildDefault()
3971
{
4072
try
@@ -368,4 +400,4 @@ public void testBuildMultiple()
368400
assertEquals(FastqVariant.FASTQ_SOLEXA, fastq.getVariant());
369401
}
370402
}
371-
}
403+
}

0 commit comments

Comments
 (0)