@Override protected void writeHeader(final String textHeader) { writeHeader(new SAMTextHeaderCodec().decode(BufferedLineReader.fromString(textHeader),fileName != null ? fileName : null)); }
@Override protected void writeHeader(final String textHeader) { writeHeader(new SAMTextHeaderCodec().decode(BufferedLineReader.fromString(textHeader),fileName != null ? fileName : null)); }
@Override public final SAMFileHeader clone() { final SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); codec.setValidationStringency(ValidationStringency.SILENT); return codec.decode(BufferedLineReader.fromString(getSAMString()), "SAMFileHeader.clone"); }
@Override public final SAMFileHeader clone() { final SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); codec.setValidationStringency(ValidationStringency.SILENT); return codec.decode(BufferedLineReader.fromString(getSAMString()), "SAMFileHeader.clone"); }
@Test public void testWrongTag() { String[] testData = new String[]{ "@hd\tVN:1.0\tSO:unsorted\n", "@sq\tSN:chrM\tLN:16571\n", "@rg\tID:1\tSM:sample1\n", "@pg\tID:1\tPN:A\n", "@co\tVN:1.0\tSO:unsorted\n" }; for (String stringHeader : testData) { SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); SAMFileHeader header = codec.decode(BufferedLineReader.fromString(stringHeader), null); String validationErrors = header.getValidationErrors().toString(); Assert.assertTrue(validationErrors.contains("Unrecognized header record type")); } }
@Test(dataProvider = "DataForWrongTagTests", expectedExceptions = SAMFormatException.class) public void testValidationStringencyStrict(String stringHeader) { SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); codec.setValidationStringency(ValidationStringency.STRICT); codec.decode(BufferedLineReader.fromString(stringHeader), null); }
@DataProvider public Object[][] compatibleNonEqualLists(){ final String s = HEADER + String.format("@SQ\tSN:phix174.seq\tLN:%d\tUR:%s\tAS:PhiX174\tM5:%s\n", 5386, "/seq/references/PhiX174/v0/PhiX174.fasta", "3332ed720ac7eaa9b3655c06f6b9e196")+ String.format("@SQ\tSN:phix175.seq\tLN:%d\tUR:%s\tAS:HiMom\tM5:%s\n", 5385, "/seq/references/PhiX174/v0/HiMom.fasta", "deadbeed"); return new Object[][]{ {makeSequenceDictionary(5386, "/seq/references/PhiX174/v0/PhiX174.fasta", "3332ed720ac7eaa9b3655c06f6b9e196"), new SAMTextHeaderCodec().decode(BufferedLineReader.fromString(s), null).getSequenceDictionary()}}; }
final BufferedLineReader headerReader = BufferedLineReader.fromString(builder.toString()); final SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); final IntervalList list = new IntervalList(codec.decode(headerReader, "BufferedReader"));
final BufferedLineReader headerReader = BufferedLineReader.fromString(builder.toString()); final SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); final IntervalList list = new IntervalList(codec.decode(headerReader, "BufferedReader"));
private SAMSequenceDictionary makeSequenceDictionary(final int length, final String ur, final String m5) { final String s = HEADER + String.format("@SQ\tSN:phix174.seq\tLN:%d\tUR:%s\tAS:PhiX174\tM5:%s\n", length, ur, m5); return new SAMTextHeaderCodec().decode(BufferedLineReader.fromString(s), null).getSequenceDictionary(); }
@Test(dataProvider = "DataForWrongTagTests") public void testValidationStringencyLenientAndSilent(String stringHeader) { SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); codec.setValidationStringency(ValidationStringency.LENIENT); SAMFileHeader headerLenient = codec.decode(BufferedLineReader.fromString(stringHeader), null); Assert.assertTrue(headerLenient.getSortOrder().equals(SAMFileHeader.SortOrder.unknown)); codec.setValidationStringency(ValidationStringency.SILENT); SAMFileHeader headerSilent = codec.decode(BufferedLineReader.fromString(stringHeader), null); Assert.assertTrue(headerSilent.getSortOrder().equals(SAMFileHeader.SortOrder.unknown)); } }
@Test public void testEncodeDecodeDictionary() throws Exception { LineReader readerOne = null; LineReader readerTwo = null; try { codec.encode(dictionary); bufferedWriter.close(); readerOne = BufferedLineReader.fromString(writer.toString()); SAMSequenceDictionary actual = codec.decode(readerOne, null); assertEquals(actual, dictionary); readerTwo = BufferedLineReader.fromString(writer.toString()); String line = readerTwo.readLine(); assertTrue(line.startsWith("@HD")); line = readerTwo.readLine(); while (line != null) { assertTrue(line.startsWith("@SQ")); line = readerTwo.readLine(); } } finally { assert readerOne != null; assert readerTwo != null; readerOne.close(); readerTwo.close(); } }
sequences.forEach(codec::encodeSequenceRecord); bufferedWriter.close(); readerOne = BufferedLineReader.fromString(writer.toString()); SAMSequenceDictionary actual = codec.decode(readerOne, null); assertEquals(actual, dictionary); readerTwo = BufferedLineReader.fromString(writer.toString());
/** * various test cases where there is no input, except perhaps a line terminator * @param terminator what the terminator should be in the input * @param lastLineTerminated does the input have a terminator */ private void fromStringEmptyTestHelper(final String terminator, final boolean lastLineTerminated) { final String input; if (lastLineTerminated) { input = terminator; } else { input = ""; } final BufferedLineReader blr = BufferedLineReader.fromString(input); blr.peek(); final String output = blr.readLine(); if (lastLineTerminated) { Assert.assertEquals(output, ""); } blr.peek(); Assert.assertNull(blr.readLine()); }
@Test(dataProvider = "DataForWrongTagTests") public void testSortOrderCodecSetting(String hdr) { String validString = "@HD\tVN:1.0\tSO:unknown\n"; SAMTextHeaderCodec codec = new SAMTextHeaderCodec(); SAMFileHeader header = codec.decode(BufferedLineReader.fromString(validString), null); header.setSortOrder(SAMFileHeader.SortOrder.coordinate); Assert.assertEquals(header.getSortOrder(), SAMFileHeader.SortOrder.coordinate); Assert.assertEquals(header.getAttribute(SAMFileHeader.SORT_ORDER_TAG), SAMFileHeader.SortOrder.coordinate.name()); header.setSortOrder(SAMFileHeader.SortOrder.unsorted); Assert.assertEquals(header.getSortOrder(), SAMFileHeader.SortOrder.unsorted); Assert.assertEquals(header.getAttribute(SAMFileHeader.SORT_ORDER_TAG), SAMFileHeader.SortOrder.unsorted.name()); header.setAttribute(SAMFileHeader.SORT_ORDER_TAG, "badname"); Assert.assertEquals(header.getSortOrder(), SAMFileHeader.SortOrder.unknown); Assert.assertEquals(header.getAttribute(SAMFileHeader.SORT_ORDER_TAG), SAMFileHeader.SortOrder.unknown.name()); header = codec.decode(BufferedLineReader.fromString(hdr), null); Assert.assertTrue(header.getSortOrder().toString().equals("unknown")); }
input = input.concat(terminator); final BufferedLineReader blr = BufferedLineReader.fromString(input); for (int i = 0; i < lines.length - 1; ++i) { blr.peek();
final SAMTextHeaderCodec headerCodec = new SAMTextHeaderCodec(); headerCodec.setValidationStringency(validationStringency); final SAMFileHeader samFileHeader = headerCodec.decode(BufferedLineReader.fromString(textHeader), source);
final SAMTextHeaderCodec headerCodec = new SAMTextHeaderCodec(); headerCodec.setValidationStringency(validationStringency); final SAMFileHeader samFileHeader = headerCodec.decode(BufferedLineReader.fromString(textHeader), source);
final SAMTextHeaderCodec headerCodec = new SAMTextHeaderCodec(); headerCodec.setValidationStringency(validationStringency); final SAMFileHeader samFileHeader = headerCodec.decode(BufferedLineReader.fromString(textHeader), source);