@Override public LocationAware makeIndexableSourceFromStream(final InputStream inputStream) { return new AsciiLineReaderIterator(AsciiLineReader.from(inputStream)); }
@Override public LocationAware makeIndexableSourceFromStream(final InputStream inputStream) { return new AsciiLineReaderIterator(AsciiLineReader.from(inputStream)); }
@Test(dataProvider="fromStream") public void testFromStream(final InputStream inStream, final Class expectedClass) { AsciiLineReader alr = AsciiLineReader.from(inStream); Assert.assertEquals(alr.getClass(), expectedClass); }
/** * Test that we read the correct number of lines * from a file * @throws Exception */ @Test public void testReadLines() throws Exception { String filePath = TestUtils.DATA_DIR + "gwas/smallp.gwas"; InputStream is = new FileInputStream(filePath); AsciiLineReader reader = AsciiLineReader.from(is); int actualLines = 0; int expectedNumber = 20; String nextLine = ""; while((nextLine = reader.readLine()) != null && actualLines < (expectedNumber + 5)){ actualLines++; //This particular test file has no empty lines assertTrue(nextLine.length() > 0); } assertEquals(expectedNumber, actualLines); }
@Test public void voidTestLineEndingLengthAtEof() throws Exception { final String input = "Hello\nWorld\r\n"; final InputStream is = new ByteArrayInputStream(input.getBytes()); final AsciiLineReader in = AsciiLineReader.from(is); Assert.assertEquals(in.getLineTerminatorLength(), -1); Assert.assertEquals(in.readLine(), "Hello"); Assert.assertEquals(in.getLineTerminatorLength(), 1); Assert.assertEquals(in.readLine(), "World"); Assert.assertEquals(in.getLineTerminatorLength(), 2); }
@Test public void voidTestLineEndingLength() throws Exception { final String input = "Hello\nThis\rIs A Silly Test\r\nSo There"; final InputStream is = new ByteArrayInputStream(input.getBytes()); final AsciiLineReader in = AsciiLineReader.from(is); Assert.assertEquals(in.getLineTerminatorLength(), -1); Assert.assertEquals(in.readLine(), "Hello"); Assert.assertEquals(in.getLineTerminatorLength(), 1); Assert.assertEquals(in.readLine(), "This"); Assert.assertEquals(in.getLineTerminatorLength(), 1); Assert.assertEquals(in.readLine(), "Is A Silly Test"); Assert.assertEquals(in.getLineTerminatorLength(), 2); Assert.assertEquals(in.readLine(), "So There"); Assert.assertEquals(in.getLineTerminatorLength(), 0); }
@Test(expectedExceptions = TribbleException.class) public void testVCFHeaderSampleRenamingMultiSampleVCF() throws Exception { final VCFCodec codec = new VCFCodec(); codec.setRemappedSampleName("FOOSAMPLE"); final AsciiLineReaderIterator vcfIterator = new AsciiLineReaderIterator(AsciiLineReader.from(new FileInputStream(variantTestDataRoot + "ex2.vcf"))); final VCFHeader header = (VCFHeader) codec.readHeader(vcfIterator).getHeaderValue(); }
@Test(expectedExceptions = TribbleException.class) public void testVCFHeaderSampleRenamingSitesOnlyVCF() throws Exception { final VCFCodec codec = new VCFCodec(); codec.setRemappedSampleName("FOOSAMPLE"); final AsciiLineReaderIterator vcfIterator = new AsciiLineReaderIterator(AsciiLineReader.from(new FileInputStream(variantTestDataRoot + "dbsnp_135.b37.1000.vcf"))); final VCFHeader header = (VCFHeader) codec.readHeader(vcfIterator).getHeaderValue(); }
@Test public void testVCFHeaderSampleRenamingSingleSampleVCF() throws Exception { final VCFCodec codec = new VCFCodec(); codec.setRemappedSampleName("FOOSAMPLE"); final AsciiLineReaderIterator vcfIterator = new AsciiLineReaderIterator(AsciiLineReader.from(new FileInputStream(variantTestDataRoot + "HiSeq.10000.vcf"))); final VCFHeader header = (VCFHeader) codec.readHeader(vcfIterator).getHeaderValue(); Assert.assertEquals(header.getNGenotypeSamples(), 1, "Wrong number of samples in remapped header"); Assert.assertEquals(header.getGenotypeSamples().get(0), "FOOSAMPLE", "Sample name in remapped header has incorrect value"); int recordCount = 0; while (vcfIterator.hasNext() && recordCount < 10) { recordCount++; final VariantContext vcfRecord = codec.decode(vcfIterator.next()); Assert.assertEquals(vcfRecord.getSampleNames().size(), 1, "Wrong number of samples in vcf record after remapping"); Assert.assertEquals(vcfRecord.getSampleNames().iterator().next(), "FOOSAMPLE", "Wrong sample in vcf record after remapping"); } }
try(final AsciiLineReader in = AsciiLineReader.from(IOUtil.openFileForReading(fastaFile))) {
try(final AsciiLineReader in = AsciiLineReader.from(IOUtil.openFileForReading(fastaFile))) {