Search in sources :

Example 21 with VCFHeader

use of htsjdk.variant.vcf.VCFHeader in project ASCIIGenome by dariober.

the class UtilsTest method canGetVCFHeaderAsString.

@Test
public void canGetVCFHeaderAsString() {
    VCFFileReader reader = new VCFFileReader(new File("test_data/ALL.wgs.mergedSV.v8.20130502.svs.genotypes.vcf.gz"));
    VCFHeader hdr = reader.getFileHeader();
    reader.close();
    List<String> str = Utils.vcfHeaderToStrings(hdr);
    assertEquals(71, str.size());
    assertTrue(str.get(str.size() - 1).startsWith("#CHROM"));
    reader = new VCFFileReader(new File("test_data/CEU.exon.2010_06.genotypes.vcf.gz"));
    hdr = reader.getFileHeader();
    reader.close();
    str = Utils.vcfHeaderToStrings(hdr);
    assertEquals(12, str.size());
    System.err.println(str);
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) Test(org.junit.Test)

Example 22 with VCFHeader

use of htsjdk.variant.vcf.VCFHeader in project ASCIIGenome by dariober.

the class GenotypeMatrixTest method genotypeKetwordInJS.

@Test
public void genotypeKetwordInJS() throws ClassNotFoundException, IOException, InvalidGenomicCoordsException, InvalidRecordException, SQLException, InvalidColourException, IOException {
    VCFFileReader reader = new VCFFileReader(new File("test_data/info_formats.vcf.gz"));
    VCFHeader vcfHeader = reader.getFileHeader();
    reader.close();
    GenomicCoords gc = new GenomicCoords("1:17822074-17822184", 80, null, null);
    TrackIntervalFeature vcf = new TrackIntervalFeature("test_data/info_formats.vcf.gz", gc);
    List<IntervalFeature> linf = vcf.getIntervalFeatureList();
    GenotypeMatrix gm = new GenotypeMatrix();
    gm.setJsScriptFilter("{HOM}");
    String x = gm.printToScreen(true, linf, 80, vcfHeader);
    assertTrue(x.contains("sample2"));
    assertTrue(!x.contains("sample1"));
    gm.setJsScriptFilter("{NO_CALL}");
    x = gm.printToScreen(true, linf, 80, vcfHeader);
    assertTrue(x.contains("sample1"));
    assertTrue(!x.contains("sample2"));
    gm.setJsScriptFilter("{HET_NON_REF}");
    x = gm.printToScreen(true, linf, 80, vcfHeader);
    assertTrue(x.contains("sample2"));
    assertTrue(!x.contains("sample1"));
    gm.setJsScriptFilter("{CALLED} && {POS} == 17822094");
    x = gm.printToScreen(true, linf, 80, vcfHeader);
    assertTrue(x.contains("sample2"));
    assertTrue(!x.contains("sample1"));
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) Test(org.junit.Test)

Example 23 with VCFHeader

use of htsjdk.variant.vcf.VCFHeader in project ASCIIGenome by dariober.

the class GenotypeMatrixTest method canInitMatrix.

@Test
public void canInitMatrix() throws IOException, InvalidGenomicCoordsException, IOException, ClassNotFoundException, InvalidRecordException, SQLException, InvalidColourException {
    VCFFileReader reader = new VCFFileReader(new File("test_data/ALL.wgs.mergedSV.v8.20130502.svs.genotypes.vcf.gz"));
    VCFHeader vcfHeader = reader.getFileHeader();
    reader.close();
    GenomicCoords gc = new GenomicCoords("1:572807-755079", 80, null, null);
    TrackIntervalFeature vcf = new TrackIntervalFeature("test_data/ALL.wgs.mergedSV.v8.20130502.svs.genotypes.vcf.gz", gc);
    List<IntervalFeature> linf = vcf.getIntervalFeatureList();
    GenotypeMatrix gm = new GenotypeMatrix();
    // No feature at all
    assertTrue(gm.printToScreen(true, new ArrayList<IntervalFeature>(), 80, vcfHeader).isEmpty());
    String x = gm.printToScreen(true, linf, 80, vcfHeader);
    // Check sample name
    assertTrue(x.startsWith("HG00096"));
    String[] rows = x.split("\n");
    assertEquals(3, rows.length);
    assertEquals(80, rows[0].length());
    // Check genotype coding
    // Missing genotype
    assertTrue(rows[0].contains("?"));
    // HOM ref
    assertTrue(rows[0].contains("."));
    // HET
    assertTrue(rows[1].contains("E"));
    // HOM alt
    assertTrue(rows[2].contains("0"));
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) Test(org.junit.Test)

Example 24 with VCFHeader

use of htsjdk.variant.vcf.VCFHeader in project ASCIIGenome by dariober.

