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.variantcontext.VariantContext;
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.utils.StingException;
import org.broadinstitute.sting.utils.cmdLine.Argument;
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
boolean isInTruthSet = false;
boolean isTrueVariant = false;
for( final GATKFeature feature : tracker.getAllRods() ) {
Object rod = feature.getUnderlyingObject();
if( rod != null && feature.getName().toUpperCase().startsWith("TRUTH") ) {
for ( VariantContext vc : tracker.getAllVariantContexts() ) {
if( vc.getName().toUpperCase().startsWith("TRUTH") ) {
isInTruthSet = true;
VariantContext variantContext = VariantContextAdaptors.toVariantContext(feature.getName(),rod);
// 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())
if (vc.isVariant())
isTrueVariant = true;
}
}
// Add each annotation in this VCF Record to the dataManager
for( final GATKFeature feature : tracker.getAllRods() ) {
Object rod = feature.getUnderlyingObject();
if( rod != null && rod instanceof RodVCF && !feature.getName().toUpperCase().startsWith("TRUTH") ) {
final RodVCF variant = (RodVCF) rod;
if( variant.isSNP() ) {
dataManager.addAnnotations( variant, SAMPLE_NAME, isInTruthSet, isTrueVariant );
for ( VariantContext vc : tracker.getAllVariantContexts() ) {
if( !vc.getName().toUpperCase().startsWith("TRUTH") ) {
if( vc.isVariant() ) {
dataManager.addAnnotations( vc, ref.getBase(), SAMPLE_NAME, isInTruthSet, isTrueVariant );
}
}
}

View File

@ -1,8 +1,10 @@
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.StingException;
import org.broadinstitute.sting.utils.genotype.vcf.VCFRecord;
import java.util.*;
import java.io.IOException;
@ -52,14 +54,16 @@ public class AnnotationDataManager {
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( 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;
}
} // else, process all samples
VCFRecord variant = VariantContextAdaptors.toVCF(vc, ref);
// Loop over each annotation in the vcf record
final Map<String,String> infoField = variant.getInfoValues();
infoField.put("QUAL", ((Double)variant.getQual()).toString() ); // add QUAL field to annotations
@ -87,10 +91,12 @@ public class AnnotationDataManager {
final boolean isNovelVariant = variant.getID().equals(".");
// Decide if the variant is a transition or transversion
if( BaseUtils.isTransition( (byte)variant.getReferenceForSNP(), (byte)variant.getAlternativeBaseForSNP()) ) {
datum.incrementTi( isNovelVariant, isInTruthSet, isTrueVariant );
} else {
datum.incrementTv( isNovelVariant, isInTruthSet, isTrueVariant );
if ( vc.isSNP() ) {
if( BaseUtils.isTransition( vc.getReference().getBases()[0], vc.getAlternateAllele(0).getBases()[0]) ) {
datum.incrementTi( isNovelVariant, isInTruthSet, isTrueVariant );
} else {
datum.incrementTv( isNovelVariant, isInTruthSet, isTrueVariant );
}
}
}
}