output = fs.create(file, false); return new FastqRecordWriter(conf, output);
@Test(expected=RuntimeException.class) public void testBadConfig() throws IOException { Configuration conf = new Configuration(); conf.set("hbam.fastq-output.base-quality-encoding", "blalbal"); writer.setConf(conf); }
public void write(Text key, SequencedFragment seq) throws IOException { // write the id line out.write('@'); if (key != null) out.write(key.getBytes(), 0, key.getLength()); else out.write(makeId(seq).getBytes(UTF8)); out.write('\n'); // write the sequence and separator out.write(seq.getSequence().getBytes(), 0, seq.getSequence().getLength()); out.write(PLUS_LINE); // now the quality if (baseQualityFormat == BaseQualityEncoding.Sanger) out.write(seq.getQuality().getBytes(), 0, seq.getQuality().getLength()); else if (baseQualityFormat == BaseQualityEncoding.Illumina) { buffer.set(seq.getQuality()); SequencedFragment.convertQuality(buffer, BaseQualityEncoding.Sanger, baseQualityFormat); out.write(buffer.getBytes(), 0, buffer.getLength()); } else throw new RuntimeException("FastqOutputFormat: unknown base quality format " + baseQualityFormat); // and the final newline out.write('\n'); }
public void write(Text key, SequencedFragment seq) throws IOException { // write the id line out.write('@'); if (key != null) out.write(key.getBytes(), 0, key.getLength()); else out.write(makeId(seq).getBytes(UTF8)); out.write('\n'); // write the sequence and separator out.write(seq.getSequence().getBytes(), 0, seq.getSequence().getLength()); out.write(PLUS_LINE); // now the quality if (baseQualityFormat == BaseQualityEncoding.Sanger) out.write(seq.getQuality().getBytes(), 0, seq.getQuality().getLength()); else if (baseQualityFormat == BaseQualityEncoding.Illumina) { buffer.set(seq.getQuality()); SequencedFragment.convertQuality(buffer, BaseQualityEncoding.Sanger, baseQualityFormat); out.write(buffer.getBytes(), 0, buffer.getLength()); } else throw new RuntimeException("FastqOutputFormat: unknown base quality format " + baseQualityFormat); // and the final newline out.write('\n'); }
public void write(Text key, SequencedFragment seq) throws IOException { // write the id line out.write('@'); if (key != null) out.write(key.getBytes(), 0, key.getLength()); else out.write(makeId(seq).getBytes(UTF8)); out.write('\n'); // write the sequence and separator out.write(seq.getSequence().getBytes(), 0, seq.getSequence().getLength()); out.write(PLUS_LINE); // now the quality if (baseQualityFormat == BaseQualityEncoding.Sanger) out.write(seq.getQuality().getBytes(), 0, seq.getQuality().getLength()); else if (baseQualityFormat == BaseQualityEncoding.Illumina) { buffer.set(seq.getQuality()); SequencedFragment.convertQuality(buffer, BaseQualityEncoding.Sanger, baseQualityFormat); out.write(buffer.getBytes(), 0, buffer.getLength()); } else throw new RuntimeException("FastqOutputFormat: unknown base quality format " + baseQualityFormat); // and the final newline out.write('\n'); }
output = fs.create(file, false); return new FastqRecordWriter(conf, output);
output = fs.create(file, false); return new FastqRecordWriter(conf, output);
@Before public void setup() throws IOException { fragment = new SequencedFragment(); fragment.setInstrument("instrument"); fragment.setRunNumber(1); fragment.setFlowcellId("xyz"); fragment.setLane(2); fragment.setTile(1001); fragment.setXpos(10000); fragment.setYpos(9999); fragment.setRead(1); fragment.setFilterPassed(true); fragment.setControlNumber(33); fragment.setIndexSequence("CATCAT"); fragment.setSequence(new Text("AAAAAAAAAA")); fragment.setQuality(new Text("##########")); outputBuffer = new ByteArrayOutputStream(); dataOutput = new DataOutputStream(outputBuffer); writer = new FastqRecordWriter(new Configuration(), dataOutput); }
@Test public void testBaseQualitiesInIllumina() throws IOException { Configuration conf = new Configuration(); conf.set("hbam.fastq-output.base-quality-encoding", "illumina"); writer.setConf(conf); // ensure sanger qualities are converted to illumina String seq = "AAAAAAAAAA"; String qual = "##########"; fragment.setSequence(new Text(seq)); fragment.setQuality(new Text(qual)); writer.write(null, fragment); writer.close(null); String[] lines = new String(outputBuffer.toByteArray(), "US-ASCII").split("\n"); assertEquals(qual.replace("#", "B"), lines[3]); }
@Test public void testSimple() throws IOException { writer.write(null, fragment); writer.close(null); String[] lines = new String(outputBuffer.toByteArray(), "US-ASCII").split("\n"); assertEquals(4, lines.length); String idLine = lines[0]; assertTrue(idLine.startsWith("@")); compareMetadata(fragment, idLine); assertEquals(fragment.getSequence().toString(), lines[1]); assertEquals("+", lines[2]); assertEquals(fragment.getQuality().toString(), lines[3]); }
@Test public void testNullControlNumber() throws IOException { fragment.setControlNumber(null); writer.write(null, fragment); writer.close(null); String[] lines = new String(outputBuffer.toByteArray(), "US-ASCII").split("\n"); assertEquals(4, lines.length); String idLine = lines[0]; assertTrue(idLine.startsWith("@")); fragment.setControlNumber(0); // when null 0 should be written compareMetadata(fragment, idLine); }
@Test public void testNullFilter() throws IOException { fragment.setFilterPassed(null); writer.write(null, fragment); writer.close(null); String[] lines = new String(outputBuffer.toByteArray(), "US-ASCII").split("\n"); assertEquals(4, lines.length); String idLine = lines[0]; assertTrue(idLine.startsWith("@")); fragment.setFilterPassed(true); // when filter not available then it passes compareMetadata(fragment, idLine); }
@Test public void testClose() throws IOException { // doesn't really do anything but exercise the code writer.close(null); }
public FastqRecordWriter(Configuration conf, OutputStream out) { this.out = out; setConf(conf); }
@Test public void testConfigureOutputInSanger() throws IOException { Configuration conf = new Configuration(); conf.set("hbam.fastq-output.base-quality-encoding", "sanger"); writer.setConf(conf); testSimple(); }
public FastqRecordWriter(Configuration conf, OutputStream out) { this.out = out; setConf(conf); }
@Test public void testCustomId() throws IOException { String customKey = "hello"; writer.write(new Text(customKey), fragment); writer.close(null); String[] lines = new String(outputBuffer.toByteArray(), "US-ASCII").split("\n"); assertEquals(4, lines.length); String idLine = lines[0]; assertTrue(idLine.startsWith("@")); assertEquals(customKey, idLine.substring(1)); }
public FastqRecordWriter(Configuration conf, OutputStream out) { this.out = out; setConf(conf); }