Complete the move over to VariantContext so that we can remove dependence on Variation (in the VCF code)

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3190 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2010-04-16 19:41:42 +00:00
parent 821e8b1c5f
commit 8c32bb8f0a
2 changed files with 20 additions and 25 deletions

View File

@ -4,11 +4,7 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.refdata.RodVCF;
import org.broadinstitute.sting.gatk.refdata.VariantContextAdaptors;
import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature;
import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.gatk.walkers.RodWalker;
import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.utils.cmdLine.Argument; import org.broadinstitute.sting.utils.cmdLine.Argument;
import java.util.HashMap; import java.util.HashMap;
@ -108,26 +104,19 @@ public class AnalyzeAnnotationsWalker extends RodWalker<Integer, Integer> {
// First find out if this variant is in the truth sets // First find out if this variant is in the truth sets
boolean isInTruthSet = false; boolean isInTruthSet = false;
boolean isTrueVariant = false; boolean isTrueVariant = false;
for( final GATKFeature feature : tracker.getAllRods() ) { for ( VariantContext vc : tracker.getAllVariantContexts() ) {
Object rod = feature.getUnderlyingObject(); if( vc.getName().toUpperCase().startsWith("TRUTH") ) {
if( rod != null && feature.getName().toUpperCase().startsWith("TRUTH") ) {
isInTruthSet = true; isInTruthSet = true;
VariantContext variantContext = VariantContextAdaptors.toVariantContext(feature.getName(),rod); if (vc.isVariant())
// First check that the conversion to VC worked correctly; next see if the truth sets say this site is variant or reference
if (variantContext == null)
throw new StingException("Truth ROD is of type that can't be converted to a VariantContext ( type = " + feature.getName() + ")");
else if (variantContext.isSNP())
isTrueVariant = true; isTrueVariant = true;
} }
} }
// Add each annotation in this VCF Record to the dataManager // Add each annotation in this VCF Record to the dataManager
for( final GATKFeature feature : tracker.getAllRods() ) { for ( VariantContext vc : tracker.getAllVariantContexts() ) {
Object rod = feature.getUnderlyingObject(); if( !vc.getName().toUpperCase().startsWith("TRUTH") ) {
if( rod != null && rod instanceof RodVCF && !feature.getName().toUpperCase().startsWith("TRUTH") ) { if( vc.isVariant() ) {
final RodVCF variant = (RodVCF) rod; dataManager.addAnnotations( vc, ref.getBase(), SAMPLE_NAME, isInTruthSet, isTrueVariant );
if( variant.isSNP() ) {
dataManager.addAnnotations( variant, SAMPLE_NAME, isInTruthSet, isTrueVariant );
} }
} }
} }

View File

@ -1,8 +1,10 @@
package org.broadinstitute.sting.playground.gatk.walkers.variantoptimizer; package org.broadinstitute.sting.playground.gatk.walkers.variantoptimizer;
import org.broadinstitute.sting.gatk.refdata.RodVCF; import org.broadinstitute.sting.gatk.refdata.VariantContextAdaptors;
import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContext;
import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.BaseUtils;
import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.utils.genotype.vcf.VCFRecord;
import java.util.*; import java.util.*;
import java.io.IOException; import java.io.IOException;
@ -52,14 +54,16 @@ public class AnnotationDataManager {
INDICATE_MEAN_NUM_VARS = _INDICATE_MEAN_NUM_VARS; INDICATE_MEAN_NUM_VARS = _INDICATE_MEAN_NUM_VARS;
} }
public void addAnnotations( final RodVCF variant, final String sampleName, final boolean isInTruthSet, final boolean isTrueVariant ) { public void addAnnotations( final VariantContext vc, final char ref, final String sampleName, final boolean isInTruthSet, final boolean isTrueVariant ) {
if( sampleName != null ) { // Only process variants that are found in the sample with this sampleName if( sampleName != null ) { // Only process variants that are found in the sample with this sampleName
if( variant.getGenotype(sampleName).isNoCall() ) { // This variant isn't found in this sample so break out if( vc.getGenotype(sampleName).isNoCall() ) { // This variant isn't found in this sample so break out
return; return;
} }
} // else, process all samples } // else, process all samples
VCFRecord variant = VariantContextAdaptors.toVCF(vc, ref);
// Loop over each annotation in the vcf record // Loop over each annotation in the vcf record
final Map<String,String> infoField = variant.getInfoValues(); final Map<String,String> infoField = variant.getInfoValues();
infoField.put("QUAL", ((Double)variant.getQual()).toString() ); // add QUAL field to annotations infoField.put("QUAL", ((Double)variant.getQual()).toString() ); // add QUAL field to annotations
@ -87,13 +91,15 @@ public class AnnotationDataManager {
final boolean isNovelVariant = variant.getID().equals("."); final boolean isNovelVariant = variant.getID().equals(".");
// Decide if the variant is a transition or transversion // Decide if the variant is a transition or transversion
if( BaseUtils.isTransition( (byte)variant.getReferenceForSNP(), (byte)variant.getAlternativeBaseForSNP()) ) { if ( vc.isSNP() ) {
if( BaseUtils.isTransition( vc.getReference().getBases()[0], vc.getAlternateAllele(0).getBases()[0]) ) {
datum.incrementTi( isNovelVariant, isInTruthSet, isTrueVariant ); datum.incrementTi( isNovelVariant, isInTruthSet, isTrueVariant );
} else { } else {
datum.incrementTv( isNovelVariant, isInTruthSet, isTrueVariant ); datum.incrementTv( isNovelVariant, isInTruthSet, isTrueVariant );
} }
} }
} }
}
public void plotCumulativeTables( final String PATH_TO_RSCRIPT, final String PATH_TO_RESOURCES, final String OUTPUT_PREFIX, public void plotCumulativeTables( final String PATH_TO_RSCRIPT, final String PATH_TO_RESOURCES, final String OUTPUT_PREFIX,
final int MIN_VARIANTS_PER_BIN, final int MAX_VARIANTS_PER_BIN ) { final int MIN_VARIANTS_PER_BIN, final int MAX_VARIANTS_PER_BIN ) {