当前位置: 首页>>代码示例>>Java>>正文


Java VCFConstants类代码示例

本文整理汇总了Java中htsjdk.variant.vcf.VCFConstants的典型用法代码示例。如果您正苦于以下问题:Java VCFConstants类的具体用法?Java VCFConstants怎么用?Java VCFConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


VCFConstants类属于htsjdk.variant.vcf包,在下文中一共展示了VCFConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseFilters

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
protected List<String> parseFilters(final String filterString) {
    // null for unfiltered
    if (filterString.equals(VCFConstants.UNFILTERED))
        return null;

    if (filterString.equals(VCFConstants.PASSES_FILTERS_v4))
        return Collections.emptyList();

    // do we have the filter string cached?
    if (filterHash.containsKey(filterString))
        return filterHash.get(filterString);

    // empty set for passes filters
    final List<String> fFields = new LinkedList<String>();
    // otherwise we have to parse and cache the value
    if (!filterString.contains(VCFConstants.FILTER_CODE_SEPARATOR))
        fFields.add(filterString);
    else
        fFields.addAll(Arrays.asList(filterString.split(VCFConstants.FILTER_CODE_SEPARATOR)));

    filterHash.put(filterString, Collections.unmodifiableList(fFields));

    return fFields;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:25,代码来源:VcfRecord2VCTransfer.java

示例2: formatVCFField

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
String formatVCFField(final Object val) {
    final String result;
    if (val == null)
        result = VCFConstants.MISSING_VALUE_v4;
    else if (val instanceof Double)
        result = formatVCFDouble((Double) val);
    else if (val instanceof Boolean)
        result = (Boolean) val ? "" : null; // empty string for true, null for false
    else if (val instanceof List) {
        result = formatVCFField(((List) val).toArray());
    } else if (val.getClass().isArray()) {
        final int length = Array.getLength(val);
        if (length == 0)
            return formatVCFField(null);
        final StringBuilder sb = new StringBuilder(formatVCFField(Array.get(val, 0)));
        for (int i = 1; i < length; i++) {
            sb.append(",");
            sb.append(formatVCFField(Array.get(val, i)));
        }
        result = sb.toString();
    } else
        result = val.toString();

    return result;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:26,代码来源:VC2VcfRecordTransfer.java

示例3: writeInfoString

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
private void writeInfoString(final Map<String, String> infoFields, final StringBuilder builder) {
    if (infoFields.isEmpty()) {
        builder.append(VCFConstants.EMPTY_INFO_FIELD);
        return;
    }

    boolean isFirst = true;
    for (final Map.Entry<String, String> entry : infoFields.entrySet()) {
        if (isFirst) isFirst = false;
        else builder.append(VCFConstants.INFO_FIELD_SEPARATOR);

        builder.append(entry.getKey());

        if (!entry.getValue().equals("")) {
            final VCFInfoHeaderLine metaData = this.header.getInfoHeaderLine(entry.getKey());
            if (metaData == null || metaData.getCountType() != VCFHeaderLineCount.INTEGER || metaData.getCount() != 0) {
                builder.append("=");
                builder.append(entry.getValue());
            }
        }
    }
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:23,代码来源:VC2VcfRecordTransfer.java

示例4: blockToVCF

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
/**
 * Convert a HomRefBlock into a VariantContext
 *
 * @param block the block to convert
 * @return a VariantContext representing the gVCF encoding for this block.
 * It will return {@code null} if input {@code block} is {@code null}, indicating that there
 * is no variant-context to be output into the VCF.
 */
private VariantContext blockToVCF(final HomRefBlock block) {
    if ( block == null ) return null;

    final VariantContextBuilder vcb = new VariantContextBuilder(block.getStartingVC());
    vcb.attributes(new HashMap<String, Object>(2)); // clear the attributes
    vcb.stop(block.getStop());
    vcb.attribute(VCFConstants.END_KEY, block.getStop());

    // create the single Genotype with GQ and DP annotations
    final GenotypeBuilder gb = new GenotypeBuilder(sampleName, GATKVariantContextUtils.homozygousAlleleList(block.getRef(),block.getPloidy()));
    gb.noAD().noPL().noAttributes(); // clear all attributes
    gb.GQ(block.getMedianGQ());
    gb.DP(block.getMedianDP());
    gb.attribute(MIN_DP_FORMAT_FIELD, block.getMinDP());
    gb.PL(block.getMinPLs());

    // This annotation is no longer standard
    //gb.attribute(MIN_GQ_FORMAT_FIELD, block.getMinGQ());

    return vcb.genotypes(gb.make()).make();
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:30,代码来源:GVCFWriter.java

示例5: annotateRsID

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
/**
 * Update rsID of vcToAnnotate with rsID match found in vcsAtLoc, if one exists
 *
 * @param vcsAtLoc a list of variant contexts starting at this location to use as sources for rsID values
 * @param vcToAnnotate a variant context to annotate
 * @return a VariantContext (may be == to vcToAnnotate) with updated rsID value
 */
public VariantContext annotateRsID(final List<VariantContext> vcsAtLoc, final VariantContext vcToAnnotate ) {
    final String rsID = getRsID(vcsAtLoc, vcToAnnotate);

    // add the ID if appropriate
    if ( rsID != null ) {
        final VariantContextBuilder vcb = new VariantContextBuilder(vcToAnnotate);

        if ( ! vcToAnnotate.hasID() ) {
            return vcb.id(rsID).make();
        } else if ( ! vcToAnnotate.getID().contains(rsID) ) {
            return vcb.id(vcToAnnotate.getID() + VCFConstants.ID_FIELD_SEPARATOR + rsID).make();
        } // falling through to return VC lower down
    }

    // nothing to do, just return vc
    return vcToAnnotate;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:25,代码来源:VariantOverlapAnnotator.java

示例6: generateFilterString

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
protected String generateFilterString(final double lod) {
	String filterString = null;
	if (TS_FILTER_LEVEL != null) {
		for (int i = tranches.size() - 1; i >= 0; i--) {
			final TruthSensitivityTranche tranche = tranches.get(i);
			if (lod >= tranche.minVQSLod) {
				if (i == tranches.size() - 1) {
					filterString = VCFConstants.PASSES_FILTERS_v4;
				} else {
					filterString = tranche.name;
				}
				break;
			}
		}

		if (filterString == null) {
			filterString = tranches.get(0).name + "+";
		}
	} else {
		filterString = (lod < VQSLOD_CUTOFF ? LOW_VQSLOD_FILTER_NAME : VCFConstants.PASSES_FILTERS_v4);
	}

	return filterString;
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:25,代码来源:ApplyVQSR.java

示例7: writeOutRecalibrationTable

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
public void writeOutRecalibrationTable(final VariantContextWriter recalWriter,
		final SAMSequenceDictionary seqDictionary) {
	// we need to sort in coordinate order in order to produce a valid VCF
	Collections.sort(data, VariantDatum.getComparator(seqDictionary));

	// create dummy alleles to be used
	List<Allele> alleles = Arrays.asList(Allele.create("N", true), Allele.create("<VQSR>", false));

	for (final VariantDatum datum : data) {
		if (VRAC.useASannotations)
			alleles = Arrays.asList(datum.referenceAllele, datum.alternateAllele); 
		VariantContextBuilder builder = new VariantContextBuilder("VQSR", datum.loc.getContig(),
				datum.loc.getStart(), datum.loc.getStop(), alleles);
		builder.attribute(VCFConstants.END_KEY, datum.loc.getStop());
		builder.attribute(GaeaVCFConstants.VQS_LOD_KEY, String.format("%.4f", datum.lod));
		builder.attribute(GaeaVCFConstants.CULPRIT_KEY,
				(datum.worstAnnotation != -1 ? annotationKeys.get(datum.worstAnnotation) : "NULL"));

		if (datum.atTrainingSite)
			builder.attribute(GaeaVCFConstants.POSITIVE_LABEL_KEY, true);
		if (datum.atAntiTrainingSite)
			builder.attribute(GaeaVCFConstants.NEGATIVE_LABEL_KEY, true);

		recalWriter.add(builder.make());
	}
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:27,代码来源:VariantDataManager.java

示例8: getNumOfReads

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
public int getNumOfReads(final VariantContext vc) {
	// don't use the full depth because we don't calculate MQ for reference
	// blocks
	int numOfReads = 0;
	if (vc.hasAttribute(VCFConstants.DEPTH_KEY)) {
		numOfReads += Integer.parseInt(vc.getAttributeAsString(VCFConstants.DEPTH_KEY, "-1"));
		if (vc.hasGenotypes()) {
			for (Genotype gt : vc.getGenotypes()) {
				if (gt.isHomRef()) {
					// site-level DP contribution will come from MIN_DP for
					// gVCF-called reference variants or DP for BP
					// resolution
					if (gt.hasExtendedAttribute("MIN_DP"))
						numOfReads -= Integer.parseInt(gt.getExtendedAttribute("MIN_DP").toString());
					else if (gt.hasDP())
						numOfReads -= gt.getDP();
				}

			}
		}
		return numOfReads;
	}
	return -1;
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:25,代码来源:RMSAnnotation.java

示例9: getVAttributeValues

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
/**
 * Pulls out the appropriate values for the INFO field attribute
 *
 * @param attribute
 *            INFO field attribute
 * @return tokenized attribute values
 */
private static Object[] getVAttributeValues(final Object attribute) {

	if (attribute == null)
		throw new IllegalArgumentException("the attribute cannot be null");

	// break the original attributes into separate tokens
	final Object[] tokens;
	if (attribute.getClass().isArray())
		tokens = (Object[]) attribute;
	else if (List.class.isAssignableFrom(attribute.getClass()))
		tokens = ((List) attribute).toArray();
	else
		tokens = attribute.toString().split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR);

	return tokens;
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:24,代码来源:GaeaGvcfVariantContextUtils.java

示例10: updateChromosomeCountsInfo

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
/**
 * Update the variant context chromosome counts info fields (AC, AN, AF)
 *
 * @param calledAltAlleles
 *            number of called alternate alleles for all genotypes
 * @param calledAlleles
 *            number of called alleles for all genotypes
 * @param builder
 *            builder for variant context
 * @throws IllegalArgumentException
 *             if calledAltAlleles or builder are null
 */
public static void updateChromosomeCountsInfo(final Map<Allele, Integer> calledAltAlleles, final int calledAlleles,
		final VariantContextBuilder builder) {
	if (calledAltAlleles == null)
		throw new IllegalArgumentException("Called alternate alleles can not be null");
	if (builder == null)
		throw new IllegalArgumentException("Variant context builder can not be null");

	builder.attribute(VCFConstants.ALLELE_COUNT_KEY, calledAltAlleles.values().toArray())
			.attribute(VCFConstants.ALLELE_NUMBER_KEY, calledAlleles);
	// Add AF is there are called alleles
	if (calledAlleles != 0) {
		final Set<Double> alleleFrequency = new LinkedHashSet<Double>(calledAltAlleles.size());
		for (final Integer value : calledAltAlleles.values()) {
			alleleFrequency.add(value.doubleValue() / calledAlleles);
		}
		builder.attribute(VCFConstants.ALLELE_FREQUENCY_KEY, alleleFrequency.toArray());
	}
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:31,代码来源:GaeaGvcfVariantContextUtils.java

示例11: decodeLine

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
private VariantContext decodeLine(final String line, final boolean includeGenotypes) {
    // the same line reader is not used for parsing the header and parsing lines, if we see a #, we've seen a header line
    if (line.startsWith(VCFHeader.HEADER_INDICATOR)) return null;

    // our header cannot be null, we need the genotype sample names and counts
    if (header == null) throw new TribbleException("VCF Header cannot be null when decoding a record");

    if (parts == null)
        parts = new String[Math.min(header.getColumnCount(), NUM_STANDARD_FIELDS+1)];

    final int nParts = ParsingUtils.split(line, parts, VCFConstants.FIELD_SEPARATOR_CHAR, true);

    // if we have don't have a header, or we have a header with no genotyping data check that we
    // have eight columns.  Otherwise check that we have nine (normal columns + genotyping data)
    if (( (header == null || !header.hasGenotypingData()) && nParts != NUM_STANDARD_FIELDS) ||
            (header != null && header.hasGenotypingData() && nParts != (NUM_STANDARD_FIELDS + 1)) )
        throw new TribbleException("Line " + lineNo + ": there aren't enough columns for line " + line + " (we expected " + (header == null ? NUM_STANDARD_FIELDS : NUM_STANDARD_FIELDS + 1) +
                " tokens, and saw " + nParts + " )");

    return parseVCFLine(parts, includeGenotypes);
}
 
开发者ID:rkataine,项目名称:BasePlayer,代码行数:22,代码来源:OwnVCFCodec.java

示例12: parseInlineGenotypeFields

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
private static boolean parseInlineGenotypeFields(String field, VariantCall.Builder vcBuilder,
    ListValue.Builder lvBuilder, IntGenotypeFieldAccessors.Accessor accessor, Genotype g) {

  final int[] intValues = accessor.getValues(g);
  if (intValues == null || intValues.length == 0) {
    return false;
  }

  if (field.equals(VCFConstants.GENOTYPE_PL_KEY)) {
    // HTSJDK folds GL's into PL's. We only use PL's to store genotype likelihood.
    for (int i = 0; i < intValues.length; i++) {
      // We add 0.0 to remove the possiblity of getting -0.0.
      vcBuilder.addGenotypeLikelihood(-(double) intValues[i] / 10.0 + 0.0);
    }
    return false;
  }

  for (int i = 0; i < intValues.length; i++) {
    lvBuilder.addValues(Value.newBuilder().setNumberValue(intValues[i]));
  }
  return true;
}
 
开发者ID:verilylifesciences,项目名称:genomewarp,代码行数:23,代码来源:VcfToVariant.java

示例13: calculateAFs

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
private void calculateAFs(final Iterable<Genotype> genotypes) {
    final int[] truthAC = new int[CopyNumberTriStateAllele.ALL_ALLELES.size()];
    final int[] callsAC = new int[CopyNumberTriStateAllele.ALL_ALLELES.size()];
    for (final Genotype genotype : genotypes) {
        final List<Allele> alleles = genotype.getAlleles();
        if (alleles.size() > 1) {
            throw new GATKException("unexpected CNV genotype ploidy: " + alleles.size());
        } else if (!alleles.isEmpty() && alleles.get(0).isCalled()) {
            final int index = CopyNumberTriStateAllele.valueOf(alleles.get(0)).index();
            callsAC[index]++;
        }
        final String truthGT = String.valueOf(genotype.getExtendedAttribute(VariantEvaluationContext.TRUTH_GENOTYPE_KEY, VCFConstants.MISSING_VALUE_v4));
        final int truthAlleleIndex = truthGT.equals(VCFConstants.MISSING_VALUE_v4) ? -1 : Integer.parseInt(truthGT);
        if (truthAlleleIndex >= 0) {
            final List<Allele> contextAlleles = getAlleles();
            if (truthAlleleIndex >= contextAlleles.size()) {
                throw new GATKException("unexpected CNV truth genotype makes reference to a non-existent allele: " + truthGT);
            }
            truthAC[CopyNumberTriStateAllele.valueOf(contextAlleles.get(truthAlleleIndex)).index()]++;
        }
        genotype.getAllele(0);
    }
    this.truthAC = truthAC;
    this.callsAC = callsAC;
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:26,代码来源:VariantEvaluationContextBuilder.java

示例14: addFilterToGenotype

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
/** Create an updated genotype string when trying to add a filter value.
 *
 * @param existingFilterValue filter string (presumably) from a genotype
 * @param newFilterToAdd new filter string to append.  Cannot be {@code null}.
 * @return Properly formatted genotype filter string
 */
public static String addFilterToGenotype(final String existingFilterValue, final String newFilterToAdd) {

    Utils.nonNull(newFilterToAdd);

    if ((existingFilterValue == null) || (existingFilterValue.trim().length() == 0)
            || (existingFilterValue.equals(VCFConstants.UNFILTERED))
            || (existingFilterValue.equals(VCFConstants.PASSES_FILTERS_v4))) {
        return newFilterToAdd;
    } else if (existingFilterValue.length() > 0) {
        return existingFilterValue + VCFConstants.FILTER_CODE_SEPARATOR + newFilterToAdd;
    } else {
        final String appendedFilterString = existingFilterValue + VCFConstants.FILTER_CODE_SEPARATOR + newFilterToAdd;
        logger.warn("Existing genotype filter could be incorrect: " + existingFilterValue + " ... Proceeding with " + appendedFilterString + " ...");
        return appendedFilterString;
    }
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:23,代码来源:OrientationBiasUtils.java

示例15: mergeAttributes

import htsjdk.variant.vcf.VCFConstants; //导入依赖的package包/类
private static Map<String, Object> mergeAttributes(int depth, Map<String, List<Comparable>> annotationMap) {
    final Map<String, Object> attributes = new LinkedHashMap<>();

    // when combining annotations use the median value from all input vcs which had annotations provided
    annotationMap.entrySet().stream()
            .filter(p -> !p.getValue().isEmpty())
            .forEachOrdered(p -> attributes.put(p.getKey(), combineAnnotationValues(p.getValue()))
    );

    if ( depth > 0 ) {
        attributes.put(VCFConstants.DEPTH_KEY, String.valueOf(depth));
    }

    // remove stale AC and AF based attributes
    removeStaleAttributesAfterMerge(attributes);
    return attributes;
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:18,代码来源:ReferenceConfidenceVariantContextMerger.java


注:本文中的htsjdk.variant.vcf.VCFConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。