use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.
the class TableCodecUnitTest method testDecodeHeader2.
@Test
public void testDecodeHeader2() {
TableCodec tc = new TableCodec();
final String str2 = "1:1 1 2 3";
LineReader reader = makeReader(asList("HEADER a b c", str2));
LineIterator li = new LineIteratorImpl(reader);
List<String> hd = tc.readActualHeader(li);
Assert.assertEquals(hd, asList("HEADER", "a", "b", "c"));
final TableFeature decode = tc.decode(str2);
Assert.assertEquals(decode.get("a"), "1");
Assert.assertEquals(decode.get("b"), "2");
Assert.assertEquals(decode.get("c"), "3");
Assert.assertEquals(decode.getLocation().getContig(), "1");
Assert.assertEquals(decode.getContig(), "1");
Assert.assertEquals(decode.getLocation().getStart(), 1);
Assert.assertEquals(decode.getLocation().getEnd(), 1);
}
use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.
the class GenomicsDBImport method getReaderFromVCFUri.
/**
* Creates a feature reader object from a given VCF URI (can also be
* a local file path) and returns it
* @param variantPath URI or file path
* @return Feature reader
*/
private AbstractFeatureReader<VariantContext, LineIterator> getReaderFromVCFUri(final String variantPath) {
final String variantURI = IOUtils.getPath(variantPath).toAbsolutePath().toUri().toString();
final Function<SeekableByteChannel, SeekableByteChannel> cloudWrapper = (cloudPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudPrefetchBuffer, is) : Function.identity());
final Function<SeekableByteChannel, SeekableByteChannel> cloudIndexWrapper = (cloudIndexPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudIndexPrefetchBuffer, is) : Function.identity());
return AbstractFeatureReader.getFeatureReader(variantURI, null, new VCFCodec(), true, cloudWrapper, cloudIndexWrapper);
}
use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.
the class GenomicsDBImportIntegrationTest method testPreserveContigOrderingInHeader.
@Test
public void testPreserveContigOrderingInHeader() throws IOException {
final String workspace = createTempDir("testPreserveContigOrderingInHeader-").getAbsolutePath() + "/workspace";
writeToGenomicsDB(Arrays.asList(GENOMICSDB_TEST_DIR + "testHeaderContigLineSorting1.g.vcf", GENOMICSDB_TEST_DIR + "testHeaderContigLineSorting2.g.vcf"), new SimpleInterval("chr20", 17959479, 17959479), workspace, 0, false, 0);
try (final GenomicsDBFeatureReader<VariantContext, PositionalBufferedStream> genomicsDBFeatureReader = new GenomicsDBFeatureReader<>(new File(workspace, GenomicsDBConstants.DEFAULT_VIDMAP_FILE_NAME).getAbsolutePath(), new File(workspace, GenomicsDBConstants.DEFAULT_CALLSETMAP_FILE_NAME).getAbsolutePath(), workspace, GenomicsDBConstants.DEFAULT_ARRAY_NAME, b38_reference_20_21, null, new BCF2Codec());
final AbstractFeatureReader<VariantContext, LineIterator> inputGVCFReader = AbstractFeatureReader.getFeatureReader(GENOMICSDB_TEST_DIR + "testHeaderContigLineSorting1.g.vcf", new VCFCodec(), true)) {
final SAMSequenceDictionary dictionaryFromGenomicsDB = ((VCFHeader) genomicsDBFeatureReader.getHeader()).getSequenceDictionary();
final SAMSequenceDictionary dictionaryFromInputGVCF = ((VCFHeader) inputGVCFReader.getHeader()).getSequenceDictionary();
Assert.assertEquals(dictionaryFromGenomicsDB, dictionaryFromInputGVCF, "Sequence dictionary from GenomicsDB does not match original sequence dictionary from input GVCF");
}
}
use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.
the class GenotypeGVCFsIntegrationTest method getVariantContexts.
/**
* Returns a list of VariantContext records from a VCF file
*
* @param vcfFile VCF file
* @return list of VariantContext records
* @throws IOException if the file does not exist or can not be opened
*/
private static List<VariantContext> getVariantContexts(final File vcfFile) throws IOException {
final VCFCodec codec = new VCFCodec();
final FileInputStream s = new FileInputStream(vcfFile);
final LineIterator lineIteratorVCF = codec.makeSourceFromStream(new PositionalBufferedStream(s));
codec.readHeader(lineIteratorVCF);
final List<VariantContext> VCs = new ArrayList<>();
while (lineIteratorVCF.hasNext()) {
final String line = lineIteratorVCF.next();
Assert.assertFalse(line == null);
VCs.add(codec.decode(line));
}
return VCs;
}
use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.
the class TableCodecUnitTest method testDecodeComment.
@Test
public void testDecodeComment() {
TableCodec tc = new TableCodec();
LineReader reader = makeReader(asList("#HEADER a b c", "HEADER d e f"));
LineIterator li = new LineIteratorImpl(reader);
List<String> hd = tc.readActualHeader(li);
Assert.assertEquals(hd, asList("HEADER", "d", "e", "f"));
}
Aggregations