htsjdk.variant.vcf.VCFFormatHeaderLine Java Examples

The following examples show how to use htsjdk.variant.vcf.VCFFormatHeaderLine. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VCFUtils.java    From Drop-seq with MIT License 5 votes vote down vote up
/**
 * Does the VCF file use genotype qualities?
 * @param vcfReader
 * @return
 */
public static boolean GQInHeader (final VCFFileReader vcfReader) {
	Collection<VCFFormatHeaderLine> r = vcfReader.getFileHeader().getFormatHeaderLines();
	for (VCFFormatHeaderLine l : r) {
		String id = l.getID();
		if (id.equals("GQ")) return true;
	}
	return false;
}
 
Example #2
Source File: MergePedIntoVcf.java    From picard with MIT License 5 votes vote down vote up
private void addAdditionalHeaderFields(VCFHeader header) {
    header.addMetaDataLine(new VCFHeaderLine(InfiniumVcfFields.ZCALL_VERSION, ZCALL_VERSION));
    header.addMetaDataLine(new VCFHeaderLine(InfiniumVcfFields.ZCALL_THRESHOLDS, ZCALL_THRESHOLDS_FILE.getName()));
    header.addMetaDataLine(new VCFInfoHeaderLine(InfiniumVcfFields.ZTHRESH_X, 1, VCFHeaderLineType.Float, "zCall X threshold"));
    header.addMetaDataLine(new VCFInfoHeaderLine(InfiniumVcfFields.ZTHRESH_Y, 1, VCFHeaderLineType.Float, "zCall Y threshold"));
    header.addMetaDataLine(new VCFFormatHeaderLine(InfiniumVcfFields.GTA, 1, VCFHeaderLineType.String, "Illumina Autocall Genotype"));
    header.addMetaDataLine(new VCFFormatHeaderLine(InfiniumVcfFields.GTZ, 1, VCFHeaderLineType.String, "zCall Genotype"));
}
 
Example #3
Source File: GenomicsDBImportIntegrationTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static File createInputVCF(final String sampleName) {
    final String contig = "chr20";
    final SAMSequenceDictionary dict = new SAMSequenceDictionary(
            Collections.singletonList(new SAMSequenceRecord(contig, 64444167)));

    final VCFFormatHeaderLine formatField = new VCFFormatHeaderLine(SAMPLE_NAME_KEY, 1, VCFHeaderLineType.String,
                                                                    "the name of the sample this genotype came from");
    final Set<VCFHeaderLine> headerLines = new HashSet<>();
    headerLines.add(formatField);
    headerLines.add(new VCFFormatHeaderLine(ANOTHER_ATTRIBUTE_KEY, 1, VCFHeaderLineType.Integer, "Another value"));
    headerLines.add(VCFStandardHeaderLines.getFormatLine("GT"));

    final File out = createTempFile(sampleName +"_", ".vcf");
    try (final VariantContextWriter writer = GATKVariantContextUtils.createVCFWriter(out.toPath(), dict, false,
                                                                                     Options.INDEX_ON_THE_FLY)) {
        final VCFHeader vcfHeader = new VCFHeader(headerLines, Collections.singleton(sampleName));
        vcfHeader.setSequenceDictionary(dict);
        writer.writeHeader(vcfHeader);
        final Allele Aref = Allele.create("A", true);
        final Allele C = Allele.create("C");
        final List<Allele> alleles = Arrays.asList(Aref, C);
        final VariantContext variant = new VariantContextBuilder("invented", contig, INTERVAL.get(0).getStart(), INTERVAL.get(0).getStart(), alleles)
                .genotypes(new GenotypeBuilder(sampleName, alleles).attribute(SAMPLE_NAME_KEY, sampleName)
                                   .attribute(ANOTHER_ATTRIBUTE_KEY, 10).make())
                .make();
        writer.add(variant);
        return out;
    }
}
 