the class IntervalFeatureTest method canFormatVCFLine.

@Test
public void canFormatVCFLine() throws InvalidGenomicCoordsException, InvalidColourException, IOException, InvalidConfigException {
    List<Double> rulerMap = new ArrayList<Double>();
    for (int i = 1; i < 100; i++) {
        rulerMap.add((double) i);
    }
    // Prepare header
    VCFFileReader reader = new VCFFileReader(new File("test_data/CHD.exon.2010_03.sites.vcf.gz"));
    VCFHeader vcfHeader = reader.getFileHeader();
    reader.close();
    VCFCodec vcfCodec = new VCFCodec();
    vcfCodec.setVCFHeader(vcfHeader, Utils.getVCFHeaderVersion(vcfHeader));
    String vcfLine = "1 10 . C G 23 PASS AA=.;AC=.;AN=.DP=.".replaceAll(" ", "\t");
    IntervalFeature ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals(1, ift.getIdeogram(true, true).size());
    assertEquals('G', ift.getIdeogram(true, true).get(0).getText());
    // Just check there is a formatting char
    assertTrue(ift.getIdeogram(true, true).get(0).format(false).contains("["));
    // Deletion
    vcfLine = "1 10 . CTTG C 23 PASS AA=.;AC=.;AN=.DP=.".replaceAll(" ", "\t");
    ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals('D', ift.getIdeogram(true, true).get(0).getText());
    assertEquals(3, ift.getIdeogram(true, true).size());
    // Insertion
    vcfLine = "1 10 . C CTTG 23 PASS AA=.;AC=.;AN=.DP=.".replaceAll(" ", "\t");
    ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals("I", ift.getIdeogram(true, true).get(0).format(true));
    assertEquals(3, ift.getIdeogram(true, true).size());
    // Multiple alleles
    vcfLine = "1 10 . C CTTG,A 23 PASS AA=.;AC=.;AN=.DP=.".replaceAll(" ", "\t");
    ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals("|", ift.getIdeogram(true, true).get(0).format(true));
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) ArrayList(java.util.ArrayList) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) Test(org.junit.Test)

Example 25 with VCFHeader

use of htsjdk.variant.vcf.VCFHeader in project ASCIIGenome by dariober.

the class IntervalFeatureTest method canFormatVCFLineStructVar.

@Test
public void canFormatVCFLineStructVar() throws InvalidGenomicCoordsException, InvalidColourException, IOException, InvalidConfigException {
    List<Double> rulerMap = new ArrayList<Double>();
    for (int i = 1; i < 100; i++) {
        rulerMap.add((double) i);
    }
    // Prepare header
    VCFFileReader reader = new VCFFileReader(new File("test_data/ALL.wgs.mergedSV.v8.20130502.svs.genotypes.vcf.gz"));
    VCFHeader vcfHeader = reader.getFileHeader();
    reader.close();
    VCFCodec vcfCodec = new VCFCodec();
    vcfCodec.setVCFHeader(vcfHeader, Utils.getVCFHeaderVersion(vcfHeader));
    String vcfLine = "1 668630 DUP_delly_DUP20532 G <CN2> . PASS AC=64;AF=0.0127795;AFR_AF=0.0015;AMR_AF=0;AN=5008;CIEND=-150,150;CIPOS=-150,150;CS=DUP_delly;EAS_AF=0.0595;END=850204;EUR_AF=0.001;IMPRECISE;NS=2504;SAS_AF=0.001;SITEPOST=1;SVTYPE=DUP GT 0|0 0|0 0|0".replaceAll(" ", "\t");
    IntervalFeature ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals(850204, ift.getTo());
    assertEquals("|", ift.getIdeogram(true, true).get(0).format(true));
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) ArrayList(java.util.ArrayList) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) Test(org.junit.Test)

Aggregations

VCFHeader (htsjdk.variant.vcf.VCFHeader)182 VariantContext (htsjdk.variant.variantcontext.VariantContext)113 File (java.io.File)93 ArrayList (java.util.ArrayList)79 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)73 VCFHeaderLine (htsjdk.variant.vcf.VCFHeaderLine)64 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)63 HashSet (java.util.HashSet)60 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)58 IOException (java.io.IOException)55 VCFInfoHeaderLine (htsjdk.variant.vcf.VCFInfoHeaderLine)52 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)49 Genotype (htsjdk.variant.variantcontext.Genotype)48 Allele (htsjdk.variant.variantcontext.Allele)47 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)47 List (java.util.List)44 Set (java.util.Set)38 VcfIterator (com.github.lindenb.jvarkit.util.vcf.VcfIterator)36 CloserUtil (htsjdk.samtools.util.CloserUtil)35 Collectors (java.util.stream.Collectors)34