Cut DeNovoSNPWalker over to the new Variation system, some renaming of methods on the Variation interface, and some corrections on the interface.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1724 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
aaron 2009-09-25 04:35:52 +00:00
parent 392152f149
commit 7ffc1d97ef
16 changed files with 112 additions and 98 deletions

View File

@ -28,7 +28,7 @@ public class PooledEMSNPROD extends TabularROD implements SNPCallFromGenotypes,
* @return
*/
@Override
public String getAlternateBase() {
public String getAlternateBases() {
return getAltBasesFWD();
}
@ -38,7 +38,7 @@ public class PooledEMSNPROD extends TabularROD implements SNPCallFromGenotypes,
* @return
*/
@Override
public List<String> getAlternateBases() {
public List<String> getAlternateBaseList() {
List<String> str = new ArrayList<String>();
str.add(this.getAltBasesFWD());
return str;

View File

@ -161,9 +161,9 @@ public class RodGLF implements VariationRod, Iterator<RodGLF> {
@Override
public char getAlternativeBaseForSNP() {
if (!this.isSNP()) throw new IllegalStateException("we're not a SNP");
if (getAlternateBase().charAt(0) == this.getReference().charAt(0))
return getAlternateBase().charAt(1);
return getAlternateBase().charAt(0);
if (getAlternateBases().charAt(0) == this.getReference().charAt(0))
return getAlternateBases().charAt(1);
return getAlternateBases().charAt(0);
}
@ -175,9 +175,9 @@ public class RodGLF implements VariationRod, Iterator<RodGLF> {
@Override
public char getReferenceForSNP() {
if (!this.isSNP()) throw new IllegalStateException("we're not a SNP");
if (getAlternateBase().charAt(0) == this.getReference().charAt(0))
return getAlternateBase().charAt(0);
return getAlternateBase().charAt(1);
if (getAlternateBases().charAt(0) == this.getReference().charAt(0))
return getAlternateBases().charAt(0);
return getAlternateBases().charAt(1);
}
@ -259,7 +259,7 @@ public class RodGLF implements VariationRod, Iterator<RodGLF> {
* @return a string, of ploidy
*/
@Override
public String getAlternateBase() {
public String getAlternateBases() {
return this.getBestGenotype(0).toString();
}
@ -269,9 +269,9 @@ public class RodGLF implements VariationRod, Iterator<RodGLF> {
* @return
*/
@Override
public List<String> getAlternateBases() {
public List<String> getAlternateBaseList() {
List<String> list = new ArrayList<String>();
list.add(this.getAlternateBase());
list.add(this.getAlternateBases());
return list;
}

View File

@ -193,7 +193,7 @@ public class RodGeliText extends BasicReferenceOrderedDatum implements Variation
* @return a string, of ploidy
*/
@Override
public String getAlternateBase() {
public String getAlternateBases() {
return this.bestGenotype;
}
@ -203,9 +203,9 @@ public class RodGeliText extends BasicReferenceOrderedDatum implements Variation
* @return
*/
@Override
public List<String> getAlternateBases() {
public List<String> getAlternateBaseList() {
List<String> list = new ArrayList<String>();
list.add(this.getAlternateBase());
list.add(this.getAlternateBases());
return list;
}

View File

@ -187,7 +187,7 @@ public class RodGenotypeChipAsGFF extends BasicReferenceOrderedDatum implements
* @return
*/
@Override
public String getAlternateBase() {
public String getAlternateBases() {
return this.feature;
}
@ -197,9 +197,9 @@ public class RodGenotypeChipAsGFF extends BasicReferenceOrderedDatum implements
* @return
*/
@Override
public List<String> getAlternateBases() {
public List<String> getAlternateBaseList() {
List<String> list = new ArrayList<String>();
list.add(this.getAlternateBase());
list.add(this.getAlternateBases());
return list;
}

View File

@ -171,7 +171,7 @@ public class RodVCF extends BasicReferenceOrderedDatum implements VariationRod,
/** are we bi-allelic? */
@Override
public boolean isBiallelic() {
return (this.getAlternateBases().size() == 1);
return (this.getAlternateBaseList().size() == 1);
}
/**
@ -201,8 +201,8 @@ public class RodVCF extends BasicReferenceOrderedDatum implements VariationRod,
* @return
*/
@Override
public String getAlternateBase() {
if (!this.isBiallelic()) throw new UnsupportedOperationException("We're not biallelic, so please call getAlternateBases instead");
public String getAlternateBases() {
if (!this.isBiallelic()) throw new UnsupportedOperationException("We're not biallelic, so please call getAlternateBaseList instead");
return this.mCurrentRecord.getAlternateAlleles().get(0);
}
@ -212,7 +212,7 @@ public class RodVCF extends BasicReferenceOrderedDatum implements VariationRod,
* @return
*/
@Override
public List<String> getAlternateBases() {
public List<String> getAlternateBaseList() {
return this.mCurrentRecord.getAlternateAlleles();
}

View File

@ -73,7 +73,7 @@ public class SimpleIndelROD extends TabularROD implements Genotype, AllelicVaria
* @return
*/
@Override
public String getAlternateBase() {
public String getAlternateBases() {
return "";
}
@ -83,7 +83,7 @@ public class SimpleIndelROD extends TabularROD implements Genotype, AllelicVaria
* @return
*/
@Override
public List<String> getAlternateBases() {
public List<String> getAlternateBaseList() {
return Arrays.asList(new String[]{""});
}
@ -171,4 +171,4 @@ public class SimpleIndelROD extends TabularROD implements Genotype, AllelicVaria
}
return KGENOMES_FORMAT;
}
}
}

View File

@ -174,7 +174,7 @@ public class rodDbSNP extends BasicReferenceOrderedDatum implements VariationRod
* @return a string, of ploidy
*/
@Override
public String getAlternateBase() {
public String getAlternateBases() {
return getAllelesFWDString();
}
@ -184,9 +184,9 @@ public class rodDbSNP extends BasicReferenceOrderedDatum implements VariationRod
* @return
*/
@Override
public List<String> getAlternateBases() {
public List<String> getAlternateBaseList() {
List<String> list = new ArrayList<String>();
list.add(this.getAlternateBase());
list.add(this.getAlternateBases());
return list;
}
@ -204,9 +204,9 @@ public class rodDbSNP extends BasicReferenceOrderedDatum implements VariationRod
public char getAlternativeBaseForSNP() {
return getAltSnpFWD(); /*
if (!this.isSNP()) throw new IllegalStateException("we're not a SNP");
if (getAlternateBase().charAt(0) == this.getReference())
return getAlternateBase().charAt(1);
return getAlternateBase().charAt(0); */
if (getAlternateBases().charAt(0) == this.getReference())
return getAlternateBases().charAt(1);
return getAlternateBases().charAt(0); */
}
/**

View File

@ -1,7 +1,10 @@
package org.broadinstitute.sting.gatk.walkers.filters;
import org.broadinstitute.sting.gatk.contexts.VariantContext;
import org.broadinstitute.sting.gatk.refdata.*;
import org.broadinstitute.sting.gatk.refdata.CleanedOutSNPROD;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.refdata.rodDbSNP;
import org.broadinstitute.sting.utils.genotype.Variation;
import java.util.HashMap;
@ -23,7 +26,7 @@ public class VECIndelArtifact implements VariantExclusionCriterion {
return;
}
AllelicVariant indelCall = (AllelicVariant)tracker.lookup("indels", null);
Variation indelCall = (Variation)tracker.lookup("indels", null);
if ( indelCall != null ) {
exclude = true;
source = "IndelCall";

View File

@ -1,11 +1,14 @@
package org.broadinstitute.sting.gatk.walkers.indels;
import org.broadinstitute.sting.gatk.refdata.*;
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.utils.*;
import org.broadinstitute.sting.gatk.refdata.AllelicVariant;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.*;
import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.GenomeLocParser;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.genotype.Variation;
@WalkerName("SNPClusters")
@Requires(value={DataSource.REFERENCE},referenceMetaData={@RMD(name="snps",type=AllelicVariant.class)})
@ -19,7 +22,7 @@ public class SNPClusterWalker extends RefWalker<GenomeLoc, GenomeLoc> {
}
public GenomeLoc map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
AllelicVariant snp = (AllelicVariant)tracker.lookup("snps", null);
Variation snp = (Variation)tracker.lookup("snps", null);
return (snp != null && snp.isSNP()) ? context.getLocation() : null;
}

View File

@ -1,13 +1,13 @@
package org.broadinstitute.sting.playground.gatk.walkers;
import org.broadinstitute.sting.gatk.walkers.*;
import org.broadinstitute.sting.gatk.refdata.*;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.utils.GenotypeUtils;
import java.util.List;
import java.util.Collection;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.refdata.VariationRod;
import org.broadinstitute.sting.gatk.walkers.*;
import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.utils.genotype.VariantBackedByGenotype;
import org.broadinstitute.sting.utils.genotype.Variation;
/**
* Created by IntelliJ IDEA.
@ -17,38 +17,42 @@ import java.util.Collection;
* To change this template use File | Settings | File Templates.
*/
@By(DataSource.REFERENCE)
@Requires(value={DataSource.REFERENCE},referenceMetaData={@RMD(name="child",type= AllelicVariant.class), @RMD(name="parent1",type= AllelicVariant.class), @RMD(name="parent2",type= AllelicVariant.class)})
@Requires(value={DataSource.REFERENCE},referenceMetaData={@RMD(name="child",type= VariationRod.class), @RMD(name="parent1",type= VariationRod.class), @RMD(name="parent2",type= VariationRod.class)})
//@Allows(value={DataSource.REFERENCE},referenceMetaData = {@RMD(name="eval",type=AllelicVariant.class), @RMD(name="dbsnp",type=AllelicVariant.class),@RMD(name="hapmap-chip",type=AllelicVariant.class), @RMD(name="interval",type=IntervalRod.class)})
//@Allows(value={DataSource.REFERENCE},referenceMetaData = {@RMD(name="dbsnp",type=AllelicVariant.class)})
public class DeNovoSNPWalker extends RefWalker<String, Integer>{
public String map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
AllelicVariant child = (AllelicVariant)tracker.lookup("child", null);
AllelicVariant parent1 = (AllelicVariant)tracker.lookup("parent1", null);
AllelicVariant parent2 = (AllelicVariant)tracker.lookup("parent2", null);
AllelicVariant dbsnp = (AllelicVariant)tracker.lookup("dbSNP", null);
Variation child = (Variation)tracker.lookup("child", null);
Variation parent1 = (Variation)tracker.lookup("parent1", null);
Variation parent2 = (Variation)tracker.lookup("parent2", null);
Variation dbsnp = (Variation)tracker.lookup("dbSNP", null);
if (child != null && parent1 != null && parent2 != null) {
if (!(parent1 instanceof VariantBackedByGenotype) || !(parent2 instanceof VariantBackedByGenotype))
throw new StingException("Both parents ROD tracks must be backed by genotype data. Ensure that your parent rod(s) contain genotyping information");
if (child.isSNP() &&
child.getVariationConfidence() > 5 && // BTR > 5
child.getNegLog10PError() > 5 && // BTR > 5
parent1.isReference() &&
parent1.getConsensusConfidence() > 5 &&
((VariantBackedByGenotype)parent1).getCalledGenotype().getNegLog10PError() > 5 &&
parent2.isReference() &&
parent2.getConsensusConfidence() > 5
((VariantBackedByGenotype)parent2).getCalledGenotype().getNegLog10PError() > 5
) {
double sumConfidences = 0.5 * (0.5 * child.getVariationConfidence() + Math.min(parent1.getConsensusConfidence(), parent2.getConsensusConfidence()));
double sumConfidences = 0.5 * (0.5 * child.getNegLog10PError() +
Math.min(((VariantBackedByGenotype)parent1).getCalledGenotype().getNegLog10PError(),
((VariantBackedByGenotype)parent2).getCalledGenotype().getNegLog10PError()));
out.format("%s\t", child.getLocation().getContig());
out.format("%s\t", child.getLocation().getStart());
out.format("%.4f\t", sumConfidences);
out.format("%.4f\t", child.getVariationConfidence());
out.format("%.4f\t", parent1.getConsensusConfidence());
out.format("%.4f\t", parent2.getConsensusConfidence());
out.format("%.4f\t", child.getNegLog10PError());
out.format("%.4f\t", ((VariantBackedByGenotype)parent1).getCalledGenotype().getNegLog10PError());
out.format("%.4f\t", ((VariantBackedByGenotype)parent2).getCalledGenotype().getNegLog10PError());
out.format("%s\t", dbsnp != null);
out.format ("%s\t", child.toString());
out.format ("%s\t", parent1.toString());
out.format ("%s", parent2.toSimpleString());
out.format ("%s", parent2.toString());
if (dbsnp != null)
out.format ("\tDBSNP\t:%s", dbsnp.toString());
out.println();

View File

@ -58,18 +58,18 @@ public class GenotypeConcordance extends BasicVariantAnalysis implements Genotyp
int truthIndex, callIndex;
if (chip == null)
truthIndex = UNKNOWN;
else if (chip.getAlternateBase().equals(g.toString()))
else if (chip.getAlternateBases().equals(g.toString()))
truthIndex = REF;
else if (chip.getAlternateBase().charAt(0) != chip.getAlternateBase().charAt(1))
else if (chip.getAlternateBases().charAt(0) != chip.getAlternateBases().charAt(1))
truthIndex = VAR_HET;
else
truthIndex = VAR_HOM;
if (eval == null)
callIndex = NO_CALL;
else if (eval.getAlternateBase().equals(g.toString()))
else if (eval.getAlternateBases().equals(g.toString()))
callIndex = REF;
else if (eval.getAlternateBase().charAt(0) != eval.getAlternateBase().charAt(1))
else if (eval.getAlternateBases().charAt(0) != eval.getAlternateBases().charAt(1))
callIndex = VAR_HET;
else
callIndex = VAR_HOM;

View File

@ -38,10 +38,10 @@ public class IndelMetricsAnalysis extends BasicVariantAnalysis implements Genoty
else
throw new RuntimeException("Variation is indel, but isn't insertion or deletion!");
if ( eval.getAlternateBase().length() < 100 ) {
sizes[eval.isDeletion() ? 0 : 1][eval.getAlternateBase().length()]++;
if ( eval.getAlternateBase().length() > maxSize )
maxSize = eval.getAlternateBase().length();
if ( eval.getAlternateBases().length() < 100 ) {
sizes[eval.isDeletion() ? 0 : 1][eval.getAlternateBases().length()]++;
if ( eval.getAlternateBases().length() > maxSize )
maxSize = eval.getAlternateBases().length();
}
}

View File

@ -183,7 +183,7 @@ class PooledConcordanceTable {
public boolean pooledCallIsRef(Variation eval, char ref) {
// code broken out for easy alteration when we start using pool-specific variations
return eval.getAlternateBase().equalsIgnoreCase((Utils.dupString(ref,2)));
return eval.getAlternateBases().equalsIgnoreCase((Utils.dupString(ref,2)));
}
public int calculateNumFrequencyIndeces(int poolSize) {
@ -207,7 +207,7 @@ class PooledConcordanceTable {
for ( Variation eval : evals ) {
if ( mismatchingCalls(firstEval, eval, ref) ) {
// todo -- make this not a StingException but go to the log
throw new StingException("Tri-Allelic Position "+eval.getAlternateBase()+"/"+firstEval.getAlternateBase() + " Ref: "+ ref + " not supported");
throw new StingException("Tri-Allelic Position "+eval.getAlternateBases()+"/"+firstEval.getAlternateBases() + " Ref: "+ ref + " not supported");
} else {
alternateFrequency += calledVariantFrequency(eval,ref);
}
@ -231,10 +231,10 @@ class PooledConcordanceTable {
public boolean mismatchingCalls(Variation eval, Variation chip, char ref) {
// eval and chip guaranteed to be non-null
char chipF = chip.getAlternateBase().charAt(0);
char chipS = chip.getAlternateBase().charAt(1);
char evalF = chip.getAlternateBase().charAt(0);
char evalS = chip.getAlternateBase().charAt(1);
char chipF = chip.getAlternateBases().charAt(0);
char chipS = chip.getAlternateBases().charAt(1);
char evalF = chip.getAlternateBases().charAt(0);
char evalS = chip.getAlternateBases().charAt(1);
boolean mismatch;
if (chipF == ref) {
if ( chipS == ref ) {
@ -259,7 +259,7 @@ class PooledConcordanceTable {
public double calledVariantFrequency( Variation var, char ref ) {
// code broken out for easy alteration when we start using pool-specific variations
String varStr = var.getAlternateBase();
String varStr = var.getAlternateBases();
double freq;
if ( varStr.charAt(0) != ref && varStr.charAt(1) != ref ) {
freq = (double) 2;

View File

@ -92,7 +92,7 @@ public class VariantDBCoverage extends BasicVariantAnalysis implements GenotypeA
if (eval != null) {
char alt = (eval.isSNP()) ? eval.getAlternativeBaseForSNP() : eval.getReference().charAt(0);
if (dbSNP != null && dbSNP.isSNP())
return !dbSNP.getAlternateBase().contains(String.valueOf(alt));
return !dbSNP.getAlternateBases().contains(String.valueOf(alt));
}
return false;
}
@ -125,7 +125,7 @@ public class VariantDBCoverage extends BasicVariantAnalysis implements GenotypeA
if (dbsnp.isSNP() && eval.isSNP() && discordantP(dbsnp, eval)) {
return String.format("Discordant [DBSNP %s] [EVAL %s]", dbsnp, eval);
} else if (dbsnp.isIndel() && eval.isSNP()) {
return String.format("SNP-at-indel DBSNP=%s %s", dbsnp.getAlternateBase(), eval);
return String.format("SNP-at-indel DBSNP=%s %s", dbsnp.getAlternateBases(), eval);
} else {
return null;
}

View File

@ -83,7 +83,7 @@ public class BasicVariation implements Variation {
}
@Override
public String getAlternateBase() {
public String getAlternateBases() {
return mBases;
}
@ -93,9 +93,9 @@ public class BasicVariation implements Variation {
* @return
*/
@Override
public List<String> getAlternateBases() {
public List<String> getAlternateBaseList() {
List<String> list = new ArrayList<String>();
list.add(this.getAlternateBase());
list.add(this.getAlternateBases());
return list;
}
@ -151,9 +151,9 @@ public class BasicVariation implements Variation {
if (!this.isSNP()) throw new IllegalStateException("we're not a SNP");
// we know that if we're a snp, the reference is a single base, so charAt(0) is safe
if (getAlternateBase().charAt(0) == this.getReference().charAt(0))
return getAlternateBase().charAt(1);
return getAlternateBase().charAt(0);
if (getAlternateBases().charAt(0) == this.getReference().charAt(0))
return getAlternateBases().charAt(1);
return getAlternateBases().charAt(0);
}
/**
@ -166,9 +166,9 @@ public class BasicVariation implements Variation {
if (!this.isSNP()) throw new IllegalStateException("we're not a SNP");
// we know that if we're a snp, the reference is a single base, so charAt(0) is safe
if (getAlternateBase().charAt(0) == this.getReference().charAt(0))
return getAlternateBase().charAt(0);
return getAlternateBase().charAt(1);
if (getAlternateBases().charAt(0) == this.getReference().charAt(0))
return getAlternateBases().charAt(0);
return getAlternateBases().charAt(1);
}

View File

@ -18,17 +18,21 @@ public interface Variation {
}
/**
* get the frequency of this variant
* get the frequency of this variant, if we're a variant. If we're reference this method
* should return 0.
*
* @return VariantFrequency with the stored frequency
* @return double with the stored frequency
*/
public double getNonRefAlleleFrequency();
/** @return the VARIANT_TYPE of the current variant */
/**
* A convenience method, for switching over the variation type
* @return the VARIANT_TYPE of the current variant
**/
public VARIANT_TYPE getType();
/**
* are we a SNP? If not we're a Indel/deletion
* are we a SNP? If not we're a Indel/deletion or the reference
*
* @return true if we're a SNP
*/
@ -42,12 +46,19 @@ public interface Variation {
public boolean isInsertion();
/**
* are we an insertion?
* are we an deletion?
*
* @return true if we are, false otherwise
*/
public boolean isDeletion();
/**
* are we a variant that represents the reference allele?
*
* @return false if we're a variant(indel, delete, SNP, etc), true if we're hom ref
*/
public boolean isReference();
/**
* get the location that this Variant represents
*
@ -68,33 +79,26 @@ public interface Variation {
/**
* get the -1 * (log 10 of the error value)
*
* @return the log based error estimate
* @return the postive number space log based error estimate
*/
public double getNegLog10PError();
/**
* are we truely a variant, given a reference
*
* @return false if we're a variant(indel, delete, SNP, etc), true if we're not
*/
public boolean isReference();
/**
* gets the alternate base. Use this method if we're biallelic
*
* @return
*/
public String getAlternateBase();
public String getAlternateBases();
/**
* gets the alternate bases. Use this method if teh allele count is greater then 2
* gets the alternate bases. Use this method if the allele count is greater then 2 (not biallelic)
*
* @return
*/
public List<String> getAlternateBases();
public List<String> getAlternateBaseList();
/**
* are we an insertion or a deletion? yes, then return true. No? Well, false then.
* are we an insertion or a deletion? yes, then return true. No? false.
*
* @return true if we're an insertion or deletion
*/