Example #4
Source File: VcfToVariant.java    From genomewarp with Apache License 2.0 4 votes vote down vote up
private static boolean parseOtherGenotypeFields(String field, VariantContext vc,
    ListValue.Builder lvBuilder, Genotype g, VCFHeader header) {

  if (!g.hasAnyAttribute(field)) {
    return false;
  }

  final VCFFormatHeaderLine metaData = header.getFormatHeaderLine(field);
  if (metaData == null) {
    logger.log(Level.WARNING, String.format("Could not find matching VCF header field for "
        + "genotype field %s", field));
    return false;
  }

  VCFHeaderLineType type = metaData.getType();
  Object value = g.getExtendedAttribute(field);
  final int fieldCount = metaData.getCount(vc);
  if (fieldCount == 1) {
    lvBuilder.addValues(createTypedValue(type, value));
    return true;
  }

  if (!(value instanceof String)) {
    throw new IllegalStateException("received non-Flag genotype field as non-String type");
  }
  String[] valueArray = ((String) value).split(",");
  if (valueArray.length == 1) {
    throw new IllegalStateException(String.format("header indicating a count greater than 1 "
        + "with non-List type found for field %s",
        field));
  }

  boolean allFalse = true;
  for (int i = 0; i < valueArray.length; i++) {
    VCFHeaderLineType thisType = VCFHeaderLineType.String;
    if (!valueArray[i].equals(VCFConstants.MISSING_VALUE_v4)) {
      thisType = type;
      allFalse = false;
    }

    lvBuilder.addValues(createTypedValue(thisType, valueArray[i]));
  }
  // We only add the lvBuilder if there is at least one non-missing value
  return !allFalse;
}
 
Example #5
Source File: StrandArtifact.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<VCFFormatHeaderLine> getDescriptions() {
    return Arrays.asList(new VCFFormatHeaderLine(POSTERIOR_PROBABILITIES_KEY, 3, VCFHeaderLineType.Float, "posterior probabilities of the presence of strand artifact"),
            new VCFFormatHeaderLine(MAP_ALLELE_FRACTIONS_KEY, 3, VCFHeaderLineType.Float, "MAP estimates of allele fraction given z"));
}
 
Example #6
Source File: PerAlleleAnnotation.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<VCFFormatHeaderLine> getDescriptions() {
    return Arrays.asList(new VCFFormatHeaderLine(getVcfKey(), VCFHeaderLineCount.A, VCFHeaderLineType.Float, getDescription()));
}
 
Example #7
Source File: DepthPerAlleleBySample.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<VCFFormatHeaderLine> getDescriptions() {
    return Collections.singletonList(VCFStandardHeaderLines.getFormatLine(getKeyNames().get(0)));
}
 
Example #8
Source File: StrandBiasBySample.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<VCFFormatHeaderLine> getDescriptions() {
    return Collections.singletonList(GATKVCFHeaderLines.getFormatLine(getKeyNames().get(0)));
}
 
Example #9
Source File: AlleleFraction.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<VCFFormatHeaderLine> getDescriptions() {
    return Collections.singletonList(GATKVCFHeaderLines.getFormatLine(getKeyNames().get(0)));
}
 
Example #10
Source File: DepthPerSampleHC.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<VCFFormatHeaderLine> getDescriptions() {
    return Collections.singletonList(VCFStandardHeaderLines.getFormatLine(VCFConstants.DEPTH_KEY));
}
 
Example #11
Source File: OrientationBiasReadCounts.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<VCFFormatHeaderLine> getDescriptions() {
    return Arrays.asList(
            GATKVCFHeaderLines.getFormatLine(GATKVCFConstants.F1R2_KEY),
            GATKVCFHeaderLines.getFormatLine(GATKVCFConstants.F2R1_KEY));
}
 
Example #12
Source File: GenotypeAnnotation.java    From gatk with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Return the descriptions used for the VCF FORMAT meta field.
 * Subclasses must ensure that this list is not null and does not contain null.
 */
public abstract List<VCFFormatHeaderLine> getDescriptions();