Search in sources :

Example 1 with SAMSequenceDictionaryCodec

use of htsjdk.samtools.SAMSequenceDictionaryCodec in project jvarkit by lindenb.

the class VcfSetSequenceDictionaryTest method test01.

@Test(dataProvider = "all-vcf-files")
public void test01(final String inputFile) throws IOException {
    final SAMSequenceDictionary dict = SAMSequenceDictionaryExtractor.extractDictionary(new File(inputFile));
    if (dict == null || dict.isEmpty())
        return;
    final File dictF = super.createTmpFile(".dict");
    final BufferedWriter bw = Files.newBufferedWriter(dictF.toPath());
    final SAMSequenceDictionaryCodec codec = new SAMSequenceDictionaryCodec(bw);
    codec.encode(new SAMSequenceDictionary(dict.getSequences().stream().map(S -> new SAMSequenceRecord(S.getSequenceName().startsWith("chr") ? S.getSequenceName().substring(3) : "chr" + S.getSequenceName(), S.getSequenceLength())).collect(Collectors.toList())));
    bw.flush();
    bw.close();
    final File output = super.createTmpFile(".vcf");
    Assert.assertEquals(0, new VcfSetSequenceDictionary().instanceMain(new String[] { "-o", output.getPath(), "-R", dictF.getPath(), inputFile }));
    assertIsVcf(output);
}
Also used : Assert(org.testng.Assert) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) IOException(java.io.IOException) Test(org.testng.annotations.Test) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMSequenceDictionaryExtractor(htsjdk.variant.utils.SAMSequenceDictionaryExtractor) Collectors(java.util.stream.Collectors) TestUtils(com.github.lindenb.jvarkit.tools.tests.TestUtils) File(java.io.File) SAMSequenceDictionaryCodec(htsjdk.samtools.SAMSequenceDictionaryCodec) SAMSequenceDictionaryCodec(htsjdk.samtools.SAMSequenceDictionaryCodec) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.testng.annotations.Test)

Aggregations

TestUtils (com.github.lindenb.jvarkit.tools.tests.TestUtils)1 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)1 SAMSequenceDictionaryCodec (htsjdk.samtools.SAMSequenceDictionaryCodec)1 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)1 SAMSequenceDictionaryExtractor (htsjdk.variant.utils.SAMSequenceDictionaryExtractor)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Collectors (java.util.stream.Collectors)1 Assert (org.testng.Assert)1 Test (org.testng.annotations.Test)1