private void fieldIsMissingFromHeaderError(final VariantContext vc, final String id, final String field) { if (!allowMissingFieldsInHeader) throw new IllegalStateException("Key " + id + " found in VariantContext field " + field + " at " + vc.getContig() + ":" + vc.getStart() + " but this key isn't defined in the VCFHeader. We require all VCFs to have" + " complete VCF headers by default."); }
@Override public int compare(final VariantContext firstVariantContext, final VariantContext secondVariantContext) { // Will throw NullPointerException -- happily -- if either of the chromosomes/contigs aren't // present. This error checking should already have been done in the constructor but it's left // in as defence anyway. final int contigCompare = this.contigIndexLookup.get(firstVariantContext.getContig()) - this.contigIndexLookup.get(secondVariantContext.getContig()); return contigCompare != 0 ? contigCompare : firstVariantContext.getStart() - secondVariantContext.getStart(); }
protected void noteCurrentRecord(VariantContext vc) { // did the user break the contract by giving a record too late? if (mostUpstreamWritableLoc != null && vc.getStart() < mostUpstreamWritableLoc) // went too far back, since may have already written anything that is <= mostUpstreamWritableLoc throw new IllegalArgumentException("Permitted to write any record upstream of position " + mostUpstreamWritableLoc + ", but a record at " + vc.getContig() + ":" + vc.getStart() + " was just added."); }
private void validateAttributeIsExpectedSize(final String attributeKey, final int numAlternateAlleles ) { final List<Object> actualValues = getAttributeAsList(attributeKey); if (!actualValues.isEmpty()) { // always have at least one actual value final int expectedValuesSize = numAlternateAlleles > 0 ? numAlternateAlleles : 1; if (actualValues.size() != expectedValuesSize) { throw new TribbleException.InternalCodecException(String.format("the %s tag has the incorrect number of records at position %s:%d, %d vs. %d", attributeKey, getContig(), getStart(), actualValues.size(), expectedValuesSize)); } } }
/** * Throws a meaningful error message when a field (INFO or FORMAT) is found when writing out a file * but there's no header line for it. * * @param vc * @param field * @param fieldType */ private void errorUnexpectedFieldToWrite(final VariantContext vc, final String field, final String fieldType) { throw new IllegalStateException("Found field " + field + " in the " + fieldType + " fields of VariantContext at " + vc.getContig() + ":" + vc.getStart() + " from " + vc.getSource() + " but this hasn't been defined in the VCFHeader"); }
static private String anchorFromVc(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); if (genotype == null || !genotype.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { return SYNTHETIC_PHASESET_PREFIX + "_" + vc.getContig() + "_" + vc.getStart(); } else { return PHASESET_PREFIX + "_" + vc.getContig() + "_" + genotype.getExtendedAttribute(VCFConstants.PHASE_SET_KEY); } }
VariantContextSet(final SAMSequenceDictionary dict) { super((lhs, rhs) -> { final int lhsContig = dict.getSequenceIndex(lhs.getContig()); final int rhsContig = dict.getSequenceIndex(rhs.getContig()); final int retval = lhsContig - rhsContig; if (retval != 0) return retval; return lhs.getStart() - rhs.getStart(); }); } }
static private String anchorFromVc(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); if (genotype == null || !genotype.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { return SYNTHETIC_PHASESET_PREFIX + "_" + vc.getContig() + "_" + vc.getStart(); } else { return PHASESET_PREFIX + "_" + vc.getContig() + "_" + genotype.getExtendedAttribute(VCFConstants.PHASE_SET_KEY); } }
public void validateRSIDs(Set<String> rsIDs) { if ( rsIDs != null && hasID() ) { for ( String id : getID().split(VCFConstants.ID_FIELD_SEPARATOR) ) { if ( id.startsWith("rs") && !rsIDs.contains(id) ) throw new TribbleException.InternalCodecException(String.format("the rsID %s for the record at position %s:%d is not in dbSNP", id, getContig(), getStart())); } } }
private static List<String> getOrderedContigList(final VariantContext... variantContexts) { final LinkedHashSet<String> contigs = new LinkedHashSet<String>(); for (final VariantContext context : variantContexts) { contigs.add(context.getContig()); } return new ArrayList<String>(contigs); }
@Override public boolean apply(final VariantContext vc) { final boolean include = !intervalsOfInterestDetector.getOverlaps(new Interval(vc.getContig(), vc.getStart(), vc.getEnd())).isEmpty(); if (!include) LOG.debug("Filtering variant at ", vc.getContig(), ":", vc.getStart(), "-", vc.getEnd()); return include; } }
/** Returns true if the variant and interval overlap. */ private boolean overlapsInterval(final VariantContext ctx, final Interval interval) { if (!ctx.getContig().equals(interval.getContig())) return false; else if (CoordMath.overlaps(ctx.getStart(), ctx.getEnd(), interval.getStart(), interval.getEnd())) return true; else return false; }
private void rejectVariant(final VariantContext ctx, final String reason) { rejects.add(new VariantContextBuilder(ctx).filter(reason).make()); failedLiftover++; trackLiftedVariantContig(rejectsByContig, ctx.getContig()); }
/** * Copy constructor * * @param other the VariantContext to copy */ protected VariantContext(VariantContext other) { this(other.getSource(), other.getID(), other.getContig(), other.getStart(), other.getEnd(), other.getAlleles(), other.getGenotypes(), other.getLog10PError(), other.getFiltersMaybeNull(), other.getAttributes(), other.fullyDecoded, NO_VALIDATION); }
@Test(dataProvider = "indelFlipDataWithOriginalAllele") public void testFlipIndelWithOriginalAlleles(final VariantContext source, final ReferenceSequence reference, final VariantContext result) { final LiftOver liftOver = new LiftOver(CHAIN_FILE); final Interval originalLocus = new Interval(source.getContig(), source.getStart(), source.getEnd()); final Interval target = liftOver.liftOver(originalLocus); if (target != null && !target.isNegativeStrand()) { throw new RuntimeException("not reversed"); } final VariantContext flipped = LiftoverUtils.liftVariant(source, target, reference, false, true); VcfTestUtils.assertEquals(flipped, result); }
@Test(dataProvider = "indelFlipData") public void testFlipIndel(final VariantContext source, final ReferenceSequence reference, final VariantContext result) { final LiftOver liftOver = new LiftOver(CHAIN_FILE); final Interval originalLocus = new Interval(source.getContig(), source.getStart(), source.getEnd()); final Interval target = liftOver.liftOver(originalLocus); if (target != null && !target.isNegativeStrand()) { throw new RuntimeException("not reversed"); } final VariantContext flipped = LiftoverUtils.liftVariant(source, target, reference, false, false); VcfTestUtils.assertEquals(flipped, result); }
@Test(dataProvider = "snpWithChangedRef") public void snpWithChangedRef(final VariantContext source, final ReferenceSequence reference, final VariantContext result) { final LiftOver liftOver = new LiftOver(POSITIVE_CHAIN_FILE); final Interval originalLocus = new Interval(source.getContig(), source.getStart(), source.getEnd()); final Interval target = liftOver.liftOver(originalLocus); final VariantContext flipped = LiftoverUtils.swapRefAlt(source, LiftoverUtils.DEFAULT_TAGS_TO_REVERSE, LiftoverUtils.DEFAULT_TAGS_TO_DROP); VcfTestUtils.assertEquals(flipped, result); }
@Test(dataProvider = "indelNoFlipData") public void testLiftOverSimpleIndels(final LiftOver liftOver, final ReferenceSequence reference, final VariantContext source, final VariantContext result) { final Interval target = liftOver.liftOver(new Interval(source.getContig(), source.getStart(), source.getEnd()), .95); VariantContextBuilder vcb = LiftoverUtils.liftSimpleVariantContext(source, target); VcfTestUtils.assertEquals(vcb == null ? null : vcb.make(), result); }