Removing experimental annotations
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2220 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
c180a76b05
commit
6a9e7bea05
|
|
@ -1,105 +0,0 @@
|
||||||
package org.broadinstitute.sting.gatk.walkers.annotator;
|
|
||||||
|
|
||||||
import org.broadinstitute.sting.utils.Pair;
|
|
||||||
import org.broadinstitute.sting.utils.pileup.ReadBackedPileup;
|
|
||||||
import org.broadinstitute.sting.utils.BaseUtils;
|
|
||||||
import org.broadinstitute.sting.utils.pileup.PileupElement;
|
|
||||||
import org.broadinstitute.sting.utils.genotype.Genotype;
|
|
||||||
import org.broadinstitute.sting.utils.genotype.Variation;
|
|
||||||
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by IntelliJ IDEA.
|
|
||||||
* User: chartl
|
|
||||||
* Date: Nov 21, 2009
|
|
||||||
* Time: 6:08:15 PM
|
|
||||||
* To change this template use File | Settings | File Templates.
|
|
||||||
*/
|
|
||||||
public class PrimaryBaseSecondaryBaseSymmetry implements VariantAnnotation{
|
|
||||||
//
|
|
||||||
// Where are the integration tests for this piece of code?
|
|
||||||
//
|
|
||||||
private static boolean USE_ZERO_MAPQ_READS = false;
|
|
||||||
private static String KEY_NAME = "1b2b_symmetry";
|
|
||||||
Logger logger = Logger.getLogger(PrimaryBaseSecondaryBaseSymmetry.class);
|
|
||||||
|
|
||||||
public boolean useZeroQualityReads() { return USE_ZERO_MAPQ_READS; }
|
|
||||||
|
|
||||||
public String annotate(ReferenceContext ref, ReadBackedPileup pileup, Variation variation, List<Genotype> genotypes) {
|
|
||||||
// todo -- this code doesn't work, should't be called
|
|
||||||
if ( true )
|
|
||||||
return null;
|
|
||||||
else {
|
|
||||||
if ( variation.isSNP() && variation.isBiallelic() ) {
|
|
||||||
byte snp = (byte)variation.getAlternativeBaseForSNP();
|
|
||||||
Pair<Integer,Double> refSecondBasePair = getProportionOfReferenceSecondBasesThatSupportAlt(ref, pileup, snp);
|
|
||||||
Pair<Integer,Double> nonrefPrimaryBasePair = getProportionOfPrimaryNonrefBasesThatSupportAlt(ref, pileup, (char)snp);
|
|
||||||
if ( refSecondBasePair == null || nonrefPrimaryBasePair == null ) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
//System.out.printf("refSecondBasePair = %s, nonrefPrimaryBasePair = %s%n", refSecondBasePair, nonrefPrimaryBasePair);
|
|
||||||
double primary_secondary_stat = refSecondBasePair.second - nonrefPrimaryBasePair.second;
|
|
||||||
return String.format("%f", primary_secondary_stat);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKeyName() { return KEY_NAME; }
|
|
||||||
|
|
||||||
public String getDescription() { return KEY_NAME + ",1,Float,\"Primary Vs. Secondary Base Symmetry\""; }
|
|
||||||
|
|
||||||
private Pair<Integer,Double> getProportionOfReferenceSecondBasesThatSupportAlt( ReferenceContext ref, ReadBackedPileup p, byte snp ) {
|
|
||||||
int depth = 0;
|
|
||||||
int support = 0;
|
|
||||||
byte refBase = (byte)ref.getBase();
|
|
||||||
|
|
||||||
for (PileupElement pile : p ) {
|
|
||||||
byte c = pile.getSecondBase();
|
|
||||||
|
|
||||||
if ( BaseUtils.isRegularBase(c) && BaseUtils.basesAreEqual(pile.getBase(), refBase)) { // stops indels et al
|
|
||||||
depth++;
|
|
||||||
support += BaseUtils.basesAreEqual(c, snp) ? 1 : 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( depth > 0 ) {
|
|
||||||
double as_prop = ( ( double ) support ) / depth;
|
|
||||||
return new Pair<Integer,Double> ( depth, as_prop );
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Pair<Integer,Double> getProportionOfPrimaryNonrefBasesThatSupportAlt( ReferenceContext ref, ReadBackedPileup p, char snp ) {
|
|
||||||
// todo -- Why is it looping?
|
|
||||||
int [] baseCounts = p.getBaseCounts();
|
|
||||||
int support = -1;
|
|
||||||
int depth = 0;
|
|
||||||
for ( char c : BaseUtils.BASES ) {
|
|
||||||
// ignore ref
|
|
||||||
if ( Character.toUpperCase(c) != Character.toUpperCase(ref.getBase()) ) {
|
|
||||||
// catch our snp
|
|
||||||
if ( Character.toUpperCase(c) == Character.toUpperCase(snp) ) {
|
|
||||||
support = baseCounts[BaseUtils.simpleBaseToBaseIndex(c)];
|
|
||||||
depth = depth + baseCounts[BaseUtils.simpleBaseToBaseIndex(c)];
|
|
||||||
} else {
|
|
||||||
depth = depth + baseCounts[BaseUtils.simpleBaseToBaseIndex(c)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( depth == 0 || support < 0 ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
double as_prop = ( ( double ) support) / depth;
|
|
||||||
|
|
||||||
return new Pair<Integer,Double> ( depth, as_prop );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
||||||
package org.broadinstitute.sting.gatk.walkers.annotator;
|
|
||||||
|
|
||||||
import org.broadinstitute.sting.utils.pileup.ReadBackedPileup;
|
|
||||||
import org.broadinstitute.sting.utils.BaseUtils;
|
|
||||||
import org.broadinstitute.sting.utils.genotype.Genotype;
|
|
||||||
import org.broadinstitute.sting.utils.genotype.Variation;
|
|
||||||
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by IntelliJ IDEA.
|
|
||||||
* User: chartl
|
|
||||||
* Date: Nov 23, 2009
|
|
||||||
* Time: 1:39:39 PM
|
|
||||||
* To change this template use File | Settings | File Templates.
|
|
||||||
*/
|
|
||||||
public class ResidualQuality implements VariantAnnotation{
|
|
||||||
private static double EPSILON = Math.pow(10,-12);
|
|
||||||
public static String KEY_NAME = "ResidualQuality";
|
|
||||||
|
|
||||||
public boolean useZeroQualityReads() { return true; } // for robustness
|
|
||||||
|
|
||||||
public String annotate( ReferenceContext ref, ReadBackedPileup p, Variation variation, List<Genotype> genotypes) {
|
|
||||||
|
|
||||||
Character snp = getSNPChar(ref, genotypes);
|
|
||||||
if ( snp == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Double logResidQual = getLogResidualQuality(p,ref.getBase(),snp);
|
|
||||||
|
|
||||||
if ( logResidQual == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.format("%f", logResidQual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKeyName() { return KEY_NAME; }
|
|
||||||
|
|
||||||
public String getDescription() { return KEY_NAME + ",1,Float,\"Log-scaled Residual Error\""; }
|
|
||||||
|
|
||||||
private Double getLogResidualQuality( ReadBackedPileup p, char ref, char snp ) {
|
|
||||||
byte[] pbp = p.getBases();
|
|
||||||
byte[] quals = p.getQuals();
|
|
||||||
if ( pbp == null || quals == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int nSNP = 0;
|
|
||||||
int nRef = 0;
|
|
||||||
int pileupSize = pbp.length;
|
|
||||||
int sumOfQuals = 0;
|
|
||||||
for ( int i = 0; i < pileupSize; i ++ ) {
|
|
||||||
if ( BaseUtils.basesAreEqual( pbp[i], (byte) ref ) ) {
|
|
||||||
// ref site
|
|
||||||
nRef ++;
|
|
||||||
} else if ( BaseUtils.basesAreEqual ( pbp[i], ( byte ) snp ) ) {
|
|
||||||
// snp site
|
|
||||||
nSNP++;
|
|
||||||
} else {
|
|
||||||
// non-ref non-snp site, increase quality
|
|
||||||
sumOfQuals += quals[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// want to return sum of qualities times the proportion of non-SNP bases they account for (includes ref bases)
|
|
||||||
// taking the log gives log(SQ) + log(non-ref non-snp bases) - log(non-snp bases)
|
|
||||||
|
|
||||||
return Math.log(sumOfQuals + EPSILON) + Math.log(pileupSize-nSNP-nRef+EPSILON) - Math.log(pileupSize-nSNP + EPSILON);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Character getSNPChar( ReferenceContext ref, List<Genotype> genotypes ) {
|
|
||||||
try {
|
|
||||||
return getNonref( genotypes, ref.getBase() );
|
|
||||||
} catch ( IllegalStateException e ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private char getNonref(List<Genotype> genotypes, char ref) {
|
|
||||||
//logger.info(genotypes.size());
|
|
||||||
for ( Genotype g : genotypes ) {
|
|
||||||
//logger.info("Genotype: "+g.getBases()+" Ref from genotype: "+g.getReference()+" Ref from method: "+ref);
|
|
||||||
if ( g.isVariant(ref) ) {
|
|
||||||
return g.toVariation(ref).getAlternativeBaseForSNP();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("List of genotypes did not contain a variant.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue