private void convertAndWrite(VariantContext vc, ReferenceContext ref) {
final Interval fromInterval = new Interval(vc.getChr(), vc.getStart(), vc.getStart(), false, String.format("%s:%d", vc.getChr(), vc.getStart()));
final int length = vc.getEnd() - vc.getStart();
final Interval toInterval = liftOver.liftOver(fromInterval);
VariantContext originalVC = vc;
if ( toInterval != null ) {
// check whether the strand flips, and if so reverse complement everything
if ( fromInterval.isPositiveStrand() != toInterval.isPositiveStrand() && vc.isPointEvent() ) {
vc = GATKVariantContextUtils.reverseComplement(vc);
}
vc = new VariantContextBuilder(vc).loc(toInterval.getSequence(), toInterval.getStart(), toInterval.getStart() + length).make();
if ( RECORD_ORIGINAL_LOCATION ) {
vc = new VariantContextBuilder(vc)
.attribute("OriginalChr", fromInterval.getSequence())
.attribute("OriginalStart", fromInterval.getStart()).make();
}
if ( originalVC.isSNP() && originalVC.isBiallelic() && GATKVariantContextUtils.getSNPSubstitutionType(originalVC) != GATKVariantContextUtils.getSNPSubstitutionType(vc) ) {
logger.warn(String.format("VCF at %s / %d => %s / %d is switching substitution type %s/%s to %s/%s",
originalVC.getChr(), originalVC.getStart(), vc.getChr(), vc.getStart(),
originalVC.getReference(), originalVC.getAlternateAllele(0), vc.getReference(), vc.getAlternateAllele(0)));
}
writer.add(vc);
successfulIntervals++;
} else {